[antlr-interest] QUESTION on: How do I handle abbreviated keywords?
Gavin Lambert
antlr at mirality.co.nz
Sat Nov 1 12:41:26 PDT 2008
At 08:11 2/11/2008, Ben Gillis wrote:
>However, the grammar compiler pukes when I try to define
keywords
>with a special sign, such as the dollar sign.
[...]
> ...
> _keywordDictionary.Add("$SOMETHING", DOLLAR_SOMETHING);
> ...
>}
>
>I get the following org.antlr.Tool on the grammar file:
>
>error(111): MyGrammar.g:26:1: reference to attribute outside of
a
>rule:
>SOMETHING
[...]
>That leads me to believe ANTLR is somehow detecting the dollar
sign
>and using it as some metasymbol.
>I thought the code snippets I put in the members block is put
out
>"as-is" like the ANTLR book tells me.
Mostly, but it does look for a couple of special characters for
use with StringTemplate and for ANTLR's own attribute replacement
(which is why you can refer to $foo.text in a rule action).
You can escape these by using \$ instead.
Also: please remember to use your Reply to All button when
replying to messages on the ANTLR list, in order to keep responses
on the list.
More information about the antlr-interest
mailing list