Skip to content

Commit cd57ae4

Browse files
committed
Remove ErrorTokens from CodeBlockItem
1 parent 0df6bb1 commit cd57ae4

File tree

7 files changed

+22
-137
lines changed

7 files changed

+22
-137
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/CommonNodes.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ public let COMMON_NODES: [Node] = [
9797
isOptional: true,
9898
tokenChoices: [
9999
"Semicolon"
100-
]),
101-
Child(name: "ErrorTokens",
102-
kind: "Syntax",
103-
isOptional: true)
100+
])
104101
],
105102
omitWhenEmpty: true),
106103

Sources/SwiftParser/TopLevel.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ extension Parser {
7373
item: .init(lastItem.item)!,
7474
lastItem.unexpectedBetweenItemAndSemicolon,
7575
semicolon: self.missingToken(.semicolon, text: nil),
76-
lastItem.unexpectedBetweenSemicolonAndErrorTokens,
77-
errorTokens: lastItem.errorTokens,
78-
lastItem.unexpectedAfterErrorTokens,
76+
lastItem.unexpectedAfterSemicolon,
7977
arena: self.arena
8078
)
8179
}
@@ -156,7 +154,6 @@ extension Parser {
156154
remainingTokens,
157155
item: .expr(RawExprSyntax(RawMissingExprSyntax(arena: self.arena))),
158156
semicolon: nil,
159-
errorTokens: nil,
160157
arena: self.arena
161158
)
162159
}
@@ -168,7 +165,6 @@ extension Parser {
168165
RawUnexpectedNodesSyntax(elements: [RawSyntax(switchCase)], arena: self.arena),
169166
item: .expr(RawExprSyntax(RawMissingExprSyntax(arena: self.arena))),
170167
semicolon: nil,
171-
errorTokens: nil,
172168
arena: self.arena
173169
)
174170
}
@@ -189,7 +185,6 @@ extension Parser {
189185
item: item,
190186
semicolon: semi,
191187
RawUnexpectedNodesSyntax(trailingSemis, arena: self.arena),
192-
errorTokens: nil,
193188
arena: self.arena
194189
)
195190
}
@@ -210,9 +205,7 @@ extension Parser {
210205
item: .init(lastElement.item)!,
211206
lastElement.unexpectedBetweenItemAndSemicolon,
212207
semicolon: parser.missingToken(.semicolon, text: nil),
213-
lastElement.unexpectedBetweenSemicolonAndErrorTokens,
214-
errorTokens: lastElement.errorTokens,
215-
lastElement.unexpectedAfterErrorTokens,
208+
lastElement.unexpectedAfterSemicolon,
216209
arena: parser.arena
217210
)
218211
} else {

Sources/SwiftSyntax/Raw/gyb_generated/RawSyntaxNodes.swift

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,17 @@ public struct RawCodeBlockItemSyntax: RawSyntaxNodeProtocol {
462462
item: Item,
463463
_ unexpectedBetweenItemAndSemicolon: RawUnexpectedNodesSyntax? = nil,
464464
semicolon: RawTokenSyntax?,
465-
_ unexpectedBetweenSemicolonAndErrorTokens: RawUnexpectedNodesSyntax? = nil,
466-
errorTokens: RawSyntax?,
467-
_ unexpectedAfterErrorTokens: RawUnexpectedNodesSyntax? = nil,
465+
_ unexpectedAfterSemicolon: RawUnexpectedNodesSyntax? = nil,
468466
arena: __shared SyntaxArena
469467
) {
470468
let raw = RawSyntax.makeLayout(
471-
kind: .codeBlockItem, uninitializedCount: 7, arena: arena) { layout in
469+
kind: .codeBlockItem, uninitializedCount: 5, arena: arena) { layout in
472470
layout.initialize(repeating: nil)
473471
layout[0] = unexpectedBeforeItem?.raw
474472
layout[1] = item.raw
475473
layout[2] = unexpectedBetweenItemAndSemicolon?.raw
476474
layout[3] = semicolon?.raw
477-
layout[4] = unexpectedBetweenSemicolonAndErrorTokens?.raw
478-
layout[5] = errorTokens?.raw
479-
layout[6] = unexpectedAfterErrorTokens?.raw
475+
layout[4] = unexpectedAfterSemicolon?.raw
480476
}
481477
self.init(raw: raw)
482478
}
@@ -493,15 +489,9 @@ public struct RawCodeBlockItemSyntax: RawSyntaxNodeProtocol {
493489
public var semicolon: RawTokenSyntax? {
494490
layoutView.children[3].map(RawTokenSyntax.init(raw:))
495491
}
496-
public var unexpectedBetweenSemicolonAndErrorTokens: RawUnexpectedNodesSyntax? {
492+
public var unexpectedAfterSemicolon: RawUnexpectedNodesSyntax? {
497493
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
498494
}
499-
public var errorTokens: RawSyntax? {
500-
layoutView.children[5]
501-
}
502-
public var unexpectedAfterErrorTokens: RawUnexpectedNodesSyntax? {
503-
layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:))
504-
}
505495
}
506496

507497
@_spi(RawSyntax)

Sources/SwiftSyntax/Raw/gyb_generated/RawSyntaxValidation.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
111111
assert(layout.count == 0)
112112
break
113113
case .codeBlockItem:
114-
assert(layout.count == 7)
114+
assert(layout.count == 5)
115115
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))
116116
assertAnyHasNoError(kind, 1, [
117117
verify(layout[1], as: RawSyntax.self),
@@ -121,8 +121,6 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
121121
assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self))
122122
assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax?.self))
123123
assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self))
124-
assertNoError(kind, 5, verify(layout[5], as: RawSyntax?.self))
125-
assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self))
126124
break
127125
case .codeBlockItemList:
128126
for (index, element) in layout.enumerated() {

Sources/SwiftSyntax/gyb_generated/SyntaxFactory.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,13 @@ public enum SyntaxFactory {
123123
}
124124
}
125125
@available(*, deprecated, message: "Use initializer on CodeBlockItemSyntax")
126-
public static func makeCodeBlockItem(_ unexpectedBeforeItem: UnexpectedNodesSyntax? = nil, item: Syntax, _ unexpectedBetweenItemAndSemicolon: UnexpectedNodesSyntax? = nil, semicolon: TokenSyntax?, _ unexpectedBetweenSemicolonAndErrorTokens: UnexpectedNodesSyntax? = nil, errorTokens: Syntax?, _ unexpectedAfterErrorTokens: UnexpectedNodesSyntax? = nil) -> CodeBlockItemSyntax {
126+
public static func makeCodeBlockItem(_ unexpectedBeforeItem: UnexpectedNodesSyntax? = nil, item: Syntax, _ unexpectedBetweenItemAndSemicolon: UnexpectedNodesSyntax? = nil, semicolon: TokenSyntax?, _ unexpectedAfterSemicolon: UnexpectedNodesSyntax? = nil) -> CodeBlockItemSyntax {
127127
let layout: [RawSyntax?] = [
128128
unexpectedBeforeItem?.raw,
129129
item.raw,
130130
unexpectedBetweenItemAndSemicolon?.raw,
131131
semicolon?.raw,
132-
unexpectedBetweenSemicolonAndErrorTokens?.raw,
133-
errorTokens?.raw,
134-
unexpectedAfterErrorTokens?.raw,
132+
unexpectedAfterSemicolon?.raw,
135133
]
136134
return withExtendedLifetime(SyntaxArena()) { arena in
137135
let raw = RawSyntax.makeLayout(kind: SyntaxKind.codeBlockItem,
@@ -151,8 +149,6 @@ public enum SyntaxFactory {
151149
nil,
152150
nil,
153151
nil,
154-
nil,
155-
nil,
156152
], arena: arena))
157153
return CodeBlockItemSyntax(data)
158154
}

Sources/SwiftSyntax/gyb_generated/syntax_nodes/SyntaxNodes.swift

Lines changed: 12 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,24 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable {
129129
self._syntaxNode = Syntax(data)
130130
}
131131

132-
public init<E: SyntaxProtocol>(
132+
public init(
133133
leadingTrivia: Trivia? = nil,
134134
_ unexpectedBeforeItem: UnexpectedNodesSyntax? = nil,
135135
item: Item,
136136
_ unexpectedBetweenItemAndSemicolon: UnexpectedNodesSyntax? = nil,
137137
semicolon: TokenSyntax? = nil,
138-
_ unexpectedBetweenSemicolonAndErrorTokens: UnexpectedNodesSyntax? = nil,
139-
errorTokens: E? = nil,
140-
_ unexpectedAfterErrorTokens: UnexpectedNodesSyntax? = nil,
138+
_ unexpectedAfterSemicolon: UnexpectedNodesSyntax? = nil,
141139
trailingTrivia: Trivia? = nil
142140
) {
143141
// Extend the lifetime of all parameters so their arenas don't get destroyed
144142
// before they can be added as children of the new arena.
145-
let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeItem, item, unexpectedBetweenItemAndSemicolon, semicolon, unexpectedBetweenSemicolonAndErrorTokens, errorTokens, unexpectedAfterErrorTokens))) { (arena, _) in
143+
let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (unexpectedBeforeItem, item, unexpectedBetweenItemAndSemicolon, semicolon, unexpectedAfterSemicolon))) { (arena, _) in
146144
let layout: [RawSyntax?] = [
147145
unexpectedBeforeItem?.raw,
148146
item.raw,
149147
unexpectedBetweenItemAndSemicolon?.raw,
150148
semicolon?.raw,
151-
unexpectedBetweenSemicolonAndErrorTokens?.raw,
152-
errorTokens?.raw,
153-
unexpectedAfterErrorTokens?.raw,
149+
unexpectedAfterSemicolon?.raw,
154150
]
155151
let raw = RawSyntax.makeLayout(
156152
kind: SyntaxKind.codeBlockItem, from: layout, arena: arena,
@@ -160,40 +156,6 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable {
160156
self.init(data)
161157
}
162158

163-
/// This initializer exists solely because Swift 5.6 does not support
164-
/// `Optional<ConcreteType>.none` as a default value of a generic parameter.
165-
/// The above initializer thus defaults to `nil` instead, but that means it
166-
/// is not actually callable when either not passing the defaulted parameter,
167-
/// or passing `nil`.
168-
///
169-
/// Hack around that limitation using this initializer, which takes a
170-
/// `Missing*` syntax node instead. `Missing*` is used over the base type as
171-
/// the base type would allow implicit conversion from a string literal,
172-
/// which the above initializer doesn't support.
173-
public init(
174-
leadingTrivia: Trivia? = nil,
175-
_ unexpectedBeforeItem: UnexpectedNodesSyntax? = nil,
176-
item: Item,
177-
_ unexpectedBetweenItemAndSemicolon: UnexpectedNodesSyntax? = nil,
178-
semicolon: TokenSyntax? = nil,
179-
_ unexpectedBetweenSemicolonAndErrorTokens: UnexpectedNodesSyntax? = nil,
180-
errorTokens: MissingSyntax? = nil,
181-
_ unexpectedAfterErrorTokens: UnexpectedNodesSyntax? = nil,
182-
trailingTrivia: Trivia? = nil
183-
) {
184-
self.init(
185-
leadingTrivia: leadingTrivia,
186-
unexpectedBeforeItem,
187-
item: item,
188-
unexpectedBetweenItemAndSemicolon,
189-
semicolon: semicolon,
190-
unexpectedBetweenSemicolonAndErrorTokens,
191-
errorTokens: Optional<Syntax>.none,
192-
unexpectedAfterErrorTokens,
193-
trailingTrivia: trailingTrivia
194-
)
195-
}
196-
197159
public var unexpectedBeforeItem: UnexpectedNodesSyntax? {
198160
get {
199161
let childData = data.child(at: 0, parent: Syntax(self))
@@ -281,78 +243,34 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable {
281243
return CodeBlockItemSyntax(newData)
282244
}
283245

284-
public var unexpectedBetweenSemicolonAndErrorTokens: UnexpectedNodesSyntax? {
246+
public var unexpectedAfterSemicolon: UnexpectedNodesSyntax? {
285247
get {
286248
let childData = data.child(at: 4, parent: Syntax(self))
287249
if childData == nil { return nil }
288250
return UnexpectedNodesSyntax(childData!)
289251
}
290252
set(value) {
291-
self = withUnexpectedBetweenSemicolonAndErrorTokens(value)
253+
self = withUnexpectedAfterSemicolon(value)
292254
}
293255
}
294256

295-
/// Returns a copy of the receiver with its `unexpectedBetweenSemicolonAndErrorTokens` replaced.
296-
/// - param newChild: The new `unexpectedBetweenSemicolonAndErrorTokens` to replace the node's
297-
/// current `unexpectedBetweenSemicolonAndErrorTokens`, if present.
298-
public func withUnexpectedBetweenSemicolonAndErrorTokens(_ newChild: UnexpectedNodesSyntax?) -> CodeBlockItemSyntax {
257+
/// Returns a copy of the receiver with its `unexpectedAfterSemicolon` replaced.
258+
/// - param newChild: The new `unexpectedAfterSemicolon` to replace the node's
259+
/// current `unexpectedAfterSemicolon`, if present.
260+
public func withUnexpectedAfterSemicolon(_ newChild: UnexpectedNodesSyntax?) -> CodeBlockItemSyntax {
299261
let arena = SyntaxArena()
300262
let raw = newChild?.raw
301263
let newData = data.replacingChild(at: 4, with: raw, arena: arena)
302264
return CodeBlockItemSyntax(newData)
303265
}
304266

305-
public var errorTokens: Syntax? {
306-
get {
307-
let childData = data.child(at: 5, parent: Syntax(self))
308-
if childData == nil { return nil }
309-
return Syntax(childData!)
310-
}
311-
set(value) {
312-
self = withErrorTokens(value)
313-
}
314-
}
315-
316-
/// Returns a copy of the receiver with its `errorTokens` replaced.
317-
/// - param newChild: The new `errorTokens` to replace the node's
318-
/// current `errorTokens`, if present.
319-
public func withErrorTokens(_ newChild: Syntax?) -> CodeBlockItemSyntax {
320-
let arena = SyntaxArena()
321-
let raw = newChild?.raw
322-
let newData = data.replacingChild(at: 5, with: raw, arena: arena)
323-
return CodeBlockItemSyntax(newData)
324-
}
325-
326-
public var unexpectedAfterErrorTokens: UnexpectedNodesSyntax? {
327-
get {
328-
let childData = data.child(at: 6, parent: Syntax(self))
329-
if childData == nil { return nil }
330-
return UnexpectedNodesSyntax(childData!)
331-
}
332-
set(value) {
333-
self = withUnexpectedAfterErrorTokens(value)
334-
}
335-
}
336-
337-
/// Returns a copy of the receiver with its `unexpectedAfterErrorTokens` replaced.
338-
/// - param newChild: The new `unexpectedAfterErrorTokens` to replace the node's
339-
/// current `unexpectedAfterErrorTokens`, if present.
340-
public func withUnexpectedAfterErrorTokens(_ newChild: UnexpectedNodesSyntax?) -> CodeBlockItemSyntax {
341-
let arena = SyntaxArena()
342-
let raw = newChild?.raw
343-
let newData = data.replacingChild(at: 6, with: raw, arena: arena)
344-
return CodeBlockItemSyntax(newData)
345-
}
346-
347267
public static var structure: SyntaxNodeStructure {
348268
return .layout([
349269
\Self.unexpectedBeforeItem,
350270
\Self.item,
351271
\Self.unexpectedBetweenItemAndSemicolon,
352272
\Self.semicolon,
353-
\Self.unexpectedBetweenSemicolonAndErrorTokens,
354-
\Self.errorTokens,
355-
\Self.unexpectedAfterErrorTokens,
273+
\Self.unexpectedAfterSemicolon,
356274
])
357275
}
358276

@@ -368,10 +286,6 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable {
368286
return nil
369287
case 4:
370288
return nil
371-
case 5:
372-
return nil
373-
case 6:
374-
return nil
375289
default:
376290
fatalError("Invalid index")
377291
}
@@ -385,9 +299,7 @@ extension CodeBlockItemSyntax: CustomReflectable {
385299
"item": Syntax(item).asProtocol(SyntaxProtocol.self),
386300
"unexpectedBetweenItemAndSemicolon": unexpectedBetweenItemAndSemicolon.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
387301
"semicolon": semicolon.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
388-
"unexpectedBetweenSemicolonAndErrorTokens": unexpectedBetweenSemicolonAndErrorTokens.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
389-
"errorTokens": errorTokens.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
390-
"unexpectedAfterErrorTokens": unexpectedAfterErrorTokens.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
302+
"unexpectedAfterSemicolon": unexpectedAfterSemicolon.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
391303
])
392304
}
393305
}

gyb_syntax_support/CommonNodes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
If present, the trailing semicolon at the end of the item.
4747
""",
4848
is_optional=True),
49-
Child('ErrorTokens', kind='Syntax', is_optional=True),
5049
]),
5150

5251
# code-block-item-list -> code-block-item code-block-item-list?

0 commit comments

Comments
 (0)