[antlr-interest] Matching Last Line in ANTLR?

Jim Idle jimi at temporal-wave.com
Tue Aug 18 09:07:45 PDT 2009


consiliens at gmail.com wrote:
> The last line, b., doesn't match the MC_INCORRECT token because there's 
> no newline after it. Is there an easy way to match this in ANTLR?
>
> Sample Input:
> 1.
> *a.
> b.
>
>
> MC_QUESTION  : INT ('.'|')') .* NEWLINE;
> MC_INCORRECT : LETTER '.' .* NEWLINE;
> MC_CORRECT   : '*' MC_INCORRECT;
>
> fragment NEWLINE : '\r'? '\n';
> fragment LETTER  : ('a'..'z'|'A'..'Z');
> fragment INT     : '0'..'9'+;
>   
Just add a newline to the end of the input before submitting it. It is 
much easier than trying to cope with it at the parsing level.

Jim


More information about the antlr-interest mailing list