I’d like to make a grammar that will allow curried function calls.
That is:
a() /// good
a()() /// good
a()()() /// good
a(a) /// good
a(a()()) /// good
/// etc
My first stab was this:
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
fncall : expr '(' (expr (',' expr)*)? ')';
expr : ID|fncall;
But that fails due to left recursion.
Assuming
(a)()would also be valid, here’s a way to solve this:The parser generated from the grammar above would parse the input:
and construct the following AST:
Without the tree rewrite rules, the grammar would look like this: