fixed () -> e short lambda parsing (close #93)

This commit is contained in:
Nicolas Cannasse
2020-05-07 10:24:04 +02:00
parent 085f4ec37e
commit ae9560124e
2 changed files with 8 additions and 0 deletions
+1
View File
@@ -101,6 +101,7 @@ class Test extends TestCase {
assertScript("/**/0", 0);
assertScript("x=1;x*=-2", -2);
assertScript("var f = x -> x + 1; f(3)", 4);
assertScript("var f = () -> 55; f()", 55);
assertScript("var f = (x) -> x + 1; f(3)", 4);
assertScript("var f = (x:Int) -> x + 1; f(3)", 4);
assertScript("var f = (x,y) -> x + y; f(3,1)", 4);
+7
View File
@@ -360,6 +360,13 @@ class Parser {
case TConst(c):
return parseExprNext(mk(EConst(c)));
case TPOpen:
tk = token();
if( tk == TPClose ) {
ensureToken(TOp("->"));
var eret = parseExpr();
return mk(EFunction([], mk(EReturn(eret),p1)), p1);
}
push(tk);
var e = parseExpr();
tk = token();
switch( tk ) {