Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.STGroupString


  }

  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 ) {
View Full Code Here


        "method(name) ::= <<"+newline+
        "$stat(name)$" +newline+
        ">>"+newline+
        "stat(name,value=\"99\") ::= \"x=$value$; // $name$\""+newline
        ;
    STGroup group = new STGroupString(templates);
    ST b = group.getInstanceOf("method");
    b.add("name", "foo");
    String expecting = "x=99; // foo";
    String result = b.render();
    assertEquals(expecting, result);
  }
View Full Code Here

      "\n" +
      "\n" +
      "]\n" +
      "\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "[  99]";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

  @Test public void testWSNoNewlineTemplate() throws Exception {
    String template =
      "t(x) ::= <%\n" +
      "\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

  }

  @Test public void testEmptyNoNewlineTemplate() throws Exception {
    String template =
      "t(x) ::= <%%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

    String template =
      "t(x) ::= <%\n" +
      "  foo\n" +
      "  <x>\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "foo99";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

      "  <if(x)>\n" +
      "    foo\n" +
      "  <endif>\n" +
      "  <x>\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "foo99";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

  @Test public void testKeepWS() throws Exception {
    String template =
      "t(x) ::= <%\n" +
      "  <x> <x> hi\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "99 99 hi";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

      "  Ignore\n" +
      "  newlines and indents\n" +
      "<x>\n\n\n" +
      "<@end>\n" +
      "%>\n";
    STGroup g = new STGroupString(template);
    ST st = g.getInstanceOf("t");
    st.add("x", 99);
    String expected = "Ignorenewlines and indents99";
    String result = st.render();
    assertEquals(expected, result);
  }
View Full Code Here

      "<variables:{ v | <v.decl:(v.format)()>}; separator=\"\\n\">"+newline +
      ">>"+newline+
      "intdecl(decl) ::= \"int <decl.name> = 0;\""+newline +
      "intarray(decl) ::= \"int[] <decl.name> = null;\""+newline
      ;
    STGroup group = new STGroupString(templates);
    ST f = group.getInstanceOf("file");
    f.addAggr("variables.{ decl,format }", new Decl("i", "int"), "intdecl");
    f.addAggr("variables.{decl ,  format}", new Decl("a", "int-array"), "intarray");
    //System.out.println("f='"+f+"'");
    String expecting = "int i = 0;" +newline+
               "int[] a = null;";
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.STGroupString

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.