[stringtemplate-interest] it, i, i0 for ST v4

Terence Parr parrt at cs.usfca.edu
Tue Dec 21 20:19:38 PST 2010


An interesting idea... but I'm starting to think that requiring another template def is ok:

<chapters:{c | <i> Chapter <c.name> <sec(c.sections, i)>}>

sec(sections, ci) ::= "<sections:{s | <ci><i>. <s.name>}>"

much simpler than allowing default args in "lambdas".  Not as pretty but it's not a super common thing I'd say to need multiple i's.

Ter
On Dec 21, 2010, at 6:19 PM, Collin Fagan wrote:

> How about an "indexOf" operator that you can apply to the named var to get the index value?
> 
> Example 1: @i
> 
> <chapters:{c| <c at i> Chapter <c.name> <c.sections:{s | <c at i><s at i>. <s.name>}>}>
> 
> Example 2: #i
> 
> <chapters:{c| <c#i> Chapter <c.name> <c.sections:{s | <c#i><s#i>. <s.name>}>}>
> 
> I don't know what looks best, just an idea.
> 
> Collin
> 
> On Tue, Dec 21, 2010 at 7:50 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> 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
> _______________________________________________
> 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/20101221/4a7c7aa9/attachment.html 


More information about the stringtemplate-interest mailing list