[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
Thu Jul 16 23:02:12 PDT 2009
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.
T
On Jul 16, 2009, at 9:45 PM, Barrie Treloar wrote:
> On Fri, Jul 17, 2009 at 1:38 PM, Terence Parr<parrt at cs.usfca.edu>
> wrote:
>> Hi Barrie,
>>
>> I think <RETYPE(v="3")> would do it. then define RETYPE to take v as
>> parameter.
>
> How do I then do the iterate loop?
>
> for i = 1 to v
> RETYPE [<v>] 0
> end for
>
> I need the RETYPE line repeated V times?
>
> Thanks
>
>> On Jul 16, 2009, at 8:16 PM, Barrie Treloar wrote:
>>
>>> I have output in my template that is common enough that I would like
>>> to refactor this out (avoid typing/typos)
>>>
>>> In the example below I would like to create a template to replace
>>> the
>>> RETYPE lines with a template call.
>>> Something like
>>> <RETYPE(3)>
>>> which would iterate over the template
>>> RETYPE [<it>] 0
>>>
>>> But I can only do this from attributes passed into the view from the
>>> model.
>>> And in this case the output is model independent.
>>>
>>> Anyone have suggestions on how to do this?
>>>
>>> e.g.
>>> S | ? | S | \& ; T1 Agnes Road
>>> COPY_A [1] temp
>>> CONCAT " " temp
>>> CONCAT [2] temp
>>> COPY temp {S1}
>>> COPY "STREET" {T1}
>>> RETYPE [1] 0
>>> RETYPE [2] 0
>>> RETYPE [3] 0
>>> RETURN
>>>
>>> S | ? | T | D | \& ; T1 Agnes Court West
>>> COPY_A [1] temp
>>> CONCAT " " temp
>>> CONCAT [2] temp
>>> COPY temp {S1}
>>> COPY_A [3] {T1}
>>> COPY_A [4] {D1}
>>> RETYPE [1] 0
>>> RETYPE [2] 0
>>> RETYPE [3] 0
>>> RETYPE [4] 0
>>> RETURN
>>>
>>> S | ? | T | D | ** | \& ; T1 Agnes Court West
>>> COPY_A [1] temp
>>> CONCAT " " temp
>>> CONCAT [2] temp
>>> COPY temp {S1}
>>> COPY_A [3] {T1}
>>> COPY_A [4] {D1}
>>> COPY_S [5] {Z1}
>>> RETYPE [1] 0
>>> RETYPE [2] 0
>>> RETYPE [3] 0
>>> RETYPE [4] 0
>>> RETYPE [5] 0
>>> RETURN
>>> _______________________________________________
>>> 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