protected boolean isValidSimpleElementNode(GrammarAST t) { switch ( t.getType() ) { case ANTLRParser.TREE_BEGIN : case ANTLRParser.TOKEN_REF : case ANTLRParser.CHAR_LITERAL : case ANTLRParser.STRING_LITERAL : case ANTLRParser.WILDCARD : return true; default : return false; } }
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 _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); } }
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 List<? extends Object> translateAction(String ruleName, GrammarAST actionTree) { if ( actionTree.getType()==ANTLRParser.ARG_ACTION ) { return translateArgAction(ruleName, actionTree); } ActionTranslator translator = new ActionTranslator(this,ruleName,actionTree); List<Object> chunks = translator.translateToChunks(); chunks = target.postProcessAction(chunks, actionTree.token); return chunks; }
public List<? extends Object> translateAction(String ruleName, GrammarAST actionTree) { if ( actionTree.getType()==ANTLRParser.ARG_ACTION ) { return translateArgAction(ruleName, actionTree); } ActionTranslator translator = new ActionTranslator(this,ruleName,actionTree); List<Object> chunks = translator.translateToChunks(); chunks = target.postProcessAction(chunks, actionTree.token); return chunks; }
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 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 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()); } }