@@ -14,13 +14,18 @@ import SwiftSyntax
14
14
15
15
// MARK: - PartialSyntaxNode
16
16
17
+ @available ( * , deprecated, renamed: " SyntaxNodeString " )
18
+ public typealias PartialSyntaxNodeString = SyntaxNodeString
19
+
17
20
/// A type that is expressible by string interpolation the same way that syntax
18
21
/// nodes are, but instead of producing a node, it stores the string interpolation
19
- /// text. Used to represent partial syntax nodes in initializers that take a
22
+ /// text.
23
+ ///
24
+ /// Used to represent partial syntax nodes in initializers that take a
20
25
/// trailing code block.
21
26
///
22
27
/// This type should always be constructed using string interpolation.
23
- public struct PartialSyntaxNodeString : SyntaxExpressibleByStringInterpolation {
28
+ public struct SyntaxNodeString : SyntaxExpressibleByStringInterpolation {
24
29
let sourceText : [ UInt8 ]
25
30
26
31
public init ( stringInterpolation: SyntaxStringInterpolation ) {
@@ -29,7 +34,7 @@ public struct PartialSyntaxNodeString: SyntaxExpressibleByStringInterpolation {
29
34
}
30
35
31
36
extension SyntaxStringInterpolation {
32
- public mutating func appendInterpolation( _ value: PartialSyntaxNodeString ) {
37
+ public mutating func appendInterpolation( _ value: SyntaxNodeString ) {
33
38
sourceText. append ( contentsOf: value. sourceText)
34
39
self . lastIndentation = nil
35
40
}
@@ -59,11 +64,11 @@ public protocol HasTrailingCodeBlock {
59
64
/// ```
60
65
///
61
66
/// Throws an error if `header` defines a different node type than the type the initializer is called on. E.g. if calling `try IfStmtSyntax("while x < 5") {}`
62
- init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) rethrows
67
+ init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) rethrows
63
68
}
64
69
65
70
public extension HasTrailingCodeBlock where Self: StmtSyntaxProtocol {
66
- init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) throws {
71
+ init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) throws {
67
72
let stmt = StmtSyntax ( " \( header) {} " )
68
73
guard let castedStmt = stmt. as ( Self . self) else {
69
74
throw SyntaxStringInterpolationError . producedInvalidNodeType ( expectedType: Self . self, actualNode: stmt)
@@ -74,7 +79,7 @@ public extension HasTrailingCodeBlock where Self: StmtSyntaxProtocol {
74
79
}
75
80
76
81
extension CatchClauseSyntax : HasTrailingCodeBlock {
77
- public init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) rethrows {
82
+ public init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) rethrows {
78
83
self = CatchClauseSyntax ( " \( header) {} " )
79
84
self . body = try CodeBlockSyntax ( statements: bodyBuilder ( ) )
80
85
}
@@ -109,11 +114,11 @@ public protocol HasTrailingOptionalCodeBlock {
109
114
/// ```
110
115
///
111
116
/// Throws an error if `header` defines a different node type than the type the initializer is called on. E.g. if calling `try FunctionDeclSyntax("init") {}`
112
- init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) throws
117
+ init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) throws
113
118
}
114
119
115
120
public extension HasTrailingOptionalCodeBlock where Self: DeclSyntaxProtocol {
116
- init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) throws {
121
+ init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ) throws {
117
122
let decl = DeclSyntax ( " \( header) {} " )
118
123
guard let castedDecl = decl. as ( Self . self) else {
119
124
throw SyntaxStringInterpolationError . producedInvalidNodeType ( expectedType: Self . self, actualNode: decl)
@@ -154,11 +159,11 @@ public protocol HasTrailingMemberDeclBlock {
154
159
/// ```
155
160
///
156
161
/// Throws an error if `header` defines a different node type than the type the initializer is called on. E.g. if calling `try StructDeclSyntax("class MyClass") {}`
157
- init ( _ header: PartialSyntaxNodeString , @MemberBlockItemListBuilder membersBuilder: ( ) throws -> MemberBlockItemListSyntax ) throws
162
+ init ( _ header: SyntaxNodeString , @MemberBlockItemListBuilder membersBuilder: ( ) throws -> MemberBlockItemListSyntax ) throws
158
163
}
159
164
160
165
public extension HasTrailingMemberDeclBlock where Self: DeclSyntaxProtocol {
161
- init ( _ header: PartialSyntaxNodeString , @MemberBlockItemListBuilder membersBuilder: ( ) throws -> MemberBlockItemListSyntax ) throws {
166
+ init ( _ header: SyntaxNodeString , @MemberBlockItemListBuilder membersBuilder: ( ) throws -> MemberBlockItemListSyntax ) throws {
162
167
let decl = DeclSyntax ( " \( header) {} " )
163
168
guard let castedDecl = decl. as ( Self . self) else {
164
169
throw SyntaxStringInterpolationError . producedInvalidNodeType ( expectedType: Self . self, actualNode: decl)
@@ -198,7 +203,7 @@ public extension IfExprSyntax {
198
203
///
199
204
/// Throws an error if `header` does not start an `if` expression. E.g. if calling `try IfExprSyntax("while true") {}`
200
205
init (
201
- _ header: PartialSyntaxNodeString ,
206
+ _ header: SyntaxNodeString ,
202
207
@CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax ,
203
208
@CodeBlockItemListBuilder `else` elseBuilder: ( ) throws -> CodeBlockItemListSyntax ? = { nil }
204
209
) throws {
@@ -246,7 +251,7 @@ public extension IfExprSyntax {
246
251
/// ```
247
252
///
248
253
/// Throws an error if `header` does not start an `if` expression. E.g. if calling `try IfExprSyntax("while true", bodyBuilder: {}, elseIf: {})`
249
- init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax , elseIf: IfExprSyntax ) throws {
254
+ init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder bodyBuilder: ( ) throws -> CodeBlockItemListSyntax , elseIf: IfExprSyntax ) throws {
250
255
let expr = ExprSyntax ( " \( header) {} " )
251
256
guard let ifExpr = expr. as ( Self . self) else {
252
257
throw SyntaxStringInterpolationError . producedInvalidNodeType ( expectedType: Self . self, actualNode: expr)
@@ -279,7 +284,7 @@ extension SwitchCaseSyntax {
279
284
/// ```
280
285
///
281
286
/// Throws an error if `header` does not start a switch case item. E.g. if calling `try SwitchCaseSyntax("func foo") {}`
282
- public init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder statementsBuilder: ( ) throws -> CodeBlockItemListSyntax ) rethrows {
287
+ public init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder statementsBuilder: ( ) throws -> CodeBlockItemListSyntax ) rethrows {
283
288
self = SwitchCaseSyntax ( " \( header) " )
284
289
self . statements = try statementsBuilder ( )
285
290
}
@@ -313,7 +318,7 @@ public extension SwitchExprSyntax {
313
318
/// ```
314
319
///
315
320
/// Throws an error if `header` does not start a switch expression. E.g. if calling `try SwitchExprSyntax("if x < 42") {}`
316
- init ( _ header: PartialSyntaxNodeString , @SwitchCaseListBuilder casesBuilder: ( ) throws -> SwitchCaseListSyntax = { SwitchCaseListSyntax ( [ ] ) } ) throws {
321
+ init ( _ header: SyntaxNodeString , @SwitchCaseListBuilder casesBuilder: ( ) throws -> SwitchCaseListSyntax = { SwitchCaseListSyntax ( [ ] ) } ) throws {
317
322
let expr = ExprSyntax ( " \( header) {} " )
318
323
guard let switchExpr = expr. as ( Self . self) else {
319
324
throw SyntaxStringInterpolationError . producedInvalidNodeType ( expectedType: Self . self, actualNode: expr)
@@ -347,7 +352,7 @@ public extension VariableDeclSyntax {
347
352
/// ```
348
353
///
349
354
/// Throws an error if `header` does not start a variable declaration. E.g. if calling `try VariableDeclSyntax("func foo") {}`
350
- init ( _ header: PartialSyntaxNodeString , @CodeBlockItemListBuilder accessor: ( ) throws -> CodeBlockItemListSyntax ) throws {
355
+ init ( _ header: SyntaxNodeString , @CodeBlockItemListBuilder accessor: ( ) throws -> CodeBlockItemListSyntax ) throws {
351
356
let decl = DeclSyntax ( " \( header) {} " )
352
357
guard let castedDecl = decl. as ( Self . self) else {
353
358
throw SyntaxStringInterpolationError . producedInvalidNodeType ( expectedType: Self . self, actualNode: decl)
0 commit comments