[stringtemplate-interest] StringTemplateGroup from String vs.loaded with CommonGroupLoader: Inconsistent Rendering behaviour

John Snyders jjsnyders at rcn.com
Fri Jan 19 08:54:48 PST 2007


> That is, surprisingly, the <..> expressions are not substituted, while
> > the $...$
> > are.

You may be clear on this but just in case. There can only be one pair of
characters to separate and bracket template code from template document
chunks.
Some examples use $$ and some use <> but you can't mix them in a single
template.

I use the same method as you for loading group files and get the same
behavior.
The $ is the character that brackets template expressions.

I did read that the default changed to <> but I have not seen this. I
actually like the $ as a delimiter. I have used ST for XHTML, SQL, and
config files. <> doesn't mix well with XML/HTML but $ works well with all of
these things so I'm not sure what the motivation is for <>. Is it just a
preference for how it looks?

I did not try this but I rememeber seeing in the API docs someplace where
you can explicitly say which lexer you want either AngleBracketTemplateLexer
or DefaultTemplateLexer. I'm not sure how this interacts with
PathGroupLoader.

-John



> -----Original Message-----
> From: stringtemplate-interest-bounces at antlr.org
> [mailto:stringtemplate-interest-bounces at antlr.org]On Behalf Of Terence
> Parr
> Sent: Friday, January 19, 2007 11:17 AM
> To: StringTemplate
> Subject: Re: [stringtemplate-interest] StringTemplateGroup from String
> vs.loaded with CommonGroupLoader: Inconsistent Rendering behaviour
>
>
> 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