[raw-string] indentation stripping

Stephen Colebourne scolebourne at joda.org
Tue May 8 23:15:50 UTC 2018


On 2 May 2018 at 06:31, John Rose <john.r.rose at oracle.com> wrote:
> I keep coming back to the idea that the final line of the quote is the
> best place to control indentation stripping.

My expectation is that IDEs will help with finding the controlling
line in the middle of the RSL - by marking out the strip level with a
thin coloured line for example. Such an IDE solution would make it
relatively easy to scroll up and down and find the problem line in
most cases (mixed tabs and spaces will mess up any design).

I don't think the trailing line is a particularly good place to act as
a control - its not what I'd expect anyway. My natural expectation is
that every line would be considered, and the minimal indent used. As
I've said elsewhere, I think that the allowed indent should be made up
of the same unicode character, such as all tabs or all spaces.

> In fact, any non-empty first line is *not* going to align with the rest of
> the lines, if indentation is in play.  Therefore, we have similar options
> as dealing with non-blanks in the trailing line:  Option A1 is to turn off
> exdenting altogether if the first line is non-empty (that's S. Colebourne's
> proposal too I think).

Yes.

This is a RSL with stripping, no new line at the end:
   String str = `
..__line one
::line fifty-two
..__line ninety-nine
..__line 100`;

This is a RSL with stripping, with new line at the end:
   String str = `
..__line one
::line fifty-two
..__line ninety-nine
.................`;  // all whitespace on this line removed

This is a RSL with no stripping:
   String str = `line one
__line fifty-two
__line ninety-nine`;

Specifically, I think it is a Good Thing that the developer has to
opt-in to stripping, and does so at the _start_ of the literal not at
the end of it. Going further, I don't see any role for the trailing
line in decision making - being at the end it feels like entirely the
wrong place to be important. (I don't think its necessary in reality
to "control" the exdent level, implying it from the body seems like
the natural and expected behaviour to me).

My first line rule is: If the delimiter is immediately followed by a
new line, then the RSL will be stripped with the body starting on the
next line, else it will be fully raw.

My last line rule is: If the last line of a stripped RSL is entirely
whitespace then the body of the RSL ends after the preceding new line.
Such a line is not considered when calculating the controlling line.

These rule, immediately makes Kevin's  rectangle appear. The only
remaining aspect is choosing the indent, which has to be done by
common whitespace prefix. The simplicity of this approach appeals to
me.

Stephen


More information about the amber-spec-observers mailing list