Refine search
public void copyFrom(PredicateContext ctx) { super.copyFrom(ctx); this.value = ctx.value; } }
private ExpressionSegment extractFunctionExpressionSegment(final ParserRuleContext functionNode) { return new FunctionExpressionSegment(functionNode.getChild(0).getText(), functionNode.getStart().getStartIndex(), ((TerminalNode) functionNode.getChild(1)).getSymbol().getStartIndex(), functionNode.getStop().getStopIndex(), -1); }
private SelectItemSegment extractFunctionSelectItemSegment(final ParserRuleContext expressionNode, final ParserRuleContext functionNode) { String functionName = functionNode.getChild(0).getText(); Optional<AggregationType> aggregationType = findAggregationType(functionName); AliasAvailable result = aggregationType.isPresent() ? extractAggregationSelectItemSegment(aggregationType.get(), functionNode) : new ExpressionSelectItemSegment(functionNode.getText(), functionNode.getStart().getStartIndex(), functionNode.getStop().getStopIndex()); Optional<ParserRuleContext> aliasNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.ALIAS); if (aliasNode.isPresent()) { result.setAlias(aliasNode.get().getText()); } return (SelectItemSegment) result; }
private static Collection<ParserRuleContext> getChildrenNodes(final ParserRuleContext node) { Collection<ParserRuleContext> result = new LinkedList<>(); for (int i = 0; i < node.getChildCount(); i++) { ParseTree child = node.getChild(i); if (child instanceof ParserRuleContext) { result.add((ParserRuleContext) child); } } return result; } }
private String getDistinctExpression(final ParserRuleContext functionNode) { StringBuilder result = new StringBuilder(); for (int i = 3; i < functionNode.getChildCount() - 1; i++) { result.append(functionNode.getChild(i).getText()); } return result.toString(); } }
@Override public void exitEveryRule(ParserRuleContext ctx) { System.out.println("exit "+getRuleNames()[ctx.getRuleIndex()]+ ", LT(1)="+_input.LT(1).getText()); } }
ParseTree mismatchedNode = null; if ( t1.getSymbol().getType() == t2.getSymbol().getType() ) { if ( t2.getSymbol() instanceof TokenTagToken ) { // x and <ID> TokenTagToken tokenTagToken = (TokenTagToken)t2.getSymbol(); if ( ruleTagToken!=null ) { ParseTreeMatch m = null; if ( r1.getRuleContext().getRuleIndex() == r2.getRuleContext().getRuleIndex() ) { if ( r1.getChildCount()!=r2.getChildCount() ) { if (mismatchedNode == null) { mismatchedNode = r1; int n = r1.getChildCount(); for (int i = 0; i<n; i++) { ParseTree childMatch = matchImpl(r1.getChild(i), patternTree.getChild(i), labels); if ( childMatch != null ) { return childMatch;
@Override public Collection<OrderByItemSegment> extract(final ParserRuleContext ancestorNode) { Collection<OrderByItemSegment> result = new LinkedList<>(); for (ParserRuleContext each : ExtractorUtils.getAllDescendantNodes(ancestorNode, RuleName.ORDER_BY_ITEM)) { OrderDirection orderDirection = 2 == each.getChildCount() && OrderDirection.DESC.name().equalsIgnoreCase(each.getChild(1).getText()) ? OrderDirection.DESC : OrderDirection.ASC; Optional<ParserRuleContext> indexNode = ExtractorUtils.findFirstChildNode(each, RuleName.NUMBER); if (indexNode.isPresent()) { result.add(new IndexOrderByItemSegment(NumberUtil.getExactlyNumber(indexNode.get().getText(), 10).intValue(), orderDirection, OrderDirection.ASC)); continue; } Optional<ParserRuleContext> expressionNode = ExtractorUtils.findFirstChildNode(each, RuleName.EXPR); if (expressionNode.isPresent()) { result.add(new ExpressionOrderByItemSegment(expressionNode.get().getText(), orderDirection, OrderDirection.ASC)); continue; } Optional<ParserRuleContext> columnNameNode = ExtractorUtils.findFirstChildNode(each, RuleName.COLUMN_NAME); if (columnNameNode.isPresent()) { result.add(new ColumnNameOrderByItemSegment(columnNameNode.get().getText(), ((ParserRuleContext) each.getChild(0)).getStart().getStartIndex(), orderDirection, OrderDirection.ASC)); } } return result; } }
@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())); } }
private Position pos(ParserRuleContext ctx, int childIndex) { ParseTree node = ctx.getChild(childIndex); if (node instanceof TerminalNode) { Token token = ((TerminalNode) node).getSymbol(); return new Position(token.getLine(), token.getCharPositionInLine()); } else if (node instanceof ParserRuleContext) { Token token = ctx.getStart(); return new Position(token.getLine(), token.getCharPositionInLine()); } throw new UnsupportedOperationException(); }
private static ParsingException parseError(String message, ParserRuleContext context) { return new ParsingException(message, null, context.getStart().getLine(), context.getStart().getCharPositionInLine()); } }
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); } }
@Override public Optional<ColumnSegment> extract(final ParserRuleContext ancestorNode) { Optional<ParserRuleContext> columnNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.COLUMN_NAME); return columnNode.isPresent() ? Optional.of(new ColumnSegment(columnNode.get().getText(), columnNode.get().getStart().getStartIndex())) : Optional.<ColumnSegment>absent(); } }
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 LimitValueSegment createLimitValueSegment(final Map<ParserRuleContext, Integer> placeholderAndNodeIndexMap, final ParserRuleContext limitValueNode) { return Symbol.QUESTION.getLiterals().equals(limitValueNode.getText()) ? new PlaceholderLimitValueSegment(placeholderAndNodeIndexMap.get(limitValueNode.getChild(0)), ((ParserRuleContext) limitValueNode.getChild(0)).getStart().getStartIndex()) : new LiteralLimitValueSegment(NumberUtil.getExactlyNumber(limitValueNode.getText(), 10).intValue(), limitValueNode.getStart().getStartIndex()); } }
protected void verifyConstructLength(Rules rule, String constructType, int length, ParserRuleContext ctx) { if (SourceFileUtil.constructTooLong(ctx, length)) { int constructLength = ctx.getStop().getLine() - ctx.getStart().getLine(); createErrorMessage(rule, constructLength, ctx, constructType, length, Messages.EXCEEDS_LINE_LIMIT); } }
public int getStartLine() { if(tree instanceof TerminalNode){ TerminalNode terminalNode = (TerminalNode) tree; return terminalNode.getSymbol().getLine(); }else if(tree instanceof ParserRuleContext){ ParserRuleContext parserRuleContext = (ParserRuleContext) tree; return parserRuleContext.getStart().getLine(); } return -1; }
@Override public void visitTerminal(TerminalNode node) { System.out.println("consume "+node.getSymbol()+" rule "+ getRuleNames()[_ctx.getRuleIndex()]); }
@Override public Optional<IndexSegment> extract(final ParserRuleContext ancestorNode) { Optional<ParserRuleContext> indexNameNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.INDEX_NAME); return indexNameNode.isPresent() ? Optional.of(new IndexSegment(new IndexToken(indexNameNode.get().getStop().getStartIndex(), indexNameNode.get().getStop().getStopIndex()))) : Optional.<IndexSegment>absent(); } }