[swift-evolution] [Accepted] SE-0168: Multi-Line String Literals

Peter Dillinger Peter.Dillinger at synopsys.com
Mon Apr 24 18:08:48 CDT 2017

(Despite Ben's claims...)

Are there no limits on interpolation?  I don't see anything about that in the informal addendum to the undetailed proposal.  Will multiline strings in interpolations in normal string literals enable them to lexically span multiple lines? Based on Swift 3.0.2 accepting this:

var x = "single line \( "strings are \( "not normally" ) allowed" ) to span multiple lines"

I assume that this would be accepted:

var x = "single line \( """
                        strings are \( "not normally" ) allowed
                        """ ) to span multiple lines"

which seems confusingly excessive.

I have someone implementing a Swift syntax highlighter right now, and we're trying to anticipate support for multiline strings.  It's vexing in combination with the following recovery/robustness feature: if you read a lexical newline while in the "-quoted string state, return to the normal code state.  (Interpreting " strings as potentially multiline opens the possibility of accidental "inversion" of the remainder of the file in case of a bug, syntax error, or not-yet-supported language feature.  Better to mess up one line than many.)

Disallowing """ multiline strings in interpolations seems a very reasonable thing to do.

Peter Dillinger, Ph.D.
Software Engineering Manager, Coverity Analysis, Software Integrity Group | Synopsys

From: swift-evolution-bounces at swift.org [mailto:swift-evolution-bounces at swift.org] On Behalf Of Ben Rimmington via swift-evolution
Sent: Thursday, April 20, 2017 12:12 PM
To: Adrian Zubarev <adrian.zubarev at devandartist.com>
Cc: swift-evolution <swift-evolution at swift.org>
Subject: Re: [swift-evolution] [Accepted] SE-0168: Multi-Line String Literals

On 20 Apr 2017, at 17:48, Adrian Zubarev wrote:

Some words about the trailing precision. Joe said that we could use \("") as workaround, but if I recall correctly literals are banned from the interpolation itself, which will result in us doing something like this:

let end = ""

let myString = """


This is a very dirty and tedious solution for that problem.

* Expressions interpolated in strings may now contain string literals.
  For example, `My name is \(attributes["name"]!)` is now a valid expression.

-- Ben

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170424/bfbaf8bf/attachment.html>

More information about the swift-evolution mailing list