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

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




I've implemented a parser, where I use an input filter to modify the
tokens a bit to make the grammar simpler. In one case, I insert double
quotes around text, and get the whole string as a "String" token.

But, after the parse, the pesky double quotes become a nuisance. I found
in .../node/TString.java that I could take this:
--------------------------------------------------------------------------
/* This file was generated by SableCC (http://www.sablecc.org/). */

package GED.GEDCOM55RDR.node;

import GED.GEDCOM55RDR.analysis.*;

public final class TString extends Token
{
    public TString(String text)
    {
        setText(text);
    }

    public TString(String text, int line, int pos)
    {
        setText(text);
        setLine(line);
        setPos(pos);
    }

    public Object clone()
    {
      return new TString(getText(), getLine(), getPos());
    }

    public void apply(Switch sw)
    {
        ((Analysis) sw).caseTString(this);
    }
}
--------------------------------------------------------------------------

and modify it this way, to get rid of the surrounding quotes:

--------------------------------------------------------------------------
/* This file was generated by SableCC (http://www.sablecc.org/). */

package GED.GEDCOM55RDR.node;

import GED.GEDCOM55RDR.analysis.*;

public final class TString extends Token
{
    public TString(String text)
    {
        setText(text.substring(1,text.length()-1));  <==== change here.
    }

    public TString(String text, int line, int pos)
    {
        setText(text.substring(1,text.length()-1));  <==== change here.
        setLine(line);
        setPos(pos);
    }

    public Object clone()
    {
      return new TString(getText(), getLine(), getPos());
    }

    public void apply(Switch sw)
    {
        ((Analysis) sw).caseTString(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....?

Many thanks,

murf


This is a digitally signed message part