I want to change the definition of getTree() methode of generated return class like statement_return (see below example). See below Sample parser grammar and respecting generated code which includes statement() and statement_return().
parser grammar
options {
output = AST;
}
statement
: rule*
-> ^(STATEMENT rule* )
;
Generated Tree Parser
public static class statement_return extends ParserRuleReturnScope {
Object tree;
public Object getTree() {
return tree;
}
};
public final Grammar.statement_return statement() throws RecognitionException {
...
...
}
I want to change the definition of getTree() methode of generated class like statement_return where PLSQLTree (extends CommonTree) is custom object. I have custom treeAdoptor which created PLSQLTree type object I want to capture start and end token for each parser rule which is required in TREE PARSER. I want the same for all the rules in my grammar.
My Overrided definition
public static class statement_return extends ParserRuleReturnScope {
Object tree;
public Object getTree() {
/*
start - Add some code in generated class
*/
PLSQLTree plsqlTree = (PLSQLTree) tree;
Token start = this.start;
plsqlTree.params.put(ParserConstants.START_TOKEN, start);
Token stop = this.stop;
plsqlTree.params.put(ParserConstants.STOP_TOKEN, stop);
/*
end - Add some code in generated class
*/
return plsqlTree;
}
};
Please help me how this can be achieved?