[antlr-interest] Re: can't override nextToken in c# version

micheal_jor open.zone at virgin.net
Thu Oct 9 19:01:25 PDT 2003


--- In antlr-interest at yahoogroups.com, "netminka" <netminka at n...> wrote:
> hi all,
> the generated nextToken() is defined as
>    public new Token nextToken()
> in the generated lexer class. 
> 
> I have used the generated lexer class as a base class to my lexer,
> and as I need to override nextToken(), I have to hand edit
> the generated lexer file after each run of antlr.Tool.
> 
> I think the signature of the generated nextToken() should be:
> 
> public virtual Token nextToken()

Megan,

You may be right about this although I seem to remember a makeToken()
method too. In the meantime you can use the following workaround in
your subclass(es):

class LexerSubClass : MyLexer, TokenStream
{
   .....
   public new /*virtual?*/ Token nextToken()
   {
      //do your stuff
      .....
      .....

      // optionally call inherited stiff
      Token t = base.nextToken();
   }
   Token TokenStream.nextToken()
   {
       return ((LexerSubClass) this).nextToken();
   }
   ....
}

Cheers,

Micheal



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list