[swift-evolution] URL Literals

David Sweeris davesweeris at mac.com
Wed Dec 28 15:03:02 CST 2016


> On Dec 28, 2016, at 11:36, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On Wed, Dec 28, 2016 at 2:29 PM, Micah Hainline via swift-evolution <swift-evolution at swift.org> wrote:
>> > SE-0039 says that resourceName should be a static-string-literal
>> 
>> It compiles just fine for me in my project. My next question was going
>> to be do we actually need a change in the language spec, or can we
>> call fixing that a bug, I think you're answering my question for me
>> before I even had to ask it!
> 
> I'd call that a bug. It doesn't run, and there's no reason why something not allowed by the grammar shouldn't be diagnosed at compile time, IMO.
> 
> From _The Swift Programming Language_:
> 
> GRAMMAR OF A STRING LITERAL
> string-literal → static-string-literal­ | interpolated-string-literal­
> static-string-literal → "­quoted-text­opt­"­
> quoted-text → quoted-text-item­ quoted-text­opt­
> quoted-text-item → escaped-character­
> quoted-text-item → Any Unicode scalar value except "­, \­, U+000A, or U+000D
> interpolated-string-literal → "­interpolated-text­opt­"­
> interpolated-text → interpolated-text-item­ interpolated-text­opt­
> interpolated-text-item → \(­expression­)­ | quoted-text-item­
> escaped-character → \0­ | \\­ | \t­ | \n­ | \r­ | \"­ | \'­
> escaped-character → \u­{­unicode-scalar-digits­}­
> unicode-scalar-digits → Between one and eight hexadecimal digit

I'm a bit surprised that part of compiling the compiler doesn't seem to involve parsing  these kinds of grammar specs directly to generate the code used to identify literals. (Or maybe it does and and we just forgot to sync up the grammar specs and the docs before the last release.)

- Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161228/8b388bbb/attachment.html>


More information about the swift-evolution mailing list