[swift-evolution] multi-line string literals.

L. Mihalkovic laurent.mihalkovic at gmail.com
Sat Apr 30 01:30:59 CDT 2016


let whyOwhy = _"\
    !!    Can't understand what improvements it truly delivers 
    !!        It basically removes a handful of characters
    !!    It works today
    !!        But I don't see it as a likable foundations for adding in future enhancements
    !!\
    !!    I don't envy the people who will have to support it outside of xcode
    !!        Or even in xcode (considering how it currently struggles with indents/formatting
    !!    As for elegance, beauty is in the eye of the beholder, they say.
    "_
 var json = _"[json]\
!!{
!!  "file" : "\(wishIhadPlaceholders)_000.md"
!!  "desc" : "and why are all examples in xml, i thought it died a while ago ;-)"
!!  "rational" : [
!!          "Here we go again"
!!          "How will xcode help make these workable"
!!       ]
!!}
"_

 [_"]  --> start string
 [_"\] --> start line + ignore spaces until eol 
 [!!\]  --> ignore everything until eol... basically the gap does not exits
 ["_]  --> terminate string
 [_"[TYPEID]\] --> start string knowing that it a verifyer or a formatter (or a chain of) understanding TYPEID can syntax check or format or or or

Regards
(From mobile)

> On Apr 29, 2016, at 4:20 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>>> On Apr 28, 2016, at 4:52 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> Did you ever really use multiline string literals before?
>> 
>> Yes. I used Perl in the CGI script era. Believe me, I have used every quoting syntax it supports extensively, including `'` strings, `"` strings, `q` strings, `qq` strings, and heredocs. This proposal is educated by knowledge of their foibles.
>> 
>> As outlined in the "Future directions for string literals in general" section, I believe alternate delimiters (so you can embed quotes) are a separate feature and should be handled in a separate proposal. Once both features are available, they can be combined. For instance, using the `_"foo"_` syntax I sketch there for alternate delimiters, you could say:
>> 
>>    let xml = _"<?xml version="1.0"?>
>>                "<catalog>
>>                " <book id="bk101" empty="">
>>                "     <author>\(author)</author>
>>                " </book>
>>                "</catalog>"_
> 
> Other than the underscores (I'm not sold on them but I could live with them), this is my favorite approach:
> 
> * It supports indented left-hand alignment, which is an important to me for readability
> * It avoids painful `\n"+` RHS constructions
> * It's easy to scan and understand
> * It's simple and harmonious
> 
> -- E
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160430/6ea8a865/attachment.html>


More information about the swift-evolution mailing list