Package org.stringtemplate.v4.compiler

Examples of org.stringtemplate.v4.compiler.Compiler


        assertEquals(stringsExpected, stringsResult);
    }

    @Test public void testOption() throws Exception {
        String template = "hi <name; separator=\"x\">";
        CompiledST code = new Compiler().compile(template);
        String asmExpected =
            "write_str 0, load_attr 1, options, load_str 2, store_option 3, write_opt";
        String asmResult = code.instrs();
        assertEquals(asmExpected, asmResult);
        String stringsExpected = "[hi , name, x]";
View Full Code Here


        assertEquals(stringsExpected, stringsResult);
    }

    @Test public void testOptionAsTemplate() throws Exception {
        String template = "hi <name; separator={, }>";
        CompiledST code = new Compiler().compile(template);
        String asmExpected =
            "write_str 0, load_attr 1, options, new 2 0, store_option 3, write_opt";
        String asmResult = code.instrs();
        assertEquals(asmExpected, asmResult);
        String stringsExpected = "[hi , name, _sub1]";
View Full Code Here

        assertEquals(stringsExpected, stringsResult);
    }

    @Test public void testOptions() throws Exception {
        String template = "hi <name; anchor, wrap=foo(), separator=\", \">";
        CompiledST code = new Compiler().compile(template);
        String asmExpected =
            "write_str 0, " +
            "load_attr 1, " +
            "options, " +
            "load_str 2, " +
View Full Code Here

        assertEquals(asmExpected, asmResult);
    }

    @Test public void testEmptyList() throws Exception {
        String template = "<[]>";
        CompiledST code = new Compiler().compile(template);
        String asmExpected = "list, write";
        String asmResult = code.instrs();
        assertEquals(asmExpected, asmResult);
        String stringsExpected = "[]";
        String stringsResult = Arrays.toString(code.strings);
View Full Code Here

        assertEquals(stringsExpected, stringsResult);
    }

    @Test public void testList() throws Exception {
        String template = "<[a,b]>";
        CompiledST code = new Compiler().compile(template);
        String asmExpected = "list, load_attr 0, add, load_attr 1, add, write";
        String asmResult = code.instrs();
        assertEquals(asmExpected, asmResult);
        String stringsExpected = "[a, b]";
        String stringsResult = Arrays.toString(code.strings);
View Full Code Here

    }

    @Test public void testEmbeddedRegion() throws Exception {
        String template = "<@r>foo<@end>";
        // compile as if in root dir and in template 'a'
        CompiledST code = new Compiler().compile("a", template);
        String asmExpected =
            "new 0 0, write";
        String asmResult = code.instrs();
        assertEquals(asmExpected, asmResult);
        String stringsExpected = "[/region__/a__r]";
View Full Code Here

    }

    @Test public void testRegion() throws Exception {
        String template = "x:<@r()>";
        // compile as if in root dir and in template 'a'
        CompiledST code = new Compiler().compile("a", template);
        String asmExpected =
            "write_str 0, new 1 0, write";
        String asmResult = code.instrs();
        assertEquals(asmExpected, asmResult);
        String stringsExpected = "[x:, /region__/a__r]";
View Full Code Here

    if ( STGroup.trackCreationEvents ) {
      if ( debugState==null ) debugState = new ST.DebugState();
      debugState.addAttrEvents.map(name, new AddAttributeEvent(name, value));
    }

    FormalArgument arg = null;
    if ( impl.hasFormalArgs ) {
      if ( impl.formalArguments!=null ) arg = impl.formalArguments.get(name);
      if ( arg==null ) {
        throw new IllegalArgumentException("no such attribute: "+name);
      }
    }
    else {
      // define and make room in locals (a hack to make new ST("simple template") work.)
      if ( impl.formalArguments!=null ) {
        arg = impl.formalArguments.get(name);
      }
      if ( arg==null ) { // not defined
        arg = new FormalArgument(name);
        impl.addArg(arg);
        if ( locals==null ) locals = new Object[1];
        //else locals = Arrays.copyOf(locals, impl.formalArguments.size());
        else {
          Object[] copy = new Object[impl.formalArguments.size()];
View Full Code Here

      if ( impl.hasFormalArgs ) {
        throw new IllegalArgumentException("no such attribute: "+name);
      }
      return;
    }
    FormalArgument arg = impl.formalArguments.get(name);
    if ( arg==null ) {
      throw new IllegalArgumentException("no such attribute: "+name);
    }
    locals[arg.index] = EMPTY_ATTR; // reset value
  }
View Full Code Here

   */
    protected void rawSetAttribute(String name, Object value) {
    if ( impl.formalArguments==null ) {
      throw new IllegalArgumentException("no such attribute: "+name);
    }
    FormalArgument arg = impl.formalArguments.get(name);
    if ( arg==null ) {
      throw new IllegalArgumentException("no such attribute: "+name);
    }
    locals[arg.index] = value;
  }
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.