[stringtemplate-interest] Force single-valued template
Sohail Somani
sohail at taggedtype.net
Sun Nov 20 11:51:30 PST 2005
On Sun, 2005-20-11 at 11:46 -0800, Terence Parr wrote:
> On Nov 20, 2005, at 10:26 AM, sohail at taggedtype.net wrote:
> >>>> power(lhs,rhs)::=<<std::power(<lhs>,<rhs>)>>
> >>>>
> >>>> for 2**3**5, this should give:
> >>>>
> >>>> std::power(2,std::power(3,5))
> >>>>
> >>>> I don't think there is a way to do it without forcing lhs and rhs
> >>>> to be
> >>>> single valued.
> >>>
> >>> How about using first(lhs) to get the first element?
> >
> > I don't particularly like this solution as it will cause a silent
> > failure.
> > I'd really like an exception to be thrown while the template is being
> > constructed.
>
> Oh I see what you mean. Well, one could look at it that the
> controller/model should determine the logic of what is valid data--
> the view should simply display it, not enforce anything dealing with
> validity of data.
Oh of course it is doing this (otherwise it wouldn't be working today),
but I think eventually someone else will modify it and screw things up.
Or am I being too paranoid? I suppose using first(lhs), first(rhs) in
the template would show the intent. The parse also documents this. Do
you think this is enough?
I prefer having less comments and better code but I think this is a case
in which only comments will help :(
More information about the stringtemplate-interest
mailing list