[antlr-interest] When can .* be used? (was: Matching Last Line in ANTLR)

Gavin Lambert antlr at mirality.co.nz
Wed Aug 19 02:41:07 PDT 2009


At 10:42 19/08/2009, David-Sarah Hopwood wrote:
 >ENDOFLINE can indeed be simplified to NEWLINE | EOF.
 >
 >However, that won't help because it is not the predicate that
 >causes the problem here; it's the fact that the match 
immediately
 >following .* uses the '|' operator. Note that it doesn't matter
 >whether this match is "inlined" or in a separate fragment rule
 >(and it also doesn't matter whether (option { greedy=false; } :
 >.)* is used instead of .*).

Right, but the version I was talking about didn't have the .* in 
it at all, so it would have worked (that far). :)

 >Therefore, .* can't be used in cases where the match following 
it
 >necessarily involves an alternation that can't be expressed 
using
 >'?'.

In my experience, .* in lexer rules only ever works properly when 
it is followed by a single inline sequence of 
characters.  (Nothing optional, no loops, no calling of other 
rules.)



More information about the antlr-interest mailing list