[stringtemplate-interest] How to write a helper template/macro for common stuff in a template (i.e. model and controller independent)

Terence Parr parrt at cs.usfca.edu
Fri Jul 17 14:18:26 PDT 2009


See

http://www.antlr.org/jira/browse/ST-56

and

http://www.antlr.org/jira/browse/ST-12

T
On Jul 16, 2009, at 11:29 PM, Barrie Treloar wrote:

> On Fri, Jul 17, 2009 at 3:32 PM, Terence Parr<parrt at cs.usfca.edu>  
> wrote:
>> ah. right. Jim Idle asked for this too.  on todo list. Or, just  
>> pass in a
>> Iterator "counter" object whose toString() returns 1, 2, 3, 4...   
>> bad bad
>> bad style but suffices until i can add "n times" thing.
>
> Fair enough. I didn't think it was possible, but no harm in asking.
> In this particular case the counter object would need to be
> constructed in the view (which is currently not possible) as the
> counter is independent of the model or controller.
>
> I think the work I am doing is an edge case and I'm finding it
> difficult to articulate what I am doing succinctly.
>
> I think the closest analogy is that I am pre-processing input to make
> the creation of the generated file easier.
>
> The resultant file is 6000 lines full of cumbersome and verbose DSL
> and I would like to be applying Dont Repeat Yourself principles to
> reduce the maintenance and development effort of that file.
>
> So the model is only really used to control some optional behaviour.
> This is where a helper/macro template that can apply itself to the
> view would be handy.
>
> I was just thinking that maybe a two pass might fix the problem, but I
> am still stuck with no model variables that control the second pass.
>
> Is there a link to the Todo item?
> Can anyone think of other scenarios where this behaviour is
> appropriate? I'm hoping seeing the problem from an alternative
> viewpoint might help my understanding.
>
> For my case, what I think I want is something like:
>  <[1..6]: {RETYPE [<it>] 0}>
> where [1..6] creates a list on the fly for me of the values  
> [1,2,3,4,5,6]



More information about the stringtemplate-interest mailing list