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

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


Thanks Jerry and Terence,

I can verified that both method worked nicely.

Jerry syntax lend itself nicely for a simple case. Though Terence answer was
closer to what I am looking for since I was looking for a general case. Both
will be used, thanks again.

Best,

Hoang



On Mon, Dec 14, 2009 at 2:24 PM, Terence Parr <parrt at cs.usfca.edu> wrote:

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


More information about the stringtemplate-interest mailing list