[stringtemplate-interest] support for set
Terence Parr
parrt at cs.usfca.edu
Sat Dec 9 13:18:56 PST 2006
On Dec 7, 2006, at 7:27 AM, John Snyders wrote:
> In a previous thread (http://www.antlr.org:8080/pipermail/
> stringtemplate-interest/2006-December/000836.html) Nate
> had asked for support for the Java Set
> "$if (someSet.moo)$ would be >> equivalent to the Java: if
> (someSet.contains("moo"))"
>
> I see no reason why Set should not be more fully supported. I agree
> that the syntax get(string) should not be supported because it acts
> as a method call.
Nate suggested, though, following:
> I would like to check in my templates if the user has
> a given capability. Eg, the template should show an "admin tools" link
> if the user has the capability "can view admin tools".
This is a serious model-view separation violations. I am
specifically trying to prevent people from doing logic in the
template. This example provides a prime case of we should not do,
therefore, I don't think allowing set testing is reasonable. This is
the same logic I used to avoid the equivalent for single element sets
(i.e., single values): the == operator.
> Because set is a collection it is already supported in that you
> can do this $myset$ and it will enumerate all the keys.
yes, but you cannot have logic, which is the key separation principle.
> $myset.key1$ should be replaced with "key1" if key1 is in the set
> and "" otherwise.
> Or should $myset.key1$ be replaced with "true" if it is present?
I think you get an empty string for $mymap.key$; I don't think I want
to open this whole a bigger, because I think you can test $if
(mymap.key)$ I just realized. Perhaps we should not advertise these
edge cases ;) Certainly I don't think we should create more of them ;)
Ter
More information about the stringtemplate-interest
mailing list