public GrammarAST getLastSibling() { GrammarAST t = this; GrammarAST last = null; while ( t!=null ) { last = t; t = (GrammarAST)t.getNextSibling(); } return last; }
public GrammarAST getLastSibling() { GrammarAST t = this; GrammarAST last = null; while ( t!=null ) { last = t; t = (GrammarAST)t.getNextSibling(); } return last; }
public String toStringList() { String result = toStringTree(); if (this.getNextSibling() != null) { result += ' ' + getNextSibling().toStringList(); } return result; }
public String toStringList() { String result = toStringTree(); if (this.getNextSibling() != null) { result += ' ' + getNextSibling().toStringList(); } return result; }
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 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(); } }
protected boolean isNextNonActionElementEOA(GrammarAST t) { while ( t.getType()==ANTLRParser.ACTION || t.getType()==ANTLRParser.SEMPRED ) { t = t.getNextSibling(); } if ( t.getType()==ANTLRParser.EOA ) { return true; } return false; } }
protected boolean isNextNonActionElementEOA(GrammarAST t) { while ( t.getType()==ANTLRParser.ACTION || t.getType()==ANTLRParser.SEMPRED ) { t = (GrammarAST)t.getNextSibling(); } if ( t.getType()==ANTLRParser.EOA ) { return true; } return false; } }
protected boolean isNextNonActionElementEOA(GrammarAST t) { while ( t.getType()==ANTLRParser.ACTION || t.getType()==ANTLRParser.SEMPRED ) { t = t.getNextSibling(); } if ( t.getType()==ANTLRParser.EOA ) { return true; } return false; } }
protected boolean isNextNonActionElementEOA(GrammarAST t) { while ( t.getType()==ANTLRParser.ACTION || t.getType()==ANTLRParser.SEMPRED ) { t = (GrammarAST)t.getNextSibling(); } if ( t.getType()==ANTLRParser.EOA ) { return true; } return false; } }
/** Return a reference to the first node (depth-first) that has * token type ttype. Assume 'this' is a root node; don't visit siblings * of root. Return null if no node found with ttype. */ public GrammarAST findFirstType(int ttype) { // check this node (the root) first if ( this.getType()==ttype ) { return this; } // else check children GrammarAST child = (GrammarAST)this.getFirstChild(); while ( child!=null ) { GrammarAST result = child.findFirstType(ttype); if ( result!=null ) { return result; } child = (GrammarAST)child.getNextSibling(); } return null; }
public boolean hasRewrite(int i) { GrammarAST blk = tree.findFirstType(ANTLRParser.BLOCK); GrammarAST alt = blk.getBlockALT(i); GrammarAST rew = alt.getNextSibling(); if ( rew!=null && rew.getType()==ANTLRParser.REWRITES ) return true; if ( alt.findFirstType(ANTLRParser.REWRITES)!=null ) return true; return false; }
public boolean hasRewrite(int i) { GrammarAST blk = tree.findFirstType(ANTLRParser.BLOCK); GrammarAST alt = blk.getBlockALT(i); GrammarAST rew = alt.getNextSibling(); if ( rew!=null && rew.getType()==ANTLRParser.REWRITES ) return true; if ( alt.findFirstType(ANTLRParser.REWRITES)!=null ) return true; return false; }
/** Return a reference to the first node (depth-first) that has * token type ttype. Assume 'this' is a root node; don't visit siblings * of root. Return null if no node found with ttype. */ public GrammarAST findFirstType(int ttype) { // check this node (the root) first if ( this.getType()==ttype ) { return this; } // else check children GrammarAST child = (GrammarAST)this.getFirstChild(); while ( child!=null ) { GrammarAST result = child.findFirstType(ttype); if ( result!=null ) { return result; } child = (GrammarAST)child.getNextSibling(); } return null; }
GrammarAST next = (GrammarAST)elementAST.getNextSibling(); if ( !isNextNonActionElementEOA(next)) { ErrorManager.grammarWarning(ErrorManager.MSG_REWRITE_FOR_MULTI_ELEMENT_ALT, case ANTLRParser.GATED_SEMPRED : ensureAltIsSimpleNodeOrTree(altAST, (GrammarAST)elementAST.getNextSibling(), outerAltNum); return;
/** 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; }
GrammarAST next = elementAST.getNextSibling(); if ( !isNextNonActionElementEOA(next)) { ErrorManager.grammarWarning(ErrorManager.MSG_REWRITE_FOR_MULTI_ELEMENT_ALT, case ANTLRParser.GATED_SEMPRED : ensureAltIsSimpleNodeOrTree(altAST, elementAST.getNextSibling(), outerAltNum); return;
/** Remove any lexer rules from a COMBINED; already passed to lexer */ protected final void trimGrammar() { if ( grammar.type != Grammar.COMBINED ) { return; } // form is (header ... ) ( grammar ID (scope ...) ... ( rule ... ) ( rule ... ) ... ) GrammarAST p = root; // find the grammar spec while ( !p.getText().equals( "grammar" ) ) { p = p.getNextSibling(); } for ( int i = 0; i < p.getChildCount(); i++ ) { if ( p.getChild( i ).getType() != RULE ) continue; String ruleName = p.getChild(i).getChild(0).getText(); //Console.Out.WriteLine( "rule " + ruleName + " prev=" + prev.getText() ); if (Rule.getRuleType(ruleName) == Grammar.LEXER) { // remove lexer rule p.deleteChild( i ); i--; } } //Console.Out.WriteLine( "root after removal is: " + root.ToStringList() ); }
/** Remove any lexer rules from a COMBINED; already passed to lexer */ protected final void trimGrammar() { if ( grammar.type != Grammar.COMBINED ) { return; } // form is (header ... ) ( grammar ID (scope ...) ... ( rule ... ) ( rule ... ) ... ) GrammarAST p = root; // find the grammar spec while ( !p.getText().equals( "grammar" ) ) { p = p.getNextSibling(); } for ( int i = 0; i < p.getChildCount(); i++ ) { if ( p.getChild( i ).getType() != RULE ) continue; String ruleName = p.getChild(i).getChild(0).getText(); //Console.Out.WriteLine( "rule " + ruleName + " prev=" + prev.getText() ); if (Rule.getRuleType(ruleName) == Grammar.LEXER) { // remove lexer rule p.deleteChild( i ); i--; } } //Console.Out.WriteLine( "root after removal is: " + root.ToStringList() ); }