Package org.antlr.v4.runtime.atn

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


   * {@code (A|B)*} is not the same thing as {@code (A|B|)+}.
   */
  @NotNull
  @Override
  public Handle star(@NotNull GrammarAST starAST, @NotNull Handle elem) {
    StarBlockStartState blkStart = (StarBlockStartState)elem.left;
    BlockEndState blkEnd = (BlockEndState)elem.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    StarLoopEntryState entry = newState(StarLoopEntryState.class, starAST);
    entry.nonGreedy = !((QuantifierAST)starAST).isGreedy();
View Full Code Here


  public Handle star(@NotNull GrammarAST starAST, @NotNull Handle elem) {
    StarBlockStartState blkStart = (StarBlockStartState)elem.left;
    BlockEndState blkEnd = (BlockEndState)elem.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    StarLoopEntryState entry = newState(StarLoopEntryState.class, starAST);
    entry.nonGreedy = !((QuantifierAST)starAST).isGreedy();
    atn.defineDecisionState(entry);
    LoopEndState end = newState(LoopEndState.class, starAST);
    StarLoopbackState loop = newState(StarLoopbackState.class, starAST);
    entry.loopBackState = loop;
View Full Code Here

    StarLoopEntryState entry = newState(StarLoopEntryState.class, starAST);
    entry.nonGreedy = !((QuantifierAST)starAST).isGreedy();
    atn.defineDecisionState(entry);
    LoopEndState end = newState(LoopEndState.class, starAST);
    StarLoopbackState loop = newState(StarLoopbackState.class, starAST);
    entry.loopBackState = loop;
    end.loopBackState = loop;

    BlockAST blkAST = (BlockAST)starAST.getChild(0);
    if ( ((QuantifierAST)starAST).isGreedy() ) {
View Full Code Here

    int n = els.size();
    for (int i = 0; i < n - 1; i++) {  // hook up elements (visit all but last)
      Handle el = els.get(i);
      // if el is of form o-x->o for x in {rule, action, pred, token, ...}
      // and not last in alt
            Transition tr = null;
            if ( el.left.getNumberOfTransitions()==1 ) tr = el.left.transition(0);
            boolean isRuleTrans = tr instanceof RuleTransition;
            if ( el.left.getStateType() == ATNState.BASIC &&
        el.right.getStateType()== ATNState.BASIC &&
        tr!=null && (isRuleTrans && ((RuleTransition)tr).followState == el.right || tr.target == el.right) )
View Full Code Here

    ATNState eofTarget = newState(null); // one unique EOF target for all rules
    for (Rule r : g.rules.values()) {
      ATNState stop = atn.ruleToStopState[r.index];
      if ( stop.getNumberOfTransitions()>0 ) continue;
      n++;
      Transition t = new AtomTransition(eofTarget, Token.EOF);
      stop.addTransition(t);
    }
    return n;
  }
View Full Code Here

    visited.add(s.stateNumber);

    visitState(s);
    int n = s.getNumberOfTransitions();
    for (int i=0; i<n; i++) {
      Transition t = s.transition(i);
      visit_(t.target, visited);
    }
  }
View Full Code Here

    //System.out.println("visit "+s);
    int n = s.getNumberOfTransitions();
    boolean stateReachesStopState = false;
    for (int i=0; i<n; i++) {
      Transition t = s.transition(i);
      if ( t instanceof RuleTransition ) {
        RuleTransition rt = (RuleTransition) t;
        Rule r = g.getRule(rt.ruleIndex);
        if ( rulesVisitedPerRuleCheck.contains((RuleStartState)t.target) ) {
          addRulesToCycle(enclosingRule, r);
        }
        else {
          // must visit if not already visited; mark target, pop when done
          rulesVisitedPerRuleCheck.add((RuleStartState)t.target);
          // send new visitedStates set per rule invocation
          boolean nullable = check(r, t.target, new HashSet<ATNState>());
          // we're back from visiting that rule
          rulesVisitedPerRuleCheck.remove((RuleStartState)t.target);
          if ( nullable ) {
            stateReachesStopState |= check(enclosingRule, rt.followState, visitedStates);
          }
        }
      }
      else if ( t.isEpsilon() ) {
        stateReachesStopState |= check(enclosingRule, t.target, visitedStates);
      }
      // else ignore non-epsilon transitions
    }
    return stateReachesStopState;
View Full Code Here

    }
    else {
      edge = 1;
    }

    Transition transition = p.transition(edge - 1);
    switch (transition.getSerializationType()) {
    case Transition.EPSILON:
      if (pushRecursionContextStates.get(p.stateNumber) && !(transition.target instanceof LoopEndState)) {
        InterpreterRuleContext ctx = new InterpreterRuleContext(_parentContextStack.peek().a, _parentContextStack.peek().b, _ctx.getRuleIndex());
        pushNewRecursionContext(ctx, atn.ruleToStartState[p.ruleIndex].stateNumber, _ctx.getRuleIndex());
      }
      break;

    case Transition.ATOM:
      match(((AtomTransition)transition).label);
      break;

    case Transition.RANGE:
    case Transition.SET:
    case Transition.NOT_SET:
      if (!transition.matches(_input.LA(1), Token.MIN_USER_TOKEN_TYPE, 65535)) {
        _errHandler.recoverInline(this);
      }
      matchWildcard();
      break;
View Full Code Here

    }
    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

      }
      if (q.getStateType() == ATNState.BASIC) {
        // we have p-x->q for x in {rule, action, pred, token, ...}
        // if edge out of q is single epsilon to block end
        // we can strip epsilon p-x->q-eps->r
        Transition trans = q.transition(0);
        if (q.getNumberOfTransitions() == 1 && trans instanceof EpsilonTransition) {
          ATNState r = trans.target;
          if (r instanceof BlockEndState || r instanceof PlusLoopbackState || r instanceof StarLoopbackState) {
            // skip over q
            if (p.transition(0) instanceof RuleTransition) {
View Full Code Here

TOP

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

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.