I'm trying to create a grammar for a programming language in Jison, and have run into a problem with calls. Functions in my language is invoked with the following syntax:
functionName arg1 arg2 arg3
In order to do arguments that aren't just simple expressions, they need to be wrapped in parenthesizes like this:
functionName (1 + 2) (3 + 3) (otherFunction 5)
However, there is a bug in my grammar that causes my parser to interpret functionName arg1 arg2 arg3
as functionName(arg1(arg2(arg3)))
instead of functionName(arg1, arg2, arg3)
.
The relevant part of my jison grammar file looks like this:
expr:
| constantExpr { $$ = $1; }
| binaryExpr { $$ = $1; }
| callExpr { $$ = $1; }
| tupleExpr { $$ = $1; }
| parenExpr { $$ = $1; }
| identExpr { $$ = $1; }
| blockExpr { $$ = $1; }
;
callArgs:
| callArgs expr { $$ = $1.concat($2); }
| expr { $$ = [$1]; }
;
callExpr:
| path callArgs { $$ = ast.Expr.Call($1, $2); }
;
identExpr:
| path { $$ = ast.Expr.Ident($1); }
;
How can I make Jison prefer the callArgs
rather than the expr
?