[antlr-interest] How can I match 1 or more tokens (or token streams) and then perform a different action or rewrite on the final one than on the others?
Joe Schmoe
shambolic at gmail.com
Thu Aug 13 23:34:53 PDT 2009
I want to perform a different embedded action (or generate a different
AST node) on the final rule in a list of rules.
Here's the most basic example I can think of:
identifierList:
: (Identifier -> ^(ID $Identifier))* (Identifier -> ^(OTHER
$Identifier))
;
This doesn't work because there are two alternatives when matching
just against one Identifier. So I tried making the first nongreedy
with no success:
identifierList:
: ( options { greedy = false; } : Identifier -> ^(ID
$Identifier))* (Identifier -> ^(OTHER $Identifier))
;
Again, ANTLR says this is ambiguous - if it's passed just "Identifier"
then it can supposedly either match the one that goes to ^(ID
$Identifier), or the one that goes to ^(OTHER $Identifier). I don't
understand how this is the case given the first one is nongreedy
My actual example is a good amount lengthier and requires referencing
the rule itself in the rewrite, so solutions that require this to be
broken into multiple rules won't help me except maybe to help me
understand ANTLR better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090813/128e1858/attachment.html
More information about the antlr-interest
mailing list