String Tapas - serving (1) I created a new amber branch “string-tapas” for delivery of Multiline String Literal.
This repo now contains the implementation of Brian’s (1) which is a multiline string literal using triple double quotes as a delimiter. I also added String::align method until we have a chance to discuss (1a). Following example works as expected: public class Test { public static void main(String... args) { String result = """ public class Main { public static void main(String... args) { System.out.println("Hello World!"); } } """.align(); System.out.println(result); } } Empty string is both "" and """""". Escape sequences and unicode escapes are always translated. CRLF and CR are translated to LF unless expressed as escape sequences. Triple double quote can be introduced using \""": public class Test { public static void main(String... args) { String result = """ public class Main { public static void main(String... args) { System.out.println(\"""Hello World!\"""); } } """.align(); System.out.println(result); } } Sated: multi-line embedded snippets of many languages (JSON, HTML, XML) without any (or minimal) escaping Sated: fat strings get fat delimiters Sated: One rule for escaping across all strings Still Hungry: Regex Still Hungry: incidental whitespace (align) Fairly minimal but handles a large set if use cases. Cheers, — Jim > On Mar 21, 2019, at 11:19 AM, fo...@univ-mlv.fr wrote: > > ----- Mail original ----- >> De: "Brian Goetz" <brian.go...@oracle.com> >> À: "Remi Forax" <fo...@univ-mlv.fr>, "John Rose" <john.r.r...@oracle.com> >> Cc: "Jim Laskey" <james.las...@oracle.com>, "amber-spec-experts" >> <amber-spec-experts@openjdk.java.net> >> Envoyé: Jeudi 21 Mars 2019 14:56:58 >> Objet: Re: String reboot (plain text) > >>> I really like in the syntax proposed by Jim the fact that the single quote >>> " is >>> retconned to allow several lines, >>> it seems the easiest thing to do if we just want to introduce a multi-lines >>> literal string. >> >> This has already been rejected, because it doesn't address the main use >> cases -- most multi-line snippets still want to have quotes in them >> (SQL, JSON, XML, etc), and thus would still have to be escaped. > > ok, i never expect to have a lot of codes using a multi-lines single quote > but it's fairly common to have DSLs like JSP, velocity marker, mustache > template etc to be compiled to Java source and they contains unicode escapes > so using raw strings is not an option. > >> >>> I disagree with Brian that we should try to have an intelligent algorithm to >>> remove the blank spaces >> >> Thought that's not actually what I proposed. What I've proposed is to >> start with a choice of "1" or "1a", the latter being "1 with intelligent >> reflow." So your preference for 1 over 1a is recorded! > > Rémi