[stringtemplate-interest] Conditionals
Jiwon Seo
jiwon at stanford.edu
Thu Sep 1 15:35:46 PDT 2011
Hi,
I'm using stringtemplate for code generation.
One thing I need to do is to generate different code based on the type
of a variable, like following:
Foo(type, a, b) ::= <<
class Foo {
<type> foo;
<if (type=="int")>
do some int thing
<elseif (type=="String">
do some string thing
<endif>
}
>>
So far, I could somehow use the map (such as, EqMap ::= ["int": "==" ,
default: ".equals"] ) but this is something that cannot be done using
the map. So I ended up using a lot of variables like following:
Foo(type, intType, stringType, ... a, b) ::= <<
class Foo {
<type> foo;
<if (intType)>
do some int thing
<elseif (stringType)>
do some string thing
<endif>
}
>>
Is there any other ways of doing this?
-Jiwon
More information about the stringtemplate-interest
mailing list