Skip to content

Commit 70f46d2

Browse files
committed
Attach leading trivia directly to decls in TokensFile
1 parent 184db64 commit 70f46d2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Sources/SwiftSyntaxBuilderGeneration/Templates/TokensFile.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ import SwiftSyntax
1515
import SwiftSyntaxBuilder
1616

1717
let tokensFile = SourceFile {
18-
ImportDecl(importTok: TokenSyntax.import.withLeadingTrivia(.docLineComment(copyrightHeader)), path: "SwiftSyntax")
18+
ImportDecl(
19+
leadingTrivia: .docLineComment(copyrightHeader),
20+
path: "SwiftSyntax"
21+
)
1922

2023
ExtensionDecl(
21-
modifiers: [TokenSyntax.public.withLeadingTrivia(.newlines(1) + .docLineComment("/// Namespace for commonly used tokens with default trivia.") + .newlines(1))],
24+
leadingTrivia: .newlines(1) + .docLineComment("/// Namespace for commonly used tokens with default trivia.") + .newlines(1),
25+
modifiers: [TokenSyntax.public],
2226
extendedType: "TokenSyntax"
2327
) {
2428
for token in SYNTAX_TOKENS {
2529
if token.isKeyword {
2630
VariableDecl(
27-
modifiers: [token.text.map { TokenSyntax.static.withLeadingTrivia(.newlines(1) + .docLineComment("/// The `\($0)` keyword") + .newlines(1)) } ?? TokenSyntax.static],
31+
leadingTrivia: token.text.map { .newlines(1) + .docLineComment("/// The `\($0)` keyword") + .newlines(1) } ?? [],
32+
modifiers: [TokenSyntax.static],
2833
letOrVarKeyword: .var
2934
) {
3035
// We need to use `CodeBlock` here to ensure there is braces around.
@@ -37,7 +42,8 @@ let tokensFile = SourceFile {
3742
}
3843
} else if let text = token.text {
3944
VariableDecl(
40-
modifiers: [TokenSyntax.static.withLeadingTrivia(.newlines(1) + .docLineComment("/// The `\(text)` token") + .newlines(1))],
45+
leadingTrivia: .newlines(1) + .docLineComment("/// The `\(text)` token") + .newlines(1),
46+
modifiers: [TokenSyntax.static],
4147
letOrVarKeyword: .var
4248
) {
4349
// We need to use `CodeBlock` here to ensure there is braces around.
@@ -74,7 +80,8 @@ let tokensFile = SourceFile {
7480
}
7581
}
7682
VariableDecl(
77-
modifiers: [TokenSyntax.static.withLeadingTrivia(.newlines(1) + .docLineComment("/// The `eof` token") + .newlines(1))],
83+
leadingTrivia: .newlines(1) + .docLineComment("/// The `eof` token") + .newlines(1),
84+
modifiers: [TokenSyntax.static],
7885
letOrVarKeyword: .var
7986
) {
8087
// We need to use `CodeBlock` here to ensure there is braces around.
@@ -88,7 +95,8 @@ let tokensFile = SourceFile {
8895
createTokenSyntaxPatternBinding("eof", accessor: body)
8996
}
9097
VariableDecl(
91-
modifiers: [TokenSyntax.static.withLeadingTrivia(.newlines(1) + .docLineComment("/// The `open` contextual token") + .newlines(1))],
98+
leadingTrivia: .newlines(1) + .docLineComment("/// The `open` contextual token") + .newlines(1),
99+
modifiers: [TokenSyntax.static],
92100
letOrVarKeyword: .var
93101
) {
94102
// We need to use `CodeBlock` here to ensure there is braces around.

0 commit comments

Comments
 (0)