[antlr-interest] Tree Rewrite Issue with Negation (~)

Foust javafoust at gmail.com
Wed Jul 30 10:44:01 PDT 2008


ANTLR Gurus,

 

There seems to be an ANTLR 3 bug (all versions through 3.1b2) when using the
token negation operator to match a series of tokens in a rule that also has
an AST rewrite rule.

 

Although this works (nonsense):

x :           ':' ( v+=(';'|'}') )* ';'  -> ^(':' $v) ;

 

this expression does not work (single tilde added in order to accept all
tokens, except those two):

x :           ':' ( v+=~(';'|'}') )* ';'  -> ^(':' $v) ;

 

It works as expected, unless the rewrite rule is added to the end. Once a
"-> ." is added, the following error is produced:

 

error(10):  internal error: T.g : java.lang.IllegalArgumentException: Can't
find template matchSetTrackAndListLabel.st

 

It may be fixed by breaking out the negation logic into a separately-named
rule:

x :           ':' ( v+= configVal )* ';'  -> ^(':' $v) ;

configVal:            ~(';'|'}')+;

 

Is this a known bug?

 

The options used are:

 

grammar T;

options {

                backtrack=true;                                //
automatically resolve similar rules (which begin the same way)

                memoize=true;                                // use extra
memory to speed up backtracking

                output=AST;                                      // generate
an abstract syntax tree from matched rules

                ASTLabelType=CommonTree;    // class of tree node (must be
cast from Object, otherwise)

}

 

Brent

 

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


More information about the antlr-interest mailing list