Skip to content

Commit c6ea0d7

Browse files
authored
Merge pull request #1561 from ahoppen/ahoppen/codegen-formatting-issues
Fix a couple cases where the formatting in CodeGeneration was off
2 parents 40fe88f + 684d268 commit c6ea0d7

File tree

14 files changed

+765
-588
lines changed

14 files changed

+765
-588
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftparser/ParserEntryFile.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ let parserEntryFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
8888
8989
let existingUnexpected: [RawSyntax]
9090
if let unexpectedNode = layout.children[layout.children.count - 1] {
91-
precondition(unexpectedNode.is(RawUnexpectedNodesSyntax.self))
92-
existingUnexpected = unexpectedNode.as(RawUnexpectedNodesSyntax.self).elements
91+
precondition(unexpectedNode.is(RawUnexpectedNodesSyntax.self))
92+
existingUnexpected = unexpectedNode.as(RawUnexpectedNodesSyntax.self).elements
9393
} else {
94-
existingUnexpected = []
94+
existingUnexpected = []
9595
}
9696
let unexpected = RawUnexpectedNodesSyntax(elements: existingUnexpected + remainingTokens, arena: self.arena)
9797

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxNodesFile.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ let rawSyntaxNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
169169
public init(elements: [\(raw: element)], arena: __shared SyntaxArena) {
170170
let raw = RawSyntax.makeLayout(
171171
kind: .\(raw: node.swiftSyntaxKind), uninitializedCount: elements.count, arena: arena) { layout in
172-
guard var ptr = layout.baseAddress else { return }
173-
for elem in elements {
174-
ptr.initialize(to: elem.raw)
175-
ptr += 1
176-
}
172+
guard var ptr = layout.baseAddress else { return }
173+
for elem in elements {
174+
ptr.initialize(to: elem.raw)
175+
ptr += 1
176+
}
177177
}
178178
self.init(unchecked: raw)
179179
}
@@ -183,7 +183,7 @@ let rawSyntaxNodesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
183183
DeclSyntax(
184184
"""
185185
public var elements: [Raw\(raw: node.collectionElementType.syntaxBaseName)] {
186-
layoutView.children.map { Raw\(raw: node.collectionElementType.syntaxBaseName)(raw: $0!) }
186+
layoutView.children.map { Raw\(raw: node.collectionElementType.syntaxBaseName)(raw: $0!) }
187187
}
188188
"""
189189
)

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/RawSyntaxValidationFile.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ let rawSyntaxValidationFile = try! SourceFileSyntax(leadingTrivia: copyrightHead
3535
DeclSyntax(
3636
#"""
3737
enum TokenChoice: CustomStringConvertible {
38-
case keyword(StaticString)
39-
case tokenKind(RawTokenKind)
38+
case keyword(StaticString)
39+
case tokenKind(RawTokenKind)
4040
41-
var description: String {
42-
switch self {
43-
case .keyword(let keyword):
44-
return "keyword('\(keyword)')"
45-
case .tokenKind(let kind):
46-
return "\(kind)"
47-
}
48-
}
49-
}
41+
var description: String {
42+
switch self {
43+
case .keyword(let keyword):
44+
return "keyword('\(keyword)')"
45+
case .tokenKind(let kind):
46+
return "\(kind)"
47+
}
48+
}
49+
}
5050
"""#
5151
)
5252

@@ -76,7 +76,7 @@ let rawSyntaxValidationFile = try! SourceFileSyntax(leadingTrivia: copyrightHead
7676
return (file, line)
7777
case .tokenMismatch(expectedTokenChoices: _, actualKind: _, actualText: _, file: let file, line: let line):
7878
return (file, line)
79-
}
79+
}
8080
}
8181
}
8282
"""#
@@ -156,13 +156,13 @@ let rawSyntaxValidationFile = try! SourceFileSyntax(leadingTrivia: copyrightHead
156156

157157
DeclSyntax(
158158
#"""
159-
func assertNoError(_ nodeKind: SyntaxKind, _ index: Int, _ error: ValidationError?) {
160-
if let error = error {
161-
let (file, line) = error.fileAndLine
162-
assertionFailure("""
163-
Error validating child at index \(index) of \(nodeKind):
164-
\(error.description)
165-
""", file: file, line: line)
159+
func assertNoError(_ nodeKind: SyntaxKind, _ index: Int, _ error: ValidationError?) {
160+
if let error = error {
161+
let (file, line) = error.fileAndLine
162+
assertionFailure("""
163+
Error validating child at index \(index) of \(nodeKind):
164+
\(error.description)
165+
""", file: file, line: line)
166166
}
167167
}
168168
"""#

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxCollectionsFile.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,12 @@ let syntaxCollectionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
191191
/// - Parameter layout: The new list of raw syntax nodes underlying this
192192
/// collection.
193193
/// - Returns: A new `\(raw: node.name)` with the new layout underlying it.
194-
internal func replacingLayout(
195-
_ layout: [RawSyntax?]) -> \(raw: node.name) {
196-
let arena = SyntaxArena()
197-
let newRaw = layoutView.replacingLayout(with: layout, arena: arena)
198-
let newData = data.replacingSelf(newRaw, arena: arena)
199-
return \(raw: node.name)(newData)
200-
}
194+
internal func replacingLayout(_ layout: [RawSyntax?]) -> \(raw: node.name) {
195+
let arena = SyntaxArena()
196+
let newRaw = layoutView.replacingLayout(with: layout, arena: arena)
197+
let newData = data.replacingSelf(newRaw, arena: arena)
198+
return \(raw: node.name)(newData)
199+
}
201200
"""
202201
)
203202

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodeFile.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ func syntaxNode(emitKind: String) -> SourceFileSyntax {
109109
DeclSyntax(
110110
"""
111111
let raw = RawSyntax.makeLayout(
112-
kind: SyntaxKind.\(raw: node.swiftSyntaxKind), from: layout, arena: arena,
113-
leadingTrivia: leadingTrivia, trailingTrivia: trailingTrivia)
112+
kind: SyntaxKind.\(raw: node.swiftSyntaxKind),
113+
from: layout,
114+
arena: arena,
115+
leadingTrivia: leadingTrivia,
116+
trailingTrivia: trailingTrivia
117+
)
114118
"""
115119
)
116120
}

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaPiecesFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ let triviaPiecesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
181181
) {
182182
for trivia in TRIVIAS {
183183
if trivia.isCollection {
184-
DeclSyntax(" case \(raw: trivia.enumCaseName)(Int)")
184+
DeclSyntax("case \(raw: trivia.enumCaseName)(Int)")
185185

186186
} else {
187187
DeclSyntax("case \(raw: trivia.enumCaseName)(SyntaxText)")

0 commit comments

Comments
 (0)