[stringtemplate-interest] Idea for passing parameters to another template...

Terence Parr parrt at cs.usfca.edu
Sat Mar 15 18:33:05 PDT 2008


Hi Mark,  seems ok, but I've kinda assumed attribute lists aren't  
ordered as they are named with <foo(a=x, b=y, ...)>.  No reason one  
couldn't design a system with ordered args.
Ter
On Mar 15, 2008, at 2:44 AM, Mark Wharton wrote:

> 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
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list