[swift-evolution] [Review] SE-0168: Multi-Line String Literals
brent at architechies.com
Tue Apr 11 19:50:40 CDT 2017
> On Apr 11, 2017, at 4:52 PM, Ricardo Parada via swift-evolution <swift-evolution at swift.org> wrote:
> I think the enabling of the indentation stripping could be relaxed a little bit and not require the opening delimiter to end its line. So for example, it would be possible to do this:
> let xml = """<?xml version="1.0"?>
> <book id="bk101" empty="">
> <title>XML Developer's Guide</title>
> <descr>An in-depth look at creating applications with XML.</descr>
We could definitely do this, but I can't figure out a simple set of rules that would support both that and this:
let xml = """
<book id="bk101" empty="">
<title>XML Developer's Guide</title>
<descr>An in-depth look at creating applications with XML.</descr>
If we have to choose only one to support, I think the second syntax is the best choice, because it does a better job of letting you format the literal flexibly. Putting the first line of the literal on the same line as the expression only works if the expression is short, as in this example. If the expression is longer or more complicated, it starts to break down.
You could support both by saying that the leading newline is stripped if the first line is blank, but that makes the rules more complicated and unprincipled, not less.
(On the other hand, I believe that adding a backslash at the end of the first line in my example would make it work with your algorithm. Hmm.)
> I think Brent did a super awesome job. The proposal is very detailed with a ton of examples. I think it covers just about everything that people have asked for.
Thanks! I really just swept in at the eleventh hour and wrote down what John was thinking, though. (The phrase "mind reading skills" was used.) I didn't work through these tradeoffs, hack several different designs into the compiler to see how they'd work, and pick an actual design.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution