Package org.antlr.v4.runtime.misc

Examples of org.antlr.v4.runtime.misc.IntervalSet


//                 lastErrorIndex+", states="+lastErrorStates);
//      System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]);
      recognizer.consume();
    }
    lastErrorIndex = recognizer.getInputStream().index();
    if ( lastErrorStates==null ) lastErrorStates = new IntervalSet();
    lastErrorStates.add(recognizer.getState());
    IntervalSet followSet = getErrorRecoverySet(recognizer);
    consumeUntil(recognizer, followSet);
  }
View Full Code Here


    case ATNState.PLUS_LOOP_BACK:
    case ATNState.STAR_LOOP_BACK:
//      System.err.println("at loop back: "+s.getClass().getSimpleName());
      reportUnwantedToken(recognizer);
      IntervalSet expecting = recognizer.getExpectedTokens();
      IntervalSet whatFollowsLoopIterationOrRule =
        expecting.or(getErrorRecoverySet(recognizer));
      consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
      break;

    default:
View Full Code Here

    beginErrorCondition(recognizer);

    Token t = recognizer.getCurrentToken();
    String tokenName = getTokenErrorDisplay(t);
    IntervalSet expecting = getExpectedTokens(recognizer);
    String msg = "extraneous input "+tokenName+" expecting "+
      expecting.toString(recognizer.getVocabulary());
    recognizer.notifyErrorListeners(t, msg, null);
  }
View Full Code Here

    }

    beginErrorCondition(recognizer);

    Token t = recognizer.getCurrentToken();
    IntervalSet expecting = getExpectedTokens(recognizer);
    String msg = "missing "+expecting.toString(recognizer.getVocabulary())+
      " at "+getTokenErrorDisplay(t);

    recognizer.notifyErrorListeners(t, msg, null);
  }
View Full Code Here

    // 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);
      return true;
    }
    return false;
  }
View Full Code Here

   * {@code null}
   */
  @Nullable
  protected Token singleTokenDeletion(@NotNull Parser recognizer) {
    int nextTokenType = recognizer.getInputStream().LA(2);
    IntervalSet expecting = getExpectedTokens(recognizer);
    if ( expecting.contains(nextTokenType) ) {
      reportUnwantedToken(recognizer);
      /*
      System.err.println("recoverFromMismatchedToken deleting "+
                 ((TokenStream)recognizer.getInputStream()).LT(1)+
                 " since "+((TokenStream)recognizer.getInputStream()).LT(2)+
View Full Code Here

   *  override this method to create the appropriate tokens.
   */
  @NotNull
  protected Token getMissingSymbol(@NotNull Parser recognizer) {
    Token currentSymbol = recognizer.getCurrentToken();
    IntervalSet expecting = getExpectedTokens(recognizer);
    int expectedTokenType = expecting.getMinElement(); // get any element
    String tokenText;
    if ( expectedTokenType== Token.EOF ) tokenText = "<missing EOF>";
    else tokenText = "<missing "+recognizer.getVocabulary().getDisplayName(expectedTokenType)+">";
    Token current = currentSymbol;
    Token lookback = recognizer.getInputStream().LT(-1);
View Full Code Here

   */
  @NotNull
  protected IntervalSet getErrorRecoverySet(@NotNull Parser recognizer) {
    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);
//    System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
View Full Code Here

        result.add(config, mergeCache);
        continue;
      }

      if (lookToEndOfRule && config.state.onlyHasEpsilonTransitions()) {
        IntervalSet nextTokens = atn.nextTokens(config.state);
        if (nextTokens.contains(Token.EPSILON)) {
          ATNState endOfRuleState = atn.ruleToStopState[config.state.ruleIndex];
          result.add(new ATNConfig(config, endOfRuleState), mergeCache);
        }
      }
    }
View Full Code Here

    }
    return ATN.INVALID_ALT_NUMBER;
  }

  protected int getAltThatFinishedDecisionEntryRule(ATNConfigSet configs) {
    IntervalSet alts = new IntervalSet();
    for (ATNConfig c : configs) {
      if ( c.getOuterContextDepth()>0 || (c.state instanceof RuleStopState && c.context.hasEmptyPath()) ) {
        alts.add(c.alt);
      }
    }
    if ( alts.size()==0 ) return ATN.INVALID_ALT_NUMBER;
    return alts.getMinElement();
  }
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.misc.IntervalSet

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.