Skip to content

Commit

Permalink
Merge pull request erg-lang#520 from GreasySlug/fix-comprehension
Browse files Browse the repository at this point in the history
Fix List Comprehension Syntax
  • Loading branch information
GreasySlug committed Sep 11, 2024
2 parents beee3b8 + 6834fbc commit 80b6426
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/erg_parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,7 @@ impl Parser {
let call = Call::new(receiver, attr_name, args);
obj = Expr::Call(call);
}
Some(t) if t.is(VBar) && !in_type_args => {
Some(t) if t.is(VBar) && !in_type_args && !self.nth_is(2, Inclusion) => {
let type_args = self
.try_reduce_type_app_args()
.map_err(|_| self.stack_dec(fn_name!()))?;
Expand Down
8 changes: 8 additions & 0 deletions tests/should_ok/comprehension.er
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
l = [i | i <- 1..4]
assert l == [1, 2, 3, 4]
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]
lc4 = [i * 5 | i <- 1..15 | i <= 5]
assert lc4 == [5, 10, 15, 20, 25]

s = {i | i <- [1, 2, 1, 2]}
assert s == {1, 2}
sc = {i * 2 | i <- 1..4}
assert sc == {2, 4, 6, 8}
sc2 = {i + 1 | i <- 1..5 | i <= 3}
assert sc2 == {2, 3, 4}
sc3 = {i <- 1..10 | i <= 5}
assert sc3 == {1, 2, 3, 4, 5}
sc4 = {i % 5 | i <- 1..100 | i % 5 != 0}
assert sc4 == {1, 2, 3, 4}

0 comments on commit 80b6426

Please sign in to comment.