From 6834fbcb8beda8c6a6b16122b191171dfdd7b56f Mon Sep 17 00:00:00 2001 From: GreasySlug <9619abgoni@gmail.com> Date: Sun, 8 Sep 2024 15:11:01 +0900 Subject: [PATCH] fix(parser): fix comprehension syntax(#495) --- crates/erg_parser/parse.rs | 2 +- tests/should_ok/comprehension.er | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/erg_parser/parse.rs b/crates/erg_parser/parse.rs index 13d35045b..b418c7f75 100644 --- a/crates/erg_parser/parse.rs +++ b/crates/erg_parser/parse.rs @@ -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!()))?; diff --git a/tests/should_ok/comprehension.er b/tests/should_ok/comprehension.er index 785ecd181..767df3d54 100644 --- a/tests/should_ok/comprehension.er +++ b/tests/should_ok/comprehension.er @@ -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}