[stringtemplate-interest] StringTemplateGroup from String vs. loaded with CommonGroupLoader: Inconsistent Rendering behaviour
Thilo Ernst
te0006 at web.de
Fri Jan 19 05:39:10 PST 2007
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
More information about the stringtemplate-interest
mailing list