Package org.antlr.v4.tool.ast

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


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

  @Override
  public void prefixAlt(AltAST originalAltTree, int alt) {
    AltAST altTree = (AltAST)originalAltTree.dupTree();
    stripAltLabel(altTree);

    int nextPrec = precedence(alt);
    // rewrite e to be e_[prec]
    altTree = addPrecedenceArgToRules(altTree, nextPrec);
View Full Code Here


   * {@code (BLOCK (ALT .))} or {@code (BLOCK (ALT 'a') (ALT .))}.
   */
  public static boolean blockHasWildcardAlt(@NotNull GrammarAST block) {
    for (Object alt : block.getChildren()) {
      if ( !(alt instanceof AltAST) ) continue;
      AltAST altAST = (AltAST)alt;
      if ( altAST.getChildCount()==1 || (altAST.getChildCount() == 2 && altAST.getChild(0).getType() == ANTLRParser.ELEMENT_OPTIONS) ) {
        Tree e = altAST.getChild(altAST.getChildCount() - 1);
        if ( e.getType()==ANTLRParser.WILDCARD ) {
          return true;
        }
      }
    }
View Full Code Here

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

      }
      // create for each literal: (RULE <uniquename> (BLOCK (ALT <lit>))
      String rname = combinedGrammar.getStringLiteralLexerRuleName(lit);
      // can't use wizard; need special node types
      GrammarAST litRule = new RuleAST(ANTLRParser.RULE);
      BlockAST blk = new BlockAST(ANTLRParser.BLOCK);
      AltAST alt = new AltAST(ANTLRParser.ALT);
      TerminalAST slit = new TerminalAST(new CommonToken(ANTLRParser.STRING_LITERAL, lit));
      alt.addChild(slit);
      blk.addChild(alt);
      CommonToken idToken = new CommonToken(ANTLRParser.TOKEN_REF, rname);
      litRule.addChild(new TerminalAST(idToken));
      litRule.addChild(blk);
      lexerRulesRoot.insertChild(insertIndex, litRule);
//      lexerRulesRoot.getChildren().add(0, litRule);
View Full Code Here

  public PlusBlock(OutputModelFactory factory,
           GrammarAST plusRoot,
           List<CodeBlockForAlt> alts)
  {
    super(factory, plusRoot, alts);
    BlockAST blkAST = (BlockAST)plusRoot.getChild(0);
    PlusBlockStartState blkStart = (PlusBlockStartState)blkAST.atnState;
    PlusLoopbackState loop = blkStart.loopBackState;
    stateNumber = blkStart.loopBackState.stateNumber;
    blockStartStateNumber = blkStart.stateNumber;
    loopBackStateNumber = loop.stateNumber;
View Full Code Here

/** */
public class LL1PlusBlockSingleAlt extends LL1Loop {
  public LL1PlusBlockSingleAlt(OutputModelFactory factory, GrammarAST plusRoot, List<CodeBlockForAlt> alts) {
    super(factory, plusRoot, alts);

    BlockAST blkAST = (BlockAST)plusRoot.getChild(0);
    PlusBlockStartState blkStart = (PlusBlockStartState)blkAST.atnState;

    stateNumber = blkStart.loopBackState.stateNumber;
    blockStartStateNumber = blkStart.stateNumber;
    PlusBlockStartState plus = (PlusBlockStartState)blkAST.atnState;
View Full Code Here

  }

  @Override
  public void finishRule(RuleAST rule, GrammarAST ID, GrammarAST block) {
    if ( rule.isLexerRule() ) return;
    BlockAST blk = (BlockAST)rule.getFirstChildWithType(BLOCK);
    int nalts = blk.getChildCount();
    GrammarAST idAST = (GrammarAST)rule.getChild(0);
    for (int i=0; i< nalts; i++) {
      AltAST altAST = (AltAST)blk.getChild(i);
      if ( altAST.altLabel!=null ) {
        String altLabel = altAST.altLabel.getText();
        // first check that label doesn't conflict with a rule
        // label X or x can't be rule x.
        Rule r = ruleCollector.rules.get(Utils.decapitalize(altLabel));
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.