[stringtemplate-interest] summarizing white space and indentation
Sam Harwell
sharwell at pixelminegames.com
Mon Nov 9 16:08:22 PST 2009
Just to toss out another idea, I believe it would be possible to keep
*all* whitespace with following 3 exceptions:
1. The single newline after <<
2. The single newline before >>
All confusion can be cleared up by *requiring* a single newline after <<
and requiring the >> fall on a line by itself. To write the template on
one line, use "template text" as before.
3. By default, trim trailing whitespace from the end of each line of the
final output, but allow this to be overridden in code.
This is a very simple set of rules. Does anyone have examples of cases
where it wouldn't work well?
Examples:
foo() ::= <<
<bar()>
>>
bar() ::= <<
>>
Output: ""
foo() ::= <<
<bar()>
>>
bar() ::= <<
text
>>
Output: " text"
foo() ::= <<
<bar()>
>>
bar() ::= <<
text
>>
Output: "\n text"
-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Terence
Parr
Sent: Saturday, November 07, 2009 4:12 PM
To: StringTemplate Mailing List
Subject: [stringtemplate-interest] summarizing white space and
indentation
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
_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org
http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list