Retoor software development Projects Research SearchXNG
Register Sign In

13 lines
387 B
Plaintext
Raw Normal View History

feat: allow trailing comma in list literal by early break on right bracket Add support for trailing commas in list literals by checking for TOKEN_RIGHT_BRACKET after parsing the last element in the list() function. When a trailing comma is followed by the closing bracket, the loop breaks immediately instead of attempting to parse another element. Include a test case verifying that lists with trailing commas parse correctly and elements are accessible by index.
2015-05-30 22:18:37 +02:00
var list = [
"a",
"b",
]
IO.print(list[0]) // expect: a
IO.print(list[1]) // expect: b
test: add invalid trailing comma tests for list and map literals Add test cases verifying that invalid trailing comma syntaxes in list literals (e.g. `[,]`, `[1,,]`, `[1,,2]`) and map literals (e.g. `{,}`, `{1:1,,}`, `{1:1,,2:2}`) correctly produce compile errors when evaluated via Meta.eval in a Fiber.
2015-05-30 22:17:12 +02:00
// Invalid syntax
IO.print(new Fiber { Meta.eval("[,]") }.try()) // expect: Could not compile source code.
IO.print(new Fiber { Meta.eval("[1,,]") }.try()) // expect: Could not compile source code.
IO.print(new Fiber { Meta.eval("[1,,2]") }.try()) // expect: Could not compile source code.
Reference in New Issue Copy Permalink
d608a03244
wren/test/language/list/trailing_comma.wren
Response time: 48ms
Mail Licenses API