Allow trailing commas when writing a compound

This commit is contained in:
2023-08-04 18:43:07 +10:00
parent 64944c24f6
commit 3783c94064
3 changed files with 13 additions and 0 deletions

View File

@@ -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;

View File

@@ -0,0 +1,8 @@
var array = [
1, 2, 3,
4, 5, 6,
7, 8, 9, //explicitly leave a trailing comma
];
print "All good";

View File

@@ -140,6 +140,7 @@ int main() {
"polyfill-remove.toy",
"short-circuiting-support.toy",
"ternary-expressions.toy",
"trailing-comma-bugfix.toy",
"types.toy",
NULL
};