[stringtemplate-interest] separator: a fix or breaking backward compatibility?

Sterling Clover s.clover at gmail.com
Thu Jul 9 18:44:35 PDT 2009


On Jul 6, 2009, at 10:18 PM, Terence Parr wrote:

>> But what about this (note the extra whitespace):
>>
>> <names:{n |  <if(n.cool)><n><endif>}; separator=",">
>>
>> To have the two behave so differently seems very unintuitive.
>
> Hi :)  Well, i do say in the manual that i consume all whitespace  
> after the '|' char.

I'll grant that :-). But the point still stands, I think, as the  
whitespace could be placed elsewhere to the same effect. (Unless  
trailing whitespace is consumed as well? I forget.)

>> What I think you really want is something closer to standard list  
>> comprehension syntax, where a list is filtered on a condition.  
>> Since this provides the same power as what you've got below, I  
>> don't think it would hurt the logic/view split that stringtemplate  
>> enforces, and it would make templates more concise and readable.  
>> Now as to what the syntax is, that's a different issue. Something  
>> like the following, perhaps?
>>
>> <names:{n: n.cool | n}; separator=",">
>>
>
> Yep. it's a good idea.  The problem is that you might get multiple  
> IF in a row that are "nullable".  Or, you could ref an attribute  
> that is a list with no elements.

For multiple ifs that are nullable, one could allow simple  
conjunctions in the comprehension. The above example could be:

<names:{n: n.cool, n.reallycool, n.yesimeancool  | n}l separator=", ">

Or, using an ampersand instead of a comma:

<names:{n: n.cool & n.reallycool & n.yesimeancool  | n}l separator=", ">


> <foo : { f | <n>}; separator=", ">
>
> if foo is List<List<string>> and one of the List<string> is length  
> 0, you'd want to avoid the extra separator, right?

Not sure I follow here. This seems to be a distinct issue from how  
ifs are handled? Rather this is about an empty list producing null  
rather than a string when rendered, I suppose.

But can't this be accomplished already anyway?
<strip(foo) : { n | <strip(n)>}; separator=", ">

Cheers,
Sterl.


More information about the stringtemplate-interest mailing list