diff --git a/source/toy_parser.c b/source/toy_parser.c index 3bb96a5..db9b15b 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -168,6 +168,10 @@ static Toy_Opcode compound(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { consume(parser, TOY_TOKEN_COMMA, "Expected ',' in array or dictionary"); } + if (match(parser, TOY_TOKEN_BRACKET_RIGHT)) { //allow for trailing commas + break; + } + iterations++; Toy_ASTNode* left = NULL; diff --git a/test/scripts/trailing-comma-bugfix.toy b/test/scripts/trailing-comma-bugfix.toy new file mode 100644 index 0000000..b9a0c22 --- /dev/null +++ b/test/scripts/trailing-comma-bugfix.toy @@ -0,0 +1,8 @@ +var array = [ + 1, 2, 3, + 4, 5, 6, + 7, 8, 9, //explicitly leave a trailing comma +]; + + +print "All good"; \ No newline at end of file diff --git a/test/test_interpreter.c b/test/test_interpreter.c index b67de22..6f1d8fa 100644 --- a/test/test_interpreter.c +++ b/test/test_interpreter.c @@ -140,6 +140,7 @@ int main() { "polyfill-remove.toy", "short-circuiting-support.toy", "ternary-expressions.toy", + "trailing-comma-bugfix.toy", "types.toy", NULL };