[antlr-interest] greedy subrule option idiom

Junkman j at junkwallah.org
Wed May 26 12:45:58 PDT 2010


Hello,

Following is a lexer rule to match quoted string that allows backslash
escape sequence.


STRING
	: 	 '"' ( options {greedy=false;} : ( ~ '\\' | '\\' . ) )* '"'
	;


It seems to work.  But if you put the '*' operator inside the subrule
like this:


STRING
	: 	 '"' ( options {greedy=false;} : ( ~ '\\' | '\\' . )* ) '"'
	;


It eats up everything to EOF.

It's as if the greedy option applies to the ((subrule)*) instead of the
subrule itself, and only if the subrule is suffixed with '*' operator
(or with '+') externally (as in (subrule)*).

To my eyes, the second version seems the "correct" one.

Thoughts?

J












More information about the antlr-interest mailing list