[antlr-interest] newbie greedy option question

Gavin Lambert antlr at mirality.co.nz
Fri Aug 28 02:23:39 PDT 2009


At 20:42 28/08/2009, stephane richard wrote:
 >text_element	
 >	:	(~(OPEN_TAG) | WS)+
 >	;
[...]
 >NEWLINE		: '\r'? '\n' ;
 >WS 		: (' '|'\t'|'\n'|'\r')+ {skip();} ;

Given that you are skipping whitespace (although not individual 
newlines for some bizarre reason), there is no possible way that a 
WS could be matched in the text_element parser rule (which is what 
the "following alternatives can never be matched" error was 
about).

Even if that wasn't the case, since WS would already be included 
in the set of tokens that aren't OPEN_TAG, specifying it at all is 
completely redundant.

If you changed the text_element rule to this then it would 
eliminate most or all of the errors, and function equivalently 
(though I'm not sure if that behaviour is what you really want):

text_element : (~OPEN_TAG)+ ;



More information about the antlr-interest mailing list