Examples of CodeGenerator


Examples of org.antlr.v4.codegen.CodeGenerator

    }
    else {
      superClass = null;
    }

    CodeGenerator gen = factory.getGenerator();
    tokenNames = translateTokenStringsToTarget(g.getTokenDisplayNames(), gen);
    literalNames = translateTokenStringsToTarget(g.getTokenLiteralNames(), gen);
    symbolicNames = translateTokenStringsToTarget(g.getTokenSymbolicNames(), gen);
  }
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

public class LeftRecursiveRuleFunction extends RuleFunction {
  public LeftRecursiveRuleFunction(OutputModelFactory factory, LeftRecursiveRule r) {
    super(factory, r);

    CodeGenerator gen = factory.getGenerator();
    // Since we delete x=lr, we have to manually add decls for all labels
    // on left-recur refs to proper structs
    for (Pair<GrammarAST,String> pair : r.leftRecursiveRuleRefLabels) {
      GrammarAST idAST = pair.a;
      String altLabel = pair.b;
      String label = idAST.getText();
      GrammarAST rrefAST = (GrammarAST)idAST.getParent().getChild(1);
      if ( rrefAST.getType() == ANTLRParser.RULE_REF ) {
        Rule targetRule = factory.getGrammar().getRule(rrefAST.getText());
        String ctxName = gen.getTarget().getRuleFunctionContextStructName(targetRule);
        RuleContextDecl d;
        if (idAST.getParent().getType() == ANTLRParser.ASSIGN) {
          d = new RuleContextDecl(factory, label, ctxName);
        }
        else {
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

    assert ast.atnState != null
      && ast.atnState.getNumberOfTransitions() == 1
      && ast.atnState.transition(0) instanceof AbstractPredicateTransition;

    GrammarAST failNode = ast.getOptionAST("fail");
    CodeGenerator gen = factory.getGenerator();
    predicate = ast.getText();
    if (predicate.startsWith("{") && predicate.endsWith("}?")) {
      predicate = predicate.substring(1, predicate.length() - 2);
    }
    predicate = gen.getTarget().getTargetStringLiteralFromString(predicate);

    if ( failNode==null ) return;

    if ( failNode instanceof ActionAST ) {
      ActionAST failActionNode = (ActionAST)failNode;
      RuleFunction rf = factory.getCurrentRuleFunction();
      failChunks = ActionTranslator.translateAction(factory, rf,
                              failActionNode.token,
                              failActionNode);
    }
    else {
      msg = gen.getTarget().getTargetStringLiteralFromANTLRStringLiteral(gen,
                                      failNode.getText(),
                                      true);
    }
  }
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

      ATNFactory factory = new ParserATNFactory(g);
      if ( g.isLexer() ) factory = new LexerATNFactory((LexerGrammar)g);
      g.atn = factory.createATN();

      CodeGenerator gen = new CodeGenerator(g);
      ST outputFileST = gen.generateParser();
      String output = outputFileST.render();
      //System.out.println(output);
      String b = "#" + actionName + "#";
      int start = output.indexOf(b);
      String e = "#end-" + actionName + "#";
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

    public BuildDependencyGenerator(Tool tool, Grammar g) {
        this.tool = tool;
    this.g = g;
    String language = g.getOptionString("language");
    generator = new CodeGenerator(tool, g, language);
    }
View Full Code Here

Examples of org.javacc.parser.CodeGenerator

  /**
   * Test method for {@link org.javacc.parser.NfaState#
   *     DumpStateSets(java.io.PrintWriter)}.
   */
  public void testDumpStateSets() {
    CodeGenerator cg = new CodeGenerator();
    NfaState.DumpStateSets(cg);
    assertEquals("static final int[] jjnextStates = {\n};\n" ,
            cg.getGeneratedCode().replaceAll("\r", ""));
  }
View Full Code Here

Examples of org.javacc.parser.CodeGenerator

  /**
   * Test method for {@link org.javacc.parser.NfaState#
   *     DumpStateSets(java.io.PrintWriter)}.
   */
  public void testDumpStateSetsInitialised() throws Exception {
    CodeGenerator cg = new CodeGenerator();
    setupState();
    NfaState.DumpStateSets(cg);
    assertEquals("static final int[] jjnextStates = {\n" +
        "   34, 35, 12, 38, 39, 42, 43, 23, 24, 26, 14, 16, 49, 51, 6, 52, \n" +
        "   59, 8, 9, 12, 23, 24, 28, 26, 34, 35, 12, 44, 45, 12, 53, 54, \n" +
        "   60, 61, 62, 10, 11, 17, 18, 20, 25, 27, 29, 36, 37, 40, 41, 46, \n" +
        "   47, 55, 56, 57, 58, 63, 64, \n" +
        "};\n" ,
        cg.getGeneratedCode().replaceAll("\r", ""));
  }
View Full Code Here

Examples of org.javacc.parser.CodeGenerator

  /**
   * Test method for {@link org.javacc.parser.NfaState#
   *     DumpCharAndRangeMoves(java.io.PrintWriter)}.
   */
  public void testDumpCharAndRangeMoves() throws Exception {
    CodeGenerator cg = new CodeGenerator();
    NfaState.DumpCharAndRangeMoves(cg);
    assertEquals(
        "         int i2 = (curChar & 0xff) >> 6;\n" +
        "         long l2 = 1L << (curChar & 077);\n" +
        "         do\n" +
        "         {\n" +
        "            switch(jjstateSet[--i])\n" +
        "            {\n" +
        "               default : break;\n" +
        "            }\n" +
        "         } while(i != startsAt);\n"
        ,cg.getGeneratedCode().replaceAll("\r", ""));
  }
View Full Code Here

Examples of org.javacc.parser.CodeGenerator

  /**
   * Test method for {@link org.javacc.parser.NfaState#
   *     DumpCharAndRangeMoves(java.io.PrintWriter)}.
   */
  public void testDumpCharAndRangeMovesInitialised() throws Exception {
    CodeGenerator cg = new CodeGenerator();
    setupState();
    NfaState.DumpCharAndRangeMoves(cg);
    assertEquals(
        "         int hiByte = (int)(curChar >> 8);\n" +
        "         int i1 = hiByte >> 6;\n" +
        "         long l1 = 1L << (hiByte & 077);\n" +
        "         int i2 = (curChar & 0xff) >> 6;\n" +
        "         long l2 = 1L << (curChar & 077);\n" +
        "         do\n" +
        "         {\n" +
        "            switch(jjstateSet[--i])\n" +
        "            {\n" +
        "               default : break;\n" +
        "            }\n" +
        "         } while(i != startsAt);\n"
        ,cg.getGeneratedCode().replaceAll("\r", ""));
  }
View Full Code Here

Examples of org.javacc.parser.CodeGenerator

  /**
   * Test method for {@link org.javacc.parser.NfaState#
   *     DumpNonAsciiMoveMethods(java.io.PrintWriter)}.
   */
  public void testDumpNonAsciiMoveMethods() {
    CodeGenerator cg = new CodeGenerator();
    NfaState.DumpNonAsciiMoveMethods(cg);
    assertEquals("", cg.getGeneratedCode());
  }
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.