Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List comprehension does not support for on new line #17

Open
fonsp opened this issue Jan 8, 2025 · 1 comment · May be fixed by #20
Open

List comprehension does not support for on new line #17

fonsp opened this issue Jan 8, 2025 · 1 comment · May be fixed by #20

Comments

@fonsp
Copy link
Member

fonsp commented Jan 8, 2025

Image
[
	a + b
	for a in 1:10
]

It is incorrectly parsed as Matrix:

Program(MatrixExpression("[",MatrixRow(BinaryExpression(Identifier,Identifier)),⚠,MatrixRow(Identifier,BinaryExpression(Identifier,in,BinaryExpression(IntegerLiteral,IntegerLiteral))),"]"))

But a generator is supported:

Image
Program(ParenExpression("(",Generator(BinaryExpression(Identifier,Identifier),GenFor(for,ForBinding(Identifier,in,BinaryExpression(IntegerLiteral,IntegerLiteral)))),")"))
@fonsp
Copy link
Member Author

fonsp commented Jan 8, 2025

Here is a new test:


# Comprehension arrays

[x for x in xs]
UInt[b(c, e) for c in d for e in f]
[
  a(1)
  for a in f
]
[
  a(1)
  for a in f
        ,b in e
]
[
  a(1)
  for a in f
        for b in e
]

==>
Program(
  ComprehensionExpression(
    Generator(
      Identifier,
      GenFor(for, ForBinding(Identifier, AssignmentOp(in), Identifier)),
    )
  ),
  IndexExpression(
    Identifier,
    ComprehensionExpression(
      Generator(
        CallExpression(Identifier, Arguments(Identifier, Identifier)),
        GenFor(for, ForBinding(Identifier, AssignmentOp(in), Identifier)),
        GenFor(for, ForBinding(Identifier, AssignmentOp(in), Identifier)),
      )
    )
  ),
  ComprehensionExpression(
    Generator(
      CallExpression(Identifier, Arguments(IntegerLiteral)),
      GenFor(
        for, 
        ForBinding(Identifier, AssignmentOp(in), Identifier),
        ForBinding(Identifier, AssignmentOp(in), Identifier),
      ),
    )
  ),
  ComprehensionExpression(
    Generator(
      CallExpression(Identifier, Arguments(IntegerLiteral)),
      GenFor(
        for, 
        ForBinding(Identifier, AssignmentOp(in), Identifier),
        for,
        ForBinding(Identifier, AssignmentOp(in), Identifier),
      ),
    )
  ),
)

@fonsp fonsp linked a pull request Jan 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant