[stringtemplate-interest] How best to do recursive hetero template calls?

Terence Parr parrt at cs.usfca.edu
Sat Feb 20 17:32:39 PST 2010


On Feb 20, 2010, at 3:03 PM, Gerald Rosenberg wrote:

> On 2/20/2010 11:43 AM, Terence Parr wrote:
> 
> Seems I borked the explanation.
>> To me,  it's not the job of ST to manage a list of your output templates. 
> To be clear, the enhancement is to allow a single template invocation to output multiple content fragments.  A mark on a template will flag when to switch to a new content buffer and the end of that template defines the switch back.  The *only* management ST does is to blindly push and pop output content buffers based on some static mark.

Hmm...not sure why ST should do splitting. user should split on ST granularity.  Also, what if "mark" isn't just "do it now"?  What if you need a predicate? ;)

>> There to many kinds of data structures you might want 
> The specific data structure is really a don't care. Did not intend to suggest that it was tied to or needed any particular data structure.

well, has to be a list of some sort.

>> and I'm not sure introducing new syntax is the right approach. In my tools, I use the same template to generate multiple output files with no problem. 
> Yes, existing behavior is one content string output per invocation of a template. But, like inheritance, it is somewhat of a blunt instrument.  
> 
> ST supports regions so you can override deep details in a parent template.

I see the analogy with regions, but not the compelling use case yet. 

>  Well, suppose rather than changing what text is generated deep in a template invocation, you just want to capture that bit of text as an independent content fragment.  One basic use case is a parent template that generates the text that includes an inner class definition.  If you can generate the text of the inner class, then you have all that you need to generate a stand-alone class right there, right then.   *Except* you need to capture the text of that stand-alone class in an independent string so you can save it to a separate file.  Like regions, it is a matter of conceptual clarity and convenience.  Likely less control code to write and maintain, also.

To me the logic controls whether to create a subclass template; templates don't think. they display. logic will ask for template and write to a file.

I typically create a large hierarchy of templates and so it's no problem to have my logic create a list of ST to shove into other files.

T


More information about the stringtemplate-interest mailing list