public static boolean blockHasSynPred(GrammarAST blockAST) { GrammarAST c1 = blockAST.findFirstType(ANTLRParser.SYN_SEMPRED); GrammarAST c2 = blockAST.findFirstType(ANTLRParser.BACKTRACK_SEMPRED); if ( c1!=null || c2!=null ) return true; // System.out.println(blockAST.enclosingRuleName+ // " "+blockAST.getLine()+":"+blockAST.getColumn()+" no preds AST="+blockAST.toStringTree()); return false; }
public static boolean blockHasSynPred(GrammarAST blockAST) { GrammarAST c1 = blockAST.findFirstType(ANTLRParser.SYN_SEMPRED); GrammarAST c2 = blockAST.findFirstType(ANTLRParser.BACKTRACK_SEMPRED); if ( c1!=null || c2!=null ) return true; // System.out.println(blockAST.enclosingRuleName+ // " "+blockAST.getLine()+":"+blockAST.getColumn()+" no preds AST="+blockAST.toStringTree()); return false; }
public static boolean blockHasSynPred(GrammarAST blockAST) { GrammarAST c1 = blockAST.findFirstType(ANTLRParser.SYN_SEMPRED); GrammarAST c2 = blockAST.findFirstType(ANTLRParser.BACKTRACK_SEMPRED); if ( c1!=null || c2!=null ) return true; // System.out.println(blockAST.enclosingRuleName+ // " "+blockAST.getLine()+":"+blockAST.getColumn()+" no preds AST="+blockAST.toStringTree()); return false; }
/** Rules like "a : ;" and "a : {...} ;" should not generate * try/catch blocks for RecognitionException. To detect this * it's probably ok to just look for any reference to an atom * that can match some input. W/o that, the rule is unlikey to have * any else. */ public boolean isEmptyRule(GrammarAST block) { GrammarAST aTokenRefNode = block.findFirstType(ANTLRParser.TOKEN_REF); GrammarAST aStringLiteralRefNode = block.findFirstType(ANTLRParser.STRING_LITERAL); GrammarAST aCharLiteralRefNode = block.findFirstType(ANTLRParser.CHAR_LITERAL); GrammarAST aWildcardRefNode = block.findFirstType(ANTLRParser.WILDCARD); GrammarAST aRuleRefNode = block.findFirstType(ANTLRParser.RULE_REF); if ( aTokenRefNode==null&& aStringLiteralRefNode==null&& aCharLiteralRefNode==null&& aWildcardRefNode==null&& aRuleRefNode==null ) { return true; } return false; }
/** Rules like "a : ;" and "a : {...} ;" should not generate * try/catch blocks for RecognitionException. To detect this * it's probably ok to just look for any reference to an atom * that can match some input. W/o that, the rule is unlikey to have * any else. */ public boolean isEmptyRule(GrammarAST block) { GrammarAST aTokenRefNode = block.findFirstType(ANTLRParser.TOKEN_REF); GrammarAST aStringLiteralRefNode = block.findFirstType(ANTLRParser.STRING_LITERAL); GrammarAST aCharLiteralRefNode = block.findFirstType(ANTLRParser.CHAR_LITERAL); GrammarAST aWildcardRefNode = block.findFirstType(ANTLRParser.WILDCARD); GrammarAST aRuleRefNode = block.findFirstType(ANTLRParser.RULE_REF); if ( aTokenRefNode==null&& aStringLiteralRefNode==null&& aCharLiteralRefNode==null&& aWildcardRefNode==null&& aRuleRefNode==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; }
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; }
/** 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; }
if ( grammarTree==null || grammarTree.findFirstType(ANTLRParser.RULE)==null ) { ErrorManager.error(ErrorManager.MSG_NO_RULES, getFileName()); return;
if ( grammarTree==null || grammarTree.findFirstType(ANTLRParser.RULE)==null ) { ErrorManager.error(ErrorManager.MSG_NO_RULES, getFileName()); return;
if ( grammarTree.findFirstType(ANTLRParser.RULE)==null ) { ErrorManager.error(ErrorManager.MSG_NO_RULES, getFileName());
if ( grammarTree.findFirstType(ANTLRParser.RULE)==null ) { ErrorManager.error(ErrorManager.MSG_NO_RULES, getFileName());
GrammarAST firstRewriteAST = (rew!=null?((GrammarAST)rew.start):null).findFirstType(REWRITE); boolean etc = (rew!=null?((GrammarAST)rew.start):null).getType()==REWRITES &&
GrammarAST firstRewriteAST = (rew!=null?((GrammarAST)rew.start):null).findFirstType(REWRITE); boolean etc = (rew!=null?((GrammarAST)rew.start):null).getType()==REWRITES &&
GrammarAST aRewriteNode = alternative_AST_in.findFirstType(REWRITE); // alt itself has rewrite? GrammarAST rewriteAST = (GrammarAST)alternative_AST_in.getNextSibling();