20
20
public protocol SyntaxTransformVisitor {
21
21
associatedtype ResultType = Void
22
22
23
- func visit( _ token: TokenSyntax ) -> [ ResultType ]
24
- func visit( _ node: UnknownSyntax ) -> [ ResultType ]
23
+ func visit( _ token: TokenSyntax ) -> ResultType
24
+ func visit( _ node: UnknownSyntax ) -> ResultType
25
25
26
26
% for node in SYNTAX_NODES:
27
27
% if is_visitable( node ) :
28
28
/// Visiting `${node.name}` specifically.
29
29
/// - Parameter node: the node we are visiting.
30
30
/// - Returns: the sum of whatever the child visitors return.
31
- func visit( _ node: ${ node. name} ) -> [ ResultType ]
31
+ func visit( _ node: ${ node. name} ) -> ResultType
32
32
% end
33
33
% end
34
34
}
35
35
36
36
extension SyntaxTransformVisitor {
37
- public func visit( _ token: TokenSyntax ) -> [ ResultType ] { [ ] }
38
- public func visit( _ node: UnknownSyntax ) -> [ ResultType ] { [ ] }
37
+ public func visit( _ token: TokenSyntax ) -> ResultType { fatalError ( " Not implemented. " ) }
38
+ public func visit( _ node: UnknownSyntax ) -> ResultType { fatalError ( " Not implemented. " ) }
39
39
40
40
% for node in SYNTAX_NODES:
41
41
% if is_visitable( node) :
42
42
/// Visiting `${node.name}` specifically.
43
43
/// - Parameter node: the node we are visiting.
44
44
/// - Returns: nil by default.
45
- public func visit( _ node: ${ node. name} ) -> [ ResultType ] {
46
- % if node. is_base ( ) :
47
- // Avoid calling into visitChildren if possible.
48
- if !node. raw. layoutView!. children. isEmpty {
49
- return visitChildren ( node)
50
- }
51
- return [ ]
52
- % else :
53
- // Avoid calling into visitChildren if possible.
54
- if !node. raw. layoutView!. children. isEmpty {
55
- return visitChildren ( node)
56
- }
57
- return [ ]
58
- % end
45
+ public func visit( _ node: ${ node. name} ) -> ResultType {
46
+ fatalError ( " Not implemented. " )
59
47
}
60
48
% end
61
49
% end
62
50
63
- public func visit( _ data: Syntax ) -> [ ResultType ] {
51
+ public func visit( _ data: Syntax ) -> ResultType {
64
52
switch data. raw. kind {
65
53
case . token:
66
54
let node = TokenSyntax ( data) !
@@ -80,7 +68,7 @@ extension SyntaxTransformVisitor {
80
68
}
81
69
}
82
70
83
- public func visit( _ data: ExprSyntax ) -> [ ResultType ] {
71
+ public func visit( _ data: ExprSyntax ) -> ResultType {
84
72
switch data. raw. kind {
85
73
% for node in NON_BASE_SYNTAX_NODES:
86
74
% if node. base_kind == " Expr " :
@@ -94,7 +82,7 @@ extension SyntaxTransformVisitor {
94
82
}
95
83
}
96
84
97
- public func visit( _ data: PatternSyntax ) -> [ ResultType ] {
85
+ public func visit( _ data: PatternSyntax ) -> ResultType {
98
86
switch data. raw. kind {
99
87
% for node in NON_BASE_SYNTAX_NODES:
100
88
% if node. base_kind == " Pattern " :
@@ -108,7 +96,7 @@ extension SyntaxTransformVisitor {
108
96
}
109
97
}
110
98
111
- public func visit( _ data: TypeSyntax ) -> [ ResultType ] {
99
+ public func visit( _ data: TypeSyntax ) -> ResultType {
112
100
switch data. raw. kind {
113
101
% for node in NON_BASE_SYNTAX_NODES:
114
102
% if node. base_kind == " Type " :
@@ -124,7 +112,7 @@ extension SyntaxTransformVisitor {
124
112
125
113
public func visitChildren< SyntaxType: SyntaxProtocol > ( _ node: SyntaxType ) -> [ ResultType ] {
126
114
let syntaxNode = Syntax ( node)
127
- return NonNilRawSyntaxChildren ( syntaxNode, viewMode: . sourceAccurate) . flatMap { rawChild in
115
+ return NonNilRawSyntaxChildren ( syntaxNode, viewMode: . sourceAccurate) . map { rawChild in
128
116
let child = Syntax ( SyntaxData ( rawChild, parent: syntaxNode) )
129
117
return visit ( child)
130
118
}
0 commit comments