Skip to content

Commit a790d59

Browse files
committed
Update swift syntax
1 parent 8e6ae6e commit a790d59

File tree

13 files changed

+1532
-1498
lines changed

13 files changed

+1532
-1498
lines changed

CodeGeneration/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
.executable(name: "generate-swiftsyntax", targets: ["generate-swiftsyntax"]),
1212
],
1313
dependencies: [
14-
.package(url: "https://github.com/apple/swift-syntax.git", revision: "d856f486d15a61625e90c1740729b3fb5244fad1"),
14+
.package(url: "https://github.com/apple/swift-syntax.git", revision: "8e6ae6eef6259c1f50692b509f776e66564ae189"),
1515
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "1.1.4")),
1616
],
1717
targets: [

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,21 @@ let syntaxBaseNodesFile = SourceFile(leadingTrivia: [.blockComment(generateCopyr
8787
}
8888
""")
8989

90-
InitializerDecl("public init?<S: SyntaxProtocol>(_ node: S)") {
91-
SwitchStmt(expression: MemberAccessExpr("node.raw.kind")) {
92-
SwitchCaseList {
93-
SwitchCase(
90+
InitializerDeclSyntax("public init?<S: SyntaxProtocol>(_ node: S)") {
91+
SwitchStmt(expression: MemberAccessExprSyntax("node.raw.kind")) {
92+
SwitchCaseListSyntax {
93+
SwitchCaseSyntax(
9494
label: .case(SwitchCaseLabel {
9595
for childNode in SYNTAX_NODES where childNode.baseKind == node.syntaxKind {
96-
CaseItem(
97-
pattern: EnumCasePattern(
98-
period: .period,
99-
caseName: .identifier(childNode.swiftSyntaxKind))
100-
)
96+
CaseItemSyntax(
97+
pattern: ExpressionPatternSyntax(
98+
expression: MemberAccessExprSyntax(
99+
base: nil,
100+
dot: .periodToken(),
101+
name: .identifier(childNode.swiftSyntaxKind)
102+
)
103+
)
104+
)
101105
}
102106
})) {
103107
Expr("self._syntaxNode = node._syntaxNode")
@@ -127,11 +131,15 @@ let syntaxBaseNodesFile = SourceFile(leadingTrivia: [.blockComment(generateCopyr
127131
SwitchCase(
128132
label: .case(SwitchCaseLabel {
129133
for childNode in SYNTAX_NODES where childNode.baseKind == node.syntaxKind {
130-
CaseItem(
131-
pattern: EnumCasePatternSyntax(
132-
period: .period,
133-
caseName: .identifier(childNode.swiftSyntaxKind))
134-
)
134+
CaseItemSyntax(
135+
pattern: ExpressionPatternSyntax(
136+
expression: MemberAccessExprSyntax(
137+
base: nil,
138+
dot: .periodToken(),
139+
name: .identifier(childNode.swiftSyntaxKind)
140+
)
141+
)
142+
)
135143
}
136144
})) {
137145
BreakStmt()

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ open class BasicFormat: SyntaxRewriter {
2626
Trivia(pieces: [.newlines(1), indentation])
2727
}
2828

29-
private var lastRewrittenToken: TokenSyntax?
29+
private var lastRewrittenToken: TokenSyntax?
3030

3131
private var putNextTokenOnNewLine: Bool = false
3232

@@ -48,13 +48,13 @@ open class BasicFormat: SyntaxRewriter {
4848
open override func visit(_ node: TokenSyntax) -> TokenSyntax {
4949
var leadingTrivia = node.leadingTrivia
5050
var trailingTrivia = node.trailingTrivia
51-
if requiresLeadingSpace(node) && leadingTrivia.isEmpty && lastRewrittenToken?.trailingTrivia.isEmpty != false {
51+
if requiresLeadingSpace(node) && leadingTrivia.isEmpty && lastRewrittenToken? .trailingTrivia.isEmpty != false {
5252
leadingTrivia += .space
5353
}
5454
if requiresTrailingSpace(node) && trailingTrivia.isEmpty {
5555
trailingTrivia += .space
5656
}
57-
if let keyPath = getKeyPath(Syntax(node)), requiresLeadingNewline(keyPath), !(leadingTrivia.first?.isNewline ?? false) {
57+
if let keyPath = getKeyPath(Syntax(node)), requiresLeadingNewline(keyPath), !(leadingTrivia.first? .isNewline ?? false) {
5858
leadingTrivia = .newline + leadingTrivia
5959
}
6060
leadingTrivia = leadingTrivia.indented(indentation: indentation)
@@ -136,7 +136,7 @@ open class BasicFormat: SyntaxRewriter {
136136
}
137137

138138
open func requiresLeadingSpace(_ token: TokenSyntax) -> Bool {
139-
switch (token.previousToken(viewMode: .sourceAccurate)?.tokenKind, token.tokenKind) {
139+
switch (token.previousToken(viewMode: .sourceAccurate)? .tokenKind, token.tokenKind) {
140140
case (.leftParen, .spacedBinaryOperator):
141141
return false
142142
default:
@@ -164,10 +164,10 @@ open class BasicFormat: SyntaxRewriter {
164164

165165
open func requiresTrailingSpace(_ token: TokenSyntax) -> Bool {
166166
// Format `[:]` as-is.
167-
if token.tokenKind == .colon && token.parent?.kind == .dictionaryExpr {
167+
if token.tokenKind == .colon && token.parent? .kind == .dictionaryExpr {
168168
return false
169169
}
170-
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)?.tokenKind) {
170+
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)? .tokenKind) {
171171
case (.asKeyword, .exclamationMark), // Ensures there is not space in `as!`
172172
(.asKeyword, .postfixQuestionMark), // Ensures there is not space in `as?`
173173
(.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()`

Sources/SwiftParser/generated/Parser+Entry.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension Parser {
3030
/// Parse the source code in the given string as Swift source file. See
3131
/// `Parser.init` for more details.
3232
public static func parse(
33-
source: UnsafeBufferPointer < UInt8 > ,
33+
source: UnsafeBufferPointer<UInt8>,
3434
maximumNestingLevel: Int? = nil,
3535
parseTransition: IncrementalParseTransition? = nil
3636
) -> SourceFileSyntax {
@@ -132,7 +132,7 @@ extension TypeSyntax: SyntaxParseable {
132132
}
133133

134134
fileprivate extension Parser {
135-
mutating func parseRemainder < R: RawSyntaxNodeProtocol > (into: R) -> R {
135+
mutating func parseRemainder<R: RawSyntaxNodeProtocol>(into: R) -> R {
136136
guard !into.raw.kind.isSyntaxCollection, let layout = into.raw.layoutView else {
137137
assertionFailure("Only support parsing of non-collection layout nodes")
138138
return into
@@ -145,6 +145,6 @@ fileprivate extension Parser {
145145

146146
let unexpected = RawUnexpectedNodesSyntax(elements: remainingTokens, arena: self.arena)
147147
let withUnexpected = layout.replacingChild(at: layout.children.count - 1, with: unexpected.raw, arena: self.arena)
148-
return R.init(withUnexpected)!
148+
return R.init(withUnexpected)!
149149
}
150150
}

0 commit comments

Comments
 (0)