[antlr-interest] Bug report: handling of %

Wincent Colaiuta win at wincent.com
Thu Jun 7 06:27:00 PDT 2007


Trying to compile this sample grammar:

   grammar Simple;

   @lexer::members {
     // %
   }

   FOO: 'foo' ;
   thing: .* EOF;

Yields the following:

   error(146): Simple.g:2:10: invalid StringTemplate % shorthand  
syntax: '%'

Evidently "%" has special meaning for StringTemplate but it seems  
that there is either a bug in ANTLR for allowing a character in a  
comment to prevent compilation, or a bug in the documentation for not  
explaining how to workaround the issue (please correct me if I'm  
wrong about that). The error message itself isn't very helpful as it  
doesn't point to the actual location of the problem.

There doesn't seem to be any way to escape the % character either, as  
\% yields the same error.

Needless to say, I wanted to do something more useful than just  
include a comment; in my real grammar I was comparing against '%'. In  
the end, the workaround was to use a literal 37 (decimal value for %  
in ASCII) in my @lexer::members section, but that kind of workaround  
may not be possible for everyone.

Cheers,
Wincent



More information about the antlr-interest mailing list