[stringtemplate-interest] summarizing white space and indentation

Zenaan Harkness zen at freedbms.net
Sat Nov 7 21:58:33 PST 2009


On Sat, Nov 07, 2009 at 02:12:22PM -0800, Terence Parr wrote:
> Ok, I have a proposed mechanism for whitespace and indentation now  
> which I can summarize.
> 
> Whitespace is left alone except that the first whitespace character of  
> multi-line templates is ignored. So <<...>> and {...} templates but  
> not "..." templates. So, for example,

What about:

t() ::= << foo
   bar
   blah
 >>

??

In this case, the template probably wants to emit a single space
character at the start. How would a multi-line template be written to
emit a single space character?


> t() ::= <<
> foo
>  >>
> 
> ignores the first \n and yields a template with four characters: "foo 
> \n". similarly,
> 
> { x | foo}
> 
> yields "foo" as does
> 
> { x |
> foo}
> 
> Indentation for IF statements is now ignored unless the entire IF is  
> on a line by itself. So
> 
> begin
>    <if(x)>
>    foo
>    <endif>
> end
> 
> gives
> 
> begin
>    foo
> end
> 
> whereas now in v3 you'd get a double indent: one for the IF M1 for the  
> indent in front of foo. Currently we have to keep the IF up against  
> the left edge.

Here we are already breaking backward compatibility.

I'd prefer strict default templates (no messing with ANY whitespace!),
and syntax pre- or in-fix operator to get "nice pretty layout"
behaviour.

Q.1:
Can we say that the advantages of strict, deterministic, non-whitespace-
consuming, low-cognitive-overhad templates take a back seat to "the
prettiest template layout we can achieve"?

Q.2:
Ter, since your the primary implementer, can you please comment on the
possibility of an in-fix or pre-fix template operator syntax for "please
remove some or all of {first, leading, last} whitespace in this
template"?

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