@@ -145,47 +145,47 @@ open class SyntaxVisitor {
145
145
public protocol SyntaxTransformVisitor {
146
146
associatedtype ResultType = Void
147
147
148
- func visit( _ token: TokenSyntax ) -> ResultType ?
149
- func visit( _ node: UnknownSyntax ) -> ResultType ?
148
+ func visit( _ token: TokenSyntax ) -> [ ResultType ]
149
+ func visit( _ node: UnknownSyntax ) -> [ ResultType ]
150
150
151
151
% for node in SYNTAX_NODES:
152
152
% if is_visitable( node) :
153
153
/// Visiting `${node.name}` specifically.
154
154
/// - Parameter node: the node we are visiting.
155
- /// - Returns: nil by default .
156
- func visit( _ node: ${ node. name} ) -> ResultType ?
155
+ /// - Returns: the sum of whatever the child visitors return .
156
+ func visit( _ node: ${ node. name} ) -> [ ResultType ]
157
157
% end
158
158
% end
159
159
}
160
160
161
161
extension SyntaxTransformVisitor {
162
- public func visit( _ token: TokenSyntax ) -> ResultType ? { nil }
163
- public func visit( _ node: UnknownSyntax ) -> ResultType ? { nil }
162
+ public func visit( _ token: TokenSyntax ) -> [ ResultType ] { [ ] }
163
+ public func visit( _ node: UnknownSyntax ) -> [ ResultType ] { [ ] }
164
164
165
165
% for node in SYNTAX_NODES:
166
166
% if is_visitable( node) :
167
167
/// Visiting `${node.name}` specifically.
168
168
/// - Parameter node: the node we are visiting.
169
169
/// - Returns: nil by default.
170
- public func visit( _ node: ${ node. name} ) -> ResultType ? {
170
+ public func visit( _ node: ${ node. name} ) -> [ ResultType ] {
171
171
% if node. is_base ( ) :
172
172
// Avoid calling into visitChildren if possible.
173
173
if !node. raw. layoutView!. children. isEmpty {
174
- return visitChildren ( node) . first
174
+ return visitChildren ( node)
175
175
}
176
- return nil
176
+ return [ ]
177
177
% else :
178
178
// Avoid calling into visitChildren if possible.
179
179
if !node. raw. layoutView!. children. isEmpty {
180
- return visitChildren ( node) . first
180
+ return visitChildren ( node)
181
181
}
182
- return nil
182
+ return [ ]
183
183
% end
184
184
}
185
185
% end
186
186
% end
187
187
188
- public func visit( _ data: SyntaxData ) -> ResultType ? {
188
+ public func visit( _ data: SyntaxData ) -> [ ResultType ] {
189
189
switch data. raw. kind {
190
190
case . token:
191
191
let node = TokenSyntax ( data)
@@ -207,7 +207,7 @@ extension SyntaxTransformVisitor {
207
207
208
208
public func visitChildren< SyntaxType: SyntaxProtocol > ( _ node: SyntaxType ) -> [ ResultType ] {
209
209
let syntaxNode = Syntax ( node)
210
- return NonNilRawSyntaxChildren ( syntaxNode, viewMode: . sourceAccurate) . compactMap { childRaw in
210
+ return NonNilRawSyntaxChildren ( syntaxNode, viewMode: . sourceAccurate) . flatMap { childRaw in
211
211
let childData = SyntaxData ( childRaw, parent: syntaxNode)
212
212
return visit ( childData)
213
213
}
0 commit comments