[stringtemplate-interest] summarizing white space and indentation

Terence Parr parrt at cs.usfca.edu
Sat Nov 7 14:12:22 PST 2009


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,

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.

This all could change as I try to apply the new ST to ANTLR's big set  
of templates, but it should get us close to the final solution.

I'd also like to find a way to allow you format, get a templates  
without messing up the output. I'm still thinking about that.

Ter


More information about the stringtemplate-interest mailing list