Examples of AltAST


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

//    System.out.println("setAltAssoc: op " + alt + ": " + t.getText()+", assoc="+assoc);
  }

  @Override
  public void binaryAlt(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

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

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

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

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

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

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

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

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

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

      // 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);
View Full Code Here

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

    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

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

   * </pre>
   */
  public void setAltASTPointers(LeftRecursiveRule r, RuleAST t) {
//    System.out.println("RULE: "+t.toStringTree());
    BlockAST ruleBlk = (BlockAST)t.getFirstChildWithType(ANTLRParser.BLOCK);
    AltAST mainAlt = (AltAST)ruleBlk.getChild(0);
    BlockAST primaryBlk = (BlockAST)mainAlt.getChild(0);
    BlockAST opsBlk = (BlockAST)mainAlt.getChild(1).getChild(0); // (* BLOCK ...)
    for (int i = 0; i < r.recPrimaryAlts.size(); i++) {
      LeftRecursiveRuleAltInfo altInfo = r.recPrimaryAlts.get(i);
      altInfo.altAST = (AltAST)primaryBlk.getChild(i);
      altInfo.altAST.leftRecursiveAltInfo = altInfo;
      altInfo.originalAltAST.leftRecursiveAltInfo = altInfo;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.