[antlr-interest] Disabling overriden rule during iheritance.

Ric Klaren ric.klaren at gmail.com
Fri Jun 10 01:29:20 PDT 2005


On 6/10/05, Mark Bednarczyk <voytechs at yahoo.com> wrote:
> I need to disable a lexer rule in the subclass grammar file.
> That is B inherits from 1.
> 
> Base class (A) contains:
> 
> IDENT: blah blah blah...
> 
> sub grammar file (B) overrides:
> 
> IDENT: /* empty */
> 
> What I really need to disable the IDENT rule since the token
> type IDENT is assigned manually in a different way.

If I understand you correctly: In grammar A you have a IDENT rule that
deals with the IDENT. In grammar B you deal with IDENT in another rule
and do a $setType or something with the IDENT tokentype?

I'm no expert on grammar inheritance but you might try make the IDENT
rule protected in the B grammar (don't know if antlr allows that, but
there's no mechanism to leave rules out anycase) if it works then the
IDENT rule should not be folded into the nextToken method of the
lexer, which should be sufficient I think. (try it on a small example
grammar where you can see if the lookahead calculations make sense)

Cheers,

Ric


More information about the antlr-interest mailing list