[stringtemplate-interest] separator: a fix or breaking backward compatibility?
Terence Parr
parrt at cs.usfca.edu
Mon Jul 6 19:18:59 PDT 2009
On Jul 6, 2009, at 6:44 PM, Sterling Clover wrote:
> I think I'm late to the party here, but I really dislike this
> change. The functionality you describe is indeed mostly missing
> without it, but the change feels semantically hackish. It feels
> cleaner to reason about a language where a template *always*
> produces a value than one where a template optionally produces one.
> For example, this is what you describe:
>
> <names:{n | <if(n.cool)><n><endif>}; separator=",">
>
> 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.
> 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=",">
>
> The problem here is of course the colon is somewhat unintuitive, but
> the standard set builder symbol for "such that" is the vertical bar,
> which is already taken. Other suggestions, all equally not ideal,
> follow:
>
> <names:{n st. n.cool | n}; separator=",">
> <names:{n & n.cool | n}; separator=",">
> <names:{n when n.cool | n}; separator=",">
> <names:{n where n.cool | n}; separator=",">
> <names:{n % n.cool | n}; separator=",">
> <names:{n ^ n.cool | n}; separator=",">
>
> You get the idea.
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.
<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?
Thanks,
Ter
More information about the stringtemplate-interest
mailing list