[antlr-interest] Rules with multiple parameters
John Ridgway
john.ridgway at trincoll.edu
Wed Oct 31 17:26:31 PDT 2007
Consider the following in a grammar with the output=AST option:
methodOrFieldDecl[Tree modifiers, Tree type]
: identifier! methodDeclaratorRest[modifiers, type
$identifier.tree]
;
methodDeclaratorRest[Tree modifiers, Tree type, Tree name]
which is a fragment of a Java 1.5 grammar. The methodDeclaratorRest
rule takes three parameters, which seems entirely reasonable
(actually it's totally unreasonable, but Java was not designed for
parsing...). In order to pass three arguments to it I have to play
with the locations of commas in the "call/usage" in order that the
generated Java is correct. If I tried to use
methodDeclaratorRest[modifiers, type, $identifier.tree]
(note the comma after type), I would end up with an extra comma in
the generated Java.
This is clearly (to me) a bug. It is likely to be fixed?
Note. It gets even worse if we want to do something like:
x
: a! b! c! d[$a $b $c]
;
This won't work even with no commas in the given code. To make it
work I have to introduce some names:
x
: a! bb=b! c! d[$a bb $c]
;
probably does work...
Peace
- John
More information about the antlr-interest
mailing list