Skip to content
Browse files

added a shorthand syntax for function one liner

  • Loading branch information...
1 parent d26c13e commit 8718cb42bcae6a62128ccf53e835c6723e185337 @thoefer2 thoefer2 committed Dec 6, 2012
Showing with 10 additions and 2 deletions.
  1. +2 −0 Ex1Test.g
  2. +4 −0 Ex1Walker.g
  3. +4 −2 index.html
View
2 Ex1Test.g
@@ -8,6 +8,7 @@ options {
tokens {
FN_CALL;
FN_DEF;
+ FN_DEF_INLINE;
EX;
}
@@ -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)
;
View
4 Ex1Walker.g
@@ -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]
View
6 index.html
@@ -29,8 +29,10 @@
};
fnResult: someFn(77, 9);
assert(fnResult(10) == 200);
-
-
+
+ voidFn: => puts(777);
+ voidFn();
+
</script>

0 comments on commit 8718cb4

Please sign in to comment.
Something went wrong with that request. Please try again.