@@ -140,15 +140,20 @@ public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
140
140
% child_token = SYNTAX_TOKEN_MAP.get(child.syntax_kind)
141
141
% param_type = syntax_buildable_child_type(child.type_name, child.syntax_kind, child.is_token(), child.is_optional)
142
142
% default_value = syntax_buildable_default_init_value(child, child_token)
143
- % init_parameters.append("%s: ExpressibleAs%s%s" % (child.swift_name, param_type, default_value))
143
+ % param_type = param_type if child.is_token() else "ExpressibleAs" + param_type
144
+ % init_parameters.append("%s: %s%s" % (child.swift_name, param_type, default_value))
144
145
% end
145
146
${',\n '.join(init_parameters)}
146
147
) {
147
148
% for child in node.children:
148
149
% create_method_dot = '?.' if child.is_optional else '.'
149
150
% child_token = SYNTAX_TOKEN_MAP.get(child.syntax_kind)
150
151
% param_type = syntax_buildable_child_type(child.type_name, child.syntax_kind, child.is_token())
152
+ % if param_type is 'TokenSyntax':
153
+ self.${child.swift_name} = ${child.swift_name}
154
+ % else:
151
155
self.${child.swift_name} = ${child.swift_name}${create_method_dot}create${param_type}()
156
+ % end
152
157
% end
153
158
}
154
159
@@ -204,11 +209,16 @@ public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
204
209
public struct ${node.syntax_kind}: SyntaxBuildable {
205
210
let elements: [${element_type}]
206
211
212
+ % param_type = element_type if node.is_token() else 'ExpressibleAs' + element_type
207
213
/// Creates a `${node.syntax_kind}` with the provided list of elements.
208
214
/// - Parameters:
209
215
/// - elements: A list of `ExpressibleAs${element_type}`
210
- public init(_ elements: [ExpressibleAs${element_type}]) {
216
+ public init(_ elements: [${param_type}]) {
217
+ % if node.is_token():
218
+ self.elements = elements
219
+ % else:
211
220
self.elements = elements.map { $0.create${element_type}() }
221
+ % end
212
222
}
213
223
214
224
public func build${node.syntax_kind}(format: Format) -> ${node.syntax_kind}Syntax {
@@ -258,36 +268,38 @@ extension ${node.syntax_kind}: ${expressible_as_type} {
258
268
259
269
% end
260
270
% end
261
- public protocol ExpressibleAsTokenSyntax {
262
- func createTokenSyntax() -> TokenSyntax
263
- }
264
-
265
- extension TokenSyntax: ExpressibleAsTokenSyntax {
266
- public func createTokenSyntax() -> TokenSyntax {
267
- self
268
- }
271
+ % expressible_as_protocols = (SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES.get('TokenSyntax') or [])[:]
272
+ % expressible_as_protocols += (SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.get('TokenSyntax') or [])[:]
273
+ % expressible_as_protocols = map(lambda x : 'ExpressibleAs' + x, expressible_as_protocols)
274
+ % if expressible_as_protocols:
275
+ extension TokenSyntax: ${', '.join(expressible_as_protocols)} {
269
276
}
277
+ % end
270
278
271
- // MARK: - Syntax buildable expressible as conformances
279
+ // MARK: - Syntax Collection buildable expressible as conformances
272
280
273
281
% for protocol, conformances in SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES.items():
274
- % for conformance in conformances:
275
- extension ExpressibleAs${protocol} {
282
+ % for conformance in conformances:
283
+ % extension_protocol = protocol if protocol is 'TokenSyntax' else 'ExpressibleAs' + protocol
284
+ extension ${extension_protocol} {
276
285
public func create${conformance}() -> ${conformance} {
277
286
${conformance}([self])
278
287
}
279
288
}
280
289
281
- % end
282
- % end
290
+ % end
291
+ % end
292
+ // MARK: - Syntax buildable expressible as conformances
293
+
283
294
% for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
284
295
% for conformance in conformances:
285
296
% node = NODE_MAP.get(conformance)
286
297
% if node and node.children:
287
298
% non_defaulted_params = filter(lambda child : syntax_buildable_default_init_value(child, SYNTAX_TOKEN_MAP.get(child.syntax_kind)) == "", node.children)
288
299
% assert len(non_defaulted_params) == 1, "ExpressibleAs conformances expects the conforming type to have an initializer with a single non-optional child"
289
300
% param = non_defaulted_params[0].swift_name
290
- extension ExpressibleAs${protocol} {
301
+ % extension_protocol = protocol if protocol is 'TokenSyntax' else 'ExpressibleAs' + protocol
302
+ extension ${extension_protocol} {
291
303
public func create${conformance}() -> ${conformance} {
292
304
${conformance}(${param}: self)
293
305
}
0 commit comments