[stringtemplate-interest] Applying templates with more than one parameter to multi-valued attributes

Varghese vcottagiri at zafinlabs.com
Tue Oct 31 01:03:01 PST 2006


Hi Terence,

There is an example template (scopedListingTest.st), test code 
(ScopedListingTest.java), output  as a  part of the first post.
http://www.antlr.org:8080/pipermail/stringtemplate-interest/2006-October/000769.html
Or do you want a simpler test case?

Also, if the template is such 'bFormatter(b, aDisplay, bIndex, arg) ::= 
<<...>>'
and it is invoked like this '<a.bList:bFormatter(aDisplay={<a.display>}, 
bIndex={<i>}), arg={ABC}>'
Isn't 'b' a formal parameter(and hence don't have to be set explicitly) 
because 'a.bList' is a array list of bs' and the template is iterating 
through the list?

The following is an example from scopedListingTest.st template file

aFormatter(a) ::= <<
aFormatter a.display:'<a.display>'
    <a.bList:bFormatter(aDisplay={<a.display>})>
 >>

bFormatter(b, aDisplay) ::= <<
bFormatter b.display:'<b.display>' a.display:'<aDisplay>'
    <b.cList:cFormatter(bDisplay={<b.display>}, aDisplay={<aDisplay>})>
 >>


In the example the aFormatter template makes a reference to bFormatter 
'<a.bList:bFormatter(aDisplay={<a.display>})>'
passing in aDisplay only as b is a formal parameter in bFormatter. 
bFormatter further looks at the collection inside 'b' and does
another template reference.

I can do

<a.bList:{ b | <bFormatter(b=b,aDisplay={<a.display>})> }>

and solve the problem.

What I am getting at is that can I use this notation 
<a.bList:bFormatter(aDisplay={<a.display>})> and pass an the elements
of the list one at a time into another template as a formal parameter 
and also set some more parameters in that template. And
would the first parameter in the called template be set to an element in 
the list? The template compiler seems to be happy with
this syntax.

Thank you for your help

Regards
Varghese

Terence Parr wrote:
> On Oct 28, 2006, at 11:50 AM, Varghese wrote:
>
>   
>> Hi,
>>
>> I seem to have trouble with applying templates to multi-valued
>> attributes. These templates have more than one input parameter.
>> The problem seems to be when applying templates to multi-valued
>> attributes, if the enclosed template has more than one parameter, then
>> the enclosed template cannot resolve the properties of the the formal
>> argument(the iterated value)
>>
>> What am i missing?
>>     
>
> Hi. Can you come up with a simple expression that doesn't work?
>
>   
>> The idea is a template formats an object and then calls on other
>> templates to format collections in that object, and so on. The other
>> templates need to access the enclosing template's attributes. Allowing
>> enclosing attributes to pass through will solve this problem, but what
>> if the called template needs the iterator index or a literal parameter
>> as formal parameters eg:
>>     <a.bList:bFormatter(aDisplay={<a.display>}, bIndex={<i>}), arg= 
>> {ABC}>
>> in which case the template definition would be
>>     bFormatter(b, aDisplay, bIndex, arg) ::= <<...>>
>>     
>
> Are you saying that example doesn't work?  Defining b but not setting  
> a value will make it null as it hides anything above.
>
> Ter
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
>
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061031/60731d0d/attachment.html 


More information about the stringtemplate-interest mailing list