String reboot - (1a) incidental whitespace
Guy Steele
guy.steele at oracle.com
Tue Apr 16 19:37:17 UTC 2019
Just in case it wasn’t clear, I want to emphasize that my suggestion of using a rectangle-of-double-quotes was intended as a serious proposal—admittedly one that looks unusual and would require good cooperation from each IDE to be practical, but one that solves a number of the problems about that we are facing about indentation and whether to strip whitespace.
—Guy
> On Apr 10, 2019, at 5:48 PM, Guy Steele <guy.steele at oracle.com> wrote:
>
>
>> On Apr 10, 2019, at 5:36 PM, Guy Steele <guy.steele at oracle.com <mailto:guy.steele at oracle.com>> wrote:
>>
>>
>>> On Apr 10, 2019, at 4:54 PM, Brian Goetz <brian.goetz at oracle.com <mailto:brian.goetz at oracle.com>> wrote:
>>>
>>> This is a plateful!
>>>
>>> Stripping "incidental" whitespace is an attractive target of opportunity; the real question is, can we do it right enough of the time, and when we get it wrong, is there an easy way for the user to recover and get what they want?
>>>
>>> Kevin described this as: "find the magic rectangle"; that there should be a rectangle enclosing the snippet that sets apart the incidental whitespace from the essential. In your examples, most of the time, the magic rectangle is, well, the actual rectangle in your text.
>>>
>>>
>>>>
>>>> Examples;
>>>>
>>>> String a = """
>>>> +--------+
>>>> | text |
>>>> +--------+
>>>> """; // first characters in first column?
>>
>> Which suggests yet another approach to multiline string literals:
>>
>> String a = “””””””””””””””””””””””””””””””””””””””
>> “A rectangle of double quotes "
>> “ can enclose any arbitrary text “
>> “ with any desired indentation, “
>> “ and you can assume any trailing “
>> “ whitespace on each line will be “
>> “ removed and that each line will “
>> “ end with a \\n <smb://n>. “
>> “ “
>> “So all you need is IDE support for “
>> “ making nice rectangles. “
>> “””””””””””””””””””””””””””””””””””””””;
>>
>> String result = “”””””””””””””””””””””””””””””””””””””””””””””””
>> “public class Main { “
>> “ public static void main(String... args) { “
>> “ System.out.println("Hello World!”); “
>> “ } “
>> “} “
>> “”””””””””””””””””””””””””””””””””””””””””””””””;
>>
>> String html = “””””””””””””””””””””””””””””””””””””””””””””””
>> “<html> “
>> “ <body style=\"width: 100vw\”> “
>> “ <p>Hello World.</p> “
>> “ </body> “
>> “ <script>console.log(\"\\nloaded\")</script>”
>> “</html> “
>> “””””””””””””””””””””””””””””””””””””””””””””””;
>>
>
> Note that I was inconsistent with my use of escapes. I reckon you should be able to use escapes, but perhaps one need not escape included double quotes because you can tell from the length of the initial line of double-quotes how much text to skip before you expect see the double quote that marks the right-hand edge of the rectangle.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20190416/84103bbc/attachment.html>
More information about the amber-spec-experts
mailing list