[stringtemplate-interest] How do I pass two variable (one is a multivariable) to a template?

Terence Parr parrt at cs.usfca.edu
Mon Dec 14 12:24:29 PST 2009


Hi. you can use

<Entity.Properties, Entity.Name:{p, n | <GenerateProperty(Property=p, Name=n)>}>

Ter

On Dec 14, 2009, at 12:09 AM, Hoang Tang wrote:

> I have a template group that look like below:
> 
> group main;
> main(Entity) ::= <<
> public class <Entity.Name> 
> {
>     <Entity.Properties:GenerateProperty()>  
> }
> >>
> 
> 
> GenerateProperty(Property) ::= <<
> <Property.Attributes; separator="\n">
> public <Property.Type> <Property.Name> 
> { 
>     get
>     {
>         return _entity.<Property.Name>;   
>     }
>     
> };
> >>
> 
> This work fine, but what happen if I want to accept another variable for the GenerateProperty tempate for example we need to add an EntityName so we can use it to call a static method.
> 
> GenerateProperty(Property, EntityName) ::= <<
> <Property.Attributes; separator="\n">
> public <Property.Type> <Property.Name> 
> { 
>     get
>     {
>         return <EntityName>.Validate(_entity.<Property.Name>);
>     }
>     
> };
> >>
> 
> How do I reference it then? <Entity.Properties, Entity.Name:GenerateProperty()> doesn't seem to work...
> 
> Where entity is a simple class
> 
> Entity
> {
>      public string Name;
>      public List<Property> Properties;
> }
> Property
> {
>      public string Name;
>      public string Type;
> }
> 
> 
> 
> 
> 
> Lastly, I must say this is one of the most elegantly design template "engine" there is. The concept of automatic enumerable of multi-valued lend itself nicely to code generation... Of course it's much more than that. Let just say that I am impressed with the whole design.
> 
> Best,
> 
> Hoang
> 
> _______________________________________________
> 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