[stringtemplate-interest] Help turning this into a template?

Barrie Treloar baerrach at gmail.com
Tue May 3 18:52:23 PDT 2011


Possibly,
The problem is that the invocation of the templates don't know about
the pattern rules.
Thus the index of operands is bound up with the pattern.
I may be able to have a "helper" object translate the indices for when
I need to generate template 3 style output.

I think I'd need a template for each pattern rule.
This is a non-trivial number, but it's currently unwieldy as it is any
way (and very error prone with cut-and-paste).

I'll think some more and do some hacking.

On Wed, May 4, 2011 at 9:30 AM, Terence Parr <parrt at cs.usfca.edu> wrote:
> Hi.Can you re-factor your templates into smaller templates? Can you pass in template parameters to other templates?
> Ter
> On Apr 20, 2011, at 9:14 PM, Barrie Treloar wrote:
>
>> I have three ways of doing essentially the same thing.
>> It feels like I should be able to templatize this in a sane way.
>>
>> 1 & 2 vary
>> * the end pattern ($ -> \&)
>> * in the variable to use (ZN -> Z1)
>>
>> 1 & 3 vary
>> * the start pattern (*\& inserted as prefix)
>> * all the operand numbers are incremented by one (e.g. [2] -> [3])
>> * in the variable to use (ZN -> Z2)
>>
>> It gets harder because the knowledge of the operands shouldn't be part
>> of the template.
>> They are part of the pattern rule.
>>
>> File 1) only includes Template 1).
>> File 2) only includes Templates 2) & 3)
>>
>> At the moment these are all "cut-n-paste" (with an if statement to
>> include template 3) which is a cause of errors, as any change to 1)
>> requires similar changes to 2) and 3).
>> I can currently templatize this so that I can go from 1) to 2) but I
>> can't get 3) because the separation of the model and view.
>> i.e. I can't add 1 to the operand positions.
>>
>> Does anyone have advice?
>>
>> 1)
>> ** | D[{}="NORTH"] | D[{}="WEST"] | T[{}="BEND"] | $; special case
>> NORTH WEST BEND
>> COPY_A [2] temp
>> RETYPE [2] 0
>> CONCAT " " temp
>> CONCAT_A [3] temp
>> RETYPE [3] 0
>> CONCAT " " temp
>> CONCAT_A [4] temp
>> RETYPE [4] 0
>> COPY temp {ZN}
>>
>> 2)
>> ** | D[{}="NORTH"] | D[{}="WEST"] | T[{}="BEND"] | \&; special case
>> NORTH WEST BEND
>> COPY_A [2] temp
>> RETYPE [2] 0
>> CONCAT " " temp
>> CONCAT_A [3] temp
>> RETYPE [3] 0
>> CONCAT " " temp
>> CONCAT_A [4] temp
>> RETYPE [4] 0
>> COPY temp {Z1}
>>
>> 3)
>> *\& | ** | D[{}="NORTH"] | D[{}="WEST"] | T[{}="BEND"] | $; special
>> case NORTH WEST BEND
>> COPY_A [3] temp
>> RETYPE [3] 0
>> CONCAT " " temp
>> CONCAT_A [4] temp
>> RETYPE [4] 0
>> CONCAT " " temp
>> CONCAT [5] temp
>> RETYPE [5] 0
>> COPY temp {Z2}
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
> _______________________________________________
> 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