[stringtemplate-interest] Suggestions: Map parameters and Template-identity checks
Terence Parr
parrt at cs.usfca.edu
Mon Dec 7 18:11:44 PST 2009
On Dec 7, 2009, at 12:40 PM, Swapnil Kashikar wrote:
> Can you explain how to use it in this example, which shows what I do
> today and also my suggested syntax:
>
> //How I define map today
> m ::=
> [ "full" : {My name is: <firstname> <middlename> <lastname>},
> "first_last" : {My name is: <firstname> <lastname>},
> "last_first" : {My name is: <lastname>, <firstname>}
> ]
>
> //Suggested syntax:
> m(firstname, lastname, middlename) ::=
> [ "full" : {My name is: <firstname> <middlename> <lastname>},
> "first_last" : {My name is: <firstname> <lastname>},
> "last_first" : {My name is: <lastname>, <firstname>}
> ]
I would probably use an object with those fields then ref
<person.first> etc... but we need something like:
<persons:m.full>
but won't work in v3 i suspect. You could do
<persons:(m.full)>
and have "full" map to a template name which had "My name is:
<firstname> <middlename> <lastname>"
>
> > It would be much simpler if we could check the identity of the
> templates directly using their actual names without having to
> declare dummy identity-attributes. Something like:
> > <if(var.instanceOf(scalar))><var>:=0;<endif>
>
> I recently encountered this exact problem when generating code in an
> example for the book. What I discovered ultimately is that this is
> data filtering, which is really the purview of the model, not the
> view. Hence, I sent in filtered lists, one for scalars and one for
> objects. In fact, I think it was the exact same problem as you have :)
>
> Well, I did consider doing that but the problem is it does not
> preserve the order of the original list and, in general, this may
> not be acceptable - for ex, a variable definition may depend on
> variables defined earlier in the list.
>
That's definitely something the model should figure out. the templates
only say how to display a var decl for example not which var decl(s)
to display.
Ter
More information about the stringtemplate-interest
mailing list