antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
943 stars 229 forks source link

How can I call template in dynamic way #174

Open NamTranHong opened 7 years ago

NamTranHong commented 7 years ago

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

parrt commented 5 years ago

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

Clashsoft commented 4 years ago

@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) ::= <%
...
%>