[swift-evolution] [Pitch] Raw mode string literals

Chris Lattner clattner at nondot.org
Sat Nov 25 00:08:20 CST 2017



> On Nov 24, 2017, at 7:52 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> etc.  Even if we don’t have a “default regex” for types, it would still be awesome to be able to write:
> 
> 
> if case /(let name: [a-zA-Z]+) (let count: Int: [0-9]+)/ = getSomeString() {
>    print(name, count)
> }
> 
> and have that transparently invoke and check the Int?(string) failable initializer.
> 
> Yes, these are very interesting options to explore, and you're right that if we want to go down this road, then we'd need to imbue regex literals with certain "smarts" as opposed to having lenient regex literal parsing that entirely defers validation to a concrete regex type conforming to ExpressibleByRegularExpressionLiteral.
> 
> I don't think it's an all-or-nothing proposition, though, as to whether the literal or the conforming type performs the validation. Personally, I think one of the strengths of Swift's literals is that they are intrinsically untyped and that multiple concrete types are expressible by them.

Right, but the string literal syntaxes we have (single and multiline) do not allow different grammars (e.g. escape sequences) depending on what type they are inferred to.  Wouldn’t it be odd if a string literal accepted “\x12\u1212\U00001212” when it converts to a "const char *” but accepted “\u{12345}” when passed to a bridged Dart API?

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171124/7ce565ce/attachment-0001.html>


More information about the swift-evolution mailing list