[antlr-interest] Question about preserving spaces in quoted strings
Gavin Lambert
antlr at mirality.co.nz
Thu Jul 2 14:05:56 PDT 2009
At 08:14 3/07/2009, Penningroth, Mark wrote:
>line 1:7 no viable alternative at input '"[Measures].[Unit
>Sales]"'
You need to change the grammar at this point to be expecting a
DQTEXT instead of whatever it is now, and remove any other
double-quote matching from your grammar.
Remember that the lexer runs up front without any context, and
produces tokens from your input. There should be no ambiguity
between lexer rules; don't try to make contextual decisions
(including checking for characters that are valid in some cases
but not others) until at least the parser level.
You will often find this process easier if you ensure that none of
your parser rules use 'string constants like this' -- all that
ends up doing anyway is creating a lexer rule. It's better to be
explicit about this; not only do you get a better-named token that
way, but it's also easier to see possible conflicts between your
lexer rules.
More information about the antlr-interest
mailing list