Skip to content

Commit df9e8ad

Browse files
committed
Conform raw choice enums to RawSyntaxNodeProtocol
1 parent 77b422c commit df9e8ad

File tree

2 files changed

+429
-19
lines changed

2 files changed

+429
-19
lines changed

Sources/SwiftSyntax/Raw/RawSyntaxNodes.swift.gyb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,32 @@ public protocol Raw${node.name}NodeProtocol: Raw${node.base_type}NodeProtocol {}
3131
public struct Raw${node.name}: Raw${node.name if node.is_base() else node.base_type}NodeProtocol, RawSyntaxToSyntax {
3232
% for child in node.children:
3333
% if child.node_choices:
34-
public enum ${child.name} {
34+
public enum ${child.name}: RawSyntaxNodeProtocol {
3535
% for choice in child.node_choices:
3636
case `${choice.swift_name}`(Raw${choice.type_name})
3737
% end
3838

39+
public static func isKindOf(_ raw: RawSyntax) -> Bool {
40+
return ${" || ".join([f"Raw{choice.type_name}.isKindOf(raw)" for choice in child.node_choices])}
41+
}
42+
3943
public var raw: RawSyntax {
4044
switch self {
4145
% for choice in child.node_choices:
4246
case .${choice.swift_name}(let node): return node.raw
4347
% end
4448
}
4549
}
50+
51+
public init?<T>(_ other: T) where T : RawSyntaxNodeProtocol {
52+
% for choice in child.node_choices:
53+
if let node = Raw${choice.type_name}(other) {
54+
self = .${choice.swift_name}(node)
55+
return
56+
}
57+
% end
58+
return nil
59+
}
4660
}
4761
% end
4862
% end

0 commit comments

Comments
 (0)