[stringtemplate-interest] Help turning this into a template?
Terence Parr
parrt at cs.usfca.edu
Tue May 3 17:00:02 PDT 2011
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
More information about the stringtemplate-interest
mailing list