Skip to content

Commit 2da764f

Browse files
committed
Allow module selectors before missing types/exprs
Since some types and expressions can have module selectors, MissingTypeSyntax and MissingExprSyntax should have a module selector child and `attach(_:to:)` should be able to attach a module selector to them. This keeps the parser from erroring on both the module selector *and* the missing node.
1 parent 25fa125 commit 2da764f

File tree

9 files changed

+253
-62
lines changed

9 files changed

+253
-62
lines changed

CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ public let COMMON_NODES: [Node] = [
233233
"MissingNode"
234234
],
235235
children: [
236+
Child(
237+
name: "moduleSelector",
238+
kind: .node(kind: .moduleSelector),
239+
experimentalFeature: .moduleSelector,
240+
documentation:
241+
"A module selector. Some expressions can be prefixed with module selectors, so if one is parsed before an invalid expression, it will be inserted here.",
242+
isOptional: true
243+
),
236244
Child(
237245
name: "placeholder",
238246
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),
@@ -318,6 +326,14 @@ public let COMMON_NODES: [Node] = [
318326
"MissingNode"
319327
],
320328
children: [
329+
Child(
330+
name: "moduleSelector",
331+
kind: .node(kind: .moduleSelector),
332+
experimentalFeature: .moduleSelector,
333+
documentation:
334+
"A module selector. Some types can be prefixed with module selectors, so if one is parsed before an invalid type, it will be inserted here.",
335+
isOptional: true
336+
),
321337
Child(
322338
name: "placeholder",
323339
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),

Sources/SwiftParser/Names.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ extension Parser {
267267
arena: self.arena
268268
)?.cast(ChildNode.self)
269269

270-
case .declReferenceExpr, .identifierType:
270+
case .declReferenceExpr, .identifierType, .missingExpr, .missingType:
271271
// This node has an expected module selector at child 1.
272272
let nodeUnexpectedBeforeModuleSelector = layout.children[0]
273273
let nodeModuleSelector = layout.children[1]

Sources/SwiftSyntax/MissingNodeInitializers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extension RawMissingDeclSyntax {
8383
extension RawMissingExprSyntax {
8484
public init(arena: __shared RawSyntaxArena) {
8585
self.init(
86+
moduleSelector: nil,
8687
placeholder: RawTokenSyntax(missing: .identifier, text: "<#expression#>", arena: arena),
8788
arena: arena
8889
)
@@ -110,6 +111,7 @@ extension RawMissingStmtSyntax {
110111
extension RawMissingTypeSyntax {
111112
public init(arena: __shared RawSyntaxArena) {
112113
self.init(
114+
moduleSelector: nil,
113115
placeholder: RawTokenSyntax(missing: .identifier, text: "<#type#>", arena: arena),
114116
arena: arena
115117
)

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/RenamedChildrenCompatibility.swift

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift

Lines changed: 40 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)