Comments and multiline string literals

Here is a fairly quick thought.

Would it be possible to allow to escape comments at end of the multiline string literal's line?

let str = """
\(foo)\n\ // comment
\(bar)
"""

I have a tiny workaround for this, but it's not ideal and on top of that it seems to confused syntax highlighting really badly.

let str = """
\(foo /* comment */)
\(bar)
"""

Maybe we can generalize this and even allow inlined comments, but that's not the main priority for me.

let str = """
\(foo)
\/* comment
    still a comment
  */
\(bar)
"""

If this something reasonable and someone would like to pick up and tackle formal proposal + implementation, feel free to do so. :slight_smile:

1 Like

I think this would be horrendously confusing to read. At a minimum I would want the escaped content to be fully delimited as with \u{1f600} or interpolations. E.g. \comment{Blah blah blah}

Following from that, another currently-available possibility for you:

extension DefaultStringInterpolation {
    func appendInterpolation(comment: StaticString) {}
}

let string = """
\(foo)\n\(comment: "Blah blah blah")
\(bar)
"""
5 Likes
Terms of Service

Privacy Policy

Cookie Policy