[stringtemplate-interest] it, i, i0 for ST v4
Terence Parr
parrt at cs.usfca.edu
Tue Dec 21 17:50:34 PST 2010
hiya! So, v4 is going to require template argument defs like:
bold(x) ::= "<b>$b$</b>"
That means that "it" iteration value is not necessary; we'll define an arg:
<names:{ n | hi <n>}>
Dynamic scoping means we can see all the way up the enclosing template chain. That means we might see an "it" we don't expect. A few recent posts about how to get at the correct version of "it" in nested templates. problem solved. you name the iteration value.
BUT, we still need i and i0 integer indexes. Same issue.
<names:{ n | <i>. <n>}>
gives
1. Ter
2. Tom
3. Sri
...
Perhaps they are only defined by those lambda-like anonymous templates? It's weird/confusing if you can see i in another template:
<names:foo()>
then:
foo(n) ::= "<i>. <n>" // where does i come from!??!
What about NESTED templates though? Here is how to dump out chapters and sections for a table of contents:
<chapters:{c | <i> Chapter <c.name> <c.sections:{s | <i><i>. <s.name>}>}>
But, what does "<i><i>" mean? First i should be chapter.
Anybody have any ideas? super.i is wrong. The only idea i had was to let people name the indexes, but how?
<chapters:{c,ci=i | <ci> Chapter <c.name> <c.sections:{s | <ci><i>. <s.name>}>}>
So, like a default argument value, we name our index so nested can see ci.
Hmm...that ain't bad I guess. Any complaints?
Ter
More information about the stringtemplate-interest
mailing list