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_BY_CONFORMANCES
7
+ SYNTAX_COLLECTION_EXPRESSIBLE_BY_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,8 +43,10 @@ public protocol ${kind}ListBuildable: SyntaxListBuildable {
42
43
43
44
% buildable_type = kind + 'Buildable'
44
45
% expressible_by_type = 'ExpressibleBy' + buildable_type
45
- % expressible_by_protocols = SYNTAX_BUILDABLE_EXPRESSIBLE_BY_CONFORMANCES.get(expressible_by_type)
46
- % if expressible_by_protocols:
46
+ % expressible_by_protocols = SYNTAX_COLLECTION_EXPRESSIBLE_BY_CONFORMANCES.get(buildable_type) or []
47
+ % expressible_by_protocols += SYNTAX_BUILDABLE_EXPRESSIBLE_BY_CONFORMANCES.get(buildable_type) or []
48
+ % expressible_by_protocols = map(lambda x : 'ExpressibleBy' +x, expressible_by_protocols)
49
+ % if expressible_by_protocols and expressible_by_protocols is not []:
47
50
public protocol ${expressible_by_type}: ${', '.join(expressible_by_protocols)} {
48
51
% else:
49
52
public protocol ${expressible_by_type} {
@@ -220,8 +223,10 @@ public struct ${node.syntax_kind}: SyntaxBuildable {
220
223
% end
221
224
% if node.is_buildable() or node.is_syntax_collection():
222
225
% expressible_by_type = 'ExpressibleBy' + node.syntax_kind
223
- % expressible_by_protocols = SYNTAX_BUILDABLE_EXPRESSIBLE_BY_CONFORMANCES.get(expressible_by_type)
224
- % if expressible_by_protocols:
226
+ % expressible_by_protocols = SYNTAX_COLLECTION_EXPRESSIBLE_BY_CONFORMANCES.get(node.syntax_kind) or []
227
+ % expressible_by_protocols += SYNTAX_BUILDABLE_EXPRESSIBLE_BY_CONFORMANCES.get(node.syntax_kind) or []
228
+ % expressible_by_protocols = map(lambda x : 'ExpressibleBy' +x, expressible_by_protocols)
229
+ % if expressible_by_protocols and expressible_by_protocols is not []:
225
230
public protocol ${expressible_by_type}: ${', '.join(expressible_by_protocols)} {
226
231
% else:
227
232
public protocol ${expressible_by_type} {
@@ -249,15 +254,18 @@ extension TokenSyntax: ExpressibleByTokenSyntax {
249
254
250
255
// MARK: - Syntax buildable expressible by conformances
251
256
252
- % for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_BY_CONFORMANCES .items():
253
- % if 'ExpressibleByConditionElementList' in conformances:
254
- extension ${protocol} {
255
- public func createConditionElementList () -> ConditionElementList {
256
- ConditionElementList ([self])
257
+ % for protocol, conformances in SYNTAX_COLLECTION_EXPRESSIBLE_BY_CONFORMANCES .items():
258
+ % for conformance in conformances:
259
+ extension ExpressibleBy ${protocol} {
260
+ public func create${conformance} () -> ${conformance} {
261
+ ${conformance} ([self])
257
262
}
258
263
}
259
264
260
265
% end
266
+ % end
267
+
268
+ % for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_BY_CONFORMANCES.items():
261
269
% if 'ExpressibleByConditionElement' in conformances:
262
270
extension ${protocol} {
263
271
public func createConditionElement() -> ConditionElement {
@@ -282,4 +290,4 @@ extension ${protocol} {
282
290
}
283
291
284
292
% end
285
- % end
293
+ % end
0 commit comments