Allow statement bodies for flow control.

This means this works now:

  if (foo) return bar
This commit is contained in:
Bob Nystrom
2013-12-24 10:27:48 -08:00
parent 8c85232b90
commit 1e0401bfc1
8 changed files with 125 additions and 112 deletions

View File

@ -2,10 +2,7 @@ var i = 0
while (true) {
i = i + 1
IO.write(i)
if (i > 2) {
// TODO: Should not require block for break.
break
}
if (i > 2) break
IO.write(i)
}
// expect: 1

View File

@ -1,18 +1,12 @@
var i = 0
while (true) {
IO.write("outer " + i.toString)
if (i > 1) {
// TODO: Should not require block for break.
break
}
if (i > 1) break
var j = 0
while (true) {
IO.write("inner " + j.toString)
if (j > 1) {
// TODO: Should not require block for break.
break
}
if (j > 1) break
j = j + 1
}

View File

@ -0,0 +1,3 @@
IO.write(fn {
if (false) "no" else return "ok"
}.call) // expect: ok

View File

@ -0,0 +1,3 @@
IO.write(fn {
if (true) return "ok"
}.call) // expect: ok

View File

@ -0,0 +1,3 @@
IO.write(fn {
while (true) return "ok"
}.call) // expect: ok

View File

@ -0,0 +1 @@
var a = "ok"; IO.write(a) // expect: ok

View File

@ -0,0 +1,8 @@
class Foo {
method {
return "ok"
IO.write("bad")
}
}
IO.write((new Foo).method) // expect: ok