erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.61k stars 53 forks source link

Invalid syntax error with array comprehension #495

Open mtshiba opened 3 months ago

mtshiba commented 3 months ago

Describe the bug?

If we use array comprehension to return the result without any processing, a syntax error will occur. It's simply a parser bug.

Reproducible code

print! [ x | x <- [1, 2] ]

Expected result

[1, 2]

Actual result

Error[#0761]: File <stdin>, line 1,

1 │ print! [ x | x <- [1, 2] ]
  ·                --

SyntaxError: expected: VBar, got: Inclusion

Additional context

The following code works.

lc = [i * 2 | i <- 1..4]
assert lc == [2, 4, 6, 8]
lc2 = [i + 1 | i <- 1..5 | i <= 3]
assert lc2 == [2, 3, 4]
lc3 = [i <- 1..10 | i <= 5]
assert lc3 == [1, 2, 3, 4, 5]

Erg version

0.6.32

Python version

None

OS

None