java类org.antlr.v4.runtime.tree.Tree的实例源码

Trees.java 文件源码 项目:codebuff 阅读 24 收藏 0 点赞 0 评论 0
/** Print out a whole tree in LISP form. Arg nodeTextProvider is used on the
 *  node payloads to get the text for the nodes.
 *
 *  @since 4.5.1
 */
public static String toStringTree(Tree t, TreeTextProvider nodeTextProvider) {
    if ( t==null ) return "null";
    String s = Utils.escapeWhitespace(nodeTextProvider.getText(t), false);
    if ( t.getChildCount()==0 ) return s;
    StringBuilder buf = new StringBuilder();
    buf.append("(");
    s = Utils.escapeWhitespace(nodeTextProvider.getText(t), false);
    buf.append(s);
    buf.append(' ');
    for (int i = 0; i<t.getChildCount(); i++) {
        if ( i>0 ) buf.append(' ');
        buf.append(toStringTree(t.getChild(i), nodeTextProvider));
    }
    buf.append(")");
    return buf.toString();
}
TreeLayoutAdaptor.java 文件源码 项目:codebuff 阅读 18 收藏 0 点赞 0 评论 0
@Override
public Iterator<Tree> iterator() {
    return new Iterator<Tree>() {
        private int i = 0;

        @Override
        public boolean hasNext() {
            return tree.getChildCount() > i;
        }

        @Override
        public Tree next() {
            if (!hasNext())
                throw new NoSuchElementException();

            return tree.getChild(i++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
TreeLayoutAdaptor.java 文件源码 项目:codebuff 阅读 16 收藏 0 点赞 0 评论 0
@Override
public Iterator<Tree> iterator() {
    return new Iterator<Tree>() {
        private int i = tree.getChildCount();

        @Override
        public boolean hasNext() {
            return i > 0;
        }

        @Override
        public Tree next() {
            if (!hasNext())
                throw new NoSuchElementException();

            return tree.getChild(--i);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
TreePostScriptGenerator.java 文件源码 项目:codebuff 阅读 21 收藏 0 点赞 0 评论 0
protected void generateEdges(Tree parent) {
        if (!getTree().isLeaf(parent)) {
            Rectangle2D.Double parentBounds = getBoundsOfNode(parent);
//          System.out.println("%% parent("+getText(parent)+")="+parentBounds);
            double x1 = parentBounds.getCenterX();
            double y1 = parentBounds.y;
            for (Tree child : getChildren(parent)) {
                Rectangle2D.Double childBounds = getBoundsOfNode(child);
//              System.out.println("%% child("+getText(child)+")="+childBounds);
                double x2 = childBounds.getCenterX();
                double y2 = childBounds.getMaxY();
                doc.line(x1, y1, x2, y2);
                generateEdges(child);
            }
        }
    }
TreeViewer.java 文件源码 项目:codebuff 阅读 27 收藏 0 点赞 0 评论 0
public void setTree(Tree root) {
    if ( root!=null ) {
        boolean useIdentity = true; // compare node identity
        this.treeLayout =
            new TreeLayout<Tree>(getTreeLayoutAdaptor(root),
                                 new TreeViewer.VariableExtentProvide(this),
                                 new DefaultConfiguration<Tree>(gapBetweenLevels,
                                                                gapBetweenNodes),
                                 useIdentity);
        // Let the UI display this new AST.
        updatePreferredSize();
    }
    else {
        this.treeLayout = null;
        repaint();
    }
}
AbstractPQLQuery.java 文件源码 项目:PQL 阅读 20 收藏 0 点赞 0 评论 0
private String toStringTree(Tree tree, List<String> ruleNames) {
    String s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
    if(tree.getChildCount() == 0) return s;

    StringBuilder buf = new StringBuilder();
    buf.append("(");
    s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
    buf.append(s);
    buf.append(' ');
    for(int i = 0; i < tree.getChildCount(); i++)
    {
        if(i > 0)
            buf.append(' ');
        buf.append(toStringTree(tree.getChild(i), ruleNames));
    }

    buf.append(")");
    return buf.toString();
}
ASTUtil.java 文件源码 项目:esper 阅读 26 收藏 0 点赞 0 评论 0
public static void dumpAST(PrintWriter printer, Tree ast, int ident) {
    char[] identChars = new char[ident];
    Arrays.fill(identChars, ' ');

    if (ast == null) {
        renderNode(identChars, null, printer);
        return;
    }
    for (int i = 0; i < ast.getChildCount(); i++) {
        Tree node = ast.getChild(i);
        if (node == null) {
            throw new NullPointerException("Null AST node");
        }
        renderNode(identChars, node, printer);
        dumpAST(printer, node, ident + 2);
    }
}
ASTExprHelper.java 文件源码 项目:esper 阅读 16 收藏 0 点赞 0 评论 0
protected static List<OnTriggerSetAssignment> getOnTriggerSetAssignments(EsperEPL2GrammarParser.OnSetAssignmentListContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
    if (ctx == null || ctx.onSetAssignment().isEmpty()) {
        return Collections.emptyList();
    }
    List<EsperEPL2GrammarParser.OnSetAssignmentContext> ctxs = ctx.onSetAssignment();
    List<OnTriggerSetAssignment> assignments = new ArrayList<OnTriggerSetAssignment>(ctx.onSetAssignment().size());
    for (EsperEPL2GrammarParser.OnSetAssignmentContext assign : ctxs) {
        ExprNode childEvalNode;
        if (assign.eventProperty() != null) {
            ExprNode prop = ASTExprHelper.exprCollectSubNodes(assign.eventProperty(), 0, astExprNodeMap).get(0);
            ExprNode value = ASTExprHelper.exprCollectSubNodes(assign.expression(), 0, astExprNodeMap).get(0);
            ExprEqualsNode equals = new ExprEqualsNodeImpl(false, false);
            equals.addChildNode(prop);
            equals.addChildNode(value);
            childEvalNode = equals;
        } else {
            childEvalNode = ASTExprHelper.exprCollectSubNodes(assign, 0, astExprNodeMap).get(0);
        }
        assignments.add(new OnTriggerSetAssignment(childEvalNode));
    }
    return assignments;
}
ASTExprHelper.java 文件源码 项目:esper 阅读 18 收藏 0 点赞 0 评论 0
public static ExprNode mathGetExpr(ParseTree ctx, Map<Tree, ExprNode> astExprNodeMap, ConfigurationInformation configurationInformation) {

        int count = 1;
        ExprNode base = ASTExprHelper.exprCollectSubNodes(ctx.getChild(0), 0, astExprNodeMap).get(0);

        while (true) {
            int token = ASTUtil.getAssertTerminatedTokenType(ctx.getChild(count));
            MathArithTypeEnum mathArithTypeEnum = tokenToMathEnum(token);

            ExprNode right = ASTExprHelper.exprCollectSubNodes(ctx.getChild(count + 1), 0, astExprNodeMap).get(0);

            ExprMathNode math = new ExprMathNode(mathArithTypeEnum,
                    configurationInformation.getEngineDefaults().getExpression().isIntegerDivision(),
                    configurationInformation.getEngineDefaults().getExpression().isDivisionByZeroReturnsNull());
            math.addChildNode(base);
            math.addChildNode(right);
            base = math;

            count += 2;
            if (count >= ctx.getChildCount()) {
                break;
            }
        }
        return base;
    }
ASTGraphHelper.java 文件源码 项目:esper 阅读 16 收藏 0 点赞 0 评论 0
public static CreateDataFlowDesc walkCreateDataFlow(EsperEPL2GrammarParser.CreateDataflowContext ctx, Map<Tree, Object> astGraphNodeMap, EngineImportService engineImportService) {
    String graphName = ctx.name.getText();

    List<GraphOperatorSpec> ops = new ArrayList<GraphOperatorSpec>();
    List<CreateSchemaDesc> schemas = new ArrayList<CreateSchemaDesc>();

    List<EsperEPL2GrammarParser.GopContext> gopctxs = ctx.gopList().gop();
    for (EsperEPL2GrammarParser.GopContext gopctx : gopctxs) {
        if (gopctx.createSchemaExpr() != null) {
            schemas.add(ASTCreateSchemaHelper.walkCreateSchema(gopctx.createSchemaExpr()));
        } else {
            ops.add(parseOp(gopctx, astGraphNodeMap, engineImportService));
        }
    }
    return new CreateDataFlowDesc(graphName, ops, schemas);
}
ASTLibFunctionHelper.java 文件源码 项目:esper 阅读 23 收藏 0 点赞 0 评论 0
public static List<ExprNode> getExprNodesLibFunc(EsperEPL2GrammarParser.LibFunctionArgsContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
    if (ctx == null) {
        return Collections.emptyList();
    }
    List<EsperEPL2GrammarParser.LibFunctionArgItemContext> args = ctx.libFunctionArgItem();
    if (args == null || args.isEmpty()) {
        return Collections.emptyList();
    }
    List<ExprNode> parameters = new ArrayList<ExprNode>(args.size());
    for (EsperEPL2GrammarParser.LibFunctionArgItemContext arg : args) {
        if (arg.expressionLambdaDecl() != null) {
            List<String> lambdaparams = getLambdaGoesParams(arg.expressionLambdaDecl());
            ExprLambdaGoesNode goes = new ExprLambdaGoesNode(lambdaparams);
            ExprNode lambdaExpr = ASTExprHelper.exprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap).get(0);
            goes.addChildNode(lambdaExpr);
            parameters.add(goes);
        } else {
            ExprNode parameter = ASTExprHelper.exprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap).get(0);
            parameters.add(parameter);
        }
    }
    return parameters;
}
ASTIndexHelper.java 文件源码 项目:esper 阅读 18 收藏 0 点赞 0 评论 0
public static CreateIndexDesc walk(EsperEPL2GrammarParser.CreateIndexExprContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
    String indexName = ctx.n.getText();
    String windowName = ctx.w.getText();

    boolean unique = false;
    if (ctx.u != null) {
        String ident = ctx.u.getText();
        if (ident.toLowerCase(Locale.ENGLISH).trim().equals("unique")) {
            unique = true;
        } else {
            throw ASTWalkException.from("Invalid keyword '" + ident + "' in create-index encountered, expected 'unique'");
        }
    }

    List<CreateIndexItem> columns = new ArrayList<>();
    List<EsperEPL2GrammarParser.CreateIndexColumnContext> cols = ctx.createIndexColumnList().createIndexColumn();
    for (EsperEPL2GrammarParser.CreateIndexColumnContext col : cols) {
        CreateIndexItem item = walk(col, astExprNodeMap);
        columns.add(item);
    }
    return new CreateIndexDesc(unique, indexName, windowName, columns);
}
ASTIndexHelper.java 文件源码 项目:esper 阅读 20 收藏 0 点赞 0 评论 0
private static CreateIndexItem walk(EsperEPL2GrammarParser.CreateIndexColumnContext col, Map<Tree, ExprNode> astExprNodeMap) {
    List<ExprNode> expressions = Collections.emptyList();
    if (col.i != null) {
        expressions = ASTExprHelper.exprCollectSubNodes(col.i, 0, astExprNodeMap);
    } else if (col.expression() != null) {
        expressions = ASTExprHelper.exprCollectSubNodes(col.expression(), 0, astExprNodeMap);
    }

    String type = CreateIndexType.HASH.getNameLower();
    if (col.t != null) {
        type = col.t.getText();
    }

    List<ExprNode> parameters = Collections.<ExprNode>emptyList();
    if (col.p != null) {
        parameters = ASTExprHelper.exprCollectSubNodes(col.p, 0, astExprNodeMap);
    }
    return new CreateIndexItem(expressions, type, parameters);
}
ASTMatchRecognizeHelper.java 文件源码 项目:esper 阅读 20 收藏 0 点赞 0 评论 0
public static RowRegexExprRepeatDesc walkOptionalRepeat(EsperEPL2GrammarParser.MatchRecogPatternRepeatContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
    if (ctx == null) {
        return null;
    }

    ExprNode e1 = ctx.e1 == null ? null : ASTExprHelper.exprCollectSubNodes(ctx.e1, 0, astExprNodeMap).get(0);
    ExprNode e2 = ctx.e2 == null ? null : ASTExprHelper.exprCollectSubNodes(ctx.e2, 0, astExprNodeMap).get(0);

    if (ctx.comma == null && ctx.e1 != null) {
        return new RowRegexExprRepeatDesc(null, null, e1);
    }

    if (e1 == null && e2 == null) {
        throw ASTWalkException.from("Invalid match-recognize quantifier '" + ctx.getText() + "', expecting an expression");
    }

    return new RowRegexExprRepeatDesc(e1, e2, null);
}
TestASTFilterSpecHelper.java 文件源码 项目:esper 阅读 22 收藏 0 点赞 0 评论 0
public void testGetPropertyName() throws Exception {
    final String PROPERTY = "a('aa').b[1].c";

    // Should parse and result in the exact same property name
    Pair<Tree, CommonTokenStream> parsed = SupportParserHelper.parseEventProperty(PROPERTY);
    Tree propertyNameExprNode = parsed.getFirst().getChild(0);
    ASTUtil.dumpAST(propertyNameExprNode);
    String propertyName = ((RuleNode) propertyNameExprNode).getText();
    assertEquals(PROPERTY, propertyName);

    // Try AST with tokens separated, same property name
    parsed = SupportParserHelper.parseEventProperty("a(    'aa'   ). b [ 1 ] . c");
    propertyNameExprNode = parsed.getFirst().getChild(0);
    propertyName = ((RuleNode) propertyNameExprNode).getText();
    assertEquals(PROPERTY, propertyName);
}
STGroupStructureViewModel.java 文件源码 项目:jetbrains-plugin-st4 阅读 24 收藏 0 点赞 0 评论 0
/** From editor's cursor, find associated parse tree node so we can highlight
 *  in structure view. It wants the parse tree node not a
 *  StructureViewTreeElement. It will try to find a path from root to
 *  that node and highlight it.
 */
@Nullable
public Object getCurrentEditorElement() {
    if (editor==null) return null;
    final int offset = editor.getCaretModel().getOffset();
    if ( parseTree==null ) return null;
    Tree selectedNode = Trees.findNodeSuchThat(parseTree, new Predicate<Tree>() {
        @Override
        public boolean test(Tree node) {
            if ( !(node instanceof TerminalNode) ) return false;
            Token t = ((TerminalNode) node).getSymbol();
            return offset>=t.getStartIndex() && offset<=t.getStopIndex();
        }
    });
    if ( selectedNode==null ) return null;
    // now walk up looking for template def node
    ParseTree p = (ParseTree)selectedNode;
    while ( p!=null && !(p instanceof STGParser.TemplateContext) ) {
        p = p.getParent();
    }
    if ( p!=null ) {
        return ((STGParser.TemplateContext)p).ID(0);
    }
    return null;
}
ParseTreeCommand.java 文件源码 项目:antlr4ide 阅读 22 收藏 0 点赞 0 评论 0
private String toStringTree(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
  if (t.getChildCount() == 0) {
    return Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
  }
  StringBuilder buf = new StringBuilder();
  buf.append(" ( ");
  String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
  buf.append(s);
  buf.append(' ');
  for (int i = 0; i < t.getChildCount(); i++) {
    if (i > 0) {
      buf.append(' ');
    }
    buf.append(toStringTree(t.getChild(i), ruleNames));
  }
  buf.append(" ) ");
  return buf.toString();
}
ParseTreeCommand.java 文件源码 项目:antlr4ide 阅读 24 收藏 0 点赞 0 评论 0
private String getNodeText(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
  if (ruleNames != null) {
    if (t instanceof RuleNode) {
      int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
      String ruleName = ruleNames.get(ruleIndex);
      return ruleName;
    }
    else if (t instanceof ErrorNode) {
      return "<" + t.toString() + ">";
    }
    else if (t instanceof TerminalNode) {
      Token symbol = ((TerminalNode) t).getSymbol();
      if (symbol != null) {
        String s = symbol.getText();
        return "'" + s + "'";
      }
    }
  }
  // no recog for rule names
  Object payload = t.getPayload();
  if (payload instanceof Token) {
    return ((Token) payload).getText();
  }
  return t.getPayload().toString();
}
XPathRuleElement.java 文件源码 项目:Scratch-ApuC 阅读 21 收藏 0 点赞 0 评论 0
@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;
}
XPathTokenElement.java 文件源码 项目:Scratch-ApuC 阅读 19 收藏 0 点赞 0 评论 0
@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 TerminalNode ) {
            TerminalNode tnode = (TerminalNode)c;
            if ( (tnode.getSymbol().getType() == tokenType && !invert) ||
                 (tnode.getSymbol().getType() != tokenType && invert) )
            {
                nodes.add(tnode);
            }
        }
    }
    return nodes;
}
TreeLayoutAdaptor.java 文件源码 项目:Scratch-ApuC 阅读 20 收藏 0 点赞 0 评论 0
@Override
public Iterator<Tree> iterator() {
    return new Iterator<Tree>() {
        private int i = 0;

        @Override
        public boolean hasNext() {
            return tree.getChildCount() > i;
        }

        @Override
        public Tree next() {
            if (!hasNext())
                throw new NoSuchElementException();

            return tree.getChild(i++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
TreeLayoutAdaptor.java 文件源码 项目:Scratch-ApuC 阅读 19 收藏 0 点赞 0 评论 0
@Override
public Iterator<Tree> iterator() {
    return new Iterator<Tree>() {
        private int i = tree.getChildCount();

        @Override
        public boolean hasNext() {
            return i > 0;
        }

        @Override
        public Tree next() {
            if (!hasNext())
                throw new NoSuchElementException();

            return tree.getChild(--i);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
TreePostScriptGenerator.java 文件源码 项目:Scratch-ApuC 阅读 20 收藏 0 点赞 0 评论 0
protected void generateEdges(Tree parent) {
        if (!getTree().isLeaf(parent)) {
            Rectangle2D.Double parentBounds = getBoundsOfNode(parent);
//          System.out.println("%% parent("+getText(parent)+")="+parentBounds);
            double x1 = parentBounds.getCenterX();
            double y1 = parentBounds.y;
            for (Tree child : getChildren(parent)) {
                Rectangle2D.Double childBounds = getBoundsOfNode(child);
//              System.out.println("%% child("+getText(child)+")="+childBounds);
                double x2 = childBounds.getCenterX();
                double y2 = childBounds.getMaxY();
                doc.line(x1, y1, x2, y2);
                generateEdges(child);
            }
        }
    }
TreeViewer.java 文件源码 项目:Scratch-ApuC 阅读 23 收藏 0 点赞 0 评论 0
public void setTree(Tree root) {
    if ( root!=null ) {
        boolean useIdentity = true; // compare node identity
        this.treeLayout =
            new TreeLayout<Tree>(new TreeLayoutAdaptor(root),
                                 new TreeViewer.VariableExtentProvide(this),
                                 new DefaultConfiguration<Tree>(gapBetweenLevels,
                                                                gapBetweenNodes),
                                 useIdentity);
        // Let the UI display this new AST.
        updatePreferredSize();
    }
    else {
        this.treeLayout = null;
        repaint();
    }
}
AntlrUtils.java 文件源码 项目:templates4j 阅读 31 收藏 0 点赞 0 评论 0
public static String getNodeText(Tree t, String[] ruleNames, String[] tokenNames) {
    if (ruleNames != null) {
        if (t instanceof RuleNode) {
            int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
            return ruleNames[ruleIndex];
        } else if (t instanceof ErrorNode) {
            return t.toString();
        } else if (t instanceof TerminalNode) {
            Token symbol = ((TerminalNode) t).getSymbol();
            if (symbol != null) {
                return "'" + symbol.getText() + "'";
            }
        }
    }
    // no recog for rule names
    Object payload = t.getPayload();
    if (payload instanceof Token) {
        return ((Token) payload).getText();
    }
    return t.getPayload().toString();
}
AltLabelTextProvider.java 文件源码 项目:intellij-plugin-v4 阅读 17 收藏 0 点赞 0 评论 0
@Override
public String getText(Tree node) {
    if ( node instanceof PreviewInterpreterRuleContext) {
        PreviewInterpreterRuleContext inode = (PreviewInterpreterRuleContext)node;
        Rule r = g.getRule(inode.getRuleIndex());
        String[] altLabels = getAltLabels(r);
        String name = r.name;
        int outerAltNum = inode.getOuterAltNum();
        if ( altLabels!=null ) {
            if ( outerAltNum>=0 && outerAltNum<altLabels.length ) {
                return name+":"+altLabels[outerAltNum];
            }
            else {
                return name;
            }
        }
        else if ( r.getOriginalNumberOfAlts()>1 ) {
            return name + ":" +outerAltNum;
        }
        else {
            return name; // don't display an alternative number if there's only one
        }
    }
    return Trees.getNodeText(node, Arrays.asList(parser.getRuleNames()));
}
JTreeViewer.java 文件源码 项目:intellij-plugin-v4 阅读 22 收藏 0 点赞 0 评论 0
private MutableTreeNode wrap(final Tree tree) {
    if (tree == null) {
        return null;
    }
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(tree) {
        @Override
        public String toString() {
            String name = treeTextProvider.getText((Tree) getUserObject());

            if (tree instanceof TerminalNode) {
                return name.equals("<EOF>") ? name : "\"" + name + "\"";
            }

            return name;
        }


    };

    for (int i = 0; i < tree.getChildCount(); i++) {
        root.add(wrap(tree.getChild(i)));
    }
    return root;
}
JTreeViewer.java 文件源码 项目:intellij-plugin-v4 阅读 17 收藏 0 点赞 0 评论 0
public void selectNodeAtOffset(int offset) {
    if (!scrollFromSource) {
        return;
    }
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot();
    Tree tree = (Tree) root.getUserObject();

    if (tree instanceof ParseTree) {
        DefaultMutableTreeNode atOffset = getNodeAtOffset(root, offset);

        if (atOffset != null) {
            TreePath path = new TreePath(atOffset.getPath());
            myTree.getSelectionModel().setSelectionPath(path);
            myTree.scrollPathToVisible(path);
        }
    }
}
ShowAmbigTreesDialog.java 文件源码 项目:intellij-plugin-v4 阅读 21 收藏 0 点赞 0 评论 0
public static void markFromRoots(final PreviewInterpreterRuleContext t, final PreviewInterpreterRuleContext u) {
    if ( t==null || u==null ) return;
    if ( !t.equals(u) ) return;
    t.reached = true;
    u.reached = true;
    int n = Math.min(t.getChildCount(), u.getChildCount());
    for (int i = 0; i<n; i++) { // for each leaf of t and u
        Tree tchild = t.getChild(i);
        Tree uchild = u.getChild(i);
        if ( !tchild.equals(uchild) ) {
            return; // don't consider other kids if ith doesn't match
        }
        if ( tchild instanceof PreviewInterpreterRuleContext &&
            uchild instanceof PreviewInterpreterRuleContext ) {
            markFromRoots((PreviewInterpreterRuleContext) tchild,
                          (PreviewInterpreterRuleContext) uchild);
        }
        else {
            return; // mismatched kids. should be caught above but...
        }
    }
}
ParsingUtils.java 文件源码 项目:intellij-plugin-v4 阅读 22 收藏 0 点赞 0 评论 0
/** Same as loadGrammar(fileName) except import vocab from existing lexer */
//  public static Grammar loadGrammar(Tool tool, String fileName, LexerGrammar lexerGrammar) {
//      GrammarRootAST grammarRootAST = parseGrammar(fileName);
//      if ( grammarRootAST==null ) return null;
//      final Grammar g = tool.createGrammar(grammarRootAST);
//      g.fileName = fileName;
//      if ( lexerGrammar!=null ) {
//            g.importVocab(lexerGrammar);
//        }
//      tool.process(g, false);
//      return g;
//  }

    public static Tree findOverriddenDecisionRoot(Tree ctx) {
        return Trees.findNodeSuchThat(ctx, new Predicate<Tree>() {
            @Override
            public boolean test(Tree t) {
                return t instanceof PreviewInterpreterRuleContext ?
                    ((PreviewInterpreterRuleContext) t).isDecisionOverrideRoot() :
                    false;
            }
        });
    }


问题


面经


文章

微信
公众号

扫码关注公众号