Package org.stringtemplate.v4.test

Examples of org.stringtemplate.v4.test.TestModelAdaptors$UserAdaptorConst


                   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

  protected void writeTemplateTestFile(String parserName,
                     String lexerName,
                     String parserStartRuleName,
                     boolean debug)
  {
    ST outputFileST = new ST(
      "import org.antlr.runtime.*;\n" +
      "import org.antlr.stringtemplate.*;\n" +
      "import org.antlr.stringtemplate.language.*;\n" +
      "import org.antlr.runtime.debug.*;\n" +
      "import java.io.*;\n" +
      "\n" +
      "class Profiler2 extends Profiler {\n" +
      "    public void terminate() { ; }\n" +
      "}\n"+
      "public class Test {\n" +
      "    static String templates = \"group T; foo(x,y) ::= \\\"\\<x> \\<y>\\\"\";\n" +
      "    static StringTemplateGroup group ="+
      "        new StringTemplateGroup(new StringReader(templates)," +
      "          AngleBracketTemplateLexer.class);"+
      "    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.setTemplateLib(group);\n"+
      "        <parserName>.<parserStartRuleName>_return r = parser.<parserStartRuleName>();\n" +
      "        if ( r.st!=null )\n" +
      "            System.out.print(r.st.toString());\n" +
      "      else\n" +
      "            System.out.print(\"\");\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

    // TODO: actually set the right Grammar instance to get the filename
    // TODO: have to update all v2 grammar files for this. or use errormanager and tool to get the current grammar
    if (g != null) {
      file = g.getFileName();
    }
    ST st = getMessageTemplate();
    if ( arg!=null ) {
      st.add("arg", arg);
    }
    return super.toString(st);
  }
View Full Code Here

    errors = 0;
    warnings = 0;
  }

  public ST getMessageTemplate(ANTLRMessage msg) {
    ST messageST = msg.getMessageTemplate(tool.longMessages);
    ST locationST = getLocationFormat();
    ST reportST = getReportFormat(msg.getErrorType().severity);
    ST messageFormatST = getMessageFormat();

    boolean locationValid = false;
    if (msg.line != -1) {
      locationST.add("line", msg.line);
      locationValid = true;
    }
    if (msg.charPosition != -1) {
      locationST.add("column", msg.charPosition);
      locationValid = true;
    }
    if (msg.fileName != null) {
      File f = new File(msg.fileName);
      // Don't show path to file in messages; too long.
      String displayFileName = msg.fileName;
      if ( f.exists() ) {
        displayFileName = f.getName();
      }
      locationST.add("file", displayFileName);
      locationValid = true;
    }

    messageFormatST.add("id", msg.getErrorType().code);
    messageFormatST.add("text", messageST);

    if (locationValid) reportST.add("location", locationST);
    reportST.add("message", messageFormatST);
    //((DebugST)reportST).inspect();
//    reportST.impl.dump();
View Full Code Here

    public ST getLocationFormat() {
        return format.getInstanceOf("location");
    }

    public ST getReportFormat(ErrorSeverity severity) {
        ST st = format.getInstanceOf("report");
        st.add("type", severity.getText());
        return st;
    }
View Full Code Here

        e.printStackTrace(System.err);
    }

  public void panic(ErrorType errorType, Object... args) {
    ToolMessage msg = new ToolMessage(errorType, args);
    ST msgST = getMessageTemplate(msg);
    String outputMsg = msgST.render();
    if ( formatWantsSingleLineMessage() ) {
      outputMsg = outputMsg.replace('\n', ' ');
    }
    panic(outputMsg);
  }
View Full Code Here

    return args;
    }

  public ST getMessageTemplate(boolean verbose) {
    ST messageST = new ST(getErrorType().msg);
    messageST.impl.name = errorType.name();

    messageST.add("verbose", verbose);
    Object[] args = getArgs();
    for (int i=0; i<args.length; i++) {
      String attr = "arg";
      if ( i>0 ) attr += i + 1;
      messageST.add(attr, args[i]);
    }
    if ( args.length<2 ) messageST.add("arg2", null); // some messages ref arg2

    Throwable cause = getCause();
    if ( cause!=null ) {
      messageST.add("exception", cause);
      messageST.add("stackTrace", cause.getStackTrace());
    }
    else {
      messageST.add("exception", null); // avoid ST error msg
      messageST.add("stackTrace", null);
    }

    return messageST;
  }
View Full Code Here

  }

  // --------- get transformed rules ----------------

  public String getArtificialOpPrecRule() {
    ST ruleST = recRuleTemplates.getInstanceOf("recRule");
    ruleST.add("ruleName", ruleName);
    ST ruleArgST = codegenTemplates.getInstanceOf("recRuleArg");
    ruleST.add("argName", ruleArgST);
    ST setResultST = codegenTemplates.getInstanceOf("recRuleSetResultAction");
    ruleST.add("setResultAction", setResultST);
    ruleST.add("userRetvals", retvals);

    LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> opPrecRuleAlts = new LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>();
    opPrecRuleAlts.putAll(binaryAlts);
    opPrecRuleAlts.putAll(ternaryAlts);
    opPrecRuleAlts.putAll(suffixAlts);
    for (int alt : opPrecRuleAlts.keySet()) {
      LeftRecursiveRuleAltInfo altInfo = opPrecRuleAlts.get(alt);
      ST altST = recRuleTemplates.getInstanceOf("recRuleAlt");
      ST predST = codegenTemplates.getInstanceOf("recRuleAltPredicate");
      predST.add("opPrec", precedence(alt));
      predST.add("ruleName", ruleName);
      altST.add("pred", predST);
      altST.add("alt", altInfo);
      altST.add("precOption", LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME);
      altST.add("opPrec", precedence(alt));
      ruleST.add("opAlts", altST);
View Full Code Here

      throw new IllegalStateException(String.format("No %s instance is available.", Tool.class.getName()));
    }

    StringBuilder buf = new StringBuilder();
    for (ANTLRMessage m : all) {
      ST st = tool.errMgr.getMessageTemplate(m);
      buf.append(st.render());
      buf.append("\n");
    }

    return buf.toString();
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.test.TestModelAdaptors$UserAdaptorConst

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.