You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds an `Expr.init(literal:)` which functions similarly to `appendInterpolation(literal:format:)` but works outside of interpolations. Also rewrite and reformat related documentation.
/// A Swift type whose value can be represented directly in source code by a Swift literal.
160
+
/// A Swift type whose value can be represented directly in source code by a
161
+
/// Swift literal.
162
+
///
163
+
/// Conforming types do not *contain* Swift source code; rather, they can be
164
+
/// *expressed* in Swift source code, and this protocol can be used to get
165
+
/// whatever source code would do that. For example, `String` is
166
+
/// `ExpressibleByLiteralSyntax` but `StringLiteralExprSyntax` is not.
167
+
///
168
+
/// This protocol is usually not used directly. Instead, conforming types can
169
+
/// be turned into syntax trees using ``Expr.init(literal:)``:
161
170
///
162
-
/// Conforming types do not *contain* Swift source code; rather, they can be *expressed* in Swift source code, and this protocol can be used to get whatever source code would do that. For example, `String` is `ExpressibleByLiteralSyntax` but `StringLiteralExprSyntax` is not.
171
+
/// let expr2 = Expr(literal: [0+1, 1+1, 2+1])
172
+
/// // `expr2` is a syntax tree for `[1, 2, 3]`.
163
173
///
164
-
/// Conforming types can be interpolated into a Swift source code literal with the syntax `\(literal: <value>)`:
174
+
/// Or interpolated into a Swift source code literal with the syntax
175
+
/// `\(literal: <value>)`:
165
176
///
166
-
/// let greeting = "Hello, world!"
167
-
/// let expr1 = ExprSyntax("print(\(literal: greeting))")
168
-
/// // `expr1` is a syntax tree for `print("Hello, world!")`
177
+
/// let greeting = "Hello, world!"
178
+
/// let expr1 = ExprSyntax("print(\(literal: greeting))")
179
+
/// // `expr1` is a syntax tree for `print("Hello, world!")`
169
180
///
170
-
/// Note that quote marks are automatically added around the contents; you don't have to write them yourself. The conformance will automatically ensure the contents are correctly escaped, possibly by using raw literals or other language features:
181
+
/// Note that quote marks are automatically added around the contents of string
182
+
/// literals; you don't have to write them yourself. The conformance for
183
+
/// `String` will automatically ensure the contents are correctly escaped,
184
+
/// possibly by using raw literals or other language features:
171
185
///
172
-
/// let msPath = "c:\\windows\\system32"
173
-
/// let expr2 = ExprSyntax("open(\(literal: msPath))")
174
-
/// // `expr2` might be a syntax tree for `open(#"c:\windows\system32"#)`
175
-
/// // or for `open("c:\\windows\\system32")`.
186
+
/// let msPath = "c:\\windows\\system32"
187
+
/// let expr3 = ExprSyntax("open(\(literal: msPath))")
188
+
/// // `expr3` might be a syntax tree for `open(#"c:\windows\system32"#)`
189
+
/// // or for `open("c:\\windows\\system32")`.
190
+
///
191
+
/// Other conformances have similar intelligent behaviors: floating-point types
192
+
/// produce correct syntax trees for infinities and NaNs, nested optionals
193
+
/// produce `.some(nil)` where appropriate, etc.
176
194
publicprotocolExpressibleByLiteralSyntax{
195
+
/// Returns a syntax tree that represents the value of this instance.
196
+
///
197
+
/// This method is usually not called directly. Instead, conforming types can
198
+
/// be turned into syntax trees using ``Expr.init(literal:)``:
199
+
///
200
+
/// let expr2 = Expr(literal: [0+1, 1+1, 2+1])
201
+
/// // `expr2` is a syntax tree for `[1, 2, 3]`.
202
+
///
203
+
/// Or interpolated into a Swift source code literal with the syntax
204
+
/// `\(literal: <value>)`:
205
+
///
206
+
/// let greeting = "Hello, world!"
207
+
/// let expr1 = ExprSyntax("print(\(literal: greeting))")
208
+
/// // `expr1` is a syntax tree for `print("Hello, world!")`
0 commit comments