Skip to content

Commit db29a03

Browse files
committed
Remove requiresLeadingNewline from basic format
1 parent d3ce991 commit db29a03

File tree

7 files changed

+11
-81
lines changed

7 files changed

+11
-81
lines changed

CodeGeneration/Sources/SyntaxSupport/Child.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public class Child {
6262
public let description: String?
6363
public let forceClassification: Bool
6464
public let isIndented: Bool
65-
public let requiresLeadingNewline: Bool
6665
public let isOptional: Bool
6766
public let classification: SyntaxClassification?
6867

@@ -158,8 +157,7 @@ public class Child {
158157
isOptional: Bool = false,
159158
classification: String? = nil,
160159
forceClassification: Bool = false,
161-
isIndented: Bool = false,
162-
requiresLeadingNewline: Bool = false
160+
isIndented: Bool = false
163161
) {
164162
if let firstCharInName = name.first {
165163
precondition(firstCharInName.isUppercase == true, "The first letter of a child’s name should be uppercase")
@@ -171,7 +169,6 @@ public class Child {
171169
self.classification = classificationByName(classification)
172170
self.forceClassification = forceClassification
173171
self.isIndented = isIndented
174-
self.requiresLeadingNewline = requiresLeadingNewline
175172
self.isOptional = isOptional
176173
}
177174
}

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public let COMMON_NODES: [Node] = [
7777
),
7878
Child(
7979
name: "RightBrace",
80-
kind: .token(choices: [.token(tokenKind: "RightBraceToken")]),
81-
requiresLeadingNewline: true
80+
kind: .token(choices: [.token(tokenKind: "RightBraceToken")])
8281
),
8382
]
8483
),

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public let DECL_NODES: [Node] = [
5555
),
5656
Child(
5757
name: "RightBrace",
58-
kind: .token(choices: [.token(tokenKind: "RightBraceToken")]),
59-
requiresLeadingNewline: true
58+
kind: .token(choices: [.token(tokenKind: "RightBraceToken")])
6059
),
6160
]
6261
),
@@ -1001,8 +1000,7 @@ public let DECL_NODES: [Node] = [
10011000
Child(
10021001
name: "PoundKeyword",
10031002
kind: .token(choices: [.token(tokenKind: "PoundIfToken"), .token(tokenKind: "PoundElseifToken"), .token(tokenKind: "PoundElseToken")]),
1004-
classification: "BuildConfigId",
1005-
requiresLeadingNewline: true
1003+
classification: "BuildConfigId"
10061004
),
10071005
Child(
10081006
name: "Condition",
@@ -1054,8 +1052,7 @@ public let DECL_NODES: [Node] = [
10541052
Child(
10551053
name: "PoundEndif",
10561054
kind: .token(choices: [.token(tokenKind: "PoundEndifToken")]),
1057-
classification: "BuildConfigId",
1058-
requiresLeadingNewline: true
1055+
classification: "BuildConfigId"
10591056
),
10601057
]
10611058
),
@@ -1366,8 +1363,7 @@ public let DECL_NODES: [Node] = [
13661363
),
13671364
Child(
13681365
name: "RightBrace",
1369-
kind: .token(choices: [.token(tokenKind: "RightBraceToken")]),
1370-
requiresLeadingNewline: true
1366+
kind: .token(choices: [.token(tokenKind: "RightBraceToken")])
13711367
),
13721368
]
13731369
),

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ public let EXPR_NODES: [Node] = [
477477
),
478478
Child(
479479
name: "RightBrace",
480-
kind: .token(choices: [.token(tokenKind: "RightBraceToken")]),
481-
requiresLeadingNewline: true
480+
kind: .token(choices: [.token(tokenKind: "RightBraceToken")])
482481
),
483482
]
484483
),
@@ -1654,8 +1653,7 @@ public let EXPR_NODES: [Node] = [
16541653
),
16551654
Child(
16561655
name: "RightBrace",
1657-
kind: .token(choices: [.token(tokenKind: "RightBraceToken")]),
1658-
requiresLeadingNewline: true
1656+
kind: .token(choices: [.token(tokenKind: "RightBraceToken")])
16591657
),
16601658
]
16611659
),

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftbasicformat/BasicFormatExtensionsFile.swift

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ let basicFormatExtensionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader)
6565
)
6666
}
6767

68-
try! ExtensionDeclSyntax("public extension TokenSyntax") {
69-
DeclSyntax(
70-
"""
71-
var requiresLeadingNewline: Bool {
72-
if let keyPath = keyPathInParent, keyPath.requiresLeadingNewline {
73-
return true
74-
}
75-
return false
76-
}
77-
"""
78-
)
79-
}
80-
8168
try! ExtensionDeclSyntax("fileprivate extension AnyKeyPath") {
8269
try VariableDeclSyntax("var requiresIndent: Bool") {
8370
try SwitchExprSyntax("switch self") {
@@ -94,21 +81,6 @@ let basicFormatExtensionsFile = SourceFileSyntax(leadingTrivia: copyrightHeader)
9481
}
9582
}
9683

97-
try VariableDeclSyntax("var requiresLeadingNewline: Bool") {
98-
try SwitchExprSyntax("switch self") {
99-
for node in SYNTAX_NODES where !node.isBase {
100-
for child in node.children where child.requiresLeadingNewline {
101-
SwitchCaseSyntax("case \\\(raw: node.type.syntaxBaseName).\(raw: child.swiftName):") {
102-
StmtSyntax("return true")
103-
}
104-
}
105-
}
106-
SwitchCaseSyntax("default:") {
107-
StmtSyntax("return false")
108-
}
109-
}
110-
}
111-
11284
try VariableDeclSyntax("var requiresLeadingSpace: Bool?") {
11385
try SwitchExprSyntax("switch self") {
11486
for node in SYNTAX_NODES where !node.isBase {

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ open class BasicFormat: SyntaxRewriter {
155155
{
156156
return false
157157
} else if let second {
158-
if second.requiresLeadingNewline {
159-
return true
160-
}
161-
162158
var ancestor: Syntax = Syntax(second)
163159
while let parent = ancestor.parent {
164160
ancestor = parent
@@ -182,7 +178,9 @@ open class BasicFormat: SyntaxRewriter {
182178
(.multilineStringQuote, .multilineStringQuote), // empty multi-line string literal
183179
(.multilineStringQuote, .stringSegment), // segment starting a multi-line string literal
184180
(.stringSegment, .multilineStringQuote), // ending a multi-line string literal that has a string interpolation segment at its end
185-
(.rightParen, .multilineStringQuote): // ending a multi-line string literal that has a string interpolation segment at its end
181+
(.rightParen, .multilineStringQuote), // ending a multi-line string literal that has a string interpolation segment at its end
182+
(_, .rightBrace),
183+
(_, .poundEndifKeyword):
186184
return true
187185
default:
188186
return false

Sources/SwiftBasicFormat/generated/BasicFormat+Extensions.swift

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ public extension SyntaxProtocol {
2323
}
2424
}
2525

26-
public extension TokenSyntax {
27-
var requiresLeadingNewline: Bool {
28-
if let keyPath = keyPathInParent, keyPath.requiresLeadingNewline {
29-
return true
30-
}
31-
return false
32-
}
33-
}
34-
3526
fileprivate extension AnyKeyPath {
3627
var requiresIndent: Bool {
3728
switch self {
@@ -70,27 +61,6 @@ fileprivate extension AnyKeyPath {
7061
}
7162
}
7263

73-
var requiresLeadingNewline: Bool {
74-
switch self {
75-
case \AccessorBlockSyntax.rightBrace:
76-
return true
77-
case \ClosureExprSyntax.rightBrace:
78-
return true
79-
case \CodeBlockSyntax.rightBrace:
80-
return true
81-
case \IfConfigClauseSyntax.poundKeyword:
82-
return true
83-
case \IfConfigDeclSyntax.poundEndif:
84-
return true
85-
case \MemberDeclBlockSyntax.rightBrace:
86-
return true
87-
case \SwitchExprSyntax.rightBrace:
88-
return true
89-
default:
90-
return false
91-
}
92-
}
93-
9464
var requiresLeadingSpace: Bool? {
9565
switch self {
9666
case \AvailabilityArgumentSyntax.entry:

0 commit comments

Comments
 (0)