[stringtemplate-interest] [RE:] Re: i0 with alternating templates

Udo Borkowski ub at abego-software.de
Fri Aug 26 02:14:33 PDT 2011


1) Defining Scope of i/i0

I agree that

> t() ::= "<i>"

looks odd and

> t(n) ::= "<n>"


is definitely better.

However the problem with the current i/i0 handling is not (only) about implicit or explicit parameter passing/dynamic scoping.

Even if I explicitly pass the i/i0 to the templates, like in this example:

> <data:t(i)>


i/i0 will not be defined in the templates.

I was expecting: after the ":" of the map/iterate variable the iteration variable i and i0 would be defined, i.e. the ":" opens the scope for i/i0. But this is not the case. I do need the anonymous templates wrapping to make it work. 

Normally an anonymous template cannot define any parameter/variable so one may wonder where the "i" in
> <data:{<t(i)>}>

comes from, when it is not defined in:

> <data:t(i)>



2) Implicit Parameter Passing of i/i0

> sometimes very hard to figure out what i is and particularly when nested {...} are used

Can you give an example for this? I thought i/i0 are only defined by the map/iterate operation <var:…>. "{…}" should not affect these values. Only another "nested" <var2:…> should change i/i0. And then we could use the simple semantic: the most inner loop defines i/i0 values. In case one needs to refer to more outer i/i0 values one must explicitly pass them through differently parameters down the call stack.

Currently I don't see why i/i0 should be handled differently from other variables. Do we really need this?

BTW: 
> t() ::= "<x>"

also looks a bit odd, however it is allowed. If the "x" attribute is defined in the calling scope it will be used (without the need for a "t(x) ::= …" definition). Why should the i/i0 be "odder"?
 
Udo

P.S.: I am also missing the "it". Some words on this?


On 26.08.2011, at 03:22, Terence Parr wrote:

> Hi Guys,
> 
> Sure. I decided that i and i0 should not be dynamically scoped / visible to invoked templates.  sometimes very hard to figure out what i is and particularly when nested {...} are used.  So it never is dynamically visible.
> 
> t() ::= "<i>"
> 
> is a bit odd, right?   no parameter def.
> 
> t(n) ::= "<n>"
> 
> is better. then we can use i from {...}
> 
> <data:{<t(i)>}>
> 
> Ter
> On Aug 24, 2011, at 7:47 AM, Daniel Brenner wrote:
> 
>> Interessting: I would have expected that i and i0 are available in each loop and not only in anonymous templates. What is the reason for this? (for me this makes no sence... so far)
>>  
>> Anyway: thanks a lot!
>>  
>> Cheers,
>>  
>> - Daniel
>>  
>>  
>>  
>>  Ursprüngliche Nachricht 
>>  Absender:	 Udo Borkowski ub at abego-software.de
>>  Gesendet am:	 23.08.2011 18:45:34
>>  Betreff:	 [RE:] Re: [stringtemplate-interest] i0 with alternating templates
>>  Empfänger:	 Daniel Brenner daniel.brenner at cas.de
>>  CC:	  stringtemplate-interest at antlr.org
>> Wrapping the template calls into anonymous templates will give you access to i and i0.
>> 
>> In your example it may look like this:
>> 
>> $results:{$resultlistOddRow(i, someVar)$}, {$resultlistEvenRow(i, someVar)$}$
>> 
>> With the templates   and resultlistEvenRow  defined like this:
>> 
>> resultlistOddRow(nr,p) ::= "$nr$. $p$ (odd)$\n$"
>> resultlistEvenRow(nr,p) ::= "$nr$. $p$ (even)$\n$"
>> 
>> and 
>> results: [A, B, C, D]
>> someVar: x
>> 
>> ST4 will render:
>> 
>> 1. x (odd)
>> 2. x (even)
>> 3. x (odd)
>> 4. x (even)
>> 
>> Udo
>> 
>> 
>> 
>> 
>> On 23.08.2011, at 14:43, Daniel Brenner wrote:
>> 
>>> Hi,
>>> 
>>> I have a table with results that was build using alternating templates. The following lines is used for this:
>>> 
>>> $results:resultlistOddRow(somevar), resultlistEvenRow(somevar)$
>>> 
>>> How can I number the rows? In the templates resultlistOddRow and resultlistEvenRow I tried to access $i$ and $i0$ but stringtemplate keeps telling me "implicitly-defined attribute i not visible" and "implicitly-defined attribute i0 not visible".
>>> 
>>> Any ideas?
>>> 
>>> Cheers,
>>> 
>>> - Daniel
>>> 
>>> _______________________________________________
>>> 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
> 
> _______________________________________________
> 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/20110826/13afe389/attachment-0001.html 


More information about the stringtemplate-interest mailing list