<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Tracking the discussion, I’ve updated the prototype toolchain to support the following types of string:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> multipart1 = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"one" "two"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> multipart2 = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">“one\n"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> “two\n"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> multipart3 = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"one</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> “two\n"</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> regex = e</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"\w[\w\d]*\n"</span></div><div class=""><br class=""></div><div class="">It can be downloaded here: <a href="http://johnholdsworth.com/swift-LOCAL-2016-04-26-a-osx.tar.gz" class="">http://johnholdsworth.com/swift-LOCAL-2016-04-26-a-osx.tar.gz</a></div><div class=""><br class=""></div><div class="">Due to an implementation detail the e”” escaped strings still process escapes and interpolation</div><div class="">which is how I would argue it should be anyway. The “e” modifier just mutes the invalid escape error.</div><div class=""><br class=""></div><div class="">I’d only like to add I hope we can avoid HEREDOC strings are compared to Brent’s continuation</div><div class="">approach as the aesthetics are not at all good.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 26 Apr 2016, at 07:04, Chris Lattner <<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Apr 25, 2016, at 5:22 PM, Brent Royal-Gordon <<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>> wrote:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">3. It might be useful to make multiline `"` strings trim trailing whitespace and comments like Perl's `/x` regex modifier does.<br class=""></blockquote><br class="">If you have modifier characters already, it is easy to build a small zoo full of these useful beasts.<br class=""></blockquote><br class="">Modifiers are definitely a workable alternative, and can be quite flexible, particularly if a future macro system can let you create new modifiers.<br class=""></blockquote><br class="">Right. I consider modifiers to be highly precedented in other languages, and therefore proven to work. If we go this way, I greatly prefer prefix to postfix modifiers.<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">* Alternative delimiters: If a string literal starts with three, or five, or seven, or etc. quotes, that is the delimiter, and fewer quotes than that in a row are simply literal quote marks. Four, six, etc. quotes is a quote mark abutting the end of the literal.<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let xml: String = """<?xml version="1.0"?><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""<catalog><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""\t<book id="bk101" empty=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""\t\t<author>\(author)</author><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""\t</book><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>"""</catalog>"""<br class=""><br class="">You can't use this syntax to express an empty string, or a string consisting entirely of quote marks, but `""` handles empty strings adequately, and escaping can help with quote marks. (An alternative would be to remove the abutting rule and permit `""""""` to mean "empty string", but abutting quotes seem more useful than long-delimiter empty strings.)<br class=""></blockquote><br class="">I agree that there is a need to support alternative delimiters, but subjectively, I find this to be pretty ugly. It is also a really unfortunate degenerate case for “I just want a large blob of XML” because you’d end up using “"” almost all the time, and you have to use it on every line.<br class=""></blockquote><br class="">On the other hand, the `"""` does form a much larger, more obvious continuation indicator. It is *extremely* obvious that the above line is not Swift code, but something else embedded in it. It's also extremely obvious what its extent is: when you stop seeing `"""`, you're back to normal Swift code.<br class=""></blockquote><br class="">Right, but it is also heavy weight and ugly. In your previous email you said about the single quote approach: "The quotation marks on the left end up forming a column that marks the lines as special”, so I don’t see a need for a triple quote syntax to solve this specific problem.<br class=""><br class=""><blockquote type="cite" class="">I *really* don't like the idea of our only alternatives being "one double-quote mark with backslashing" or "use an entire heredoc". Heredocs have their place, but they are a *very* heavyweight quoting mechanism, and relatively short strings with many double-quotes are pretty common. (Consider, for instance, strings containing unparsed JSON.) I think we need *some* alternative to double-quotes, either single-quotes (with the same semantics, just as an alternative) or this kind of quote-stacking.<br class=""></blockquote><br class="">I agree that this is a real problem that would be great to solve.<br class=""><br class="">If I step back and look at the string literal space we’re discussing, I feel like there are three options:<br class=""><br class="">1) single and simple multiline strings, using “<br class="">2) your triple quote sort of string, specifically tuned to avoid having to escape “ when it occurs once or twice in sequence.<br class="">3) heredoc, which is a very general (but also very heavy weight) solution to quoting problems.<br class=""><br class="">I’m trying to eliminate the middle one, so we only have to have "two things”. Here are some alternative ways to solve the problem, which might have less of an impact on the language:<br class=""><br class="">A) Introduce single quoted string literals to avoid double quote problems specifically, e.g.: ‘look “here” I say!’. This is another form of #2 which is less ugly. It also doesn’t help you if you have both “ and ‘ in your string.<br class=""><br class="">B) Introduce a modifier character that requires a more complex closing sequence to close off the string, see C++ raw string literals for prior art on this approach. Perhaps something like:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span> Rxxx”look “ here “ I can use quotes “xxx<br class=""><br class="">That said, I still prefer C) "ignore this issue for now”. In other words, I wouldn’t want to block progress on improving the string literal situation overall on this issue, because anything we do here is an further extension to a proposal that doesn’t solve this problem.<br class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">For cases like this, I think it would be reasonable to have a “heredoc” like scheme, which does not allow leading indentation, and does work with all the same modifier characters above. I do not have a preference on a particular syntax, and haven’t given it any thought, but this would allow you to do things like:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let str = <<EOF<br class=""><?xml version="1.0"?><br class=""><catalog><br class="">\t<book id="bk101" empty=""><br class="">\t\t<author>\(author)</author><br class="">\t</book><br class=""></catalog><br class="">EOF<br class=""><br class="">for example. You could then turn off escaping and other knobs using the modifier character (somehow, it would have to be incorporated into the syntax of course).<br class=""></blockquote><br class="">There are two questions and a suggestion I have whenever heredoc syntax comes up.<br class=""><br class="">Q1: Does the heredoc begin immediately, at the next line, or at the next valid place for a statement to start? Heredocs traditionally take the second approach.<br class=""><br class="">Q2: Do you permit heredocs to stack—that is, for a single line to specify multiple heredocs?<br class=""><br class="">S: During the Perl 6 redesign, they decided to use the delimiter's indentation to determine the base indentation for the heredoc:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func x() -> String {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>return <<EOF<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><?xml version="1.0"?><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span><catalog><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>\t<book id="bk101" empty=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>\t\t<author>\(author)</author><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>\t</book><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span></catalog><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>EOF<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class="">Does that seem like a good approach?<br class=""></blockquote><br class="">I think that either approach could work, that you have a lot more experience on these topics than I do, and I would expect a vigorous community debate about these topics. :-)<br class=""><br class="">That said, if you look at what we’re discussing:<br class=""><br class="">1. “Continuation" string literals, to allow a multi-line string literal. You and I appear to completely agree about this.<br class="">2. Heredoc: You and I seem to agree that they are a good “fully general” solution to have, but there are the details you outline above to iron out.<br class="">3. Modifier characters: I’m in favor, but I don’t know where you stand. There is also still much to iron out here (such as the specific characters).<br class="">4. A way to avoid having to escape “ in a non-heredoc literal. I’m still unconvinced, and think that any solution to this problem will be orthogonal to the problems solved by 1-3 (and therefore can be added after getting experience with the other parts).<br class=""><br class="">If you agree that these are all orthogonal pieces, then treat them as such: I’d suggest that you provide a proposal that just tackles the continuation string literals. This seems simple, and possible to get in for Swift 3. After that, we can discuss heredoc and modifiers (if you think they’re a good solution) on their own threads. If those turn out to be uncontroversial, then perhaps they can get in too.<br class=""><br class="">On the heredoc aspects specifically, unless others chime in with strong opinions about the topics you brought up, I’d suggest that you craft a proposal for adding them with your preferred solution to these. You can mention the other answers (along with their tradeoffs and rationale for why you picked whatever you think is right) in the proposal, and we can help the community hash it out.<br class=""><br class="">What do you think?<br class=""><br class="">-Chris<br class=""><br class=""><br class=""><br class=""><br class=""><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>