[stringtemplate-interest] whitespace in IF

Zenaan Harkness zen at freedbms.net
Fri Nov 6 21:42:59 PST 2009


On Fri, Nov 06, 2009 at 06:11:33PM -0800, Terence Parr wrote:
> ok, a related problem.   Is
> 
> <if(x)>
> foo
> <else>
> bar
> <endif>
> 
> same as
> 
> <if(x)>foo<else>bar<endif>
> 
> It's same in v3. I'm wondering if we want the \n after foo or bar.

What will likely happen is complaints of inconsistency.

Although right now it's not so 'clean' in certain circumstances,
I have worked around most of that in my projects by subroutining
my template group file templates, to clean things up visually "as
much as possible".

So right now we have consistency (first/last \n ignored), but
sometimes messy template group files, and the proposal would
mean (as far as I can tell) cleaner template group files, at the
cost of a reduction in consistency of how templates work.

Which is better?

Already, the ignoring of boundary \n's in templates is a concession
to readability, so there is certainly the precedent to introduce
inconsistency in syntax, for the benefit of readbility.

A thought: is it possible to have a slightly different syntax,
to get clarity at the ST-code level of visual-vs-consistent output
differences?

Eg:

   <if(x);>
   foo
   <else;>
   bar
   <endif>

would mean 'sloppy syntax/ layout, to look pretty' and say:

   <if(x):>
   foo
   <else:>
   bar
   <endif>

would mean 'no, I really want all whitespace (spaces, tabs, \n's)
inside the template to be part of the output, and of course:

   <if(x)> foo
   <else>
bar
<endif>

would be the backwards-compatible version which is hard to remember,
'but generally does the right thing', and of course 'is backwards
compatible' which I think is a really nice trait.

As to characters and placement, perhaps ":" and ";" would clash with
existing syntax - it's just examples, and anything that fits would be
fine of course.

best
zen

-- 
Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.


More information about the stringtemplate-interest mailing list