Skip to content

Commit 3634b8b

Browse files
committed
Add a bit of documentation to TokenStreamCreator.
1 parent 5177dfb commit 3634b8b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import SwiftSyntax
1717

1818
private let rangeOperators: Set = ["...", "..<"]
1919

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.
2022
private final class TokenStreamCreator: SyntaxVisitor {
2123
private var tokens = [Token]()
2224
private var beforeMap = [TokenSyntax: [Token]]()
@@ -40,10 +42,14 @@ private final class TokenStreamCreator: SyntaxVisitor {
4042

4143
var openings = 0
4244

45+
/// If the syntax token is non-nil, enqueue the given list of formatting tokens before it in the
46+
/// token stream.
4347
func before(_ token: TokenSyntax?, tokens: Token...) {
4448
before(token, tokens: tokens)
4549
}
4650

51+
/// If the syntax token is non-nil, enqueue the given list of formatting tokens before it in the
52+
/// token stream.
4753
func before(_ token: TokenSyntax?, tokens: [Token]) {
4854
guard let tok = token else { return }
4955
for preToken in tokens {
@@ -57,10 +63,14 @@ private final class TokenStreamCreator: SyntaxVisitor {
5763
beforeMap[tok, default: []] += tokens
5864
}
5965

66+
/// If the syntax token is non-nil, enqueue the given list of formatting tokens after it in the
67+
/// token stream.
6068
func after(_ token: TokenSyntax?, tokens: Token...) {
6169
after(token, tokens: tokens)
6270
}
6371

72+
/// If the syntax token is non-nil, enqueue the given list of formatting tokens after it in the
73+
/// token stream.
6474
func after(_ token: TokenSyntax?, tokens: [Token]) {
6575
guard let tok = token else { return }
6676
for postToken in tokens {
@@ -74,6 +84,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
7484
afterMap[tok, default: []].append(tokens)
7585
}
7686

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).
7789
private func insertTokens<Node: SyntaxCollection>(
7890
_ tokens: Token...,
7991
betweenElementsOf collectionNode: Node
@@ -83,6 +95,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
8395
}
8496
}
8597

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).
86100
private func insertTokens<Node: SyntaxCollection>(
87101
_ tokens: Token...,
88102
betweenElementsOf collectionNode: Node
@@ -92,6 +106,8 @@ private final class TokenStreamCreator: SyntaxVisitor {
92106
}
93107
}
94108

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).
95111
private func insertTokens<Node: SyntaxCollection>(
96112
_ tokens: Token...,
97113
betweenElementsOf collectionNode: Node

0 commit comments

Comments
 (0)