[antlr-interest] AST Rewrite Question

Ben Gillis wbgillis at gmail.com
Wed Jan 7 19:22:11 PST 2009


I'm curious why labels do not work with AST rewrites in a rule such as this:

myRule : 'KEYWORD' '=' (INTEGER | FLOATNUMBER | HEXNUMBER | identifier | QUOTED_STRING)


per the Definitive Guide to ANTLR, it *seems* like this would work:

myRule : 'KEYWORD' '=' keyvalue=(INTEGER | FLOATNUMBER | HEXNUMBER | identifier | QUOTED_STRING) -> ^(KEYWORD $keyvalue)


and, the above is certainly more intuitive (no?) than what does work:

myRule : 'KEYWORD' '=' (INTEGER | FLOATNUMBER | HEXNUMBER | identifier | QUOTED_STRING) -> ^(KEYWORD INTEGER* FLOATNUMBER* HEXNUMBER* identifier* QUOTED_STRING*)


The keyvalue example throws a RewriteEmptyStreamException because the generated code adds a null node to a RewriteRuleTokenStream, which causes a .NextNode() call to bomb out because there's no tokens in the stream at the time that call is made.  

I'm rather puzzled why that's the case.

Question: would the label format work if I follow some guidelines in subrules???  

Regards,
Ben

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090107/cfc73c22/attachment.html 


More information about the antlr-interest mailing list