StringInterpolationConvertible and StringLiteralConvertible inheritance


(Ben Rimmington) #1

StringInterpolationConvertible inheritance of StringLiteralConvertible would
allow "static-string" and \(string-expression) segments to be differentiated.

/// For example, `"<p>\(paragraph)</p>" as HTML` would invoke:
///
/// HTML.init(stringInterpolation:
/// HTML.init(stringLiteral: "<p>"),
/// HTML.init(stringInterpolationSegment: paragraph),
/// HTML.init(stringLiteral: "</p>")
/// )
///
/// The conforming HTML type would be able to escape "<" and ">" characters
/// in the \(paragraph) string, without affecting the "<p>" and "</p>" tags.
///
protocol StringInterpolationConvertible : StringLiteralConvertible {
    init(stringInterpolation: Self...)
    init<T>(stringInterpolationSegment: T)
}

I also wonder why the following inheritance is needed:

* StringLiteralConvertible : ExtendedGraphemeClusterLiteralConvertible
* ExtendedGraphemeClusterLiteralConvertible : UnicodeScalarLiteralConvertible

-- Ben


(Brent Royal-Gordon) #2

StringInterpolationConvertible inheritance of StringLiteralConvertible would
allow "static-string" and \(string-expression) segments to be differentiated.

/// For example, `"<p>\(paragraph)</p>" as HTML` would invoke:
///
/// HTML.init(stringInterpolation:
/// HTML.init(stringLiteral: "<p>"),
/// HTML.init(stringInterpolationSegment: paragraph),
/// HTML.init(stringLiteral: "</p>")
/// )
///
/// The conforming HTML type would be able to escape "<" and ">" characters
/// in the \(paragraph) string, without affecting the "<p>" and "</p>" tags.
///
protocol StringInterpolationConvertible : StringLiteralConvertible {
   init(stringInterpolation: Self...)
   init<T>(stringInterpolationSegment: T)
}

I have some questions too about the relationship between StringInterpolationConvertible and StringLiteralConvertible, but I feel like I don't understand the rationale of the existing design well enough yet to suggest changes. So, can anybody involved in that provide some color?

···

--
Brent Royal-Gordon
Architechies