[stringtemplate-interest] template existence testing

Terence Parr parrt at cs.usfca.edu
Mon Mar 31 09:37:15 PDT 2008


hi Zenaan you cannot cat major and minor version strings in model and  
push in.  that is a view issue.  So, have a template called version  
that you override to be either <major><minor> or just <minor>.  I am  
rushed so might not be understanding...sorry.
Ter
On Mar 30, 2008, at 12:33 AM, Zenaan Harkness wrote:
> On Sat, Mar 29, 2008 at 01:07:25PM -0700, Terence Parr wrote:
>>
>> On Mar 29, 2008, at 5:43 AM, Zenaan Harkness wrote:
>>> Hi, I've come across a feature which I would find useful:
>>>
>>> It might sound odd, but I would like to be able to, within an  
>>> <if(...)>
>>> block, test for the existence of a specific template name.
>>>
>>> I need to provide template-level specialization of getter/setter  
>>> method
>>> bodies, and I'd like the template name to be tested for  
>>> automatically in
>>> the if block, so that a default method body is used normally, and  
>>> the
>>> specialization is used otherwise.
>>
>> Wouldn't normal group inheritance handle this case?
>
> For inheritance to work, I would have to have an empty get-, set- and
> misc- template in a parent group, for _every_ conceivable attribute  
> that
> my model might want to model, which is simply silly.
>
> The attributes of a particular model, a farm let's say, might be
> land-size, water-flow, crops, etc, whereas a model of a music album
> would have artist, recording company and track attributes. My views
> cannot possibly guess the attributes desired by my models (and the
> models are totally separate).
>
> So the thing is, I want, on occasion, to have a specialization of  
> say, a
> Java Bean view template, and I have in this actual example, attributes
> of att-version-major, att-version-minor, and att-version. Now
> att-version is in my current implementation, to be rendered as a
> concatenation of the major and minor version strings, so I want,  
> instead
> of a normal "return _attVersion;" getter for att-version, a
> specialization (in a one-shot sub-template), where att-version's  
> getter
> body is specialized into "return _attVersionMajor +  
> _attVersionMinor;".
>
> Since there are three attributes, how does my standard javaBean
> template's getterBody(att)... template know that the sub-template- 
> group
> wants to override that _particular_ attribute's getter method body and
> leave the other two as standard getters?
>
> I can already see many other uses for such template specialization,
> where the specialization is per-model-attribute, where the model
> attribute is entirely unknown in advance, and the polymorphic
> sub-template-group feature of StringTemplate would otherwise very
> cleanly solve this problem, if I could only test for the existence  
> of a
> particular template (in the sub group), the name of which is unknown  
> in
> advance, but should be used if it exists.
>
>
> -- 
> Homepage: www.SoulSound.net -- Free Australia: www.UPMART.org
> Please respect the confidentiality of this email as sensibly  
> warranted.
> _______________________________________________
> 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