Skip to content

Commit 2355440

Browse files
committed
Generate extensions for protocolsMap.py
1 parent e73e11b commit 2355440

File tree

2 files changed

+13
-54
lines changed

2 files changed

+13
-54
lines changed

Sources/SwiftSyntaxBuilder/Buildables.swift.gyb

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from gyb_syntax_support.kinds import syntax_buildable_child_type, syntax_buildable_default_init_value
66
from gyb_syntax_support.protocolsMap import SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES
77
SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES = syntax_collection_element_to_collection_mapping()
8+
NODE_MAP = create_node_map()
89
# -*- mode: Swift -*-
910
# Ignore the following admonition it applies to the resulting .swift file only
1011
}%
@@ -264,57 +265,17 @@ extension TokenSyntax: ExpressibleAsTokenSyntax {
264265

265266
% end
266267
% end
267-
268-
% for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
269-
% if 'ExpressibleAsConditionElementList' in conformances:
270-
extension ${protocol} {
271-
public func createConditionElementList() -> ConditionElementList {
272-
ConditionElementList([self])
273-
}
274-
}
275-
276-
% end
277-
% end
278-
279268
% for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
280-
% if 'ConditionElement' in conformances:
269+
% for conformance in conformances:
270+
% node = NODE_MAP.get(conformance)
271+
% if node and node.children:
272+
% param = filter(lambda x : x.type_name != "TokenSyntax", node.children)[0].swift_name
281273
extension ExpressibleAs${protocol} {
282-
public func createConditionElement() -> ConditionElement {
283-
ConditionElement(condition: self)
284-
}
285-
}
286-
287-
% end
288-
% if 'CodeBlockItem' in conformances:
289-
extension ExpressibleAs${protocol} {
290-
public func createCodeBlockItem() -> CodeBlockItem {
291-
CodeBlockItem(item: self)
292-
}
293-
}
294-
295-
% end
296-
% if 'MemberDeclListItem' in conformances:
297-
extension ExpressibleAs${protocol} {
298-
public func createMemberDeclListItem() -> MemberDeclListItem {
299-
MemberDeclListItem(decl: self)
300-
}
301-
}
302-
303-
% end
304-
% if 'TypeAnnotation' in conformances:
305-
extension ExpressibleAs${protocol} {
306-
public func createTypeAnnotation() -> TypeAnnotation {
307-
TypeAnnotation(type: self)
274+
public func create${conformance}() -> ${conformance} {
275+
${conformance}(${param}: self)
308276
}
309277
}
310278

279+
% end
311280
% end
312-
% if 'TypeExpr' in conformances:
313-
extension ExpressibleAs${protocol} {
314-
public func createTypeExpr() -> TypeExpr {
315-
TypeExpr(type: self)
316-
}
317-
}
318-
319-
% end
320281
% end

Sources/SwiftSyntaxBuilder/gyb_generated/Buildables.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11424,8 +11424,6 @@ extension TokenSyntax: ExpressibleAsTokenSyntax {
1142411424
}
1142511425
}
1142611426

11427-
11428-
1142911427
extension ExpressibleAsDeclBuildable {
1143011428
public func createCodeBlockItem() -> CodeBlockItem {
1143111429
CodeBlockItem(item: self)
@@ -11456,9 +11454,9 @@ extension ExpressibleAsSimpleTypeIdentifier {
1145611454
}
1145711455
}
1145811456

11459-
extension ExpressibleAsSimpleTypeIdentifier {
11460-
public func createTypeExpr() -> TypeExpr {
11461-
TypeExpr(type: self)
11462-
}
11463-
}
11457+
extension ExpressibleAsSimpleTypeIdentifier {
11458+
public func createTypeExpr() -> TypeExpr {
11459+
TypeExpr(type: self)
11460+
}
11461+
}
1146411462

0 commit comments

Comments
 (0)