File tree Expand file tree Collapse file tree 2 files changed +429
-19
lines changed Expand file tree Collapse file tree 2 files changed +429
-19
lines changed Original file line number Diff line number Diff line change @@ -31,18 +31,32 @@ public protocol Raw${node.name}NodeProtocol: Raw${node.base_type}NodeProtocol {}
31
31
public struct Raw ${ node. name} : Raw${ node. name if node. is_base( ) else node. base_type} NodeProtocol, RawSyntaxToSyntax {
32
32
% for child in node. children:
33
33
% if child. node_choices:
34
- public enum ${ child. name} {
34
+ public enum ${ child. name} : RawSyntaxNodeProtocol {
35
35
% for choice in child. node_choices :
36
36
case `${choice.swift_name}`( Raw ${ choice. type_name} )
37
37
% end
38
38
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
+
39
43
public var raw : RawSyntax {
40
44
switch self {
41
45
% for choice in child. node_choices:
42
46
case . ${ choice. swift_name} ( let node) : return node. raw
43
47
% end
44
48
}
45
49
}
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
+ }
46
60
}
47
61
% end
48
62
% end
You can’t perform that action at this time.
0 commit comments