[antlr-interest] Match A with exception of B .....how do I do that?
Gavin Lambert
antlr at mirality.co.nz
Mon Feb 23 10:46:12 PST 2009
At 04:26 24/02/2009, Vlastimil Adamovsky wrote:
>I am still wrestling with ANLR and learning the secret ways
>....:)))
>You write:
>
>"but for better error messages it is recommend just to match the
>superset
>and to check in the parser for incorrect characters."
>
>How do I do that? BTW, yor suggestion with "C : (~B)=> A;" did
>not work for me,
>but it is possible it is all my fault. I like your second
>suggestion better, but don't know how do it.......I find the
>ANTLR an amazing software, but still it takes time to "get it"...
There are a couple of "secret ways" that might help you here :)
The first is that in ANTLR, any rule that starts with a leading
uppercase character is a lexer rule, and anything with a leading
lowercase character is a parser rule. You should try to keep the
lexer as simple as possible, and in particular avoid creating
multiple top-level lexer rules that can match the same input
(which in general means that a non-fragment lexer rule should not
refer to any other non-fragment lexer rules). (Almost all of the
rules you posted earlier look like they should be parser rules.)
The second is that ~ only operates on sets, not sequences. In the
lexer, that means that ~ will only work on individual characters;
in the parser, that means that ~ will only work on individual
tokens.
More information about the antlr-interest
mailing list