From c0866022fbe7f275bb31129fd8ac38e04c2fae60 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 24 Sep 2023 19:35:40 +0800 Subject: [PATCH] fix a compiler bug of `[]` --- src/compiler.cpp | 2 ++ tests/05_list.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index 9f2379a2..86f806fd 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -392,6 +392,7 @@ namespace pkpy{ // a[<0> : state<3> : state<5>] int state = 0; do{ + match_newlines_repl(); switch(state){ case 0: if(match(TK(":"))){ @@ -439,6 +440,7 @@ namespace pkpy{ break; case 5: consume(TK("]")); goto __SUBSCR_END; } + match_newlines_repl(); }while(true); __SUBSCR_END: if(is_slice){ diff --git a/tests/05_list.py b/tests/05_list.py index 3efeccff..30ed88fb 100644 --- a/tests/05_list.py +++ b/tests/05_list.py @@ -83,4 +83,15 @@ assert b == [1, 2, 3, 4, 5] a = [] b = [*a, 1, 2, 3, *a, *a] -assert b == [1, 2, 3] \ No newline at end of file +assert b == [1, 2, 3] + +assert b[ + 1 +] == 2 + +assert b[0 +] == 1 + +assert b[0] == 1 +assert b[ + 0] == 1