[stringtemplate-interest] StringTemplate type proxies

Udo Borkowski ub at abego-software.de
Tue Dec 14 01:34:22 PST 2010


When I ran into an issue like the one described I found it sufficient to use the AttributeRenderer approach. In this renderer I can also do type-specific stuff by checking the type of the attribute evaluated. Rather than extending the model I tend to extend the AttributeRenderer. 

Typically I create one special AttributeRenderer per project and use the format string to select the various "cases". To help me doing this I created a "general" StringRenderer that selects one specific renderer based on the given format string, making it easier to reuse renderers.

Udo

On 14.12.2010, at 04:07, Terence Parr wrote:

> Hi Sam, I'm still trying to figure out how I get away without this.  I'm leary of adding features when I haven't ever needed them.
> 
> Ter
> On Dec 13, 2010, at 2:55 PM, Sam Harwell wrote:
> 
>> I implemented this in the C# port of ST, and submitted it in changelist 7307. I also updated the way items are registered so registrations apply to derived types and interface implementations. Here is the order in which the search is performed (the * indicates “until null”):
>>  
>> 1.       Search current template
>> 2.       Search enclosing template*
>> 3.       Search group
>> 4.       Search super group*
>>  
>> Here is the order in which a match for type T is found. This check is performed at each step of the above process until a match is found (with some key optimizations in place to keep it from going slow).
>>  
>> 1.       Check for a registration for T (exact match).
>> 2.       Check each registration K at the current level – if T is derived from class K or implements interface K, then it is a candidate. If this step reveals candidates,
>> a.       If there is exactly one candidate, it is chosen as a weak match and the process is complete.
>> b.      For each pair of candidates T1!=T2, if T2 is derived from class T1 or implements interface T1, then T2 is a strictly stronger match and T1 is removed from the set of candidates.
>> c.       The filtering process always leaves 1 or more candidates. If only 1 candidate remains, it is chosen as the weak match and the process is complete.
>> d.      If >1 candidates remain, an AmbiguousMatchException is thrown.
>>  
>> From: stringtemplate-interest-bounces at antlr.org [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Sam Harwell
>> Sent: Sunday, December 12, 2010 9:41 PM
>> To: stringtemplate-interest
>> Subject: [stringtemplate-interest] StringTemplate type proxies
>>  
>> I recently started using StringTemplate for a significant code generation project. I’m quite happy with the way things are progressing, but I’m noticing there are several times where I have to add a new property to my code objects just so StringTemplate can produce the desired output. In a manner similar to attribute renderers, I believe the addition of type proxies would be extremely beneficial. Suppose the user registers a type proxy for type T. The type proxy exposes the following method:
>>  
>> object createProxy(object value);
>>  
>> Whenever an attribute resolves to a value of type T, the proxy’s createProxy() method is called. Attributes on the object are resolved against the value returned by the proxy.
>>  
>> Any thoughts on this?
>>  
>> Thanks,
>> Sam
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20101214/8d7f88d2/attachment.html 


More information about the stringtemplate-interest mailing list