2

I need apply a variable sequence of templates to an argument. The template secuence is determined in runtime in the controller layer, and these templates are applied to only one argument like:

arg:tpl1():tpl2():...:tplN()

In resume, I need apply a serie of templates to an argument, but this sequence calculated in runtime and in the controller layer.

Thank you!!

1 Answers1

2

You need to iterate over the template name and the parameter lists at the same time. From the documentation, http://www.antlr.org/wiki/display/ST4/Templates, you will find this example:

<names,phones:{ n,p | <n>: <p>}>

In your case, you need something like

<names,values:{ n,v | <(n)(v)>}>

Oh, per your comment, to apply a list of templates to another list requires a nested map-apply I think.

<values:{v | <names:{n | <(n)(v)>}}>

That applies each template named in names to each value in values.

Terence Parr
  • 5,912
  • 26
  • 32
  • My problem is a little different. I need apply the dynamic list of templates ever to the same argument, stacking the output yielded for the templates on the list `myArg:tpl1():tpl2():...:tplN()` Example: We have a line of text in my argument textArg, now, in the runtime we calculate the list of templates to apply (**bold** and _italic_), y put bold and italic template name in a list and I wait for StringTemplate should yield a result like `textArg:bold():italic()`. I need to determine in runtime and in the controller layer, the template list to apply to my argument. – Diego Martinez Dec 17 '12 at 12:11
  • Answer link is dead (404), I believe this is the current link for that documentation: https://github.com/antlr/stringtemplate4/blob/master/doc/templates.md – Kanmuri Jun 06 '16 at 20:22