[stringtemplate-interest] String manipulations

Zenaan Harkness zen at freedbms.net
Thu Sep 28 19:24:37 PDT 2006


On Thu, Sep 28, 2006 at 03:29:00PM -0400, John Snyders wrote:
> > From: Terence Parr
> > On Sep 27, 2006, at 9:39 PM, John Snyders wrote:

> > > Option 3 looks like any normal template invocation over a
> > > collection. Again
> > > one would not expect a template to have an effect on rendering.
> >
> > Well, I'd say you're right, but rendering and apply-template are very
> > similar in concept, just not implementation.
> >
> > Option 3 has the problem of "caching/reloading from disk"; the
> > renderers are not set automatically for upperCase template.  If the
> > template is thrown out and reloaded by ST group then the renderer is
> > lost.
> 
> Now I finaly understand what you talkig about. This seems to be a general
> problem. If it makes sense to have per StringTemplate renderers then they
> shouldn't be lost just because the cache is flushed. Or perhaps the rule is
> that templates from disk can't have renderers.
> I guess I didn't have that problem because the upperCase template was
> created from code.

Would it make sense to have a syntax for templates where the
template (/group /global specification), specifies which renderer
Classes should be attached to this template (/group /global
default) ??

> > > Here is another distinction between options 2, 3, and 4. With
> > > option 2 there
> > > is no way that the rendering can be applied to anything but the
> > > value of the
> > > attribute. With 3 the rendering done by the template upperCase can
> > > apply to
> > > attributes, string literals, and templates.
> >
> > Very true.  Hadn't thought of that.
> >
> > > When applied to templates only
> > > attributes referenced within that template get uppercased. Example
> > > from my
> > > previous email (correcting the typo):
> > > $upperCase(it={$message(p0=name)$})$    produces: "Hello JOHN!"
> > > "Not HELLO
> > > JOHN"
> >
> > If args are defined you can say:
> >
> > $upperCase({$message(name)$})$
> >
> > Hmm...sees that the whole message should be uppercased, but youre
> > right...it only does on the renderering of attributes not string
> > literals.  So option 3 seems not so good.
> 
> Yes, I think option 3 should be dismissed.

I was taking quite a liking to the option 3 syntax. However on the
upside it feels like option 4 is simpler to implement, and higher
performance (you're not applying a whole template, just looking up
a renderer) ... any ideas if this is correct thinking?

> > > If this is the difference then YES I think it is the right solution
> > > for the
> > > implementation.
> >
> > Meaning the name.toUpper or name; format="toUpper"?
> 
> I like $name; format="toUpper"$ because it s clear what the intention is. No
> question about if .toUpper is a property or formatter.

I concur.

> > > To sum up I would like to see option 4 supported and implemented as
> > > you
> > > described. The formatting would apply to (the result of) templates
> > > to be
> > > consistent with the ;separator.
> >
> > Yes, so I'd evaluate the entire expressions even if
> >
> > $names:{$i$. <b>$it$</b>}$; format="upperCase"$
> >
> > Here, the entire list of crap would be uppercased including the $i$
> > numbers.  Right?
> 
> Yes I think that makes sense.

'separator' applies "between item pairs". Intuitively I would
expect 'format' to apply "to each item".

What if format="initialCaps"? In this case I would expect format
to be passed each item one by one.

How about these:

/* add separator after each name: */
$names:separator=","$

/* add separator after all but last name: */
$names;separator=","$


$names:{$i$. <b>$it$</b>}:format="upperCase"$
$names:{$i$. <b>$it$</b>};format="upperCase"$

$names:{$i$. <b>$it:format="upperCase"$</b>}$
$names:{$i$. <b>$it;format="upperCase"$</b>}$

$(names:{$i$. <b>$it$</b>}):format="upperCase"$
$(names:{$i$. <b>$it$</b>});format="upperCase"$


$names:{$i$. <b>$it$</b>}:format="initialCaps"$
$names:{$i$. <b>$it$</b>};format="initialCaps"$

$names:{$i$. <b>$it:format="initialCaps"$</b>}$
$names:{$i$. <b>$it;format="initialCaps"$</b>}$

$(names:{$i$. <b>$it$</b>}):format="initialCaps"$
$(names:{$i$. <b>$it$</b>});format="initialCaps"$

??

Just throwing out options ... only just learning ST.

cheers
zen

-- 
Free Australia - www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.


More information about the stringtemplate-interest mailing list