[stringtemplate-interest] [ST4] How to avoid map key iteration?
James Briant
jab.antlr at species.org
Mon Feb 14 21:29:35 PST 2011
I ran into this problem a while back on Java and I just hacked ST so it
wouldn't iterate Maps.
Jamie
On Mon, Feb 14, 2011 at 8:01 AM, Udo Borkowski <ub at abego-software.de> wrote:
> Hi Sam,
>
> your suggestion of using a syntax like "line2(adr)" to invoke an anonymous
> template goes exactly in a direction I was thinking for a while now:
>
> (Start of dreams of the future)
>
> The "Unified ST4 template" syntax
>
> Currently we defined "normal" templates like
>
> t1(p1,p2) ::= <<…>>
>
> or
>
> t1(p1,p2) ::= "…"
>
> Anonymous templates (or sub templates) are defines like
>
> {p1,p2| …}.
>
>
> What about defining a "normal" template like this:
>
> t1 = {p1,p2| …}
>
> I.e. a "normal" template is just an anonymous template with a name, i.e.
> the template can be referenced through this name.
>
> To invoke a template use the same syntax as before:
>
> <t1(x,y)>
>
> However one can also just *reference* a template (without invoking it),
> just by naming it without the (...).
>
> The "iterate" feature would work on a (named or anonymous) template (as
> now), but would get a slightly different syntax for named templates:
>
> <x,y:t1>
>
> I.e. no "t1()" as with a template invocation, but just "t1" to reference
> the template. This perfectly fits into the "<x,y:{…}>" syntax: here the
> "{…}" is not written as "{…}()", too.
>
> This changed syntax also makes the difference between a normal template
> call:
>
> <t2()>
>
> and the iterate feature:
>
> <x,y:t1>
>
> a little bit more obvious. (Another way to see this: the () behind the
> template name in an iterate feature serve no real purpose, they will always
> be empty).
>
> To come back to my initial question "how to avoid map key iteration" I
> could imagine an extension to the "iterate" syntax:
>
> Either
>
> <x*,y:t1>
>
> Meaning: only the x parameter is used as an iterator, the other parameters
> are just passed to the template unchanged.
>
> Or
>
> <x,y!:t1>
>
> Meaning: every parameter not marked with "!" is used as an iterator.
>
> ( '*' and '!' are just used as examples. Use your favorite syntax here to
> mark a parameter either as "iterator" or as "pure value").
>
>
> (End of dreams of the future)
>
>
> Udo
>
>
> On 14.02.2011, at 15:35, Sam Harwell wrote:
>
> Hi Udo,
>
> The problem is the operation in use when you write it the way you
> originally did – the ‘:’ is a map operation as opposed to a pass to a
> function method. In theory, the following syntax could solve the problem:
>
> t2(adr,line2={x|<x.zip> <x.city>}) ::= <<
> <adr.firstname> <adr.lastname>
> <line2(adr)>
> >>
>
> I know this syntax doesn’t work in ST3, and I’m guessing it doesn’t in ST4
> either. Considering the way parameters and local variables work in many
> languages, I don’t think allowing this would be unexpected.
>
> Sam
>
> *From:* Udo Borkowski [mailto:ub at abego-software.de]
> *Sent:* Monday, February 14, 2011 3:21 AM
> *To:* Sam Harwell
> *Cc:* stringtemplate-interest List
> *Subject:* Re: [stringtemplate-interest] [ST4] How to avoid map key
> iteration?
>
> Hi Sam,
>
>
> If you write it this way:
> ...
> <t2(adr=p,line2={<adr.city>, <adr.zip>})>
>
>
> Good point.
>
> I guess it is just my personal style (and background) that makes me raise
> the issue. Inside a subtemplate I'd prefer to access the parameters of the
> subtemplate (the {p1,p2|…}) over the access of something outside of the
> subtemplate, especially with the dynamic name lookup of ST4 in mind.
>
>
> Udo
>
>
>
>
> _______________________________________________
> 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/20110214/a1902dd2/attachment.html
More information about the stringtemplate-interest
mailing list