Skip to content

Generate extensions for protocolsMap.py #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 10 additions & 47 deletions Sources/SwiftSyntaxBuilder/Buildables.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from gyb_syntax_support.kinds import syntax_buildable_child_type, syntax_buildable_default_init_value
from gyb_syntax_support.protocolsMap import SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES
SYNTAX_COLLECTION_EXPRESSIBLE_AS_CONFORMANCES = syntax_collection_element_to_collection_mapping()
NODE_MAP = create_node_map()
# -*- mode: Swift -*-
# Ignore the following admonition it applies to the resulting .swift file only
}%
Expand Down Expand Up @@ -264,57 +265,19 @@ extension TokenSyntax: ExpressibleAsTokenSyntax {

% end
% end

% for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
% if 'ExpressibleAsConditionElementList' in conformances:
extension ${protocol} {
public func createConditionElementList() -> ConditionElementList {
ConditionElementList([self])
}
}

% end
% end
Comment on lines -268 to -277
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one properly slipped through when added #334


% for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
% if 'ConditionElement' in conformances:
% for conformance in conformances:
% node = NODE_MAP.get(conformance)
% if node and node.children:
% non_defaulted_params = filter(lambda child : syntax_buildable_default_init_value(child, SYNTAX_TOKEN_MAP.get(child.syntax_kind)) == "", node.children)
% assert len(non_defaulted_params) == 1, "ExpressibleAs conformances expects the conforming type to have an initializer with a single non-optional child"
% param = non_defaulted_params[0].swift_name
extension ExpressibleAs${protocol} {
public func createConditionElement() -> ConditionElement {
ConditionElement(condition: self)
}
}

% end
% if 'CodeBlockItem' in conformances:
extension ExpressibleAs${protocol} {
public func createCodeBlockItem() -> CodeBlockItem {
CodeBlockItem(item: self)
}
}

% end
% if 'MemberDeclListItem' in conformances:
extension ExpressibleAs${protocol} {
public func createMemberDeclListItem() -> MemberDeclListItem {
MemberDeclListItem(decl: self)
}
}

% end
% if 'TypeAnnotation' in conformances:
extension ExpressibleAs${protocol} {
public func createTypeAnnotation() -> TypeAnnotation {
TypeAnnotation(type: self)
public func create${conformance}() -> ${conformance} {
${conformance}(${param}: self)
}
}

% end
% end
% if 'TypeExpr' in conformances:
extension ExpressibleAs${protocol} {
public func createTypeExpr() -> TypeExpr {
TypeExpr(type: self)
}
}

% end
% end
12 changes: 5 additions & 7 deletions Sources/SwiftSyntaxBuilder/gyb_generated/Buildables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11424,8 +11424,6 @@ extension TokenSyntax: ExpressibleAsTokenSyntax {
}
}



extension ExpressibleAsDeclBuildable {
public func createCodeBlockItem() -> CodeBlockItem {
CodeBlockItem(item: self)
Expand Down Expand Up @@ -11456,9 +11454,9 @@ extension ExpressibleAsSimpleTypeIdentifier {
}
}

extension ExpressibleAsSimpleTypeIdentifier {
public func createTypeExpr() -> TypeExpr {
TypeExpr(type: self)
}
}
extension ExpressibleAsSimpleTypeIdentifier {
public func createTypeExpr() -> TypeExpr {
TypeExpr(type: self)
}
}