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,
|
end,
|
||||||
["return"] = function(self, node)
|
["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,
|
end,
|
||||||
["break"] = function(self, node)
|
["break"] = function(self, node)
|
||||||
return "break"
|
return "break"
|
||||||
|
@ -64,7 +64,7 @@ line_compile =
|
|||||||
@stm {"assign", {name}, {{"exp", name, op_final, exp}}}
|
@stm {"assign", {name}, {{"exp", name, op_final, exp}}}
|
||||||
|
|
||||||
return: (node) =>
|
return: (node) =>
|
||||||
@line "return ", @value node[2]
|
@line "return ", if node[2] != "" then @value node[2]
|
||||||
|
|
||||||
break: (node) =>
|
break: (node) =>
|
||||||
"break"
|
"break"
|
||||||
|
@ -291,7 +291,7 @@ local build_grammar = wrap(function()
|
|||||||
|
|
||||||
BreakLoop = Ct(key"break"/trim),
|
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",
|
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=1,y,@z="hello world") =>
|
||||||
|
|
||||||
|
|
||||||
|
x -> return
|
||||||
|
y -> return 1
|
||||||
|
z -> return 1, "hello", "world"
|
||||||
|
k -> if yes then return else return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,3 +94,19 @@ _ = function(self, x, y, z)
|
|||||||
end
|
end
|
||||||
self.x, self.z = x, z
|
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 else world
|
||||||
-> if hello then 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:
|
- 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
|
- allow a return without an argument
|
||||||
* maybe with assigns only
|
|
||||||
|
|
||||||
my_func if something
|
|
||||||
"one arg"
|
|
||||||
else
|
|
||||||
"other arg"
|
|
||||||
|
|
||||||
|
|
||||||
- class expressions, x = class extends Hello do new: => print "hello"
|
- class expressions, x = class extends Hello do new: => print "hello"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user