[antlr-interest] Lexer Strangeness

Jim Idle jimi at temporal-wave.com
Tue Mar 13 14:36:20 PDT 2007


Ter,

I think that there is bug in there somewhere though, I will try and
track this down. If you use (~(NEWLINE)) where NEWLINE is a fragment,
then it gets the set wrong. I will distill out a better example of this
for you and send it offline.

jim

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Tuesday, March 13, 2007 1:22 PM
To: ANTLR Interest
Subject: Re: [antlr-interest] Lexer Strangeness


On Feb 13, 2007, at 1:15 PM, Scott Fortmann-Roe wrote:

> 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.

Hmm...that is a parser error not lexer.  I wonder if you are missing  
some other rules?

Ter



More information about the antlr-interest mailing list