Skip to content

Commit 78d29cf

Browse files
committed
Add a visitAny func requirement and use that as the default impl for all visitors.
1 parent 6b7d20e commit 78d29cf

File tree

3 files changed

+280
-278
lines changed

3 files changed

+280
-278
lines changed

Sources/SwiftSyntax/SyntaxTransform.swift.gyb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
public protocol SyntaxTransformVisitor {
2121
associatedtype ResultType = Void
2222

23+
func visitAny(_ node: Syntax) -> ResultType
24+
2325
func visit(_ token: TokenSyntax) -> ResultType
2426
func visit(_ node: UnknownSyntax) -> ResultType
2527

@@ -34,16 +36,16 @@ public protocol SyntaxTransformVisitor {
3436
}
3537

3638
extension SyntaxTransformVisitor {
37-
public func visit(_ token: TokenSyntax) -> ResultType { fatalError("Not implemented.") }
38-
public func visit(_ node: UnknownSyntax) -> ResultType { fatalError("Not implemented.") }
39+
public func visit(_ token: TokenSyntax) -> ResultType { visitAny(Syntax(token)) }
40+
public func visit(_ node: UnknownSyntax) -> ResultType { visitAny(Syntax(node)) }
3941

4042
% for node in SYNTAX_NODES:
4143
% if is_visitable(node):
4244
/// Visiting `${node.name}` specifically.
4345
/// - Parameter node: the node we are visiting.
4446
/// - Returns: nil by default.
4547
public func visit(_ node: ${node.name}) -> ResultType {
46-
fatalError("Not implemented.")
48+
visitAny(Syntax(node))
4749
}
4850
% end
4951
% end

0 commit comments

Comments
 (0)