switch tests, parse switch non-cascade expression

This commit is contained in:
leaf corcoran 2011-11-18 19:07:17 -08:00
parent 7334678579
commit 3f6c1d517e
6 changed files with 99 additions and 3 deletions

View File

@ -340,6 +340,7 @@ local build_grammar = wrap_env(function()
SimpleValue =
If +
Switch +
With +
ForEach + For + While +
sym"-" * -SomeSpace * Exp / mark"minus" +

View File

@ -494,7 +494,6 @@ Statement = Transformer({
end,
switch = function(self, node, ret)
local _, exp, conds = unpack(node)
print("compiling switch", ret)
local exp_name = NameProxy("exp")
local convert_cond
convert_cond = function(cond)

View File

@ -269,8 +269,6 @@ Statement = Transformer {
switch: (node, ret) =>
_, exp, conds = unpack node
print "compiling switch", ret
exp_name = NameProxy "exp"
-- convert switch conds into if statment conds

44
tests/inputs/switch.moon Normal file
View File

@ -0,0 +1,44 @@
switch value
when "cool"
print "hello world"
switch value
when "cool"
print "hello world"
else
print "okay rad"
switch value
when "cool"
print "hello world"
when "yeah"
[[FFFF]] + [[MMMM]]
when 2323 + 32434
print "okay"
else
print "okay rad"
out = switch value
when "cool" then print "hello world"
else print "okay rad"
out = switch value
when "cool" then xxxx
when "umm" then 34340
else error "this failed big time"
with something
switch \value!
when .okay
"world"
else
"yesh"
fix this
call_func switch something
when 1 then "yes"
else "no"

53
tests/outputs/switch.lua Normal file
View File

@ -0,0 +1,53 @@
local _exp_0 = value
if "cool" == _exp_0 then
print("hello world")
end
local _exp_1 = value
if "cool" == _exp_1 then
print("hello world")
else
print("okay rad")
end
local _exp_2 = value
if "cool" == _exp_2 then
print("hello world")
elseif "yeah" == _exp_2 then
local _ = [[FFFF]] + [[MMMM]]
elseif 2323 + 32434 == _exp_2 then
print("okay")
else
print("okay rad")
end
local out
local _exp_3 = value
if "cool" == _exp_3 then
out = print("hello world")
else
out = print("okay rad")
end
local _exp_4 = value
if "cool" == _exp_4 then
out = xxxx
elseif "umm" == _exp_4 then
out = 34340
else
out = error("this failed big time")
end
do
local _with_0 = something
local _exp_5 = _with_0:value()
if _with_0.okay == _exp_5 then
local _ = "world"
else
local _ = "yesh"
end
end
fix(this)
call_func((function()
local _exp_5 = something
if 1 == _exp_5 then
return "yes"
else
return "no"
end
end)())

1
todo
View File

@ -2,6 +2,7 @@
- don't reuse _, put a local on it, so we don't keep around trash
-- swithc X with Func
- or= and=