@@ -40,7 +40,18 @@ open class SyntaxRewriter {
40
40
open func visit( _ token: TokenSyntax ) -> Syntax {
41
41
return token
42
42
}
43
+
44
+ /// The function called before visiting the node and its descendents.
45
+ /// - node: the node we are about to visit.
46
+ open func visitPre( _ node: Syntax ) { }
47
+
48
+ /// The function called after visting the node and its descendents.
49
+ /// - node: the node we just finished visiting.
50
+ open func visitPost( _ node: Syntax ) { }
51
+
43
52
public func visit( _ node: Syntax ) -> Syntax {
53
+ visitPre ( node)
54
+ defer { visitPost ( node) }
44
55
switch node. raw. kind {
45
56
case . token: return visit ( node as! TokenSyntax )
46
57
% for node in SYNTAX_NODES:
@@ -70,7 +81,17 @@ open class SyntaxVisitor {
70
81
71
82
open func visit( _ token: TokenSyntax ) { }
72
83
84
+ /// The function called before visiting the node and its descendents.
85
+ /// - node: the node we are about to visit.
86
+ open func visitPre( _ node: Syntax ) { }
87
+
88
+ /// The function called after visting the node and its descendents.
89
+ /// - node: the node we just finished visiting.
90
+ open func visitPost( _ node: Syntax ) { }
91
+
73
92
public func visit( _ node: Syntax ) {
93
+ visitPre ( node)
94
+ defer { visitPost ( node) }
74
95
switch node. raw. kind {
75
96
case . token: visit ( node as! TokenSyntax )
76
97
% for node in SYNTAX_NODES:
0 commit comments