Examples of ATNState


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

   * some reason speed is suffering for you, you can turn off this
   * functionality by simply overriding this method as a blank { }.</p>
   */
  @Override
  public void sync(Parser recognizer) throws RecognitionException {
    ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
//    System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName());
    // If already recovering, don't try to sync
    if (inErrorRecoveryMode(recognizer)) {
      return;
    }

        TokenStream tokens = recognizer.getInputStream();
        int la = tokens.LA(1);

        // try cheaper subset first; might get lucky. seems to shave a wee bit off
        if ( recognizer.getATN().nextTokens(s).contains(la) || la==Token.EOF ) return;

    // Return but don't end recovery. only do that upon valid token match
    if (recognizer.isExpectedToken(la)) {
      return;
    }

    switch (s.getStateType()) {
    case ATNState.BLOCK_START:
    case ATNState.STAR_BLOCK_START:
    case ATNState.PLUS_BLOCK_START:
    case ATNState.STAR_LOOP_ENTRY:
      // report error and recover if possible
View Full Code Here

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

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

    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

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

  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

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

    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

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

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

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

  }

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

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

  }

  @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

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

    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

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

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