/**Duplicate a tree, assuming this is a root node of a tree-- * duplicate that node and what's below; ignore siblings of root node. */ public static GrammarAST dupTreeNoActions(GrammarAST t, GrammarAST parent) { if ( t==null ) { return null; } int ttype = t.getType(); if ( ttype==ANTLRParser.REWRITE ) { return null; } if ( ttype==ANTLRParser.BANG || ttype==ANTLRParser.ROOT ) { // return x from ^(ROOT x) return (GrammarAST)dupListNoActions((GrammarAST)t.getFirstChild(), t); } /* DOH! Must allow labels for sem preds if ( (ttype==ANTLRParser.ASSIGN||ttype==ANTLRParser.PLUS_ASSIGN) && (parent==null||parent.getType()!=ANTLRParser.OPTIONS) ) { return dupTreeNoActions(t.getChild(1), t); // return x from ^(ASSIGN label x) } */ GrammarAST result = dup(t); // make copy of root // copy all children of root. GrammarAST kids = dupListNoActions((GrammarAST)t.getFirstChild(), t); result.setFirstChild(kids); return result; }
/**Duplicate a tree, assuming this is a root node of a tree-- * duplicate that node and what's below; ignore siblings of root node. */ public static GrammarAST dupTreeNoActions(GrammarAST t, GrammarAST parent) { if ( t==null ) { return null; } int ttype = t.getType(); if ( ttype==ANTLRParser.REWRITE ) { return null; } if ( ttype==ANTLRParser.BANG || ttype==ANTLRParser.ROOT ) { // return x from ^(ROOT x) return (GrammarAST)dupListNoActions((GrammarAST)t.getFirstChild(), t); } /* DOH! Must allow labels for sem preds if ( (ttype==ANTLRParser.ASSIGN||ttype==ANTLRParser.PLUS_ASSIGN) && (parent==null||parent.getType()!=ANTLRParser.OPTIONS) ) { return dupTreeNoActions(t.getChild(1), t); // return x from ^(ASSIGN label x) } */ GrammarAST result = dup(t); // make copy of root // copy all children of root. GrammarAST kids = dupListNoActions((GrammarAST)t.getFirstChild(), t); result.setFirstChild(kids); return result; }