Examples of ParseTree


Examples of org.antlr.v4.runtime.tree.ParseTree

          }
        }
      }
      if(arg0.getParent() instanceof ExpressionContext) {
        // we are the leftmost child of the expression
        ParseTree chld = arg0.getParent().getChild(arg0.getParent().getChildCount()-1);
        if(!chld.equals(arg0)) return;
        addQuery(classUtils.expandExpression(arg0.getParent().getText(), registry));
      }
    }
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

//    parser.setTokenFactory(factory);
    parser.addErrorListener(new DiagnosticErrorListener());
    parser.getInterpreter().setPredictionMode(
        PredictionMode.LL_EXACT_AMBIG_DETECTION);
    parser.setBuildParseTree(true);
    ParseTree tree = parser.mson();
    // show tree in text form
    // System.out.println(tree.toStringTree(parser));

    ParseTreeWalker walker = new ParseTreeWalker();
    SymbolTable symtab = new SymbolTable();
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

               String parserName, String lexerName)
    throws Exception
  {
    Pair<Parser, Lexer> pl = getParserAndLexer(input, parserName, lexerName);
    Parser parser = pl.a;
    ParseTree tree = execStartRule(startRuleName, parser);

    IllegalArgumentException e = null;
    try {
      XPath.findAll(tree, path, parser);
    }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

                     String parserName, String lexerName)
    throws Exception
  {
    Pair<Parser, Lexer> pl = getParserAndLexer(input, parserName, lexerName);
    Parser parser = pl.a;
    ParseTree tree = execStartRule(startRuleName, parser);

    List<String> nodes = new ArrayList<String>();
    for (ParseTree t : XPath.findAll(tree, xpath, parser) ) {
      if ( t instanceof RuleContext) {
        RuleContext r = (RuleContext)t;
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

          String parseTree)
  {
    LexerInterpreter lexEngine = lg.createLexerInterpreter(new ANTLRInputStream(input));
    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
    ParserInterpreter parser = g.createParserInterpreter(tokens);
    ParseTree t = parser.parse(g.rules.get(startRule).index);
    System.out.println("parse tree: "+t.toStringTree(parser));
    assertEquals(parseTree, t.toStringTree(parser));
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

    catch (NoSuchMethodException nsme) {
      // try with int _p arg for recursive func
      startRule = parser.getClass().getMethod(startRuleName, int.class);
      args = new Integer[] {0};
    }
    ParseTree result = (ParseTree)startRule.invoke(parser, args);
//    System.out.println("parse tree = "+result.toStringTree(parser));
    return result;
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

  /** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a
   *  compiled pattern instead of a string representation of a tree pattern.
   */
  public boolean matches(ParseTree tree, ParseTreePattern pattern) {
    MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>();
    ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels);
    return mismatchedNode == null;
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

   * string representation of a tree pattern.
   */
  @NotNull
  public ParseTreeMatch match(@NotNull ParseTree tree, @NotNull ParseTreePattern pattern) {
    MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>();
    ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels);
    return new ParseTreeMatch(tree, pattern, labels, mismatchedNode);
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

                                 parser.getVocabulary(),
                                 Arrays.asList(parser.getRuleNames()),
                                 parser.getATNWithBypassAlts(),
                                 tokens);

    ParseTree tree = null;
    try {
      parserInterp.setErrorHandler(new BailErrorStrategy());
      tree = parserInterp.parse(patternRuleIndex);
//      System.out.println("pattern tree = "+tree.toStringTree(parserInterp));
    }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.ParseTree

    // x and <ID>, x and y, or x and x; or could be mismatched types
    if ( tree instanceof TerminalNode && patternTree instanceof TerminalNode ) {
      TerminalNode t1 = (TerminalNode)tree;
      TerminalNode t2 = (TerminalNode)patternTree;
      ParseTree mismatchedNode = null;
      // both are tokens and they have same type
      if ( t1.getSymbol().getType() == t2.getSymbol().getType() ) {
        if ( t2.getSymbol() instanceof TokenTagToken ) { // x and <ID>
          TokenTagToken tokenTagToken = (TokenTagToken)t2.getSymbol();
          // track label->list-of-nodes for both token name and label (if any)
          labels.map(tokenTagToken.getTokenName(), tree);
          if ( tokenTagToken.getLabel()!=null ) {
            labels.map(tokenTagToken.getLabel(), tree);
          }
        }
        else if ( t1.getText().equals(t2.getText()) ) {
          // x and x
        }
        else {
          // x and y
          if (mismatchedNode == null) {
            mismatchedNode = t1;
          }
        }
      }
      else {
        if (mismatchedNode == null) {
          mismatchedNode = t1;
        }
      }

      return mismatchedNode;
    }

    if ( tree instanceof ParserRuleContext && patternTree instanceof ParserRuleContext ) {
      ParserRuleContext r1 = (ParserRuleContext)tree;
      ParserRuleContext r2 = (ParserRuleContext)patternTree;
      ParseTree mismatchedNode = null;
      // (expr ...) and <expr>
      RuleTagToken ruleTagToken = getRuleTagToken(r2);
      if ( ruleTagToken!=null ) {
        ParseTreeMatch m = null;
        if ( r1.getRuleContext().getRuleIndex() == r2.getRuleContext().getRuleIndex() ) {
          // track label->list-of-nodes for both rule name and label (if any)
          labels.map(ruleTagToken.getRuleName(), tree);
          if ( ruleTagToken.getLabel()!=null ) {
            labels.map(ruleTagToken.getLabel(), tree);
          }
        }
        else {
          if (mismatchedNode == null) {
            mismatchedNode = r1;
          }
        }

        return mismatchedNode;
      }

      // (expr ...) and (expr ...)
      if ( r1.getChildCount()!=r2.getChildCount() ) {
        if (mismatchedNode == null) {
          mismatchedNode = r1;
        }

        return mismatchedNode;
      }

      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;
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.