[stringtemplate-interest] StringTemplateGroup from String vs. loaded with CommonGroupLoader: Inconsistent Rendering behaviour
Terence Parr
parrt at cs.usfca.edu
Fri Jan 19 08:17:08 PST 2007
Hi. I believe it's because STG now using <...> as default because
it's use more for code gen than HTML.
Ter
On Jan 19, 2007, at 6:39 AM, Thilo Ernst wrote:
> Hello StringTemplate users,
>
> and first of all, thanks to Terence Parr for such a powerful library.
> I'm still pretty new to ST so I'm in doubt whether the following
> problem
> is a bug in ST or simply my own lack of sufficient insight. Here we
> go:
>
> I first tried the introductory example from
> http://www.antlr.org/wiki/display/ST/Group+Files, which creates
> a StringTemplateGroup from a string using a StringReader instance:
>
> String templates = "group simple; vardef(type,name)::=
> \"$type$
> <name>;\"";
> StringTemplateGroup group = new StringTemplateGroup(new
> StringReader(templates));
> StringTemplate t = group.getInstanceOf("vardef");
> t.setAttribute("type", "int");
> t.setAttribute("name", "foo");
> System.out.println("Generated: [["+t.toString()+"]]");
>
> Expectedly, this works:
> Generated: [[int foo;]]
>
> Now I tried to get the same thing to work with a StringTemplateGroup
> loaded with a
> PathGroupLoader:
>
> String location="templates";
> StringTemplateGroupLoader loader =
> new PathGroupLoader(location, new LogSTEL());
> StringTemplateGroup.registerGroupLoader (loader);
> StringTemplateGroup group = StringTemplateGroup.loadGroup
> ("test");
> System.out.println("TemplateGroup loaded ");
> StringTemplate t = group.getInstanceOf("vardef");
> t.setAttribute("type", "int");
> t.setAttribute("name", "foo");
> System.out.println("Generated: [["+t.toString()+"]]");
>
> This is the contents of templates/test.stg:
>
> group simple;
> vardef(type,name) ::= "$type$ <name>;"
>
> The output:
> Generated: [[int <name>;]]
>
> That is, surprisingly, the <..> expressions are not substituted, while
> the $...$
> are.
>
> I don't think the interpolation behaviour should depend on the way the
> StringTemplateGroup object is created. Did I run into a bug, or am I
> just too
> stupid?
>
> NB: The problem occurs as well when using CommonGroupLoader.
> I'm using stringtemplate-3.0 on j2sdk1.5-sun. Any hints appreciated.
>
> Best regards, Thilo
>
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list