Posted By:
Patrick_Vachon
Posted On:
Tuesday, December 23, 2003 07:31 AM
Hi, How do we extend our own defined Parser? Take this sample myParser.g: class myParser extends Parser { options { importVocab=myLexer; } ... isATag {} : "TAG" {} ( t:NUMBER { _counter++; } )+ END; } I would like to extend myParser to provide a new isATag method. Here is myExtParser.g: class myExtParser extends myParser { options { importVocab=myLexer; } ... isATag {} : "TAG" {} ( t:NUMBER { _counter += 2; } )+ END; } I do not want to do it directly in Java, I prefer to use another .g file to implement myExtParser
More>>
Hi,
How do we extend our own defined Parser?
Take this sample myParser.g:
class myParser extends Parser {
options { importVocab=myLexer; }
...
isATag {} : "TAG" {}
( t:NUMBER { _counter++; } )+
END;
}
I would like to extend myParser to provide a new isATag method. Here is myExtParser.g:
class myExtParser extends myParser {
options { importVocab=myLexer; }
...
isATag {} : "TAG" {}
( t:NUMBER { _counter += 2; } )+
END;
}
I do not want to do it directly in Java, I prefer to use another .g file to implement myExtParser class to minimize maintenance.
The problem is when I try to generate myExtParser.java, I got an error:
error: grammar myParser not defined
Is there a way to do it in a separate .g file?
Thanks a lot for your help.
Patrick
<<Less