/** Duplicate tree including siblings of root. */ public static GrammarAST dupListNoActions(GrammarAST t, GrammarAST parent) { GrammarAST result = dupTreeNoActions(t, parent); // if t == null, then result==null GrammarAST nt = result; while (t != null) { // for each sibling of the root t = (GrammarAST)t.getNextSibling(); if ( t!=null && t.getType()==ANTLRParser.ACTION ) { continue; } GrammarAST d = dupTreeNoActions(t, parent); if ( d!=null ) { if ( nt!=null ) { nt.setNextSibling(d); // dup each subtree, building new tree } nt = d; } } return result; }
/** Duplicate tree including siblings of root. */ public static GrammarAST dupListNoActions(GrammarAST t, GrammarAST parent) { GrammarAST result = dupTreeNoActions(t, parent); // if t == null, then result==null GrammarAST nt = result; while (t != null) { // for each sibling of the root t = (GrammarAST)t.getNextSibling(); if ( t!=null && t.getType()==ANTLRParser.ACTION ) { continue; } GrammarAST d = dupTreeNoActions(t, parent); if ( d!=null ) { if ( nt!=null ) { nt.setNextSibling(d); // dup each subtree, building new tree } nt = d; } } 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; } GrammarAST result = (GrammarAST)t.dupNode(); for (GrammarAST subchild : getChildrenForDupTree(t)) { result.addChild(dupTreeNoActions(subchild, result)); } 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; } GrammarAST result = (GrammarAST)t.dupNode(); for (GrammarAST subchild : getChildrenForDupTree(t)) { result.addChild(dupTreeNoActions(subchild, result)); } return result; }
/** Create a copy of the alt and make it into a BLOCK; all actions, * labels, tree operators, rewrites are removed. */ protected GrammarAST createBlockFromDupAlt(GrammarAST alt) { /* * ^(BLOCK["BLOCK"] {GrammarAST.dupTreeNoActions(alt)} EOB["<end-of-block>"]) */ GrammarAST nalt = GrammarAST.dupTreeNoActions(alt, null); GrammarAST block = (GrammarAST)adaptor.create(BLOCK, alt.getToken(), "BLOCK"); adaptor.addChild( block, nalt ); adaptor.addChild( block, adaptor.create( EOB, "<end-of-block>" ) ); return block; }
/** Create a copy of the alt and make it into a BLOCK; all actions, * labels, tree operators, rewrites are removed. */ protected GrammarAST createBlockFromDupAlt(GrammarAST alt) { /* * ^(BLOCK["BLOCK"] {GrammarAST.dupTreeNoActions(alt)} EOB["<end-of-block>"]) */ GrammarAST nalt = GrammarAST.dupTreeNoActions(alt, null); GrammarAST block = (GrammarAST)adaptor.create(BLOCK, alt.getToken(), "BLOCK"); adaptor.addChild( block, nalt ); adaptor.addChild( block, adaptor.create( EOB, "<end-of-block>" ) ); return block; }