[antlr-interest] Rules of this form no longer working for me under new ANTLR

Gavin Lambert antlr at mirality.co.nz
Tue Oct 21 00:09:25 PDT 2008


At 15:57 21/10/2008, Shaun Bogan wrote:
 >squarecall
 >	:	(SQUARELEFT (statementnocolon (',' statementnocolon)*)?
 >SQUARERIGHT)-> statementnocolon*
 >	;

If the problem really is in this rule, then try:

   squarecall
     :  SQUARELEFT (a+=statementnocolon
          (',' a+=statementnocolon)*)? SQUARERIGHT
          -> $a*
     ;

(I can never remember if that $ is supposed to be there or not, 
though.)

However I think it's much more likely that the problem is not with 
this rule itself but rather with the rule that calls this.  I bet 
you're doing something like this:

    ... squarecall ... -> ... squarecall ...

Since squarecall can produce an empty tree, you need to use this 
instead:

    ... squarecall ... -> ... squarecall? ...



More information about the antlr-interest mailing list