Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.ST$AttributeList


  /** Generate TParser.java and TLexer.java from T.g4 if combined, else
   *  just use T.java as output regardless of type.
   */
  public String getRecognizerFileName() {
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String recognizerName = g.getRecognizerName();
    return recognizerName+extST.render();
  }
View Full Code Here


  /** A given grammar T, return the listener name such as
   *  TListener.java, if we're using the Java target.
    */
  public String getListenerFileName() {
    assert g.name != null;
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String listenerName = g.name + "Listener";
    return listenerName+extST.render();
  }
View Full Code Here

  /** A given grammar T, return the visitor name such as
   *  TVisitor.java, if we're using the Java target.
    */
  public String getVisitorFileName() {
    assert g.name != null;
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String listenerName = g.name + "Visitor";
    return listenerName+extST.render();
  }
View Full Code Here

  /** A given grammar T, return a blank listener implementation
   *  such as TBaseListener.java, if we're using the Java target.
    */
  public String getBaseListenerFileName() {
    assert g.name != null;
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String listenerName = g.name + "BaseListener";
    return listenerName+extST.render();
  }
View Full Code Here

  /** A given grammar T, return a blank listener implementation
   *  such as TBaseListener.java, if we're using the Java target.
    */
  public String getBaseVisitorFileName() {
    assert g.name != null;
    ST extST = getTemplates().getInstanceOf("codeFileExtension");
    String listenerName = g.name + "BaseVisitor";
    return listenerName+extST.render();
  }
View Full Code Here

  public String getVocabFileName() {
    return g.name+VOCAB_FILE_EXTENSION;
  }

  public String getHeaderFileName() {
    ST extST = getTemplates().getInstanceOf("headerFileExtension");
    if ( extST==null ) return null;
    String recognizerName = g.getRecognizerName();
    return recognizerName+extST.render();
  }
View Full Code Here

    public void testActions(String location, String[] pairs, String template) {
        for (int i = 0; i < pairs.length; i+=2) {
            String action = pairs[i];
            String expected = pairs[i+1];
            ST st = new ST(template);
            st.add(location, action);
            String grammar = st.render();
            testErrors(new String[] {grammar, expected}, false);
        }
    }
View Full Code Here

  public void testActions(String templates, String actionName, String action, String expected) throws org.antlr.runtime.RecognitionException {
    int lp = templates.indexOf('(');
    String name = templates.substring(0, lp);
    STGroup group = new STGroupString(templates);
    ST st = group.getInstanceOf(name);
    st.add(actionName, action);
    String grammar = st.render();
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(grammar, equeue);
    if ( g.ast!=null && !g.ast.hasErrors ) {
      SemanticPipeline sem = new SemanticPipeline(g);
      sem.process();

      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 + "#";
      int end = output.indexOf(e);
View Full Code Here

                 String lexerName,
                 String parserStartRuleName,
                 boolean debug,
                 boolean profile)
  {
    ST outputFileST = new ST(
      "import org.antlr.v4.runtime.*;\n" +
      "import org.antlr.v4.runtime.tree.*;\n" +
      "import org.antlr.v4.runtime.atn.*;\n" +
      "import java.util.Arrays;\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.setBuildParseTree(true);\n" +
      "     <profile>\n"+
      "        ParserRuleContext tree = parser.<parserStartRuleName>();\n" +
      "     <if(profile)>System.out.println(Arrays.toString(profiler.getDecisionInfo()));<endif>\n" +
      "        ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);\n" +
      "    }\n" +
      "\n" +
      "  static class TreeShapeListener implements ParseTreeListener {\n" +
      "    @Override public void visitTerminal(TerminalNode node) { }\n" +
      "    @Override public void visitErrorNode(ErrorNode node) { }\n" +
      "    @Override public void exitEveryRule(ParserRuleContext ctx) { }\n" +
      "\n" +
      "    @Override\n" +
      "    public void enterEveryRule(ParserRuleContext ctx) {\n" +
      "      for (int i = 0; i \\< ctx.getChildCount(); i++) {\n" +
      "        ParseTree parent = ctx.getChild(i).getParent();\n" +
      "        if (!(parent instanceof RuleNode) || ((RuleNode)parent).getRuleContext() != ctx) {\n" +
      "          throw new IllegalStateException(\"Invalid parse tree shape detected.\");\n" +
      "        }\n" +
      "      }\n" +
      "    }\n" +
      "  }\n" +
      "}"
      );
        ST createParserST = new ST("        <parserName> parser = new <parserName>(tokens);\n");
    if ( debug ) {
      createParserST =
        new ST(
        "        <parserName> parser = new <parserName>(tokens);\n" +
                "        parser.addErrorListener(new DiagnosticErrorListener());\n");
    }
    if ( profile ) {
      outputFileST.add("profile",
View Full Code Here

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

  protected void writeLexerTestFile(String lexerName, boolean showDFA) {
    ST outputFileST = new ST(
      "import org.antlr.v4.runtime.*;\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" +
      "        tokens.fill();\n" +
      "        for (Object t : tokens.getTokens()) System.out.println(t);\n" +
      (showDFA?"System.out.print(lex.getInterpreter().getDFA(Lexer.DEFAULT_MODE).toLexerString());\n":"")+
      "    }\n" +
      "}"
      );

    outputFileST.add("lexerName", lexerName);
    writeFile(tmpdir, "Test.java", outputFileST.render());
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.ST$AttributeList

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.