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

Hoang Tang firefly4321 at gmail.com
Mon Dec 14 00:09:23 PST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20091214/f3af41c5/attachment.html 


More information about the stringtemplate-interest mailing list