[stringtemplate-interest] String manipulations

Kay Roepke kroepke at classdump.org
Fri Sep 22 12:47:04 PDT 2006


Hi *,

On 22. Sep 2006, at 16:12 Uhr, John Snyders wrote:

> I can't think of any reason why dup wouldn't copy the renderers. As  
> it is
> now it means that the only  time assigning a specific renderer to a
> StringTemplate would work is if it is the top level template (from  
> your
> code's perspective the one you are calling toString on).

Correct.

> I assume you made the change to dup. How do we go about giving this  
> code
> back so that it can be included as a bug fix?

Simply post it to the list, possibly CC'ing Terence to get his  
attention ;)

> Or can someone explain why dup should not copy the renderers?

I think it should and consider that a bug. Normally individual  
templates don't have their own renderers and instead rely on the  
group's renderers to do the work. Still, when dup'ing them they  
should retain everything except the enclosing instance.

Ter is away until Sunday, so we'd have to talk it through with him  
again then.

>> From Oliver's original post: "For me, that's just not practical as  
>> it does not work for attribute properties and it would be just too  
>> awkward to add eachproperty as a first-class attribute."
>
> I did not think there was anything special about properties in  
> terms of how
> they are processed by templates so a wrapper class would work just  
> as well
> for a property. You just have to make sure that the value of your  
> property
> contains the wrapped class {setDate(new WrappedDate(somedate)); }  
> It doesn't
> happen automatically as in the example where a derived  
> StringTemplate is
> used. Perhaps this is what you ment that it is not automatic and  
> you can't
> change all your model objects.

You can subclass ST's setAttribute method and perform the wrapping in  
there. I believe this is mentioned in Ter's ST paper somewhere.
Works great, and requires no changes to your model classes whatsoever.

> Looking at dup makes me wonder about the performance of  
> StringTemplate it
> seems that templates will be copied many times. But this is a  
> different
> subject and I will check the archives first.

For an earlier discussion of this see: <http://www.antlr.org:8080/ 
pipermail/stringtemplate-interest/2006-June/000501.html>
I just looked in the depot and it seems the proposed changes have  
never been implemented. For now, if you want to go with renderers,  
add the
corresponding line to dup() or override setAttribute() and do the  
wrapping there, based on the object's class.


cheers,
-k
-- 
Kay Röpke <kroepke at classdump.org>
classdump Software
Key fingerprint = A849 0F2C C322 4022 379E  8661 7E1B FE0D 4CD2 A6D0





More information about the stringtemplate-interest mailing list