Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.ParserRuleContext


//    lexer.setTokenFactory(factory);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
   
    MsonParser parser = new MsonParser(tokens);
//    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
View Full Code Here


    ClassUtils cu = new ClassUtils();
    setup(cu);
    registry.clearForType(JavaCompletionTypes.CUSTOM_TYPE);
    registry.clearForType(JavaCompletionTypes.FIELD);
    registry.clearForType(JavaCompletionTypes.NAME);
    Lexer lexer = new JavaLexer(new ANTLRInputStream(txt));
    CommonTokenStream tokens = new CommonTokenStream(lexer);

    // Create a parser that reads from the scanner
    JavaParser parser = new JavaParser(tokens);
    parser.removeErrorListeners();
View Full Code Here

    // Create a parser that reads from the scanner
    JavaParser parser = new JavaParser(tokens);
    parser.removeErrorListeners();
   
    // start parsing at the compilationUnit rule
    ParserRuleContext t = parser.compilationUnit();
    ParseTreeWalker walker = new ParseTreeWalker();
    List<AutocompleteCandidate> q = new ArrayList<AutocompleteCandidate>();
         
    ImportDeclarationCompletion extractor = new ImportDeclarationCompletion(txt,cur,registry,cps,cu);
    NameBuilder extractor2 = new NameBuilder(registry,cu );
View Full Code Here

    isKeywords = false;
  }

  @Override
  public void enterPackage(@NotNull PackageContext ctx) {
    ParserRuleContext prc = ctx.getParent();
    if (!(prc instanceof DomainArrayContext)) {
      return;
    }
    DomainArrayContext dac = (DomainArrayContext) prc;
    DomainHeaderContext dhctx = (DomainHeaderContext) dac.getChild(0);
View Full Code Here

      parser.setInputStream(tokens);
      Rule r = g.rules.get(startRule);
      if ( r==null ) {
        return parser.getParseInfo().getDecisionInfo();
      }
      ParserRuleContext t = parser.parse(r.index);
//      try {
//        Utils.waitForClose(t.inspect(parser).get());
//      }
//      catch (Exception e) {
//        e.printStackTrace();
View Full Code Here

      parser.setTokenStream(tokens);
      parser.setTrace(trace);

      try {
        Method startRule = parserClass.getMethod(startRuleName);
        ParserRuleContext tree = (ParserRuleContext)startRule.invoke(parser, (Object[])null);

        if ( printTree ) {
          System.out.println(tree.toStringTree(parser));
        }
        if ( gui ) {
          tree.inspect(parser);
        }
        if ( psFile!=null ) {
          tree.save(parser, psFile); // Generate postscript
        }
      }
      catch (NoSuchMethodException nsme) {
        System.err.println("No method for rule "+startRuleName+" or it has arguments");
      }
View Full Code Here

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

   * {@link ParseTreeListener#enterEveryRule} and a
   * {@link RuleContext}-specific event. First we trigger the generic and then
   * the rule specific. We to them in reverse order upon finishing the node.
   */
    protected void enterRule(ParseTreeListener listener, RuleNode r) {
    ParserRuleContext ctx = (ParserRuleContext)r.getRuleContext();
    listener.enterEveryRule(ctx);
    ctx.enterRule(listener);
    }
View Full Code Here

    listener.enterEveryRule(ctx);
    ctx.enterRule(listener);
    }

    protected void exitRule(ParseTreeListener listener, RuleNode r) {
    ParserRuleContext ctx = (ParserRuleContext)r.getRuleContext();
    ctx.exitRule(listener);
    listener.exitEveryRule(ctx);
    }
View Full Code Here

      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;
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.