[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's the best way to override a node class?

Steve Murphy wrote:
> But, after the parse, the pesky double quotes become a nuisance. I found
> in .../node/TString.java that I could take this:
> and this small tweak works beautifully. BUT.... this is a generated
> file, and I need to NOT do this in this file! What's the cleanest way to
> override the functions in this class? I'm still a bit new as a Java
> programmer, so please, have mercy on me. I've overridden functions like
> crazy in the analysis (traversal) class, but this is a different sort of
> thing....?

You're right, modifying a generated file is not the thing to do.

Here's a simple solution that solves your problem: a custom lexer.

You write something like:

public class SomeLexer extends Lexer
   ... /* constructor, ...*/

   /* Filter */
   protected void filter()
     if (token instanceof TString)
       String text = token.getText();
       int length = text.length();
       token.setText(text.substring(1, length - 2));

This way, you won't need to modify generated code anymore.

Have fun!

Etienne M. Gagnon                    http://www.info.uqam.ca/~egagnon/
SableVM:                                       http://www.sablevm.org/
SableCC:                                       http://www.sablecc.org/