Skip to content

Commit 146f79e

Browse files
committed
Refactor joining trivia pieces into Trivia(joining:)
1 parent a31c1e7 commit 146f79e

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,7 @@ public class Child {
114114
"""
115115
)
116116

117-
let separator = SwiftSyntax.Trivia(pieces: [TriviaPiece.newlines(1), TriviaPiece.docLineComment("///"), TriviaPiece.newlines(1)])
118-
119-
// Grab the documentation secions, filter out empty ones, and join them
120-
// with an empty documentation line inbetween.
121-
return [documentationSummary, tokenChoicesTrivia]
122-
.filter { !$0.isEmpty }
123-
.joined(separator: separator)
124-
.reduce(SwiftSyntax.Trivia(), { $0.appending($1) })
117+
return SwiftSyntax.Trivia(joining: [documentationSummary, tokenChoicesTrivia])
125118
}
126119

127120
// If this child is not a token kind, return documentation summary without the choices list.

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SyntaxNodesFile.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,12 @@ import Utils
2222
func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
2323
SourceFileSyntax(leadingTrivia: copyrightHeader) {
2424
for node in SYNTAX_NODES.compactMap(\.layoutNode) where nodesStartingWith.contains(node.kind.syntaxType.description.first!) {
25-
let documentationSections = [
26-
node.documentation,
27-
node.grammar,
28-
node.containedIn,
29-
]
30-
let documentation =
31-
documentationSections
32-
.filter { !$0.isEmpty }
33-
.map { [$0] }
34-
.joined(separator: [Trivia.newline, Trivia.docLineComment("///"), Trivia.newline])
35-
.reduce(Trivia(), +)
36-
3725
// We are actually handling this node now
3826
try! StructDeclSyntax(
3927
"""
4028
// MARK: - \(node.kind.syntaxType)
4129
42-
\(documentation)
30+
\(SwiftSyntax.Trivia(joining: [node.documentation, node.grammar, node.containedIn]))
4331
\(node.node.apiAttributes())\
4432
public struct \(node.kind.syntaxType): \(node.baseType.syntaxBaseName)Protocol, SyntaxHashable, \(node.base.leafProtocolType)
4533
"""

0 commit comments

Comments
 (0)