[stringtemplate-interest] Re: StringTemplate, Maps

Oliver Flege o.flege at market-maker.de
Tue Jul 18 23:12:43 PDT 2006


Hi,

Terence Parr wrote:
> Ah. still on todo list:
> 
> o We need to be able to walk maps as maps not lists.  Maps are ok as
> it's a data relationship not a type.  Have to use $m.key$ and $m.value$
> rather than $map:\{key,value|...}$ as it breaks idea of parallel list
> walking that args must match number of lists to walk.  Maybe this:
> <<
> $map:{m|$m.key$ $m.value$}$

+1, so m would be a Map.Entry object, which I think is the "natural" way to
iterate a Map. The problem would of course be that it breaks old code, as
ASTExpr.convertAnythingToIterator currently returns an iterator for the values
and not for the entries.

> $map$ -> keys

-1, $map$ -> entries  would be more appropriate (and consistent with the iterator above)

> $map.keys$
> $map.values$

-1, not really necessary if Entry iterator is available, indistinguishable from "$map.bob$"
unless "keys" and "values" are introduced as keywords, which would prevent me from using
them as keys in my maps => confusion.


=> In order to support iterating map entries, it would be sufficient to replace

		else if ( o instanceof Map ) {
			iter = ((Map)o).values().iterator();
with
		else if ( o instanceof Map ) {
			iter = ((Map)o).entrySet().iterator();

in ASTExpr.convertAnythingToIterator (if breaking old code is acceptable).

Oliver





More information about the stringtemplate-interest mailing list