[antlr-interest] ANTLR 2: single-line comment lexing with no newline
Matt Benson
gudnabrsam at yahoo.com
Thu Mar 8 12:50:23 PST 2007
--- Gavin Lambert <antlr at mirality.co.nz> wrote:
> At 08:03 9/03/2007, Matt Benson wrote:
> >I have the following lexer rules (can't remember
> how
> >much of them are copied vs. original). My intent
> is,
> >as implied by my subject line, to recognize a
> >single-line comment at the end of the file--an old
> >problem. I am seeing ANTLR spin forever when it
> hits
> >the comment with these rules. Can anyone see what
> >might be wrong? Rules follow.
> [...]
> >// Single-line comments
> >SL_COMMENT
> > : "//"
> > (~('\n'|'\r'))* (NL)?
> > {$setType(Token.SKIP);}
> > ;
>
> My first thought is that since you've made NL
> optional and
> permitted just about anything before it, it's doing
> the greediest
> possible match first (the entire file) and working
> its way back,
> spinning for ages.
>
> Try either making NL not optional, or using NL|EOF
> (also not
> optional).
>
>
Actually, I tried ( NL | EOF ) but I get the error
that there is no EOF token. That would probably work
better in a parser rule. How can I recognize EOF as a
"character" in a lexer?
Thanks,
Matt
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
More information about the antlr-interest
mailing list