mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
support return statement with no arguments
This commit is contained in:
parent
ad7c91ad53
commit
6fae81994c
@ -130,7 +130,11 @@ line_compile = {
|
||||
})
|
||||
end,
|
||||
["return"] = function(self, node)
|
||||
return self:line("return ", self:value(node[2]))
|
||||
return self:line("return ", (function()
|
||||
if node[2] ~= "" then
|
||||
return self:value(node[2])
|
||||
end
|
||||
end)())
|
||||
end,
|
||||
["break"] = function(self, node)
|
||||
return "break"
|
||||
|
@ -64,7 +64,7 @@ line_compile =
|
||||
@stm {"assign", {name}, {{"exp", name, op_final, exp}}}
|
||||
|
||||
return: (node) =>
|
||||
@line "return ", @value node[2]
|
||||
@line "return ", if node[2] != "" then @value node[2]
|
||||
|
||||
break: (node) =>
|
||||
"break"
|
||||
|
@ -291,7 +291,7 @@ local build_grammar = wrap(function()
|
||||
|
||||
BreakLoop = Ct(key"break"/trim),
|
||||
|
||||
Return = key"return" * (ExpListLow/ mark"explist") / mark"return",
|
||||
Return = key"return" * (ExpListLow/mark"explist" + C"") / mark"return",
|
||||
|
||||
With = key"with" * Exp * key"do"^-1 * Body / mark"with",
|
||||
|
||||
|
@ -52,3 +52,10 @@ something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") ->
|
||||
(@x=1,y,@z="hello world") =>
|
||||
|
||||
|
||||
x -> return
|
||||
y -> return 1
|
||||
z -> return 1, "hello", "world"
|
||||
k -> if yes then return else return
|
||||
|
||||
|
||||
|
||||
|
@ -93,4 +93,20 @@ _ = function(self, x, y, z)
|
||||
z = "hello world"
|
||||
end
|
||||
self.x, self.z = x, z
|
||||
end
|
||||
end
|
||||
x(function()
|
||||
return
|
||||
end)
|
||||
y(function()
|
||||
return 1
|
||||
end)
|
||||
z(function()
|
||||
return 1, "hello", "world"
|
||||
end)
|
||||
k(function()
|
||||
if yes then
|
||||
return
|
||||
else
|
||||
return
|
||||
end
|
||||
end)
|
13
todo
13
todo
@ -3,20 +3,9 @@
|
||||
if hello else world
|
||||
-> if hello then hello else world
|
||||
|
||||
|
||||
- enhance with documentation
|
||||
- fix variable names starting with and, not, or, etc..
|
||||
|
||||
- varargs that get put in a nested generated function aren't valid anymore:
|
||||
|
||||
- cascading expressions in function call? this looks too much like line decorator
|
||||
* maybe with assigns only
|
||||
|
||||
my_func if something
|
||||
"one arg"
|
||||
else
|
||||
"other arg"
|
||||
|
||||
- allow a return without an argument
|
||||
|
||||
- class expressions, x = class extends Hello do new: => print "hello"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user