4
4
from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS
5
5
from gyb_syntax_support.kinds import syntax_buildable_child_type, syntax_buildable_default_init_value
6
6
from gyb_syntax_support.protocolsMap import SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES
7
+ SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES = syntax_collection_element_to_collection_mapping()
7
8
# -*- mode: Swift -*-
8
9
# Ignore the following admonition it applies to the resulting .swift file only
9
10
}%
@@ -42,7 +43,9 @@ public protocol ${kind}ListBuildable: SyntaxListBuildable {
42
43
43
44
% buildable_type = kind + 'Buildable'
44
45
% expressible_as_type = 'ExpressibleAs' + buildable_type
45
- % expressible_as_protocols = SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.get(expressible_as_type)
46
+ % expressible_as_protocols = SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES.get(buildable_type) or []
47
+ % expressible_as_protocols += SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.get(buildable_type) or []
48
+ % expressible_as_protocols = map(lambda x : 'ExpressibleAs' + x, expressible_as_protocols)
46
49
% if expressible_as_protocols:
47
50
public protocol ${expressible_as_type}: ${', '.join(expressible_as_protocols)} {
48
51
% else:
@@ -220,7 +223,9 @@ public struct ${node.syntax_kind}: SyntaxBuildable {
220
223
% end
221
224
% if node.is_buildable() or node.is_syntax_collection():
222
225
% expressible_as_type = 'ExpressibleAs' + node.syntax_kind
223
- % expressible_as_protocols = SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.get(expressible_as_type)
226
+ % expressible_as_protocols = SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES.get(node.syntax_kind) or []
227
+ % expressible_as_protocols += SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.get(node.syntax_kind) or []
228
+ % expressible_as_protocols = map(lambda x : 'ExpressibleAs' + x, expressible_as_protocols)
224
229
% if expressible_as_protocols:
225
230
public protocol ${expressible_as_type}: ${', '.join(expressible_as_protocols)} {
226
231
% else:
@@ -249,6 +254,17 @@ extension TokenSyntax: ExpressibleAsTokenSyntax {
249
254
250
255
// MARK: - Syntax buildable expressible as conformances
251
256
257
+ % for protocol, conformances in SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES.items():
258
+ % for conformance in conformances:
259
+ extension ExpressibleAs${protocol} {
260
+ public func create${conformance}() -> ${conformance} {
261
+ ${conformance}([self])
262
+ }
263
+ }
264
+
265
+ % end
266
+ % end
267
+
252
268
% for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
253
269
% if 'ExpressibleAsConditionElementList' in conformances:
254
270
extension ${protocol} {
@@ -258,28 +274,31 @@ extension ${protocol} {
258
274
}
259
275
260
276
% end
261
- % if 'ExpressibleAsConditionElement' in conformances:
262
- extension ${protocol} {
277
+ % end
278
+
279
+ % for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
280
+ % if 'ConditionElement' in conformances:
281
+ extension ExpressibleAs${protocol} {
263
282
public func createConditionElement() -> ConditionElement {
264
283
ConditionElement(condition: self)
265
284
}
266
285
}
267
286
268
287
% end
269
- % if 'ExpressibleAsCodeBlockItem ' in conformances:
270
- extension ${protocol} {
288
+ % if 'CodeBlockItem ' in conformances:
289
+ extension ExpressibleAs ${protocol} {
271
290
public func createCodeBlockItem() -> CodeBlockItem {
272
291
CodeBlockItem(item: self)
273
292
}
274
293
}
275
294
276
295
% end
277
- % if 'ExpressibleAsMemberDeclListItem ' in conformances:
278
- extension ${protocol} {
296
+ % if 'MemberDeclListItem ' in conformances:
297
+ extension ExpressibleAs ${protocol} {
279
298
public func createMemberDeclListItem() -> MemberDeclListItem {
280
299
MemberDeclListItem(decl: self)
281
300
}
282
301
}
283
302
284
303
% end
285
- % end
304
+ % end
0 commit comments