Examples of IntervalSet


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

    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

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

    }

    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

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

    // 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

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

   * {@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

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

   *  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

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

   */
  @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

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

        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

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

    }
    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

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

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

            ctx = (ParserRuleContext)ctx.parent;
        }

        if ( following.contains(Token.EPSILON) && symbol == Token.EOF ) {
            return true;
        }

        return false;
    }
View Full Code Here

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

  @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());
        set.add(a, b);
      }
      else if ( t.getType()==ANTLRParser.LEXER_CHAR_SET ) {
        set.addAll(getSetFromCharSetLiteral(t));
      }
      else if ( t.getType()==ANTLRParser.STRING_LITERAL ) {
        int c = CharSupport.getCharValueFromGrammarCharLiteral(t.getText());
        if ( c != -1 ) {
          set.add(c);
        }
        else {
          g.tool.errMgr.grammarError(ErrorType.INVALID_LITERAL_IN_LEXER_SET,
                         g.fileName, t.getToken(), t.getText());

        }
      }
      else if ( t.getType()==ANTLRParser.TOKEN_REF ) {
        g.tool.errMgr.grammarError(ErrorType.UNSUPPORTED_REFERENCE_IN_LEXER_SET,
                       g.fileName, t.getToken(), t.getText());
      }
    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
      Transition transition;
      if (set.getIntervals().size() == 1) {
        Interval interval = set.getIntervals().get(0);
        transition = new RangeTransition(right, interval.a, interval.b);
      } else {
        transition = new SetTransition(right, set);
      }
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.