Thanks Jerry and Terence,<br><br>I can verified that both method worked nicely.<br><br>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.<br>
<br>Best,<br><br>Hoang<br><br><br><br><div class="gmail_quote">On Mon, Dec 14, 2009 at 2:24 PM, Terence Parr <span dir="ltr"><<a href="mailto:parrt@cs.usfca.edu">parrt@cs.usfca.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi. you can use<br>
<br>
<Entity.Properties, Entity.Name:{p, n | <GenerateProperty(Property=p, Name=n)>}><br>
<br>
Ter<br>
<div><div></div><div class="h5"><br>
On Dec 14, 2009, at 12:09 AM, Hoang Tang wrote:<br>
<br>
> I have a template group that look like below:<br>
><br>
> group main;<br>
> main(Entity) ::= <<<br>
> public class <Entity.Name><br>
> {<br>
> <Entity.Properties:GenerateProperty()><br>
> }<br>
> >><br>
><br>
><br>
> GenerateProperty(Property) ::= <<<br>
> <Property.Attributes; separator="\n"><br>
> public <Property.Type> <Property.Name><br>
> {<br>
> get<br>
> {<br>
> return _entity.<Property.Name>;<br>
> }<br>
><br>
> };<br>
> >><br>
><br>
> 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.<br>
><br>
> GenerateProperty(Property, EntityName) ::= <<<br>
> <Property.Attributes; separator="\n"><br>
> public <Property.Type> <Property.Name><br>
> {<br>
> get<br>
> {<br>
> return <EntityName>.Validate(_entity.<Property.Name>);<br>
> }<br>
><br>
> };<br>
> >><br>
><br>
> How do I reference it then? <Entity.Properties, Entity.Name:GenerateProperty()> doesn't seem to work...<br>
><br>
> Where entity is a simple class<br>
><br>
> Entity<br>
> {<br>
> public string Name;<br>
> public List<Property> Properties;<br>
> }<br>
> Property<br>
> {<br>
> public string Name;<br>
> public string Type;<br>
> }<br>
><br>
><br>
><br>
><br>
><br>
> 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.<br>
><br>
> Best,<br>
><br>
> Hoang<br>
><br>
</div></div><div><div></div><div class="h5">> _______________________________________________<br>
> stringtemplate-interest mailing list<br>
> <a href="mailto:stringtemplate-interest@antlr.org">stringtemplate-interest@antlr.org</a><br>
> <a href="http://www.antlr.org/mailman/listinfo/stringtemplate-interest" target="_blank">http://www.antlr.org/mailman/listinfo/stringtemplate-interest</a><br>
<br>
</div></div></blockquote></div><br>