[antlr-interest] Disabling Lexer rules using predicates

Jim Idle jimi at temporal-wave.com
Wed Apr 2 10:28:28 PDT 2008


You do want a gated predicate, but you may find that you have to use the latest snapshot of 3.1 to make this work. The three main targets Java/C/C# are being worked on for release now and this should happen pretty soon. But if you are using the Java or C targets, then the 3.1b snapshots should be fine for you to use. 

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Martin Probst
> Sent: Wednesday, April 02, 2008 4:04 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Disabling Lexer rules using predicates
> 
> 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