Package org.stringtemplate.v4.compiler

Examples of org.stringtemplate.v4.compiler.Compiler


    @Override
    public ST genExpr(CodeGenerator generator,
                    STGroup templates,
                    DFA dfa)
    {
      ST eST;
      if ( templates!=null ) {
        eST = templates.getInstanceOf("notPredicate");
      }
      else {
        eST = new ST("!(<pred>)");
      }
      eST.add("pred", ctx.genExpr(generator,templates,dfa));
      return eST;
    }
View Full Code Here


    this.cycles = cycles;
  }

  @Override
  public String toString() {
    ST st = getMessageTemplate();
    st.add("listOfCycles", cycles);
    return super.toString(st);
  }
View Full Code Here

        // add output vocab file; e.g., T.tokens. This is always generated to
        // the base output directory, which will be just . if there is no -o option
        //
        files.add(new File(tool.getOutputDirectory(), generator.getVocabFileName()));
        // are we generating a .h file?
        ST headerExtST = null;
        ST extST = generator.getTemplates().getInstanceOf("codeFileExtension");
        if (generator.getTemplates().isDefined("headerFile")) {
            headerExtST = generator.getTemplates().getInstanceOf("headerFileExtension");
            String suffix = Grammar.grammarTypeToFileNameSuffix[grammar.type];
            String fileName = grammar.name + suffix + headerExtST.render();
            files.add(new File(outputDir, fileName));
        }
        if (grammar.type == Grammar.COMBINED) {
            // add autogenerated lexer; e.g., TLexer.java TLexer.h TLexer.tokens
            // don't add T__.g (just a temp file)
           
            String suffix = Grammar.grammarTypeToFileNameSuffix[Grammar.LEXER];
            String lexer = grammar.name + suffix + extST.render();
            files.add(new File(outputDir, lexer));

            // TLexer.h
            if (headerExtST != null) {
                String header = grammar.name + suffix + headerExtST.render();
                files.add(new File(outputDir, header));
            }
        // for combined, don't generate TLexer.tokens
        }

        // handle generated files for imported grammars
        List<Grammar> imports =
                grammar.composite.getDelegates(grammar.composite.getRootGrammar());
        for (Grammar g : imports) {
            outputDir = tool.getOutputDirectory(g.getFileName());
            String fname = groomQualifiedFileName(outputDir.toString(), g.getRecognizerName() + extST.render());
            files.add(new File(fname));
        }

        if (files.isEmpty()) {
            return null;
View Full Code Here

        return files;
    }

    public ST getDependencies() {
        loadDependencyTemplates();
        ST dependenciesST = templates.getInstanceOf("dependencies");
        dependenciesST.add("in", getDependenciesFileList());
        dependenciesST.add("out", getGeneratedFileList());
        dependenciesST.add("grammarFileName", grammar.fileName);
        return dependenciesST;
    }
View Full Code Here

    String fileName = probe.dfa.nfa.grammar.getFileName();
    if ( fileName!=null ) {
      file = fileName;
    }

    ST st = getMessageTemplate();
    String ruleName = probe.dfa.getNFADecisionStartState().enclosingRule.name;
    st.add("ruleName", ruleName);
    List<Integer> sortedAlts = new ArrayList<Integer>();
    sortedAlts.addAll(altsWithRecursion);
    Collections.sort(sortedAlts); // make sure it's 1, 2, ...
    st.add("alts", sortedAlts);

    return super.toString(st);
  }
View Full Code Here

    Grammar g = new Grammar(grammarStr);

    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    ST recogST = generator.genRecognizer();
    String code = recogST.render();
    assertTrue("not expecting label", code.indexOf("x=b();")<0);

    assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
  }
View Full Code Here

  protected void writeTestFile(String parserName,
                 String lexerName,
                 String parserStartRuleName,
                 boolean debug)
  {
    ST outputFileST = new ST(
      "import org.antlr.runtime.*;\n" +
      "import org.antlr.runtime.tree.*;\n" +
      "import org.antlr.runtime.debug.*;\n" +
      "\n" +
      "class Profiler2 extends Profiler {\n" +
      "    public void terminate() { ; }\n" +
      "}\n"+
      "public class Test {\n" +
      "    public static void main(String[] args) throws Exception {\n" +
      "        CharStream input = new ANTLRFileStream(args[0]);\n" +
      "        <lexerName> lex = new <lexerName>(input);\n" +
      "        CommonTokenStream tokens = new CommonTokenStream(lex);\n" +
      "        <createParser>\n"+
      "        parser.<parserStartRuleName>();\n" +
      "    }\n" +
      "}"
      );
    ST createParserST =
      new ST(
      "        Profiler2 profiler = new Profiler2();\n"+
      "        <parserName> parser = new <parserName>(tokens,profiler);\n" +
      "        profiler.setParser(parser);\n");
    if ( !debug ) {
      createParserST =
        new ST(
        "        <parserName> parser = new <parserName>(tokens);\n");
    }
    outputFileST.add("createParser", createParserST);
    outputFileST.add("parserName", parserName);
    outputFileST.add("lexerName", lexerName);
View Full Code Here

    outputFileST.add("parserStartRuleName", parserStartRuleName);
    writeFile(tmpdir, "Test.java", outputFileST.render());
  }

  protected void writeLexerTestFile(String lexerName, boolean debug) {
    ST outputFileST = new ST(
      "import org.antlr.runtime.*;\n" +
      "import org.antlr.runtime.tree.*;\n" +
      "import org.antlr.runtime.debug.*;\n" +
      "\n" +
      "class Profiler2 extends Profiler {\n" +
      "    public void terminate() { ; }\n" +
      "}\n"+
      "public class Test {\n" +
      "    public static void main(String[] args) throws Exception {\n" +
      "        CharStream input = new ANTLRFileStream(args[0]);\n" +
      "        <lexerName> lex = new <lexerName>(input);\n" +
      "        CommonTokenStream tokens = new CommonTokenStream(lex);\n" +
      "        System.out.println(tokens);\n" +
      "    }\n" +
      "}"
      );
    outputFileST.add("lexerName", lexerName);
    writeFile(tmpdir, "Test.java", outputFileST.render());
  }
View Full Code Here

                   String lexerName,
                   String parserStartRuleName,
                   String treeParserStartRuleName,
                   boolean debug)
  {
    ST outputFileST = new ST(
      "import org.antlr.runtime.*;\n" +
      "import org.antlr.runtime.tree.*;\n" +
      "import org.antlr.runtime.debug.*;\n" +
      "\n" +
      "class Profiler2 extends Profiler {\n" +
      "    public void terminate() { ; }\n" +
      "}\n"+
      "public class Test {\n" +
      "    public static void main(String[] args) throws Exception {\n" +
      "        CharStream input = new ANTLRFileStream(args[0]);\n" +
      "        <lexerName> lex = new <lexerName>(input);\n" +
      "        TokenRewriteStream tokens = new TokenRewriteStream(lex);\n" +
      "        <createParser>\n"+
      "        <parserName>.<parserStartRuleName>_return r = parser.<parserStartRuleName>();\n" +
      "        <if(!treeParserStartRuleName)>\n" +
      "        if ( r.tree!=null ) {\n" +
      "            System.out.println(((Tree)r.tree).toStringTree());\n" +
      "            ((CommonTree)r.tree).sanityCheckParentAndChildIndexes();\n" +
      "     }\n" +
      "        <else>\n" +
      "        CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree);\n" +
      "        nodes.setTokenStream(tokens);\n" +
      "        <treeParserName> walker = new <treeParserName>(nodes);\n" +
      "        walker.<treeParserStartRuleName>();\n" +
      "        <endif>\n" +
      "    }\n" +
      "}"
      );
    ST createParserST =
      new ST(
      "        Profiler2 profiler = new Profiler2();\n"+
      "        <parserName> parser = new <parserName>(tokens,profiler);\n" +
      "        profiler.setParser(parser);\n");
    if ( !debug ) {
      createParserST =
        new ST(
        "        <parserName> parser = new <parserName>(tokens);\n");
    }
    outputFileST.add("createParser", createParserST);
    outputFileST.add("parserName", parserName);
    outputFileST.add("treeParserName", treeParserName);
View Full Code Here

                      String lexerName,
                      String parserStartRuleName,
                      String treeParserStartRuleName,
                      boolean debug)
  {
    ST outputFileST = new ST(
      "import org.antlr.runtime.*;\n" +
      "import org.antlr.runtime.tree.*;\n" +
      "import org.antlr.runtime.debug.*;\n" +
      "\n" +
      "class Profiler2 extends Profiler {\n" +
      "    public void terminate() { ; }\n" +
      "}\n"+
      "public class Test {\n" +
      "    public static void main(String[] args) throws Exception {\n" +
      "        CharStream input = new ANTLRFileStream(args[0]);\n" +
      "        <lexerName> lex = new <lexerName>(input);\n" +
      "        TokenRewriteStream tokens = new TokenRewriteStream(lex);\n" +
      "        <createParser>\n"+
      "        <parserName>.<parserStartRuleName>_return r = parser.<parserStartRuleName>();\n" +
      "        ((CommonTree)r.tree).sanityCheckParentAndChildIndexes();\n" +
      "        CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree);\n" +
      "        nodes.setTokenStream(tokens);\n" +
      "        <treeParserName> walker = new <treeParserName>(nodes);\n" +
      "        <treeParserName>.<treeParserStartRuleName>_return r2 = walker.<treeParserStartRuleName>();\n" +
      "     CommonTree rt = ((CommonTree)r2.tree);\n" +
      "     if ( rt!=null ) System.out.println(((CommonTree)r2.tree).toStringTree());\n" +
      "    }\n" +
      "}"
      );
    ST createParserST =
      new ST(
      "        Profiler2 profiler = new Profiler2();\n"+
      "        <parserName> parser = new <parserName>(tokens,profiler);\n" +
      "        profiler.setParser(parser);\n");
    if ( !debug ) {
      createParserST =
        new ST(
        "        <parserName> parser = new <parserName>(tokens);\n");
    }
    outputFileST.add("createParser", createParserST);
    outputFileST.add("parserName", parserName);
    outputFileST.add("treeParserName", treeParserName);
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.compiler.Compiler

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.