[antlr-interest] Disabling Lexer rules using predicates

Martin Probst mail at martin-probst.com
Wed Apr 2 04:04:27 PDT 2008


Hi all,

I'm trying to disable certain lexer rules depending on some fancy  
logic in the lexer. However ANTLR seems to have a different opinion on  
what is a validating and what is a disambiguating predicate.

My rule looks like this:

ElementContentChar
	:	{ inElement }?
		(('\u0020'..'\u0025' | '\u0027'..'\u003B' | '\u003D'..'\u007A' |
		'\u007C'..'\u007C' | '\u007E'..'\uD7FF' | '\uE000'..'\uFFFD')+);

Which was supposed to mean "only enter this rule if 'inElement' is  
true". ANTLR seems to interpret this as a validating predicate,  
throwing an exception if 'inElement' is false. Is there a way to force  
ANTLR into considering this as a semantic predicate? I already tried  
"{ inElement }?=>" but that didn't help.

Is there a way to globally disable certain Lexer rules if a certain  
condition holds?

Regards,
Martin


More information about the antlr-interest mailing list