Package org.antlr.v4.runtime.atn

Examples of org.antlr.v4.runtime.atn.ATNState


  protected boolean singleTokenInsertion(@NotNull Parser recognizer) {
    int currentSymbolType = recognizer.getInputStream().LA(1);
    // if current token is consistent with what could come after current
    // ATN state, then we know we're missing a token; error recovery
    // is free to conjure up and insert the missing token
    ATNState currentState = recognizer.getInterpreter().atn.states.get(recognizer.getState());
    ATNState next = currentState.transition(0).target;
    ATN atn = recognizer.getInterpreter().atn;
    IntervalSet expectingAtLL2 = atn.nextTokens(next, recognizer._ctx);
//    System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames()));
    if ( expectingAtLL2.contains(currentSymbolType) ) {
      reportMissingToken(recognizer);
View Full Code Here


    ATN atn = recognizer.getInterpreter().atn;
    RuleContext ctx = recognizer._ctx;
    IntervalSet recoverSet = new IntervalSet();
    while ( ctx!=null && ctx.invokingState>=0 ) {
      // compute what follows who invoked us
      ATNState invokingState = atn.states.get(ctx.invokingState);
      RuleTransition rt = (RuleTransition)invokingState.transition(0);
      IntervalSet follow = atn.nextTokens(rt.followState);
      recoverSet.addAll(follow);
      ctx = ctx.parent;
    }
        recoverSet.remove(Token.EPSILON);
View Full Code Here

  public FailedPredicateException(@NotNull Parser recognizer,
                  @Nullable String predicate,
                  @Nullable String message)
  {
    super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx);
    ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());

    AbstractPredicateTransition trans = (AbstractPredicateTransition)s.transition(0);
    if (trans instanceof PredicateTransition) {
      this.ruleIndex = ((PredicateTransition)trans).ruleIndex;
      this.predicateIndex = ((PredicateTransition)trans).predIndex;
    }
    else {
View Full Code Here

    else {
      enterRule(rootContext, startRuleStartState.stateNumber, startRuleIndex);
    }

    while ( true ) {
      ATNState p = getATNState();
      switch ( p.getStateType() ) {
      case ATNState.RULE_STOP :
        // pop; return from rule
        if ( _ctx.isEmpty() ) {
          if (startRuleStartState.isPrecedenceRule) {
            ParserRuleContext result = _ctx;
View Full Code Here

   */
    public boolean isExpectedToken(int symbol) {
//       return getInterpreter().atn.nextTokens(_ctx);
        ATN atn = getInterpreter().atn;
    ParserRuleContext ctx = _ctx;
        ATNState s = atn.states.get(getState());
        IntervalSet following = atn.nextTokens(s);
        if (following.contains(symbol)) {
            return true;
        }
//        System.out.println("following "+s+"="+following);
        if ( !following.contains(Token.EPSILON) ) return false;

        while ( ctx!=null && ctx.invokingState>=0 && following.contains(Token.EPSILON) ) {
            ATNState invokingState = atn.states.get(ctx.invokingState);
            RuleTransition rt = (RuleTransition)invokingState.transition(0);
            following = atn.nextTokens(rt.followState);
            if (following.contains(symbol)) {
                return true;
            }

View Full Code Here

  }

  @NotNull
    public IntervalSet getExpectedTokensWithinCurrentRule() {
        ATN atn = getInterpreter().atn;
        ATNState s = atn.states.get(getState());
       return atn.nextTokens(s);
     }
View Full Code Here

  }

  @Override
  public Handle action(String action) {
    if (action.trim().isEmpty()) {
      ATNState left = newState(null);
      ATNState right = newState(null);
      epsilon(left, right);
      return new Handle(left, right);
    }

    // define action AST for this rule as if we had found in grammar
View Full Code Here

    currentRule.defineActionInAlt(currentOuterAlt, ast);
    return action(ast);
  }

  protected Handle action(GrammarAST node, LexerAction lexerAction) {
    ATNState left = newState(node);
    ATNState right = newState(node);
    boolean isCtxDependent = false;
    int lexerActionIndex = getLexerActionIndex(lexerAction);
    ActionTransition a =
      new ActionTransition(right, currentRule.index, lexerActionIndex, isCtxDependent);
    left.addTransition(a);
View Full Code Here

    return action(cmdST.render());
  }

  @Override
  public Handle range(GrammarAST a, GrammarAST b) {
    ATNState left = newState(a);
    ATNState right = newState(b);
    int t1 = CharSupport.getCharValueFromGrammarCharLiteral(a.getText());
    int t2 = CharSupport.getCharValueFromGrammarCharLiteral(b.getText());
    left.addTransition(new  RangeTransition(right, t1, t2));
    a.atnState = left;
    b.atnState = left;
View Full Code Here

    return new Handle(left, right);
  }

  @Override
  public Handle set(GrammarAST associatedAST, List<GrammarAST> alts, boolean invert) {
    ATNState left = newState(associatedAST);
    ATNState right = newState(associatedAST);
    IntervalSet set = new IntervalSet();
    for (GrammarAST t : alts) {
      if ( t.getType()==ANTLRParser.RANGE ) {
        int a = CharSupport.getCharValueFromGrammarCharLiteral(t.getChild(0).getText());
        int b = CharSupport.getCharValueFromGrammarCharLiteral(t.getChild(1).getText());
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.atn.ATNState

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.