[stringtemplate-interest] How to call a template from another when using formal args
Marziou, Gael
gael.marziou at hp.com
Tue Apr 7 01:45:05 PDT 2009
OK I understood how to pass attributes in arguments of another template, I just found that I did not need to enclose them within '$' chars.
So in my example, I rewrote it this way and it worked:
String templates =
"group test; " +
"zero(var) ::= <<$equals(var=var, value=0)$>> " +
"equals(var, value) ::= <<$var$ = $value$>>";
Gael
> -----Original Message-----
> From: stringtemplate-interest-bounces at antlr.org
> [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf
> Of Marziou, Gael
> Sent: Monday, April 06, 2009 7:54 PM
> To: stringtemplate-interest at antlr.org
> Subject: Re: [stringtemplate-interest] How to call a template
> from another when using formal args
>
> Thanks for your reply.
>
> Equals is not a reserved word, however some of your
> suggestions helped me to find a solution inspired by
> testFormalArgumentAssignmentInApply().
>
> The trick was to use $it$.
>
> String templates =
> "group test; " +
> "zero(var) ::= \"$var:equals(value=0)$\" " +
> "equals(value) ::= \"$it$ = $value$\"";
>
>
> However, when I tried to use 2 formal arguments it did not work:
>
> String templates =
> "group test; " +
> "zero(var) ::= \"$equals(var=$var$, value=0)$\" " +
> "equals(var, value) ::= \"$var$ = $value$\"";
>
> Then I tried to pass a constant string, still no luck:
>
> String templates =
> "group test; " +
> "zero(var) ::= \"$equals(var=\"a\", value=0)$\" " +
> "equals(var, value) ::= \"$var$ = $value$\"";
>
> So I switched to "<< >>" syntax and it worked:
>
> String templates =
> "group test; " +
> "zero(var) ::= <<$equals(var=\"a\", value=0)$>> " +
> "equals(var, value) ::= <<$var$ = $value$>>";
>
> I guess there is something fundamental that I did not get on
> passing arguments because it does work easily when I am just
> passing integers.
> Something wrong probably with quoting.
>
> String templates =
> "group test; " +
> "zero(var) ::= \"$equals(var=1, value=0)$\" " +
> "equals(var, value) ::= \"$var$ = $value$\"";
>
>
> Thanks,
>
> Gael
> _______________________________________________
> 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