JDK-8227870 - Escape Sequences For Line Continuation and White Space (Preview)

Brian Goetz brian.goetz at oracle.com
Tue Oct 1 01:37:01 UTC 2019


This seems to cross the line between “new escape sequence” and “bespoke string literal language..."


> On Sep 30, 2019, at 9:30 PM, John Rose <john.r.rose at oracle.com> wrote:
> 
> On Sep 30, 2019, at 4:45 AM, Jim Laskey <james.laskey at oracle.com> wrote:
>> 
>> During the discussion on Text Blocks, several of you stated a need for a line continuation construct. I have since created a CSR to propose the creation of two new escape sequences: \<line terminator> and \s.
>> 
>> 	https://bugs.openjdk.java.net/browse/JDK-8227870
>> 
> 
> One observation:  Some traditional uses of \LT, as in C macros, makefiles, and shell,
> line up the \ characters in a single column as a sort of right-hand fence:
> 
>   foo bar     \
>     baz        \
>       bat
> 
> This can be done only in settings where the spaces before the \ are treated as
> ancillary format, not payload characters.  We could make a similar rule for multi-line
> literals, by saying that unescaped spaces *before* the \LT are also deleted when
> the \LT sequence is deleted.
> 
> In other words, the \ at the end of the line is *not* a fence that transforms the 
> 
> So:
> 
> var x = “””
>   foo bar     \
>     baz        \
>       bat      \
>  “””;
> assert x.equals(“foo bar baz   bat”);
> 
> The single space before baz and the three spaces before bat are the left-hand
> leading spaces, not the ancillary spaces before the \ characters.
> 
> If some of those trailing spaces are desirable, then \s can be used to make
> a fence that saves them from stripping.
> 
> var x = “””
>   foo bar\s   \
>   baz  \s      \
>   bat\s         \
>  “””;
> assert x.equals(“foo bar baz   bat ”);
> 
> This rule decouples the two functions of \LT in the current proposal:  (1) It joins
> lines, and (2) it creates a fence which makes previously ancillary spaces into
> real payload spaces.  These are distinct jobs and should not be conflated.
> I think it’s a small but real improvement to separate the jobs, and allow \s
> to handle (2) and \LT to handle only (1).
> 
> — John
> 
> P.S.  A variation of the above suggestion, probably less preferable, would delete
> spaces both *before* and *after* \LT, leading to this:
> 
> var x = “””
>   foo bar     \
>     baz        \
>       bat      \
>  “””;
> assert x.equals(“foo barbazbat”);
> 
> Again, \s could save spaces from stripping.
> 
> 



More information about the amber-spec-experts mailing list