@@ -29,38 +29,42 @@ public protocol Raw${node.name}NodeProtocol: Raw${node.base_type}NodeProtocol {}
29
29
30
30
@_spi ( RawSyntax)
31
31
public struct Raw ${ node. name} : Raw${ node. name if node. is_base( ) else node. base_type} NodeProtocol, RawSyntaxToSyntax {
32
+ % enums = [ ]
32
33
% for child in node. children:
33
34
% if child. node_choices:
34
- public enum ${ child. name} : RawSyntaxNodeProtocol {
35
- % for choice in child. node_choices :
36
- case `${choice.swift_name}`( Raw ${ choice. type_name} )
37
- % end
35
+ % enums . append( ( child. name, [ ( choice. swift_name, choice. type_name) for choice in child. node_choices] ) )
36
+ % end
37
+ % end
38
+ % for ( name, choices) in enum s:
39
+ public enum ${ name} : RawSyntaxNodeProtocol {
40
+ % for (swift_name, type_name) in choices :
41
+ case `${swift_name}`( Raw ${ type_name} )
42
+ % end
38
43
39
44
public static func isKindOf ( _ raw: RawSyntax) - > Bool {
40
- return ${ " || " . join ( [ f" Raw{choice. type_name}.isKindOf(raw) " for choice in child . node_choices ] ) }
45
+ return ${ " || " . join ( [ f" Raw{type_name}.isKindOf(raw) " for ( swift_name , type_name ) in choices ] ) }
41
46
}
42
47
43
48
public var raw: RawSyntax {
44
49
switch self {
45
- % for choice in child . node_choices :
46
- case . ${ choice . swift_name} ( let node) : return node. raw
47
- % end
50
+ % for ( swift_name , type_name ) in choices :
51
+ case . ${ swift_name} ( let node) : return node. raw
52
+ % end
48
53
}
49
54
}
50
55
51
56
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)
57
+ % for ( swift_name , type_name ) in choices :
58
+ if let node = Raw${ type_name} ( other) {
59
+ self = . ${ swift_name} ( node)
55
60
return
56
61
}
57
- % end
62
+ % end
58
63
return nil
59
64
}
60
65
}
61
- % end
62
- % end
63
66
67
+ % end
64
68
public typealias SyntaxType = ${ node. name}
65
69
66
70
@_spi ( RawSyntax)
0 commit comments