Skip to content

Commit 4a3f0c0

Browse files
ahoppenbnbarham
andcommitted
Improve implementation of BasicFormat (yet again)
This re-writes the implementation of BasicFormat once again to better handle user-indented code. Co-authored-by: Ben Barham <ben_barham@apple.com>
1 parent 560df35 commit 4a3f0c0

27 files changed

+1123
-678
lines changed

CodeGeneration/Sources/SyntaxSupport/Trivia.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class Trivia {
1515
public let comment: String
1616
public let characters: [Character]
1717
public let swiftCharacters: [Character]
18-
public let isNewLine: Bool
1918
public let isComment: Bool
2019

2120
public var lowerName: String { lowercaseFirstWord(name: name) }
@@ -36,17 +35,23 @@ public class Trivia {
3635

3736
public var isCollection: Bool { charactersLen > 0 }
3837

38+
public var isBlank: Bool {
39+
characters.contains { $0.isWhitespace }
40+
}
41+
42+
public var isNewLine: Bool {
43+
characters.contains { $0.isNewline }
44+
}
45+
3946
init(
4047
name: String,
4148
comment: String,
4249
characters: [Character] = [],
4350
swiftCharacters: [Character] = [],
44-
isNewLine: Bool = false,
4551
isComment: Bool = false
4652
) {
4753
self.name = name
4854
self.comment = comment
49-
self.isNewLine = isNewLine
5055
self.isComment = isComment
5156
self.characters = characters
5257

@@ -86,8 +91,7 @@ public let TRIVIAS: [Trivia] = [
8691
],
8792
swiftCharacters: [
8893
Character("\r")
89-
],
90-
isNewLine: true
94+
]
9195
),
9296

9397
Trivia(
@@ -100,8 +104,7 @@ public let TRIVIAS: [Trivia] = [
100104
swiftCharacters: [
101105
Character("\r"),
102106
Character("\n"),
103-
],
104-
isNewLine: true
107+
]
105108
),
106109

107110
Trivia(
@@ -142,8 +145,7 @@ public let TRIVIAS: [Trivia] = [
142145
],
143146
swiftCharacters: [
144147
Character("\n")
145-
],
146-
isNewLine: true
148+
]
147149
),
148150

149151
Trivia(

CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct GenerateSwiftSyntax: ParsableCommand {
8080
let fileSpecs: [GeneratedFileSpec] =
8181
[
8282
// SwiftBasicFormat
83-
GeneratedFileSpec(swiftBasicFormatGeneratedDir + ["BasicFormat.swift"], basicFormatFile),
83+
GeneratedFileSpec(swiftBasicFormatGeneratedDir + ["BasicFormat+Extensions.swift"], basicFormatExtensionsFile),
8484

8585
// IDEUtils
8686
GeneratedFileSpec(ideUtilsGeneratedDir + ["SyntaxClassification.swift"], syntaxClassificationFile),

CodeGeneration/Sources/generate-swiftsyntax/templates/basicformat/BasicFormatFile.swift

Lines changed: 0 additions & 315 deletions
This file was deleted.

0 commit comments

Comments
 (0)