stringtemplate4 icon indicating copy to clipboard operation
stringtemplate4 copied to clipboard

How can I call template in dynamic way

Open NamTranHong opened this issue 7 years ago • 2 comments

I have a template like this MethodBlock(block) ::= << <block.elements:{e|<e:(e.class.simpleName)()>}; separator="\n">

It will call to template MethodDeclaration if simple Name is MethodDeclaration

But I want to add prefix to template name, like this MethodBlock(block) ::= << <block.elements:{e|<e:(temp_(e.class.simpleName))()>}; separator="\n">

I like to call temp_MethodDeclaration

But it fires error. How can I fix it?

Thnks Alex

NamTranHong avatar Mar 21 '17 14:03 NamTranHong

@NamTranHong What is the error? Maybe use a {...} subtemplate

parrt avatar Nov 08 '18 19:11 parrt

@NamTranHong maybe you want something like this?

type(type) ::= <%
<(typeTemplate(type))(type)>
%>

typeTemplate(type) ::= <%
type_<type.class.simpleName>
%>

type_NamedType(type) ::= <%
...
%>

type_ArrayType(type) ::= <%
...
%>

type_ListType(type) ::= <%
...
%>

type_MapType(type) ::= <%
...
%>

type_OptionalType(type) ::= <%
...
%>

Clashsoft avatar Jun 30 '20 14:06 Clashsoft