[stringtemplate-interest] Multi-valued argument stuff...

Terence Parr parrt at cs.usfca.edu
Mon Jun 25 18:12:25 PDT 2007


On Jun 26, 2007, at 5:47 AM, Tim Spurway wrote:
> I am assigning attributes to my template like so:
>
> List<Map<String,Object>> x = getXFromSomewhere();
> template.setAttribute( "someXes", x );
>
> in my template, i can iterate the normal way.  For example:
>
> $someXes:{ anX | This is the Y value of the $i$th X --> $anX.Y$ }
>
> works like a charm.

hi :)  maps iterate through values not keys so the object values in  
your map are assigned to anX.

> however, this chunk of code doesn't work as expected:
>
> $first(someXes):{ firstX | This is the Y value of first X -->  
> $firstX.Y$ }

First of a map probably gives you the key.

> $rest(someXes):{ restX | This is the Y value of the $i$th X-->  
> $restX.Y$ }
>
> I am getting a traceback complaining:
>
> "Class java.lang.String has no such attribute: Y ... "

yeah, probably due to difference there.  i tried changing iteration  
to use the keys, but it broke a huge amount of existing templates. :(

Ter


More information about the stringtemplate-interest mailing list