public GrammarAST getLastChild() { if (getChildCount() == 0) return null; return (GrammarAST)getChild(getChildCount() - 1); }
public void setTreeEnclosingRuleNameDeeply(String rname) { GrammarAST t = this; t.enclosingRuleName = rname; t = t.getChild(0); while (t != null) { // for each sibling of the root t.setTreeEnclosingRuleNameDeeply(rname); t = (GrammarAST)t.getNextSibling(); } }
public GrammarAST getLastChild() { if (getChildCount() == 0) return null; return (GrammarAST)getChild(getChildCount() - 1); }
public void setTreeEnclosingRuleNameDeeply(String rname) { GrammarAST t = this; t.enclosingRuleName = rname; t = t.getChild(0); while (t != null) { // for each sibling of the root t.setTreeEnclosingRuleNameDeeply(rname); t = (GrammarAST)t.getNextSibling(); } }
public final int countAltsForBlock(GrammarAST t) { int n = 0; for ( int i = 0; i < t.getChildCount(); i++ ) { if ( t.getChild(i).getType() == ALT ) n++; } return n; }
public void stripLeftRecursion(GrammarAST altAST) { GrammarAST rref = (GrammarAST)altAST.getChild(0); if ( rref.getType()== ANTLRParser.RULE_REF && rref.getText().equals(ruleName)) { // remove rule ref altAST.deleteChild(0); // reset index so it prints properly GrammarAST newFirstChild = (GrammarAST) altAST.getChild(0); altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex()); } }
public final int countAltsForBlock(GrammarAST t) { int n = 0; for ( int i = 0; i < t.getChildCount(); i++ ) { if ( t.getChild(i).getType() == ALT ) n++; } return n; }
public void stripLeftRecursion(GrammarAST altAST) { GrammarAST rref = (GrammarAST)altAST.getChild(0); if ( rref.getType()== ANTLRParser.RULE_REF && rref.getText().equals(ruleName)) { // remove rule ref altAST.deleteChild(0); // reset index so it prints properly GrammarAST newFirstChild = (GrammarAST) altAST.getChild(0); altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex()); } }
@Override public int getLine() { int line=0; if ( token!=null ) { line = token.getLine(); } if ( line==0 ) { Tree child = getChild(0); if ( child!=null ) { line = child.getLine(); } } return line; }
public void _findAllType(int ttype, List<GrammarAST> nodes) { // check this node (the root) first if ( this.getType()==ttype ) nodes.add(this); // check children for (int i = 0; i < getChildCount(); i++){ GrammarAST child = (GrammarAST)getChild(i); child._findAllType(ttype, nodes); } }
@Override public int getCharPositionInLine(){ int col=0; if ( token!=null ) { col = token.getCharPositionInLine(); } if ( col==0 ) { Tree child = getChild(0); if ( child!=null ) { col = child.getCharPositionInLine(); } } return col; }
public void _findAllType(int ttype, List<GrammarAST> nodes) { // check this node (the root) first if ( this.getType()==ttype ) nodes.add(this); // check children for (int i = 0; i < getChildCount(); i++){ GrammarAST child = (GrammarAST)getChild(i); child._findAllType(ttype, nodes); } }
@Override public int getLine() { int line=0; if ( token!=null ) { line = token.getLine(); } if ( line==0 ) { Tree child = getChild(0); if ( child!=null ) { line = child.getLine(); } } return line; }
public void addRule(GrammarAST grammarTree, GrammarAST t) { GrammarAST p = null; for (int i = 0; i < grammarTree.getChildCount(); i++ ) { p = (GrammarAST)grammarTree.getChild(i); if (p == null || p.getType() == ANTLRParser.RULE || p.getType() == ANTLRParser.PREC_RULE) { break; } } if (p != null) { grammarTree.addChild(t); } }
public void stripSynPred(GrammarAST altAST) { GrammarAST t = (GrammarAST)altAST.getChild(0); if ( t.getType()==ANTLRParser.BACKTRACK_SEMPRED || t.getType()==ANTLRParser.SYNPRED || t.getType()==ANTLRParser.SYN_SEMPRED ) { altAST.deleteChild(0); // kill it } }
public static GrammarAST dupTree(GrammarAST t) { if ( t==null ) { return null; } GrammarAST root = dup(t); // make copy of root // copy all children of root. for (int i= 0; i < t.getChildCount(); i++) { GrammarAST child = (GrammarAST)t.getChild(i); root.addChild(dupTree(child)); } return root; }
public void stripSynPred(GrammarAST altAST) { GrammarAST t = (GrammarAST)altAST.getChild(0); if ( t.getType()==ANTLRParser.BACKTRACK_SEMPRED || t.getType()==ANTLRParser.SYNPRED || t.getType()==ANTLRParser.SYN_SEMPRED ) { altAST.deleteChild(0); // kill it } }
public void addRule(GrammarAST grammarTree, GrammarAST t) { GrammarAST p = null; for (int i = 0; i < grammarTree.getChildCount(); i++ ) { p = (GrammarAST)grammarTree.getChild(i); if (p == null || p.getType() == ANTLRParser.RULE || p.getType() == ANTLRParser.PREC_RULE) { break; } } if (p != null) { grammarTree.addChild(t); } }
public static GrammarAST dupTree(GrammarAST t) { if ( t==null ) { return null; } GrammarAST root = dup(t); // make copy of root // copy all children of root. for (int i= 0; i < t.getChildCount(); i++) { GrammarAST child = (GrammarAST)t.getChild(i); root.addChild(dupTree(child)); } return root; }