@@ -18,31 +18,31 @@ import SyntaxSupport
18
18
/// SwiftSyntaxBuilder. In particular, this includes the functionality to create
19
19
/// the `*Buildable`, `ExpressibleAs*` and `*Syntax` Swift types from the syntax
20
20
/// kind.
21
- struct SyntaxBuildableType : Hashable {
22
- let syntaxKind : String
23
- let tokenKind : String ?
24
- let isOptional : Bool
21
+ public struct SyntaxBuildableType : Hashable {
22
+ public let syntaxKind : String
23
+ public let tokenKind : String ?
24
+ public let isOptional : Bool
25
25
26
26
/// Whether this is a token.
27
- var isToken : Bool {
27
+ public var isToken : Bool {
28
28
syntaxKind == " Token "
29
29
}
30
30
31
31
/// This type with `isOptional` set to false.
32
- var nonOptional : Self {
32
+ public var nonOptional : Self {
33
33
tokenKind. map { Self ( syntaxKind: $0) } ?? Self ( syntaxKind: syntaxKind)
34
34
}
35
35
36
36
/// The token if this is a token.
37
- var token : TokenSpec ? {
37
+ public var token : TokenSpec ? {
38
38
tokenKind. flatMap { SYNTAX_TOKEN_MAP [ $0] }
39
39
}
40
40
41
41
/// If the type has a default value (because it is optional or a token
42
42
/// with fixed test), return an expression of the form ` = defaultValue`
43
43
/// that can be used as the default value for a function parameter.
44
44
/// Otherwise, return the empty string.
45
- var defaultInitialization : ExpressibleAsExprBuildable ? {
45
+ public var defaultInitialization : ExpressibleAsExprBuildable ? {
46
46
if isOptional {
47
47
return NilLiteralExpr ( )
48
48
} else if isToken {
@@ -56,14 +56,14 @@ struct SyntaxBuildableType: Hashable {
56
56
}
57
57
58
58
/// Whether the type is a syntax collection.
59
- var isSyntaxCollection : Bool {
59
+ public var isSyntaxCollection : Bool {
60
60
syntaxKind == " SyntaxCollection "
61
61
|| ( baseType. map ( \. isSyntaxCollection) ?? false )
62
62
}
63
63
64
64
/// The raw base name of this kind. Used for the `build*` methods in the
65
65
/// defined in the buildable types.
66
- var baseName : String {
66
+ public var baseName : String {
67
67
syntaxKind
68
68
}
69
69
@@ -75,20 +75,20 @@ struct SyntaxBuildableType: Hashable {
75
75
/// - For base kinds: `<BaseKind>Buildable`, e.g. `ExprBuildable` (these are implemented as protocols)
76
76
/// - For token: `TokenSyntax` (tokens don't have a dedicated type in SwiftSyntaxBuilder)
77
77
/// If the type is optional, the type is wrapped in an `OptionalType`.
78
- var buildable : ExpressibleAsTypeBuildable {
78
+ public var buildable : ExpressibleAsTypeBuildable {
79
79
optionalWrapped ( type: buildableBaseName)
80
80
}
81
81
82
82
/// Whether parameters of this type should be initializable by a result builder.
83
83
/// Used for certain syntax collections and block-like structures (e.g. `CodeBlock`,
84
84
/// `MemberDeclList`).
85
- var isBuilderInitializable : Bool {
85
+ public var isBuilderInitializable : Bool {
86
86
BUILDER_INITIALIZABLE_TYPES . keys. contains ( buildableBaseName)
87
87
}
88
88
89
89
/// A type suitable for initializing this type through a result builder (e.g.
90
90
/// returns `CodeBlockItemList` for `CodeBlock`) and otherwise itself.
91
- var builderInitializableType : Self {
91
+ public var builderInitializableType : Self {
92
92
Self (
93
93
syntaxKind: BUILDER_INITIALIZABLE_TYPES [ buildableBaseName] . flatMap { $0 } ?? buildableBaseName,
94
94
isOptional: isOptional
@@ -97,7 +97,7 @@ struct SyntaxBuildableType: Hashable {
97
97
98
98
/// The type from `buildable()` without any question marks attached.
99
99
/// This is used for the `create*` methods defined in the `ExpressibleAs*` protocols.
100
- var buildableBaseName : String {
100
+ public var buildableBaseName : String {
101
101
if SYNTAX_BASE_KINDS . contains ( syntaxKind) {
102
102
return " \( syntaxKind) Buildable "
103
103
} else {
@@ -107,7 +107,7 @@ struct SyntaxBuildableType: Hashable {
107
107
108
108
/// The `ExpressibleAs*` Swift type for this syntax kind without any
109
109
/// question marks attached.
110
- var expressibleAsBaseName : String {
110
+ public var expressibleAsBaseName : String {
111
111
if isToken {
112
112
// Tokens don't have a dedicated ExpressibleAs type.
113
113
return buildableBaseName
@@ -119,13 +119,13 @@ struct SyntaxBuildableType: Hashable {
119
119
/// The `ExpressibleAs*` Swift type for this syntax kind. Tokens don't
120
120
/// have an `ExpressibleAs*` type, so for those this method just returns
121
121
/// `TokenSyntax`. If the type is optional, this terminates with a `?`.
122
- var expressibleAs : ExpressibleAsTypeBuildable {
122
+ public var expressibleAs : ExpressibleAsTypeBuildable {
123
123
optionalWrapped ( type: expressibleAsBaseName)
124
124
}
125
125
126
126
/// The corresponding `*Syntax` type defined in the `SwiftSyntax` module,
127
127
/// without any question marks attached.
128
- var syntaxBaseName : String {
128
+ public var syntaxBaseName : String {
129
129
if syntaxKind == " Syntax " {
130
130
return " Syntax "
131
131
} else {
@@ -136,60 +136,60 @@ struct SyntaxBuildableType: Hashable {
136
136
/// The corresponding `*Syntax` type defined in the `SwiftSyntax` module,
137
137
/// which will eventually get built from `SwiftSyntaxBuilder`. If the type
138
138
/// is optional, this terminates with a `?`.
139
- var syntax : ExpressibleAsTypeBuildable {
139
+ public var syntax : ExpressibleAsTypeBuildable {
140
140
optionalWrapped ( type: syntaxBaseName)
141
141
}
142
142
143
143
/// Assuming that this is a base kind, return the corresponding `*ListBuildable` type
144
144
/// without any question marks attached.
145
- var listBuildableBaseName : String {
145
+ public var listBuildableBaseName : String {
146
146
assert ( SYNTAX_BASE_KINDS . contains ( syntaxKind) , " ListBuildable types only exist for syntax base kinds " )
147
147
return " \( syntaxKind) ListBuildable "
148
148
}
149
149
150
150
/// Assuming that this is a base kind, return the corresponding `*ListBuildable` type.
151
- var listBuildable : ExpressibleAsTypeBuildable {
151
+ public var listBuildable : ExpressibleAsTypeBuildable {
152
152
optionalWrapped ( type: listBuildableBaseName)
153
153
}
154
154
155
155
/// Assuming that this is a collection type, the non-optional type of the result builder
156
156
/// that can be used to build the collection.
157
- var resultBuilderBaseName : String {
157
+ public var resultBuilderBaseName : String {
158
158
" \( syntaxKind) Builder "
159
159
}
160
160
161
161
/// Assuming that this is a collection type, the type of the result builder
162
162
/// that can be used to build the collection.
163
- var resultBuilder : ExpressibleAsTypeBuildable {
163
+ public var resultBuilder : ExpressibleAsTypeBuildable {
164
164
optionalWrapped ( type: resultBuilderBaseName)
165
165
}
166
166
167
167
/// The collection types in which this type occurs as an element.
168
168
/// We automatically make the `ExpressibleAs*` protocols conform to the
169
169
/// `ExpressibleAs*` protocol of the collection they occur in.
170
- var elementInCollections : [ Self ] {
170
+ public var elementInCollections : [ Self ] {
171
171
SYNTAX_NODES
172
172
. filter { $0. isSyntaxCollection && $0. collectionElementType == self }
173
173
. map { $0. type }
174
174
}
175
175
176
176
/// Whether this type has the `WithTrailingComma` trait.
177
- var hasWithTrailingCommaTrait : Bool {
177
+ public var hasWithTrailingCommaTrait : Bool {
178
178
SYNTAX_NODES . contains { $0. type == self && $0. traits. contains ( " WithTrailingComma " ) }
179
179
}
180
180
181
181
/// Types that take a single non-optional parameter of this types
182
182
/// and to which this type is thus convertible. We automatically
183
183
/// make the `ExpressibleAs*` of this type conform to the `ExpressibleAs*`
184
184
/// protocol of the convertible types.
185
- var convertibleToTypes : [ Self ] {
185
+ public var convertibleToTypes : [ Self ] {
186
186
( SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES [ buildableBaseName] ?? [ ] )
187
187
. map { Self ( syntaxKind: $0) }
188
188
}
189
189
190
190
/// If this type is not a base kind, its base type (see `SyntaxBuildableNode.base_type()`),
191
191
/// otherwise `nil`.
192
- var baseType : Self ? {
192
+ public var baseType : Self ? {
193
193
if !SYNTAX_BASE_KINDS. contains ( syntaxKind) && !isToken {
194
194
return Node . from ( type: self ) . baseType
195
195
} else {
@@ -199,7 +199,7 @@ struct SyntaxBuildableType: Hashable {
199
199
200
200
/// The types to which this `ExpressibleAs*` type conforms to via
201
201
/// automatically generated conformances.
202
- var generatedExpressibleAsConformances : [ Self ] {
202
+ public var generatedExpressibleAsConformances : [ Self ] {
203
203
var conformances = elementInCollections + convertibleToTypes
204
204
if let baseType = baseType, baseType. baseName != " SyntaxCollection " {
205
205
conformances. append ( baseType)
@@ -209,7 +209,7 @@ struct SyntaxBuildableType: Hashable {
209
209
210
210
/// The types to which this `ExpressibleAs*` type conforms to via
211
211
/// automatically generated conformances, including transitive conformances.
212
- var transitiveExpressibleAsConformances : [ Self ] {
212
+ public var transitiveExpressibleAsConformances : [ Self ] {
213
213
generatedExpressibleAsConformances. flatMap { conformance in
214
214
[ conformance] + conformance. transitiveExpressibleAsConformances
215
215
}
@@ -218,13 +218,13 @@ struct SyntaxBuildableType: Hashable {
218
218
/// The types to which this `ExpressibleAs*` type implicitly conforms
219
219
/// to via transitive conformances. These conformances don't need to be
220
220
/// spelled out explicitly in the source code.
221
- var impliedExpressibleAsConformances : [ Self ] {
221
+ public var impliedExpressibleAsConformances : [ Self ] {
222
222
generatedExpressibleAsConformances. flatMap { conformance in
223
223
conformance. transitiveExpressibleAsConformances
224
224
}
225
225
}
226
226
227
- init ( syntaxKind: String , isOptional: Bool = false ) {
227
+ public init ( syntaxKind: String , isOptional: Bool = false ) {
228
228
self . isOptional = isOptional
229
229
if syntaxKind. hasSuffix ( " Token " ) {
230
230
// There are different token kinds but all of them are represented by `Token` in the Swift source (see `kind_to_type` in `gyb_syntax_support`).
@@ -237,7 +237,7 @@ struct SyntaxBuildableType: Hashable {
237
237
}
238
238
239
239
/// Wraps a type in an optional depending on whether `isOptional` is true.
240
- func optionalWrapped( type: ExpressibleAsTypeBuildable ) -> ExpressibleAsTypeBuildable {
240
+ public func optionalWrapped( type: ExpressibleAsTypeBuildable ) -> ExpressibleAsTypeBuildable {
241
241
if isOptional {
242
242
return OptionalType ( wrappedType: type)
243
243
} else {
@@ -246,7 +246,7 @@ struct SyntaxBuildableType: Hashable {
246
246
}
247
247
248
248
/// Wraps a type in an optional chaining depending on whether `isOptional` is true.
249
- func optionalChained( expr: ExpressibleAsExprBuildable ) -> ExpressibleAsExprBuildable {
249
+ public func optionalChained( expr: ExpressibleAsExprBuildable ) -> ExpressibleAsExprBuildable {
250
250
if isOptional {
251
251
return OptionalChainingExpr ( expression: expr)
252
252
} else {
@@ -255,7 +255,7 @@ struct SyntaxBuildableType: Hashable {
255
255
}
256
256
257
257
/// Wraps a type in a force unwrap expression depending on whether `isOptional` is true.
258
- func forceUnwrappedIfNeeded( expr: ExpressibleAsExprBuildable ) -> ExpressibleAsExprBuildable {
258
+ public func forceUnwrappedIfNeeded( expr: ExpressibleAsExprBuildable ) -> ExpressibleAsExprBuildable {
259
259
if isOptional {
260
260
return ForcedValueExpr ( expression: expr)
261
261
} else {
@@ -265,7 +265,7 @@ struct SyntaxBuildableType: Hashable {
265
265
266
266
/// Generate an expression that converts a variable named `varName`
267
267
/// which is of `expressibleAs` type to an object of type `buildable`.
268
- func generateExprConvertParamTypeToStorageType( varName: String ) -> ExpressibleAsExprBuildable {
268
+ public func generateExprConvertParamTypeToStorageType( varName: String ) -> ExpressibleAsExprBuildable {
269
269
if isToken {
270
270
return varName
271
271
} else {
0 commit comments