[antlr-interest] Matching Last Line in ANTLR?
Gavin Lambert
antlr at mirality.co.nz
Tue Aug 18 14:28:28 PDT 2009
At 09:05 19/08/2009, consiliens at gmail.com wrote:
>For testing I removed the .* and, while there are no errors, it
>still doesn't match b. as the token MC_INCORRECT unless there
>is a newline after it.
[...]
>MC_QUESTION : INT ('.'|')') ENDOFLINE;
>MC_INCORRECT : LETTER '.' ENDOFLINE;
>MC_CORRECT : '*' MC_INCORRECT;
>
>fragment ENDOFLINE : NEWLINE | { input.LA(1) == EOF }?;
Are you using the debugger or the interpreter to test with? The
interpreter doesn't execute predicates, so it won't work properly;
you need to use the debugger.
It also might pay to try a few variations on the ENDOFLINE rule;
sometimes ANTLR seems to ignore predicates if it thinks that
they're not accomplishing anything. Try this, for example:
fragment ENDOFLINE : { input.LA(1) == EOF }? => | NEWLINE ;
or this:
fragment ENDOFLINE : NEWLINE | EOF ;
More information about the antlr-interest
mailing list