Package org.antlr.v4.runtime.atn

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


    //System.out.println("prefixAlt " + alt + ": " + altText + ", rewrite=" + rewriteText);
  }

  @Override
  public void suffixAlt(AltAST originalAltTree, int alt) {
    AltAST altTree = (AltAST)originalAltTree.dupTree();
    String altLabel = altTree.altLabel!=null ? altTree.altLabel.getText() : null;

    String label = null;
    boolean isListLabel = false;
    GrammarAST lrlabel = stripLeftRecursion(altTree);
View Full Code Here


//    System.out.println("suffixAlt " + alt + ": " + altText + ", rewrite=" + rewriteText);
  }

  @Override
  public void otherAlt(AltAST originalAltTree, int alt) {
    AltAST altTree = (AltAST)originalAltTree.dupTree();
    stripAltLabel(altTree);
    String altText = text(altTree);
    String altLabel = altTree.altLabel!=null ? altTree.altLabel.getText() : null;
    LeftRecursiveRuleAltInfo a =
      new LeftRecursiveRuleAltInfo(alt, altText, null, altLabel, false, originalAltTree);
View Full Code Here

    end.loopBackState = loop;

    plusAST.atnState = loop;
    epsilon(blkEnd, loop);    // blk can see loop back

    BlockAST blkAST = (BlockAST)plusAST.getChild(0);
    if ( ((QuantifierAST)plusAST).isGreedy() ) {
      if (expectNonGreedy(blkAST)) {
        g.tool.errMgr.grammarError(ErrorType.EXPECTED_NON_GREEDY_WILDCARD_BLOCK, g.fileName, plusAST.getToken(), plusAST.getToken().getText());
      }
View Full Code Here

    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() ) {
      if (expectNonGreedy(blkAST)) {
        g.tool.errMgr.grammarError(ErrorType.EXPECTED_NON_GREEDY_WILDCARD_BLOCK, g.fileName, starAST.getToken(), starAST.getToken().getText());
      }
View Full Code Here

    AltAST altTree = (AltAST)originalAltTree.dupTree();
    String altLabel = altTree.altLabel!=null ? altTree.altLabel.getText() : null;

    String label = null;
    boolean isListLabel = false;
    GrammarAST lrlabel = stripLeftRecursion(altTree);
    if ( lrlabel!=null ) {
      label = lrlabel.getText();
      isListLabel = lrlabel.getParent().getType() == PLUS_ASSIGN;
      leftRecursiveRuleRefLabels.add(new Pair<GrammarAST,String>(lrlabel,altLabel));
    }

    stripAltLabel(altTree);
View Full Code Here

    AltAST altTree = (AltAST)originalAltTree.dupTree();
    String altLabel = altTree.altLabel!=null ? altTree.altLabel.getText() : null;

    String label = null;
    boolean isListLabel = false;
    GrammarAST lrlabel = stripLeftRecursion(altTree);
    if ( lrlabel!=null ) {
      label = lrlabel.getText();
      isListLabel = lrlabel.getParent().getType() == PLUS_ASSIGN;
      leftRecursiveRuleRefLabels.add(new Pair<GrammarAST,String>(lrlabel,altLabel));
    }
    stripAltLabel(altTree);
    String altText = text(altTree);
    altText = altText.trim();
View Full Code Here

    for (GrammarAST x : outerAltRuleRefs) {
      RuleRefAST rref = (RuleRefAST)x;
      boolean recursive = rref.getText().equals(ruleName);
      boolean rightmost = rref == outerAltRuleRefs.get(outerAltRuleRefs.size()-1);
      if ( recursive && rightmost ) {
        GrammarAST dummyValueNode = new GrammarAST(new CommonToken(ANTLRParser.INT, ""+prec));
        rref.setOption(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME, dummyValueNode);
      }
    }
    return t;
  }
View Full Code Here

   * Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*)))
   * Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))
   */
  public static boolean hasImmediateRecursiveRuleRefs(GrammarAST t, String ruleName) {
    if ( t==null ) return false;
    GrammarAST blk = (GrammarAST)t.getFirstChildWithType(BLOCK);
    if ( blk==null ) return false;
    int n = blk.getChildren().size();
    for (int i = 0; i < n; i++) {
      GrammarAST alt = (GrammarAST)blk.getChildren().get(i);
      Tree first = alt.getChild(0);
      if ( first==null ) continue;
      if (first.getType() == ELEMENT_OPTIONS) {
        first = alt.getChild(1);
        if (first == null) {
          continue;
        }
      }
      if ( first.getType()==RULE_REF && first.getText().equals(ruleName) ) return true;
View Full Code Here

    createRuleStartAndStopATNStates();

    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    for (Rule r : rules) {
      // find rule's block
      GrammarAST blk = (GrammarAST)r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
      CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
      ATNBuilder b = new ATNBuilder(nodes,this);
      try {
        setCurrentRuleName(r.name);
        Handle h = b.ruleBlock(null);
View Full Code Here

  // TODO: this strips the tree properly, but since text()
  // uses the start of stop token index and gets text from that
  // ineffectively ignores this routine.
  public GrammarAST stripLeftRecursion(GrammarAST altAST) {
    GrammarAST lrlabel=null;
    GrammarAST first = (GrammarAST)altAST.getChild(0);
    int leftRecurRuleIndex = 0;
    if ( first.getType() == ELEMENT_OPTIONS ) {
      first = (GrammarAST)altAST.getChild(1);
      leftRecurRuleIndex = 1;
    }
    Tree rref = first.getChild(1); // if label=rule
    if ( (first.getType()==RULE_REF && first.getText().equals(ruleName)) ||
       (rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName)) )
    {
      if ( first.getType()==ASSIGN || first.getType()==PLUS_ASSIGN ) lrlabel = (GrammarAST)first.getChild(0);
      // remove rule ref (first child unless options present)
      altAST.deleteChild(leftRecurRuleIndex);
      // reset index so it prints properly (sets token range of
      // ALT to start to right of left recur rule we deleted)
      GrammarAST newFirstChild = (GrammarAST)altAST.getChild(leftRecurRuleIndex);
      altAST.setTokenStartIndex(newFirstChild.getTokenStartIndex());
    }
    return lrlabel;
  }
View Full Code Here

TOP

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

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.