Skip to content

Commit 94ff88a

Browse files
committed
Remove ErrorTokens from CodeBlockItem
1 parent 1ba6172 commit 94ff88a

File tree

7 files changed

+21
-136
lines changed

7 files changed

+21
-136
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/CommonNodes.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ public let COMMON_NODES: [Node] = [
9494
isOptional: true,
9595
tokenChoices: [
9696
"Semicolon"
97-
]),
98-
Child(name: "ErrorTokens",
99-
kind: "Syntax",
100-
isOptional: true)
97+
])
10198
],
10299
omitWhenEmpty: true),
103100

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: 11 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,21 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable {
127127
self._syntaxNode = Syntax(data)
128128
}
129129

130-
public init<E: SyntaxProtocol>(
130+
public init(
131131
leadingTrivia: Trivia? = nil,
132132
_ unexpectedBeforeItem: UnexpectedNodesSyntax? = nil,
133133
item: Item,
134134
_ unexpectedBetweenItemAndSemicolon: UnexpectedNodesSyntax? = nil,
135135
semicolon: TokenSyntax? = nil,
136-
_ unexpectedBetweenSemicolonAndErrorTokens: UnexpectedNodesSyntax? = nil,
137-
errorTokens: E? = nil,
138-
_ unexpectedAfterErrorTokens: UnexpectedNodesSyntax? = nil,
136+
_ unexpectedAfterSemicolon: UnexpectedNodesSyntax? = nil,
139137
trailingTrivia: Trivia? = nil
140138
) {
141139
let layout: [RawSyntax?] = [
142140
unexpectedBeforeItem?.raw,
143141
item.raw,
144142
unexpectedBetweenItemAndSemicolon?.raw,
145143
semicolon?.raw,
146-
unexpectedBetweenSemicolonAndErrorTokens?.raw,
147-
errorTokens?.raw,
148-
unexpectedAfterErrorTokens?.raw,
144+
unexpectedAfterSemicolon?.raw,
149145
]
150146
let data: SyntaxData = withExtendedLifetime(SyntaxArena()) { arena in
151147
let raw = RawSyntax.makeLayout(
@@ -156,40 +152,6 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable {
156152
self.init(data)
157153
}
158154

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

280-
public var unexpectedBetweenSemicolonAndErrorTokens: UnexpectedNodesSyntax? {
242+
public var unexpectedAfterSemicolon: UnexpectedNodesSyntax? {
281243
get {
282244
let childData = data.child(at: 4, parent: Syntax(self))
283245
if childData == nil { return nil }
284246
return UnexpectedNodesSyntax(childData!)
285247
}
286248
set(value) {
287-
self = withUnexpectedBetweenSemicolonAndErrorTokens(value)
249+
self = withUnexpectedAfterSemicolon(value)
288250
}
289251
}
290252

291-
/// Returns a copy of the receiver with its `unexpectedBetweenSemicolonAndErrorTokens` replaced.
292-
/// - param newChild: The new `unexpectedBetweenSemicolonAndErrorTokens` to replace the node's
293-
/// current `unexpectedBetweenSemicolonAndErrorTokens`, if present.
294-
public func withUnexpectedBetweenSemicolonAndErrorTokens(_ newChild: UnexpectedNodesSyntax?) -> CodeBlockItemSyntax {
253+
/// Returns a copy of the receiver with its `unexpectedAfterSemicolon` replaced.
254+
/// - param newChild: The new `unexpectedAfterSemicolon` to replace the node's
255+
/// current `unexpectedAfterSemicolon`, if present.
256+
public func withUnexpectedAfterSemicolon(_ newChild: UnexpectedNodesSyntax?) -> CodeBlockItemSyntax {
295257
let arena = SyntaxArena()
296258
let raw = newChild?.raw
297259
let newData = data.replacingChild(at: 4, with: raw, arena: arena)
298260
return CodeBlockItemSyntax(newData)
299261
}
300262

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

@@ -364,10 +282,6 @@ public struct CodeBlockItemSyntax: SyntaxProtocol, SyntaxHashable {
364282
return nil
365283
case 4:
366284
return nil
367-
case 5:
368-
return nil
369-
case 6:
370-
return nil
371285
default:
372286
fatalError("Invalid index")
373287
}
@@ -381,9 +295,7 @@ extension CodeBlockItemSyntax: CustomReflectable {
381295
"item": Syntax(item).asProtocol(SyntaxProtocol.self),
382296
"unexpectedBetweenItemAndSemicolon": unexpectedBetweenItemAndSemicolon.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
383297
"semicolon": semicolon.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
384-
"unexpectedBetweenSemicolonAndErrorTokens": unexpectedBetweenSemicolonAndErrorTokens.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
385-
"errorTokens": errorTokens.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
386-
"unexpectedAfterErrorTokens": unexpectedAfterErrorTokens.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
298+
"unexpectedAfterSemicolon": unexpectedAfterSemicolon.map(Syntax.init)?.asProtocol(SyntaxProtocol.self) as Any,
387299
])
388300
}
389301
}

gyb_syntax_support/CommonNodes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
If present, the trailing semicolon at the end of the item.
4545
""",
4646
is_optional=True),
47-
Child('ErrorTokens', kind='Syntax', is_optional=True),
4847
]),
4948

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

0 commit comments

Comments
 (0)