[antlr-interest] Problems defining StringLiteral processing in a grammar
Gavin Lambert
antlr at mirality.co.nz
Mon Dec 15 23:21:53 PST 2008
At 09:41 16/12/2008, James Abley wrote:
>My grammar contains the following rule:
>
>stringLiteral : '"' (~'"')* '"'
> | '\'' (~'\'')* '\''
> ;
[...]
>Using the ANTLR 3.0.1 runtime, I'm seeing unexpected behaviour
in
>that having certain characters; e.g. '?', '!'; in my literal
>strings are proving problematic.
>
>line 1:27 no viable alternative at character '!'
>line 1:61 no viable alternative at character '?'
This needs to be a lexer rule (initial capital letter, eg.
StringLiteral) in order to work. Using ~ in a parser rule means
"any *token* except these" and is almost never what you really
want.
More information about the antlr-interest
mailing list