[stringtemplate-interest] auto-flattening lists

Terence Parr parrt at cs.usfca.edu
Fri Nov 9 15:27:00 PST 2007


On Nov 9, 2007, at 8:34 AM, John Snyders wrote:

> Thanks for entering a bug for this.
>     Even though |$table(t=[ [ "a", "b" ], [ "c", "d" ] ])$| is  
> allowed it gets flattened.
>
> The bug isn't explicit about what the expected fix is. Perhaps it  
> is obvious but I'll say it anyway.
> My expectation is that the t argument to the table template be set  
> to a list which contains two elements
> the first being a list of elements "a" and "b" and the second being  
> a list of elements "c" and "d".

Yes, makes sense when you use a list literal inside the template...i  
never do that.  is that common?

> The blog post is all about the data model of ST and has nothing to  
> say about Java API calls
> such as setAttribute. Am I correct that the use you are asking  
> about is where setAttribute is
> used to build up a list item by item? I don't think I used that  
> pattern much. I tend to have a
> fully formed data structure already and then just do one  
> setAttribute for it.

Me too.  It should not flatten in that case.  I don't believe the  
software flattens it now.  Only repeated setAttributes do that.

>
> I think that the setAttribute behavior is correct

ok, cool.

> // myList is "a","b"
> // myOther list is "c", "d"
> setAttribute(foo, myList)
> setAttribute(foo, myOtherList)
> setAttribute(foo, "e")
> // should result in foo being the list "a", "b", "c", "d", "e"
> If you want deep structure to your attributes just build it first  
> then call setAttribute once.

Great. Ok, i'll just leave everything as is for now.  That bug for  
list literals can be left for a while.

Ter



More information about the stringtemplate-interest mailing list