Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.ParserRuleContext


      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


                    } else {
                        trimLeft = prev instanceof DirectiveContext;
                        if (trimLeft) {
                            // inline directive, 对于一个内联的 #if, #for 指令,后面有要求保留一个 NewLine
                            // @see https://github.com/subchen/jetbrick-template/issues/25
                            ParserRuleContext directive = (ParserRuleContext) ((DirectiveContext) prev).getChild(0);
                            if (directive instanceof If_directiveContext || directive instanceof For_directiveContext) {
                                if (directive.getStart().getLine() == directive.getStop().getLine()) {
                                    keepLeftNewLine = true; // 保留一个 NewLine
                                }
                            }
                        }
                    }
View Full Code Here

    }

    // 检验 ctx 必须在 #for 里面, 但不能在 for-else 里面
    private void assert_inside_of_for_directive(ParserRuleContext ctx, String name) {
        // 还有一种方法,直接看 forStack 是否为空就可以了
        ParserRuleContext p = ctx.getParent();
        while (p != null) {
            if (p instanceof For_directiveContext) {
                return;
            }
            if (p instanceof Else_directiveContext) {
                // 跳过可能的  for-else 的情况, 继续向上查找
                // 当然如果时候 if-else 的情况, 也可以跳过这个 #if,没有问题
                p = p.getParent();
            }
            p = p.getParent();
        }
        throw reportError(name + " cannot be used outside of a #for directive", ctx);
    }
View Full Code Here

    for (GrammarAST t : terminals) {
      int ttype = g.getTokenType(t.getText());
      set.add(ttype);
    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
      left.addTransition(new SetTransition(right, set));
    }
    associatedAST.atnState = left;
View Full Code Here

        BlockStartState star = newState(StarBlockStartState.class, ebnfRoot);
        if ( alts.size()>1 ) atn.defineDecisionState(star);
        h = makeBlock(star, blkAST, alts);
        return star(ebnfRoot, h);
      case ANTLRParser.POSITIVE_CLOSURE :
        PlusBlockStartState plus = newState(PlusBlockStartState.class, ebnfRoot);
        if ( alts.size()>1 ) atn.defineDecisionState(plus);
        h = makeBlock(plus, blkAST, alts);
        return plus(ebnfRoot, h);
    }
    return null;
View Full Code Here

   * start.
   */
  @NotNull
  @Override
  public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) {
    PlusBlockStartState blkStart = (PlusBlockStartState)blk.left;
    BlockEndState blkEnd = (BlockEndState)blk.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    PlusLoopbackState loop = newState(PlusLoopbackState.class, plusAST);
    loop.nonGreedy = !((QuantifierAST)plusAST).isGreedy();
View Full Code Here

  public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) {
    PlusBlockStartState blkStart = (PlusBlockStartState)blk.left;
    BlockEndState blkEnd = (BlockEndState)blk.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    PlusLoopbackState loop = newState(PlusLoopbackState.class, plusAST);
    loop.nonGreedy = !((QuantifierAST)plusAST).isGreedy();
    atn.defineDecisionState(loop);
    LoopEndState end = newState(LoopEndState.class, plusAST);
    blkStart.loopBackState = loop;
    end.loopBackState = loop;
View Full Code Here

    ATNState right = newState(pred);

    AbstractPredicateTransition p;
    if (pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
      int precedence = Integer.parseInt(pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
      p = new PrecedencePredicateTransition(right, precedence);
    }
    else {
      boolean isCtxDependent = UseDefAnalyzer.actionIsContextDependent(pred);
      p = new PredicateTransition(right, currentRule.index, g.sempreds.get(pred), isCtxDependent);
    }
View Full Code Here

      int precedence = Integer.parseInt(pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
      p = new PrecedencePredicateTransition(right, precedence);
    }
    else {
      boolean isCtxDependent = UseDefAnalyzer.actionIsContextDependent(pred);
      p = new PredicateTransition(right, currentRule.index, g.sempreds.get(pred), isCtxDependent);
    }

    left.addTransition(p);
    pred.atnState = left;
    return new Handle(left, right);
View Full Code Here

  /* start->ruleblock->end */
  @NotNull
  @Override
  public Handle rule(@NotNull GrammarAST ruleAST, @NotNull String name, @NotNull Handle blk) {
    Rule r = g.getRule(name);
    RuleStartState start = atn.ruleToStartState[r.index];
    epsilon(start, blk.left);
    RuleStopState stop = atn.ruleToStopState[r.index];
    epsilon(blk.right, stop);
    Handle h = new Handle(start, stop);
//    ATNPrinter ser = new ATNPrinter(g, h.left);
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.