(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
www.synopsys.com/software




From: [email protected] 
[mailto:[email protected]] On Behalf Of Ben Rimmington via 
swift-evolution
Sent: Thursday, April 20, 2017 12:12 PM
To: Adrian Zubarev <[email protected]>
Cc: swift-evolution <[email protected]>
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 = """

   <space><space>foo<space><space>\(end)

   """
This is a very dirty and tedious solution for that problem.
<https://github.com/apple/swift/blob/master/CHANGELOG.md#swift-21<https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_apple_swift_blob_master_CHANGELOG.md-23swift-2D21&d=DwMFAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=8mE7AItVCy7oLAwEVNP0_aca5QRASuJBqHQ_PFtDm-U&m=EBRF67tyQfqzwXnmP-XZ3jeiXtQcJ-HWYhol3nrfncs&s=oGf6XXh8EkR8GeYJFTzJcvjWe6dhObt4RsGlrbrml0o&e=>>

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

-- Ben

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to