@@ -17,6 +17,8 @@ import SwiftSyntax
17
17
18
18
private let rangeOperators : Set = [ " ... " , " ..< " ]
19
19
20
+ /// Visits the nodes of a syntax tree and constructs a linear stream of formatting tokens that
21
+ /// tell the pretty printer how the source text should be laid out.
20
22
private final class TokenStreamCreator : SyntaxVisitor {
21
23
private var tokens = [ Token] ( )
22
24
private var beforeMap = [ TokenSyntax: [ Token] ] ( )
@@ -40,10 +42,14 @@ private final class TokenStreamCreator: SyntaxVisitor {
40
42
41
43
var openings = 0
42
44
45
+ /// If the syntax token is non-nil, enqueue the given list of formatting tokens before it in the
46
+ /// token stream.
43
47
func before( _ token: TokenSyntax ? , tokens: Token ... ) {
44
48
before ( token, tokens: tokens)
45
49
}
46
50
51
+ /// If the syntax token is non-nil, enqueue the given list of formatting tokens before it in the
52
+ /// token stream.
47
53
func before( _ token: TokenSyntax ? , tokens: [ Token ] ) {
48
54
guard let tok = token else { return }
49
55
for preToken in tokens {
@@ -57,10 +63,14 @@ private final class TokenStreamCreator: SyntaxVisitor {
57
63
beforeMap [ tok, default: [ ] ] += tokens
58
64
}
59
65
66
+ /// If the syntax token is non-nil, enqueue the given list of formatting tokens after it in the
67
+ /// token stream.
60
68
func after( _ token: TokenSyntax ? , tokens: Token ... ) {
61
69
after ( token, tokens: tokens)
62
70
}
63
71
72
+ /// If the syntax token is non-nil, enqueue the given list of formatting tokens after it in the
73
+ /// token stream.
64
74
func after( _ token: TokenSyntax ? , tokens: [ Token ] ) {
65
75
guard let tok = token else { return }
66
76
for postToken in tokens {
@@ -74,6 +84,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
74
84
afterMap [ tok, default: [ ] ] . append ( tokens)
75
85
}
76
86
87
+ /// Enqueues the given list of formatting tokens between each element of the given syntax
88
+ /// collection (but not before the first one nor after the last one).
77
89
private func insertTokens< Node: SyntaxCollection > (
78
90
_ tokens: Token ... ,
79
91
betweenElementsOf collectionNode: Node
@@ -83,6 +95,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
83
95
}
84
96
}
85
97
98
+ /// Enqueues the given list of formatting tokens between each element of the given syntax
99
+ /// collection (but not before the first one nor after the last one).
86
100
private func insertTokens< Node: SyntaxCollection > (
87
101
_ tokens: Token ... ,
88
102
betweenElementsOf collectionNode: Node
@@ -92,6 +106,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
92
106
}
93
107
}
94
108
109
+ /// Enqueues the given list of formatting tokens between each element of the given syntax
110
+ /// collection (but not before the first one nor after the last one).
95
111
private func insertTokens< Node: SyntaxCollection > (
96
112
_ tokens: Token ... ,
97
113
betweenElementsOf collectionNode: Node
0 commit comments