Skip to content

Commit

Permalink
added a shorthand syntax for function one liner
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTriple committed Dec 6, 2012
1 parent d26c13e commit 8718cb4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Ex1Test.g
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ options {
tokens {
FN_CALL;
FN_DEF;
FN_DEF_INLINE;
EX;
}

Expand All @@ -20,6 +21,7 @@ prog: exprStmt* EOF -> exprStmt*

exprStmt: ID ':' expr ';' -> ^(':' ID expr)
| name=ID ':' '{' (arg+=ID)? (',' arg+=ID)* '=>' body+=exprStmt* '}' ';' -> ^(FN_DEF $name $arg* $body*)
| name=ID ':' '=>' inline=exprStmt -> ^(FN_DEF_INLINE $name $inline)
| expr ';' -> ^(EX expr)
;

Expand Down
4 changes: 4 additions & 0 deletions Ex1Walker.g
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ exprStmt returns [node]
this.popScope();
}
| ^(EX expr) { $node = $expr.node; }
| ^(FN_DEF_INLINE name=ID {var node = new L.FunctionDef(this.currentScope, $name.text, this.pushScope()); } (e=exprStmt { node.body.push($e.node); }) ) {
$node = node;
this.popScope();
}
;

expr returns [node]
Expand Down
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
};
fnResult: someFn(77, 9);
assert(fnResult(10) == 200);



voidFn: => puts(777);
voidFn();

</script>


Expand Down

0 comments on commit 8718cb4

Please sign in to comment.