[stringtemplate-interest] [RE:] Re: i0 with alternating templates
Terence Parr
parrt at cs.usfca.edu
Sat Aug 27 10:50:00 PDT 2011
Hi Udo, excellent analysis as always! comments in-line
On Aug 26, 2011, at 2:14 AM, Udo Borkowski wrote:
> 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.
You're right. I was being lazy. I will add to the list for the next release, assuming it's easy enough to do.
http://www.antlr.org/jira/browse/STFOUR-15
> 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?
users:{ u |
<i>: <u.phones: { p |
<i>: <p>
}>
}
That is okay in this case, but if I move the error sub template to another template, it gets confusing. In general, dynamic scoping is not a good idea, as people learned from list in the old days. It's very useful for templates for attributes that the user controls. I just don't think that it works well for the implicitly managed variables. I can remember answering a number of questions about why i it is not the right value or how do I access the outer "right" i?
> 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?
Well, the distinction is implicit versus explicitly defined attributes. It make sense to me that the scope of an implicit iteration variable ("it" as well in the old days) should be scoped to simply the iteration and not within. Though, I must admit that is different than nested for loops in Java. Hmm...well, I definitely remember people having trouble with this but maybe I'm thinking of it and not i.
> 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"?
I think it's the difference between implicit and explicit attributes.
>
> Udo
>
> P.S.: I am also missing the "it". Some words on this?
It, or attr as it was originally known, came into existence because we didn't have parameter definitions. I suppose it wouldn't be the worst thing in the world had, but again we run into the trouble of which "it" you are talking about. people seemed to use <it> like this:
t() ::= "<it>"
and then wondered why it did not give them the right value.
Ter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110827/d93ccc68/attachment.html
More information about the stringtemplate-interest
mailing list