Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.ParserRuleContext


   * Return a list of all nodes starting at {@code t} as root that satisfy the
   * path. The root {@code /} is relative to the node passed to
   * {@link #evaluate}.
   */
  public Collection<ParseTree> evaluate(final ParseTree t) {
    ParserRuleContext dummyRoot = new ParserRuleContext();
    dummyRoot.children = Collections.singletonList(t); // don't set t's parent.

    Collection<ParseTree> work = Collections.<ParseTree>singleton(dummyRoot);

    int i = 0;
View Full Code Here


  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);
        }
      }
    }
View Full Code Here

    {
        if (aTree instanceof TerminalNode) {
            return ((TerminalNode) aTree).getSymbol().getLine() - 1;
        }
        else {
            final ParserRuleContext rule = (ParserRuleContext) aTree;
            return rule.start.getLine() - 1;
        }
    }
View Full Code Here

    {
        if (aTree instanceof TerminalNode) {
            return ((TerminalNode) aTree).getSymbol().getCharPositionInLine();
        }
        else {
            final ParserRuleContext rule = (ParserRuleContext) aTree;
            return rule.start.getCharPositionInLine();
        }
    }
View Full Code Here

  protected <T> void setNodeAttributes(T data, ParseTree startNode, ParseTree endNode) {
    if (data instanceof Node) {
      Node node = (Node) data;

      if (startNode instanceof ParserRuleContext) {
        ParserRuleContext context = (ParserRuleContext) startNode;
        node.setStartLine(context.getStart().getLine());
        node.setStartIndex(context.getStart().getStartIndex());
      } else if (startNode instanceof TerminalNode) {
        TerminalNode terminal = (TerminalNode) startNode;
        node.setStartLine(terminal.getSymbol().getLine());
        node.setStartIndex(terminal.getSymbol().getStartIndex());
      }

      if (endNode instanceof ParserRuleContext) {
        ParserRuleContext context = (ParserRuleContext) endNode;
        node.setEndLine(context.getStop().getLine());
        node.setEndIndex(context.getStop().getStopIndex());
      } else if (endNode instanceof TerminalNode) {
        TerminalNode terminal = (TerminalNode) endNode;
        node.setEndLine(terminal.getSymbol().getLine());
        node.setEndIndex(terminal.getSymbol().getStopIndex());
      }
View Full Code Here

        ASTUtil.dumpAST(writer, node, 0);
        return buf.toString();
    }

    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);
    }
View Full Code Here

            printer.print("NULL NODE");
        }
        else
        {
            if (node instanceof ParserRuleContext) {
                ParserRuleContext ctx = (ParserRuleContext) node;
                int ruleIndex = ctx.getRuleIndex();
                String ruleName = EsperEPL2GrammarParser.ruleNames[ruleIndex];
                printer.print(ruleName);
            }
            else {
                TerminalNode terminal = (TerminalNode) node;
View Full Code Here

  protected <T> void setNodeAttributes(T data, ParseTree startNode, ParseTree endNode) {
    if (data instanceof Node) {
      Node node = (Node) data;

      if (startNode instanceof ParserRuleContext) {
        ParserRuleContext context = (ParserRuleContext) startNode;
        node.setStartLine(context.getStart().getLine());
        node.setStartColumn(context.getStart().getCharPositionInLine());
      } else if (startNode instanceof TerminalNode) {
        TerminalNode terminal = (TerminalNode) startNode;
        node.setStartLine(terminal.getSymbol().getLine());
        node.setStartColumn(terminal.getSymbol().getCharPositionInLine());
      }

      if (endNode instanceof ParserRuleContext) {
        ParserRuleContext context = (ParserRuleContext) endNode;
        node.setEndLine(context.getStop().getLine());
        node.setEndColumn(context.getStop().getCharPositionInLine()
            + context.getStop().getText().length() - 1);
      } else if (endNode instanceof TerminalNode) {
        TerminalNode terminal = (TerminalNode) endNode;
        node.setEndLine(terminal.getSymbol().getLine());
        node.setEndColumn(terminal.getSymbol().getCharPositionInLine()
            + terminal.getSymbol().getText().length() - 1);
View Full Code Here

       * get parser
       */
      Parser parser = (Parser) parserConstructor.newInstance(tokens);
      parser.setErrorHandler(new BailErrorStrategy());
      final Method method = parserClass.getMethod(entryPoint);
      ParserRuleContext parserRuleContext = (ParserRuleContext) method.invoke(parser);
      /*
       * show the tree
       */
      if (showTree) {
         final String lispTree = Trees.toStringTree(parserRuleContext, parser);
View Full Code Here

      if ( diag ) parser.addErrorListener(new DiagnosticErrorListener());
      if ( bail ) parser.setErrorHandler(new BailErrorStrategy());
      if ( SLL ) parser.getInterpreter().setPredictionMode(PredictionMode.SLL);

      // start parsing at the compilationUnit rule
      ParserRuleContext t = parser.compilationUnit();
      if ( notree ) parser.setBuildParseTree(false);
      if ( gui ) t.inspect(parser);
      if ( printTree ) System.out.println(t.toStringTree(parser));
    }
    catch (Exception e) {
      System.err.println("parser exception: "+e);
      e.printStackTrace();   // so we can get stack trace
    }
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.ParserRuleContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.