[antlr-interest] Lexer Strangeness

Scott Fortmann-Roe sfortma1 at swarthmore.edu
Tue Feb 13 13:15:27 PST 2007


Hi,

I am having a small issue with matching line comments in the lexer.
The following code works correctly:

fragment NEWLINE
       :       '\r'|'\n'
;
LINECOMMENT
       :       '//' (~('\r'|'\n'))* NEWLINE {$channel=HIDDEN;}
;


But if I convert the line comment command to the following form ANTLR
complains that the start state cannot be found for the rule:

LINECOMMENT
       :       '//' (~(NEWLINE))* NEWLINE {$channel=HIDDEN;}
;

I am having a hard time seeing how these are functionally different.
I'm a noob though so please help.

Thanks, Scott


More information about the antlr-interest mailing list