private static int findTotalRegisters(SmaliParser.SMethodContext ctx, int ins) { int totalRegisters = -1; List<SmaliParser.SInstructionContext> instructionContexts = ctx.sInstruction(); for (SmaliParser.SInstructionContext instructionContext : instructionContexts) { ParserRuleContext parserRuleContext = (ParserRuleContext) instructionContext.getChild(0); if (parserRuleContext != null) { int ruleIndex = parserRuleContext.getRuleIndex(); if (ruleIndex == SmaliParser.RULE_fregisters) { totalRegisters = parseInt(((SmaliParser.FregistersContext) parserRuleContext).xregisters.getText()); break; } else if (ruleIndex == SmaliParser.RULE_flocals) { totalRegisters = ins + parseInt(((SmaliParser.FlocalsContext) parserRuleContext).xlocals.getText()); break; } } } return totalRegisters; }
private static void acceptAnnotation(DexAnnotationVisitor dexAnnotationVisitor, String name, SmaliParser.SAnnotationValueContext ctx) { ParserRuleContext t = (ParserRuleContext) ctx.getChild(0); switch (t.getRuleIndex()) { case SmaliParser.RULE_sSubannotation: { SmaliParser.SSubannotationContext subannotationContext = (SmaliParser.SSubannotationContext) t;
@Override public void exitNonReserved(SqlBaseParser.NonReservedContext context) { // we can't modify the tree during rule enter/exit event handling unless we're dealing with a terminal. // Otherwise, ANTLR gets confused an fires spurious notifications. if (!(context.getChild(0) instanceof TerminalNode)) { int rule = ((ParserRuleContext) context.getChild(0)).getRuleIndex(); throw new AssertionError("nonReserved can only contain tokens. Found nested rule: " + ruleNames.get(rule)); } // replace nonReserved words with IDENT tokens context.getParent().removeLastChild(); Token token = (Token) context.getChild(0).getPayload(); context.getParent().addChild(new CommonToken( new Pair<>(token.getTokenSource(), token.getInputStream()), SqlBaseLexer.IDENTIFIER, token.getChannel(), token.getStartIndex(), token.getStopIndex())); } }
public ParserRuleContext getInvokingContext(int ruleIndex) { ParserRuleContext p = _ctx; while ( p!=null ) { if ( p.getRuleIndex() == ruleIndex ) return p; p = (ParserRuleContext)p.parent; } return null; }
@Override public Collection<ParseTree> evaluate(ParseTree t) { // return all children of t that match nodeName List<ParseTree> nodes = new ArrayList<ParseTree>(); for (Tree c : Trees.getChildren(t)) { if ( c instanceof ParserRuleContext ) { ParserRuleContext ctx = (ParserRuleContext)c; if ( (ctx.getRuleIndex() == ruleIndex && !invert) || (ctx.getRuleIndex() != ruleIndex && invert) ) { nodes.add(ctx); } } } return nodes; } }
@Override public void exitEveryRule(ParserRuleContext ctx) { System.out.println("exit "+getRuleNames()[ctx.getRuleIndex()]+ ", LT(1)="+_input.LT(1).getText()); } }
@Override public void enterEveryRule(ParserRuleContext ctx) { System.out.println("enter " + getRuleNames()[ctx.getRuleIndex()] + ", LT(1)=" + _input.LT(1).getText()); }
@Override public void visitTerminal(TerminalNode node) { System.out.println("consume "+node.getSymbol()+" rule "+ getRuleNames()[_ctx.getRuleIndex()]); }
public static void _findAllNodes(ParseTree t, int index, boolean findTokens, List<? super ParseTree> nodes) { // check this node (the root) first if ( findTokens && t instanceof TerminalNode ) { TerminalNode tnode = (TerminalNode)t; if ( tnode.getSymbol().getType()==index ) nodes.add(t); } else if ( !findTokens && t instanceof ParserRuleContext ) { ParserRuleContext ctx = (ParserRuleContext)t; if ( ctx.getRuleIndex() == index ) nodes.add(t); } // check children for (int i = 0; i < t.getChildCount(); i++){ _findAllNodes(t.getChild(i), index, findTokens, nodes); } }
/** * This is called by {@link #reportError} when the exception is a * {@link FailedPredicateException}. * * @see #reportError * * @param recognizer the parser instance * @param e the recognition exception */ protected void reportFailedPredicate(Parser recognizer, FailedPredicateException e) { String ruleName = recognizer.getRuleNames()[recognizer._ctx.getRuleIndex()]; String msg = "rule "+ruleName+" "+e.getMessage(); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
public ParserRuleContext getInvokingContext(int ruleIndex) { ParserRuleContext p = _ctx; while ( p!=null ) { if ( p.getRuleIndex() == ruleIndex ) return p; p = (ParserRuleContext)p.parent; } return null; }
public ParserRuleContext getInvokingContext(int ruleIndex) { ParserRuleContext p = _ctx; while ( p!=null ) { if ( p.getRuleIndex() == ruleIndex ) return p; p = (ParserRuleContext)p.parent; } return null; }
createInterpreterRuleContext(_parentContextStack.peek().a, _parentContextStack.peek().b, _ctx.getRuleIndex()); pushNewRecursionContext(localctx, atn.ruleToStartState[p.ruleIndex].stateNumber, _ctx.getRuleIndex());
public ParentSiblingListKey(ParserRuleContext parent, ParserRuleContext child, int separatorTokenType) { parentRuleIndex = parent.getRuleIndex(); parentRuleAlt = parent.getAltNumber(); childRuleIndex = child.getRuleIndex(); childRuleAlt = child.getAltNumber(); this.separatorTokenType = separatorTokenType; }
public void exitWhereClause(EsperEPL2GrammarParser.WhereClauseContext ctx) { if (ctx.getParent().getRuleIndex() != EsperEPL2GrammarParser.RULE_subQueryExpr && ASTUtil.isRecursiveParentRule(ctx, WHERE_CLAUSE_WALK_EXCEPTIONS_RECURSIVE)) { // ignore pattern return; } if (astExprNodeMap.size() != 1) { throw new IllegalStateException("Where clause generated zero or more then one expression nodes"); } // Just assign the single root ExprNode not consumed yet statementSpec.setWhereClause(astExprNodeMap.values().iterator().next()); astExprNodeMap.clear(); }
public void exitWhereClause(EsperEPL2GrammarParser.WhereClauseContext ctx) { if (ctx.getParent().getRuleIndex() != EsperEPL2GrammarParser.RULE_subQueryExpr && ASTUtil.isRecursiveParentRule(ctx, WHERE_CLAUSE_WALK_EXCEPTIONS_RECURSIVE)) { // ignore pattern return; } if (astExprNodeMap.size() != 1) { throw new IllegalStateException("Where clause generated zero or more then one expression nodes"); } // Just assign the single root ExprNode not consumed yet statementSpec.setWhereClause(astExprNodeMap.values().iterator().next()); astExprNodeMap.clear(); }
public static boolean isRecursiveParentRule(ParserRuleContext ctx, Set<Integer> rulesIds) { ParserRuleContext parent = ctx.getParent(); if (parent == null) { return false; } return rulesIds.contains(parent.getRuleIndex()) || isRecursiveParentRule(parent, rulesIds); }
public static boolean isRecursiveParentRule(ParserRuleContext ctx, Set<Integer> rulesIds) { ParserRuleContext parent = ctx.getParent(); if (parent == null) { return false; } return rulesIds.contains(parent.getRuleIndex()) || isRecursiveParentRule(parent, rulesIds); }
protected void reportFailedPredicate(@NotNull Parser recognizer, @NotNull FailedPredicateException e) { String ruleName = recognizer.getRuleNames()[recognizer.getContext().getRuleIndex()]; BeetlException exception = new BeetlParserException(BeetlException.PARSER_PREDICATE_ERROR, ruleName, e); // exception.token = this.getGrammarToken(e.getOffendingToken()); exception.pushToken(this.getGrammarToken(e.getOffendingToken())); throw exception; }
protected void reportFailedPredicate(@NotNull Parser recognizer, @NotNull FailedPredicateException e) { String ruleName = recognizer.getRuleNames()[recognizer.getContext().getRuleIndex()]; BeetlException exception = new BeetlParserException(BeetlException.PARSER_PREDICATE_ERROR, ruleName, e); // exception.token = this.getGrammarToken(e.getOffendingToken()); exception.pushToken(this.getGrammarToken(e.getOffendingToken())); throw exception; }