[stringtemplate-interest] [ST4] How to avoid map key iteration?
Terence Parr
parrt at cs.usfca.edu
Fri Feb 11 08:39:07 PST 2011
Hi. my first thought is, don't try to iterate over the object.
<adr.zip> <adr.city>
is same as:
<adr:{t|<t.zip> <t.city>}>
Ter
On Feb 11, 2011, at 5:45 AM, Udo Borkowski wrote:
> Hi,
>
> is there any way to prevent the "iteration" over map keys when using a template like <m:{t|…}> (m may be a map or a simple object)?
>
> Details:
>
> I am using a template like this:
>
> writeAddress(adr) ::= <<
> ...
> <adr:{t|<t.zip> <t.city>}>
> ...
> >>
>
> adr represents an "Address" with properties "street", "zip", "city" etc.
>
> Initially this was implemented by a bean-style model class Address. Everything worked as expected.
>
> Now I changed the model class to a more "dynamic" implementation by using a Map. I.e. "zip", "city", etc. are now keys in the map, mapping to their resp. values.
>
> Expressions like this:
>
> <a.zip>
>
> still work fine, but
>
> <adr:{t|<t.zip> <t.city>}>
>
> runs into an error:
>
> no such property or can't access: java.lang.String.zip
>
> This is because the new model instance "accidentally" is a Map and the expression now iterates over the keys of the map ("zip" being the first).
>
> How can this iteration be avoided?
>
>
> Udo
>
>
> _______________________________________________
> 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/20110211/7bd5cc8d/attachment.html
More information about the stringtemplate-interest
mailing list