@@ -128,15 +128,20 @@ public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
128
128
% child_token = SYNTAX_TOKEN_MAP.get(child.syntax_kind)
129
129
% param_type = syntax_buildable_child_type(child.type_name, child.syntax_kind, child.is_token(), child.is_optional)
130
130
% default_value = syntax_buildable_default_init_value(child, child_token)
131
- % init_parameters.append("%s: ExpressibleAs%s%s" % (child.swift_name, param_type, default_value))
131
+ % param_type = param_type if child.is_token() else "ExpressibleAs" + param_type
132
+ % init_parameters.append("%s: %s%s" % (child.swift_name, param_type, default_value))
132
133
% end
133
134
${',\n '.join(init_parameters)}
134
135
) {
135
136
% for child in node.children:
136
137
% create_method_dot = '?.' if child.is_optional else '.'
137
138
% child_token = SYNTAX_TOKEN_MAP.get(child.syntax_kind)
138
139
% param_type = syntax_buildable_child_type(child.type_name, child.syntax_kind, child.is_token())
140
+ % if param_type is 'TokenSyntax':
141
+ self.${child.swift_name} = ${child.swift_name}
142
+ % else:
139
143
self.${child.swift_name} = ${child.swift_name}${create_method_dot}create${param_type}()
144
+ % end
140
145
% end
141
146
}
142
147
@@ -192,8 +197,13 @@ public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
192
197
public struct ${node.syntax_kind}: SyntaxBuildable {
193
198
let elements: [${element_type}]
194
199
195
- public init(_ elements: [ExpressibleAs${element_type}]) {
200
+ % param_type = element_type if node.is_token() else 'ExpressibleAs' + element_type
201
+ public init(_ elements: [${param_type}]) {
202
+ % if node.is_token():
203
+ self.elements = elements
204
+ % else:
196
205
self.elements = elements.map { $0.create${element_type}() }
206
+ % end
197
207
}
198
208
199
209
public func build${node.syntax_kind}(format: Format) -> ${node.syntax_kind}Syntax {
@@ -243,21 +253,13 @@ extension ${node.syntax_kind}: ${expressible_as_type} {
243
253
244
254
% end
245
255
% end
246
- public protocol ExpressibleAsTokenSyntax {
247
- func createTokenSyntax() -> TokenSyntax
248
- }
249
-
250
- extension TokenSyntax: ExpressibleAsTokenSyntax {
251
- public func createTokenSyntax() -> TokenSyntax {
252
- self
253
- }
254
- }
255
256
256
257
// MARK: - Syntax buildable expressible as conformances
257
258
258
259
% for protocol, conformances in SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES.items():
259
260
% for conformance in conformances:
260
- extension ExpressibleAs${protocol} {
261
+ % extension_protocol = protocol if protocol is 'TokenSyntax' else 'ExpressibleAs' + protocol
262
+ extension ${extension_protocol} {
261
263
public func create${conformance}() -> ${conformance} {
262
264
${conformance}([self])
263
265
}
@@ -272,7 +274,8 @@ extension TokenSyntax: ExpressibleAsTokenSyntax {
272
274
% non_defaulted_params = filter(lambda child : syntax_buildable_default_init_value(child, SYNTAX_TOKEN_MAP.get(child.syntax_kind)) == "", node.children)
273
275
% assert len(non_defaulted_params) == 1, "ExpressibleAs conformances expects the conforming type to have an initializer with a single non-optional child"
274
276
% param = non_defaulted_params[0].swift_name
275
- extension ExpressibleAs${protocol} {
277
+ % extension_protocol = protocol if protocol is 'TokenSyntax' else 'ExpressibleAs' + protocol
278
+ extension ${extension_protocol} {
276
279
public func create${conformance}() -> ${conformance} {
277
280
${conformance}(${param}: self)
278
281
}
0 commit comments