[stringtemplate-interest] StringTemplateGroup from String vs. loaded with CommonGroupLoader: Inconsistent Rendering behaviour
Thilo Ernst
te0006 at web.de
Fri Jan 19 08:48:09 PST 2007
Hello Terence,
thanks for a quick reply!
I meanwhile found DefaultTemplateLexer, AngleBracketTemplateLexer &
StringTemplateGroup.registerDefaultLexer() , so I can deal with the issue.
In case anybody else stumbles into this, here is the new code, showing
how to select the lexer before loading the templates:
StringTemplateGroupLoader loader =
new PathGroupLoader(location, new LogSTEL());
StringTemplateGroup.registerGroupLoader (loader);
//
StringTemplateGroup.registerDefaultLexer(DefaultTemplateLexer.class);
StringTemplateGroup.registerDefaultLexer(AngleBracketTemplateLexer.class);
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()+"]]");
Still, I find it non-intuitive that STG uses a different default lexer
just because
another way of _creating_ the STG object happens to be used. But of course
this is a minor issue.
Thanks & best regards, Thilo
Terence Parr schrieb:
>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
>>
>>
>
>_______________________________________________
>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