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

Sam Harwell sharwell at pixelminegames.com
Tue Dec 21 20:22:48 PST 2010


For your chapters/sections example, I currently use an intermediate:

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

This whole issue is an edge case of a larger "problem" I'm facing - I wish
that templates with one unassigned argument could be used any place a
template with a single arg can be used. From your bold(x) example, what I
mean is this:

format(tag,x) ::= "<$tag$>$x$</$tag$>"

<names:format(tag="b")>

The anonymous template version this is exactly what you suggested, with
exactly 1 named but unassigned parameter and 0 or more named assignments.

Sam

-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Tuesday, December 21, 2010 7:51 PM
To: stringtemplate-interest List
Subject: [stringtemplate-interest] it, i, i0 for ST v4

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



More information about the stringtemplate-interest mailing list