Package org.antlr.v4.runtime.atn

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


  /** From label {@code A} build graph {@code o-A->o}. */
  @NotNull
  @Override
  public Handle tokenRef(@NotNull TerminalAST node) {
    ATNState left = newState(node);
    ATNState right = newState(node);
    int ttype = g.getTokenType(node.getText());
    left.addTransition(new AtomTransition(right, ttype));
    node.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here


   *  This also handles {@code ~A}, converted to {@code ~{A}} set.
     */
  @NotNull
  @Override
  public Handle set(@NotNull GrammarAST associatedAST, @NotNull List<GrammarAST> terminals, boolean invert) {
    ATNState left = newState(associatedAST);
    ATNState right = newState(associatedAST);
    IntervalSet set = new IntervalSet();
    for (GrammarAST t : terminals) {
      int ttype = g.getTokenType(t.getText());
      set.add(ttype);
    }
View Full Code Here

    if ( r==null ) {
      g.tool.errMgr.grammarError(ErrorType.INTERNAL_ERROR, g.fileName, node.getToken(), "Rule "+node.getText()+" undefined");
      return null;
    }
    RuleStartState start = atn.ruleToStartState[r.index];
    ATNState left = newState(node);
    ATNState right = newState(node);
    int precedence = 0;
    if (((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
      precedence = Integer.parseInt(((GrammarASTWithOptions)node).getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
    }
    RuleTransition call = new RuleTransition(start, r.index, precedence, right);
View Full Code Here

  /** From an empty alternative build {@code o-e->o}. */
  @NotNull
  @Override
  public Handle epsilon(@NotNull GrammarAST node) {
    ATNState left = newState(node);
    ATNState right = newState(node);
    epsilon(left, right);
    node.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here

   */
  @NotNull
  @Override
  public Handle sempred(@NotNull PredAST pred) {
    //System.out.println("sempred: "+ pred);
    ATNState left = newState(pred);
    ATNState right = newState(pred);

    AbstractPredicateTransition p;
    if (pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
      int precedence = Integer.parseInt(pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
      p = new PrecedencePredicateTransition(right, precedence);
View Full Code Here

   */
  @NotNull
  @Override
  public Handle action(@NotNull ActionAST action) {
    //System.out.println("action: "+action);
    ATNState left = newState(action);
    ATNState right = newState(action);
    ActionTransition a = new ActionTransition(right, currentRule.index);
    left.addTransition(a);
    action.atnState = left;
    return new Handle(left, right);
  }
View Full Code Here

   */
  @NotNull
  @Override
  public Handle optional(@NotNull GrammarAST optAST, @NotNull Handle blk) {
    BlockStartState blkStart = (BlockStartState)blk.left;
    ATNState blkEnd = blk.right;
    preventEpsilonOptionalBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    boolean greedy = ((QuantifierAST)optAST).isGreedy();
    blkStart.nonGreedy = !greedy;
    epsilon(blkStart, blk.right, !greedy);
View Full Code Here

  /** Build an atom with all possible values in its label. */
  @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

   *  not invoked by another rule (they can only be invoked from outside).
   *  These are the start rules.
     */
  public int addEOFTransitionToStartRules() {
    int n = 0;
    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

    throw new UnsupportedOperationException(message, cause);
  }

  @NotNull
  public ATNState newState(@Nullable GrammarAST node) {
    ATNState n = new BasicState();
    n.setRuleIndex(currentRule.index);
    atn.addState(n);
    return n;
  }
View Full Code Here

TOP

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

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.