[antlr-interest] Bug in ANTLR-3.1.2 with tree grammar wildcard list label x+= ?

Gavin Lambert antlr at mirality.co.nz
Fri Feb 27 16:17:03 PST 2009


At 13:07 28/02/2009, Laurent Caillette wrote:
 >part
 >  : ( mediumbreak | largebreak )?
 >
 >    (   p += levelIntroducer
 >      | p += paragraph
 >      | p += blockQuote
 >      | p += literal
 >      | p += bigDashedListItem
 >      | p += cellRowSequence
 >    )
[...]
 >/Users/Shared/Scratch/Novelang/antlrworks/java/NovelangParser.java:
 >754:
 >incompatible types
 >found   : NovelangParser.levelIntroducer_return
 >required: NovelangParser.cellRowSequence_return
 >                     p=levelIntroducer();
 >                                   ^
 >
 >It seems that p has taken the type of the first rule
 >(levelIntroducer). Then attempting to set the result of
 >cellRowSequence doesn't work.

I'm surprised that you managed to get it to work as long as you 
did -- that's been on my list of "don't do that" for most of v3.

You can fix it by creating a subrule:

content
   : levelIntroducer
   | paragraph
   | blockQuote
   | literal
   | bigDashedListItem
   | cellRowSequence
   ;

And then use p+=content in your original rule.



More information about the antlr-interest mailing list