[antlr-interest] Lexing C-style strings - problems matching characters not in vocab

Ric Klaren ric.klaren at gmail.com
Sat Feb 25 11:03:56 PST 2006


On 2/25/06, Chris Seaton <chris at chrisseaton.com> wrote:
> At the moment I'm using the following, which seems to be how most of
> the grammars on the site also work,
>
> STRING :
>      '"' (~('\r' | '\n' | '"' | '\\') | '\\' '"')* '"'
>    ;
>
> Looking at the generated code I can see that this won't work though -
> the ~ operator doesn't match any character apart from the ones
> specified, it seems to match a set of basic characters minus the
> one's I've negated.

You have to set the charVocabulary option to make the ~ operator behave.

Cheers,

Ric


More information about the antlr-interest mailing list