[antlr-interest] Bug report: handling of %
Benjamin Niemann
pink at odahoda.de
Thu Jun 7 07:07:17 PDT 2007
Wincent Colaiuta wrote:
> 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).
ANTLR does not know that it is in a comment - it does not parse the action
code (because then it would have to know the grammars for all target
languages), it just replaces $.. and %.. stuff with the appropriate code.
I don't know, if it is documented and where - but I rarely read
documentation anyway... Oh wait - I wrote a note about the '%' for the
Python target, because in Python the use of the % operator is rather
common.
> 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.
mm... usually \% should do the trick.
testing..
mmm?!?
Without \ I get
error(146): /tmp/Simple.g:3:17: invalid StringTemplate % shorthand
syntax: '%'
error(146): /tmp/Simple.g:2:10: invalid StringTemplate % shorthand
syntax: '%'
The first one is the 'expected' error. And it goes away when the % is
escaped.
The second error is nonsense... there is nothing at 2:10, line 2 is empty -
where does this come from?
Strange...
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
More information about the antlr-interest
mailing list