[stringtemplate-interest] Suggestions: Map parameters and Template-identity checks
Swapnil Kashikar
swapnil.kashikar at gmail.com
Mon Dec 7 12:40:29 PST 2009
Hi Ter,
> To solve this I would suggest that maps be allowed to take more than one
> parameter. The first one can be designated as the 'key' and the rest can
> function like the regular parameters of a named-template.
>
> Hmm...I think the easiest way to handle this is to use the default
> parameter. I should have done this in the book. basically let's say we have
> a map that looks like this ( or dictionary as I'm calling it now):
>
> m ::= [ "foo" : {*<it>*} ]
>
> Then we can access that with <m.foo> but a how do we set "it"? perhaps,
> <"dog":m.foo> ???
>
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>}
]
NameGen(f_name, l_name, m_name, style) ::=<<
//How I use the map today
<f_name,l_name,m_name: {firstname,lastname, middlename| m.(<style>)}>
//Suggested syntax:
<m(style, f_name, l_name, m_name)>
>>
>
> > 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.
Thanks,
Swapnil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20091207/2cf880d2/attachment.html
More information about the stringtemplate-interest
mailing list