Move newline handling down into parser.
This lets us make it a grammar feature and not a lexer trick. Newlines are explicitly ignored in some parts of the grammar. This lets, for example, things like "|" ignore the newline when used as an operator, but not when used as a parameter delimiter in a block argument.
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
class // expect error
|
||||
Foo {}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
static // expect error
|
||||
method {} // expect error
|
||||
}
|
||||
|
||||
// The second error is cascaded.
|
||||
@@ -1 +1 @@
|
||||
true ? 1 : // expect error
|
||||
(true ? 1 :) // expect error
|
||||
|
||||
@@ -1 +1 @@
|
||||
true ? : 2 // expect error
|
||||
(true ? : 2) // expect error
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Newline after '?'.
|
||||
IO.print(true ?
|
||||
"yes" : "no") // expect: yes
|
||||
|
||||
// Newline after ':'.
|
||||
IO.print(false ? "yes" :
|
||||
"no") // expect: no
|
||||
@@ -1,20 +0,0 @@
|
||||
// Single-expression body.
|
||||
for (i in [1, 2, 3]) IO.print(i)
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
|
||||
// Block body.
|
||||
for (i in [1, 2, 3]) {
|
||||
IO.print(i)
|
||||
}
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
|
||||
// Newline after "for".
|
||||
for
|
||||
(i in [1, 2, 3]) IO.print(i)
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
@@ -0,0 +1,2 @@
|
||||
for // expect error
|
||||
(i in [1, 2, 3]) IO.print(i)
|
||||
@@ -0,0 +1,2 @@
|
||||
for (i // expect error
|
||||
in [1]) IO.print(i)
|
||||
+6
-12
@@ -1,20 +1,14 @@
|
||||
// Single-expression body.
|
||||
for (i in [1, 2, 3]) IO.print(i)
|
||||
for (i in [1]) IO.print(i)
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
|
||||
// Block body.
|
||||
for (i in [1, 2, 3]) {
|
||||
for (i in [1]) {
|
||||
IO.print(i)
|
||||
}
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
|
||||
// Newline after "for".
|
||||
for
|
||||
(i in [1, 2, 3]) IO.print(i)
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
// Newline after "in".
|
||||
for (i in
|
||||
[1]) IO.print(i)
|
||||
// expect: 1
|
||||
@@ -1,2 +1,2 @@
|
||||
new Fn {
|
||||
IO.print("ok") }.call // expect error
|
||||
IO.print("ok") } // expect error
|
||||
@@ -4,7 +4,3 @@ if (false) IO.print("bad") else IO.print("good") // expect: good
|
||||
|
||||
// Allow block body.
|
||||
if (false) null else { IO.print("block") } // expect: block
|
||||
|
||||
// Newline after "else".
|
||||
if (false) IO.print("bad") else
|
||||
IO.print("good") // expect: good
|
||||
|
||||
@@ -8,7 +8,3 @@ if (true) { IO.print("block") } // expect: block
|
||||
// Assignment in if condition.
|
||||
var a = false
|
||||
if (a = true) IO.print(a) // expect: true
|
||||
|
||||
// Newline after "if".
|
||||
if
|
||||
(true) IO.print("good") // expect: good
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
if (true) "ok" else // expect error
|
||||
@@ -0,0 +1,2 @@
|
||||
if // expect error
|
||||
(true) IO.print("bad")
|
||||
@@ -30,3 +30,7 @@ IO.print(123 is Class) // expect: false
|
||||
|
||||
// TODO: Non-class on RHS.
|
||||
// TODO: Precedence and associativity.
|
||||
|
||||
// Ignore newline after "is".
|
||||
IO.print(123 is
|
||||
Num) // expect: true
|
||||
@@ -0,0 +1,2 @@
|
||||
var list = ["a"
|
||||
, "b"] // expect error
|
||||
@@ -1,14 +1,10 @@
|
||||
// Allow newlines in most places.
|
||||
// Allow after '[' and ',', and before ']'.
|
||||
var list = [
|
||||
|
||||
"a"
|
||||
, "b",
|
||||
|
||||
"c", "d"
|
||||
"a",
|
||||
"b"
|
||||
|
||||
]
|
||||
|
||||
IO.print(list[0]) // expect: a
|
||||
IO.print(list[1]) // expect: b
|
||||
IO.print(list[2]) // expect: c
|
||||
IO.print(list[3]) // expect: d
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
new // expect error
|
||||
Fn {}
|
||||
@@ -0,0 +1,2 @@
|
||||
var // expect error
|
||||
foo = 123
|
||||
@@ -0,0 +1,2 @@
|
||||
while // expect error
|
||||
(true) IO.print("bad")
|
||||
@@ -14,11 +14,3 @@ while (a < 3) {
|
||||
// expect: 0
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
|
||||
// Newline after "while".
|
||||
var d = 0
|
||||
while
|
||||
(d < 3) IO.print(d = d + 1)
|
||||
// expect: 1
|
||||
// expect: 2
|
||||
// expect: 3
|
||||
|
||||
Reference in New Issue
Block a user