[stringtemplate-interest] How do I pass two variable (one is a multivariable) to a template?
jerry wang
yinqiwen at gmail.com
Mon Dec 14 01:24:41 PST 2009
Hi, Hoang
Maybe you should try using 'it' as the default argument, and another
specified for 'Entity.name'
eg:
test(value) ::= <<
<value.list:element(value.name); separator="\n\n">
>>
element(name) ::= <<
<name> <it.name>;
>>
Regards
2009/12/14 Hoang Tang <firefly4321 at gmail.com>
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20091214/49cf7122/attachment.html
More information about the stringtemplate-interest
mailing list