Package org.antlr.v4.tool.ast

Examples of org.antlr.v4.tool.ast.BlockAST


    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
      left.addTransition(new SetTransition(right, set));
    }
    associatedAST.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here


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

  @NotNull
  @Override
  public Handle wildcard(@NotNull GrammarAST node) {
    ATNState left = newState(node);
    ATNState right = newState(node);
    left.addTransition(new WildcardTransition(right));
    node.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here

    // ignore tokens from existing option subtrees like:
    //    (ELEMENT_OPTIONS (= assoc right))
    //
    // element options are added back according to the values in the map
    // returned by getOptions().
    IntervalSet ignore = new IntervalSet();
    List<GrammarAST> optionsSubTrees = t.getNodesWithType(ELEMENT_OPTIONS);
    for (GrammarAST sub : optionsSubTrees) {
      ignore.add(sub.getTokenStartIndex(), sub.getTokenStopIndex());
    }

    // Individual labels appear as RULE_REF or TOKEN_REF tokens in the tree,
    // but do not support the ELEMENT_OPTIONS syntax. Make sure to not try
    // and add the tokenIndex option when writing these tokens.
    IntervalSet noOptions = new IntervalSet();
    List<GrammarAST> labeledSubTrees = t.getNodesWithType(new IntervalSet(ASSIGN,PLUS_ASSIGN));
    for (GrammarAST sub : labeledSubTrees) {
      noOptions.add(sub.getChild(0).getTokenStartIndex());
    }

    StringBuilder buf = new StringBuilder();
    for (int i=tokenStartIndex; i<=tokenStopIndex; i++) {
      if ( ignore.contains(i) ) {
        continue;
      }

      Token tok = tokenStream.get(i);

      StringBuilder elementOptions = new StringBuilder();
      if (!noOptions.contains(i)) {
        GrammarAST node = t.getNodeWithTokenIndex(tok.getTokenIndex());
        if ( node!=null &&
           (tok.getType()==TOKEN_REF ||
            tok.getType()==STRING_LITERAL ||
            tok.getType()==RULE_REF) )
View Full Code Here

TOP

Related Classes of org.antlr.v4.tool.ast.BlockAST

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.