proper return statement + with expression

This commit is contained in:
leaf corcoran 2011-07-16 12:35:43 -07:00
parent 8c461eae6b
commit 9c000857fc
6 changed files with 54 additions and 8 deletions

View File

@ -57,6 +57,13 @@ value_compile = {
local _, delim, inner, delim_end = unpack(node)
return delim .. inner .. (delim_end or delim)
end,
with = function(self, node)
do
local _with_0 = self:block("(function()", "end)()")
_with_0:stm(node, returner)
return _with_0
end
end,
["if"] = function(self, node)
do
local _with_0 = self:block("(function()", "end)()")

View File

@ -38,6 +38,10 @@ value_compile =
_, delim, inner, delim_end = unpack node
delim..inner..(delim_end or delim)
with: (node) =>
with @block "(function()", "end)()"
\stm node, returner
if: (node) =>
with @block "(function()", "end)()"
\stm node, returner

View File

@ -244,7 +244,7 @@ local build_grammar = wrap(function()
Block = Ct(Line * (Break^1 * Line)^0),
Line = Cmt(Indent, check_indent) * Statement + _Space * Comment,
Statement = (Import + While + With + For + Foreach
Statement = (Import + While + With + For + Foreach + Return
+ ClassDecl + Export + BreakLoop + Ct(ExpList) / flatten_or_mark"explist" * Space) * (
-- statement decorators
key"if" * Exp * (key"else" * Exp)^-1 * Space / mark"if" +
@ -264,6 +264,8 @@ local build_grammar = wrap(function()
BreakLoop = Ct(key"break"/trim),
Return = key"return" * (ExpListLow/ mark"explist") / mark"return",
With = key"with" * Exp * key"do"^-1 * Body / mark"with",
If = key"if" * Exp * key"then"^-1 * Body *
@ -300,6 +302,7 @@ local build_grammar = wrap(function()
SimpleValue =
If +
With +
sym"-" * -SomeSpace * Exp / mark"minus" +
sym"#" * Exp / mark"length" +
sym"not" * Exp / mark"not" +

View File

@ -37,6 +37,21 @@ yeah = ((1+5)*3)/2 + i % 100
whoa = (1+2) * (3+4) * (4+5)
->
if something
return 1,2,4
print "hello"
->
if hello
"heloo", "world"
else
no, way
-> 1,2,34
return 5 + () -> 4 + 2
return 5 + (() -> 4) + 2

View File

@ -24,12 +24,28 @@ local yeah = (1 + 5) * 3
yeah = ((1 + 5) * 3) / 2
yeah = ((1 + 5) * 3) / 2 + i % 100
local whoa = (1 + 2) * (3 + 4) * (4 + 5)
return(5 + function()
_ = function()
if something then
return 1, 2, 4
end
return print("hello")
end
_ = function()
if hello then
return "heloo", "world"
else
return no, way
end
end
_ = function()
return 1, 2, 34
end
return 5 + function()
return 4 + 2
end)
return(5 + (function()
end
return 5 + (function()
return 4
end) + 2)
end) + 2
print(5 + function()
_ = 34
return good(nads)

7
todo
View File

@ -3,13 +3,14 @@
- use `with` as an arugment to function (normal expression)
- varargs that get put in a nested generated function aren't valid anymore:
- cascading expressions in function
- assigning a for loop
- class expressions, x = class extends Hello do new: => print "hello"
* issues with whitespace on the end of lines
* default arguments
* multiline comments
* table slices
* add a proper return statement
* table slices (almost)
* add continue keyword (ouch)
* vim syntax file