[stringtemplate-interest] Idea for passing parameters to another template...
Mark Wharton
contact at moonbase.com.au
Sat Mar 15 02:44:38 PDT 2008
Hello,
I'm looking for feedback on an idea for passing parameters to another template...
In "Passing Parameters To Another Template" section of http://www.antlr.org/wiki/display/ST/Expressions it states:
"If you are using StringTemplate groups, then you have formal parameters and for those templates with a sole formal argument, you can pass just an expression instead of doing an assignment to the argument name. For example, if you do $bold(name)$ and bold has one formal argument called item, then item gets the value of name just as if you had said {$bold(item=name)$}."
Could this be extended to support multiple arguments, where just expressions can be passed for each of the formal arguments in a template?
Take the following for example:
group sample;
main(a, bitems, c) ::= "<bitems:item(a, it, c)>"
item(a, b, c) ::= "a = <a>, b = <b>, c = <c>"
In the above example, the template application in main is passing (a, it, c) where 'it' is eventually assigned to 'b'. It fits well in the context of formal arguments and interfaces etc. It really makes sense in template application, for regular template includes I don't believe it makes so much sense, but it's basically OK. For me, it's clearer than the equivalent "<bitems:item(b=it, ...)>", which is how it works in the current StringTemplate implementation.
Does the idea seem reasonable, or does it violate the basic rules of StringTemplate? My reason for asking - I'm thinking about supporting this feature in a lightweight implementation of StringTemplate which I'm working on, but I don't want to completely mess up on the compatibility! If StringTemplate could support this one day then great, otherwise, I'll most probably drop the idea and just support assignment to the argument name, as in (b=it, ...).
Thanks,
Mark
Mark Wharton
+ 8190 9834 2559
contact at moonbase.com.au
More information about the stringtemplate-interest
mailing list