[stringtemplate-interest] Re : Templates that get another templates as arguments?

Udo Borkowski ub at abego-software.de
Mon Jun 27 15:08:52 PDT 2011


> I know that StringTemplate will lookup the template name through the
> call stack, but is that better than explicitly passing the argument in
> to the template?

I guess this is partly a question of personal taste. 

In general I'd prefer to always pass things through explicitly defined parameters. This better documents what parameters a template depends on. 

However in this case I was working on an existing example and I wanted to change as little as necessary on the original code. 

With explicit parameters I need to add a parameter to "hello" and pass the pattern, either explicitly:

greet(pattern)::=<<
<hello("Bob",pattern)>
<hello("John",pattern)>
<hello("Kate",pattern)>
<hello("Barbara",pattern)>
>>

hello(name,pattern)::=<<
Hello, <pattern>
>>

or using the "…" passthru (This requires we also pass the name "by name")

greet(pattern)::=<<
<hello(name="Bob",...)>
<hello(name="John",...)>
<hello(name="Kate",...)>
<hello(name="Barbara",…)>
>>

hello(name,pattern)::=<<
Hello, <pattern>
>>



Udo
On 27.06.2011, at 22:30, Barrie Treloar wrote:

> 2011/6/27 Udo Borkowski <Udo.Borkowski at gmx.de>:
>> Matthieu is right, the indirect template expression is one way to solve
>> this.
>> Alternatively you may also use anonymous templates. Therefore you don't even
>> need to create an extra template for each "greeting pattern". Here the
>> complete example:
> 
> [del]
>> hello(name)::=<<
>> Hello, <pattern>
> 
> [del]
> 
>> hello(name)::=<<
>> Hello, <(processName)(name)>
> 
> I know that StringTemplate will lookup the template name through the
> call stack, but is that better than explicitly passing the argument in
> to the template?
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list