[antlr-interest] greedy=false for lexersBy default

Terence Parr parrt at cs.usfca.edu
Sat May 24 10:05:15 PDT 2008


On May 24, 2008, at 5:32 AM, Gavin Lambert wrote:

> At 10:32 24/05/2008, Terence Parr wrote:
> >  I'm thinking of changing lexers to use greedy=false by default so
> >
> >that things like
> >
> >STRING : '"' ('\\' '"'|.)* '"' ;
> >
> >  so I don't have to say
> >
> >STRING : '"' (options {greedy=false;}:'\\' '"'|.)* '"' ;
>
> Provided it only goes non-greedy if there's a following character.   
> Otherwise I think it'd lead to too much change in behaviour.  (And  
> I'm not sure what makes sense if the following character can be  
> optional.)

you are right!  yeah, i found that out the hard way when I turned it  
nogreedy.  Has to be a following char. ok, i'll leave alone for now.

> But yeah, like Loring I almost never use a . in this sort of case;  
> it's more common to do something along the lines of:
>
> STRING : '"' ('\\' ('"' | '\\' | 'r' | 'n') | ~('\\' | '"'))* '"';

gotcha

Ter


More information about the antlr-interest mailing list