Package org.antlr.v4.tool

Examples of org.antlr.v4.tool.Rule


  @Override
  public void discoverLexerRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers,
                  GrammarAST block)
  {
    int numAlts = block.getChildCount();
    Rule r = new Rule(g, ID.getText(), rule, numAlts);
    r.mode = currentModeName;
    if ( !modifiers.isEmpty() ) r.modifiers = modifiers;
    rules.put(r.name, r);
  }
View Full Code Here


  }

  void identifyStartRules(SymbolCollector collector) {
    for (GrammarAST ref : collector.rulerefs) {
      String ruleName = ref.getText();
      Rule r = g.getRule(ruleName);
      if ( r!=null ) r.isStartRule = false;
    }
  }
View Full Code Here

      startState = startState.transition(0).target;
    }

    DOTGenerator dot = new DOTGenerator(g);
    System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule("a").index]));
    Rule r = g.getRule("e");
    if ( r!=null ) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));

    int result = interp.matchATN(input, startState);
    assertEquals(expected, result);
  }
View Full Code Here

    CommonTokenStream tokens = new CommonTokenStream(lexEngine);

    ParserInterpreter parser = g.createParserInterpreter(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(printError);
    Rule start = g.getRule(startRule);
    ParseTree tree = parser.parse(start.index);

    // this loop works around a bug in ANTLR 4.2
    // https://github.com/antlr/antlr4/issues/461
    // https://github.com/antlr/intellij-plugin-v4/issues/23
View Full Code Here

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

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

TOP

Related Classes of org.antlr.v4.tool.Rule

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.