Reorganize trailing comma code a bit.

- Split out syntax error tests.
- Avoid redundant handling of empty literals.
This commit is contained in:
Bob Nystrom
2015-08-31 07:23:36 -07:00
parent d7eed08774
commit 2b044666ee
12 changed files with 82 additions and 51 deletions
+1
View File
@@ -0,0 +1 @@
{1:1,,2:2} // expect error
@@ -0,0 +1 @@
{1:1,,} // expect error
@@ -0,0 +1 @@
{,} // expect error
+27
View File
@@ -0,0 +1,27 @@
// Allow after '{', ':', and ',', and before ']'.
var map = {
"a":
"a value",
"b": "b value"
}
IO.print(map["a"]) // expect: a value
IO.print(map["b"]) // expect: b value
// Newline after trailing comma.
map = {"c": "c value",
}
IO.print(map["c"]) // expect: c value
// Newline in empty map.
map = {
}
IO.print(map.count) // expect: 0
-6
View File
@@ -5,9 +5,3 @@ var map = {
IO.print(map["a"]) // expect: 1
IO.print(map["b"]) // expect: 2
// Invalid syntax
// Parentheses are necessary to have these interpret as maps and not as blocks.
IO.print(new Fiber { Meta.eval("({,})") }.try()) // expect: Could not compile source code.
IO.print(new Fiber { Meta.eval("({1:1,,})") }.try()) // expect: Could not compile source code.
IO.print(new Fiber { Meta.eval("({1:1,,2:2})") }.try()) // expect: Could not compile source code.