Skip to content

Commit 14dcd7b

Browse files
committed
Add supporting code.
1 parent 0dad1b1 commit 14dcd7b

14 files changed

+513
-3
lines changed

Sources/SwiftParser/generated/ExperimentalFeatures.swift

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ extension Parser.ExperimentalFeatures {
5151
/// Whether to enable the parsing of 'unsafe' expression.
5252
public static let unsafeExpression = Self (rawValue: 1 << 8)
5353

54+
/// Whether to enable the parsing of keypaths with method members.
55+
public static let keypathWithMethodMembers = Self (rawValue: 1 << 9)
56+
5457
/// Creates a new value representing the experimental feature with the
5558
/// given name, or returns nil if the name is not recognized.
5659
public init?(name: String) {
@@ -73,6 +76,8 @@ extension Parser.ExperimentalFeatures {
7376
self = .abiAttribute
7477
case "WarnUnsafe":
7578
self = .unsafeExpression
79+
case "KeypathWithMethodMembers":
80+
self = .keypathWithMethodMembers
7681
default:
7782
return nil
7883
}

Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift

+2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? {
206206
return "generic where clause"
207207
case \KeyPathExprSyntax.root:
208208
return "root"
209+
case \KeyPathMethodComponentSyntax.arguments:
210+
return "arguments"
209211
case \KeyPathSubscriptComponentSyntax.arguments:
210212
return "arguments"
211213
case \LabeledExprSyntax.label:

Sources/SwiftParserDiagnostics/generated/SyntaxKindNameForDiagnostics.swift

+2
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ extension SyntaxKind {
241241
return "key path component"
242242
case .keyPathExpr:
243243
return "key path"
244+
case .keyPathMethodComponent:
245+
return "key path method component"
244246
case .keyPathOptionalComponent:
245247
return "key path optional component"
246248
case .keyPathPropertyComponent:

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

+18
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,24 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
18871887
return "components"
18881888
case \KeyPathExprSyntax.unexpectedAfterComponents:
18891889
return "unexpectedAfterComponents"
1890+
case \KeyPathMethodComponentSyntax.unexpectedBeforeDeclName:
1891+
return "unexpectedBeforeDeclName"
1892+
case \KeyPathMethodComponentSyntax.declName:
1893+
return "declName"
1894+
case \KeyPathMethodComponentSyntax.unexpectedBetweenDeclNameAndLeftParen:
1895+
return "unexpectedBetweenDeclNameAndLeftParen"
1896+
case \KeyPathMethodComponentSyntax.leftParen:
1897+
return "leftParen"
1898+
case \KeyPathMethodComponentSyntax.unexpectedBetweenLeftParenAndArguments:
1899+
return "unexpectedBetweenLeftParenAndArguments"
1900+
case \KeyPathMethodComponentSyntax.arguments:
1901+
return "arguments"
1902+
case \KeyPathMethodComponentSyntax.unexpectedBetweenArgumentsAndRightParen:
1903+
return "unexpectedBetweenArgumentsAndRightParen"
1904+
case \KeyPathMethodComponentSyntax.rightParen:
1905+
return "rightParen"
1906+
case \KeyPathMethodComponentSyntax.unexpectedAfterRightParen:
1907+
return "unexpectedAfterRightParen"
18901908
case \KeyPathOptionalComponentSyntax.unexpectedBeforeQuestionOrExclamationMark:
18911909
return "unexpectedBeforeQuestionOrExclamationMark"
18921910
case \KeyPathOptionalComponentSyntax.questionOrExclamationMark:

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

+14
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,20 @@ open class SyntaxAnyVisitor: SyntaxVisitor {
12921292
visitAnyPost(node._syntaxNode)
12931293
}
12941294

1295+
#if compiler(>=5.8)
1296+
@_spi(ExperimentalLanguageFeatures)
1297+
#endif
1298+
override open func visit(_ node: KeyPathMethodComponentSyntax) -> SyntaxVisitorContinueKind {
1299+
return visitAny(node._syntaxNode)
1300+
}
1301+
1302+
#if compiler(>=5.8)
1303+
@_spi(ExperimentalLanguageFeatures)
1304+
#endif
1305+
override open func visitPost(_ node: KeyPathMethodComponentSyntax) {
1306+
visitAnyPost(node._syntaxNode)
1307+
}
1308+
12951309
override open func visit(_ node: KeyPathOptionalComponentSyntax) -> SyntaxVisitorContinueKind {
12961310
return visitAny(node._syntaxNode)
12971311
}

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,7 @@ extension Syntax {
16711671
.node(KeyPathComponentListSyntax.self),
16721672
.node(KeyPathComponentSyntax.self),
16731673
.node(KeyPathExprSyntax.self),
1674+
.node(KeyPathMethodComponentSyntax.self),
16741675
.node(KeyPathOptionalComponentSyntax.self),
16751676
.node(KeyPathPropertyComponentSyntax.self),
16761677
.node(KeyPathSubscriptComponentSyntax.self),

Sources/SwiftSyntax/generated/SyntaxEnum.swift

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ public enum SyntaxEnum: Sendable {
174174
case keyPathComponentList(KeyPathComponentListSyntax)
175175
case keyPathComponent(KeyPathComponentSyntax)
176176
case keyPathExpr(KeyPathExprSyntax)
177+
#if compiler(>=5.8)
178+
@_spi(ExperimentalLanguageFeatures)
179+
#endif
180+
case keyPathMethodComponent(KeyPathMethodComponentSyntax)
177181
case keyPathOptionalComponent(KeyPathOptionalComponentSyntax)
178182
case keyPathPropertyComponent(KeyPathPropertyComponentSyntax)
179183
case keyPathSubscriptComponent(KeyPathSubscriptComponentSyntax)
@@ -635,6 +639,8 @@ extension Syntax {
635639
return .keyPathComponent(KeyPathComponentSyntax(self)!)
636640
case .keyPathExpr:
637641
return .keyPathExpr(KeyPathExprSyntax(self)!)
642+
case .keyPathMethodComponent:
643+
return .keyPathMethodComponent(KeyPathMethodComponentSyntax(self)!)
638644
case .keyPathOptionalComponent:
639645
return .keyPathOptionalComponent(KeyPathOptionalComponentSyntax(self)!)
640646
case .keyPathPropertyComponent:

Sources/SwiftSyntax/generated/SyntaxKind.swift

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ public enum SyntaxKind: Sendable {
174174
case keyPathComponentList
175175
case keyPathComponent
176176
case keyPathExpr
177+
#if compiler(>=5.8)
178+
@_spi(ExperimentalLanguageFeatures)
179+
#endif
180+
case keyPathMethodComponent
177181
case keyPathOptionalComponent
178182
case keyPathPropertyComponent
179183
case keyPathSubscriptComponent
@@ -760,6 +764,8 @@ public enum SyntaxKind: Sendable {
760764
return KeyPathComponentSyntax.self
761765
case .keyPathExpr:
762766
return KeyPathExprSyntax.self
767+
case .keyPathMethodComponent:
768+
return KeyPathMethodComponentSyntax.self
763769
case .keyPathOptionalComponent:
764770
return KeyPathOptionalComponentSyntax.self
765771
case .keyPathPropertyComponent:

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

+19
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,16 @@ open class SyntaxRewriter {
11751175
return ExprSyntax(KeyPathExprSyntax(unsafeCasting: visitChildren(node._syntaxNode)))
11761176
}
11771177

1178+
/// Visit a `KeyPathMethodComponentSyntax`.
1179+
/// - Parameter node: the node that is being visited
1180+
/// - Returns: the rewritten node
1181+
#if compiler(>=5.8)
1182+
@_spi(ExperimentalLanguageFeatures)
1183+
#endif
1184+
open func visit(_ node: KeyPathMethodComponentSyntax) -> KeyPathMethodComponentSyntax {
1185+
return KeyPathMethodComponentSyntax(unsafeCasting: visitChildren(node._syntaxNode))
1186+
}
1187+
11781188
/// Visit a ``KeyPathOptionalComponentSyntax``.
11791189
/// - Parameter node: the node that is being visited
11801190
/// - Returns: the rewritten node
@@ -2919,6 +2929,11 @@ open class SyntaxRewriter {
29192929
Syntax(visit(KeyPathExprSyntax(unsafeCasting: node)))
29202930
}
29212931

2932+
@inline(never)
2933+
private func visitKeyPathMethodComponentSyntaxImpl(_ node: Syntax) -> Syntax {
2934+
Syntax(visit(KeyPathMethodComponentSyntax(unsafeCasting: node)))
2935+
}
2936+
29222937
@inline(never)
29232938
private func visitKeyPathOptionalComponentSyntaxImpl(_ node: Syntax) -> Syntax {
29242939
Syntax(visit(KeyPathOptionalComponentSyntax(unsafeCasting: node)))
@@ -3913,6 +3928,8 @@ open class SyntaxRewriter {
39133928
return self.visitKeyPathComponentSyntaxImpl(_:)
39143929
case .keyPathExpr:
39153930
return self.visitKeyPathExprSyntaxImpl(_:)
3931+
case .keyPathMethodComponent:
3932+
return self.visitKeyPathMethodComponentSyntaxImpl(_:)
39163933
case .keyPathOptionalComponent:
39173934
return self.visitKeyPathOptionalComponentSyntaxImpl(_:)
39183935
case .keyPathPropertyComponent:
@@ -4493,6 +4510,8 @@ open class SyntaxRewriter {
44934510
return visitKeyPathComponentSyntaxImpl(node)
44944511
case .keyPathExpr:
44954512
return visitKeyPathExprSyntaxImpl(node)
4513+
case .keyPathMethodComponent:
4514+
return visitKeyPathMethodComponentSyntaxImpl(node)
44964515
case .keyPathOptionalComponent:
44974516
return visitKeyPathOptionalComponentSyntaxImpl(node)
44984517
case .keyPathPropertyComponent:

Sources/SwiftSyntax/generated/SyntaxVisitor.swift

+30
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,24 @@ open class SyntaxVisitor {
18821882
open func visitPost(_ node: KeyPathExprSyntax) {
18831883
}
18841884

1885+
/// Visiting `KeyPathMethodComponentSyntax` specifically.
1886+
/// - Parameter node: the node we are visiting.
1887+
/// - Returns: how should we continue visiting.
1888+
#if compiler(>=5.8)
1889+
@_spi(ExperimentalLanguageFeatures)
1890+
#endif
1891+
open func visit(_ node: KeyPathMethodComponentSyntax) -> SyntaxVisitorContinueKind {
1892+
return .visitChildren
1893+
}
1894+
1895+
/// The function called after visiting `KeyPathMethodComponentSyntax` and its descendants.
1896+
/// - node: the node we just finished visiting.
1897+
#if compiler(>=5.8)
1898+
@_spi(ExperimentalLanguageFeatures)
1899+
#endif
1900+
open func visitPost(_ node: KeyPathMethodComponentSyntax) {
1901+
}
1902+
18851903
/// Visiting ``KeyPathOptionalComponentSyntax`` specifically.
18861904
/// - Parameter node: the node we are visiting.
18871905
/// - Returns: how should we continue visiting.
@@ -4739,6 +4757,14 @@ open class SyntaxVisitor {
47394757
visitPost(KeyPathExprSyntax(unsafeCasting: node))
47404758
}
47414759

4760+
@inline(never)
4761+
private func visitKeyPathMethodComponentSyntaxImpl(_ node: Syntax) {
4762+
if visit(KeyPathMethodComponentSyntax(unsafeCasting: node)) == .visitChildren {
4763+
visitChildren(node)
4764+
}
4765+
visitPost(KeyPathMethodComponentSyntax(unsafeCasting: node))
4766+
}
4767+
47424768
@inline(never)
47434769
private func visitKeyPathOptionalComponentSyntaxImpl(_ node: Syntax) {
47444770
if visit(KeyPathOptionalComponentSyntax(unsafeCasting: node)) == .visitChildren {
@@ -6129,6 +6155,8 @@ open class SyntaxVisitor {
61296155
return self.visitKeyPathComponentSyntaxImpl(_:)
61306156
case .keyPathExpr:
61316157
return self.visitKeyPathExprSyntaxImpl(_:)
6158+
case .keyPathMethodComponent:
6159+
return self.visitKeyPathMethodComponentSyntaxImpl(_:)
61326160
case .keyPathOptionalComponent:
61336161
return self.visitKeyPathOptionalComponentSyntaxImpl(_:)
61346162
case .keyPathPropertyComponent:
@@ -6709,6 +6737,8 @@ open class SyntaxVisitor {
67096737
self.visitKeyPathComponentSyntaxImpl(node)
67106738
case .keyPathExpr:
67116739
self.visitKeyPathExprSyntaxImpl(node)
6740+
case .keyPathMethodComponent:
6741+
self.visitKeyPathMethodComponentSyntaxImpl(node)
67126742
case .keyPathOptionalComponent:
67136743
self.visitKeyPathOptionalComponentSyntaxImpl(node)
67146744
case .keyPathPropertyComponent:

Sources/SwiftSyntax/generated/raw/RawSyntaxNodesJKLMN.swift

+105-1
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,22 @@ public struct RawKeyPathComponentListSyntax: RawSyntaxNodeProtocol {
6666
public struct RawKeyPathComponentSyntax: RawSyntaxNodeProtocol {
6767
public enum Component: RawSyntaxNodeProtocol {
6868
case property(RawKeyPathPropertyComponentSyntax)
69+
/// - Note: Requires experimental feature `keypathWithMethodMembers`.
70+
@_spi(ExperimentalLanguageFeatures)
71+
case method(RawKeyPathMethodComponentSyntax)
6972
case `subscript`(RawKeyPathSubscriptComponentSyntax)
7073
case optional(RawKeyPathOptionalComponentSyntax)
7174

7275
public static func isKindOf(_ raw: RawSyntax) -> Bool {
73-
RawKeyPathPropertyComponentSyntax.isKindOf(raw) || RawKeyPathSubscriptComponentSyntax.isKindOf(raw) || RawKeyPathOptionalComponentSyntax.isKindOf(raw)
76+
RawKeyPathPropertyComponentSyntax.isKindOf(raw) || RawKeyPathMethodComponentSyntax.isKindOf(raw) || RawKeyPathSubscriptComponentSyntax.isKindOf(raw) || RawKeyPathOptionalComponentSyntax.isKindOf(raw)
7477
}
7578

7679
public var raw: RawSyntax {
7780
switch self {
7881
case .property(let node):
7982
return node.raw
83+
case .method(let node):
84+
return node.raw
8085
case .subscript(let node):
8186
return node.raw
8287
case .optional(let node):
@@ -87,6 +92,8 @@ public struct RawKeyPathComponentSyntax: RawSyntaxNodeProtocol {
8792
public init?(_ node: __shared some RawSyntaxNodeProtocol) {
8893
if let node = node.as(RawKeyPathPropertyComponentSyntax.self) {
8994
self = .property(node)
95+
} else if let node = node.as(RawKeyPathMethodComponentSyntax.self) {
96+
self = .method(node)
9097
} else if let node = node.as(RawKeyPathSubscriptComponentSyntax.self) {
9198
self = .subscript(node)
9299
} else if let node = node.as(RawKeyPathOptionalComponentSyntax.self) {
@@ -247,6 +254,103 @@ public struct RawKeyPathExprSyntax: RawExprSyntaxNodeProtocol {
247254
}
248255
}
249256

257+
#if compiler(>=5.8)
258+
@_spi(ExperimentalLanguageFeatures)
259+
#endif
260+
@_spi(RawSyntax)
261+
public struct RawKeyPathMethodComponentSyntax: RawSyntaxNodeProtocol {
262+
@_spi(RawSyntax)
263+
public var layoutView: RawSyntaxLayoutView {
264+
return raw.layoutView!
265+
}
266+
267+
public static func isKindOf(_ raw: RawSyntax) -> Bool {
268+
return raw.kind == .keyPathMethodComponent
269+
}
270+
271+
public var raw: RawSyntax
272+
273+
init(raw: RawSyntax) {
274+
precondition(Self.isKindOf(raw))
275+
self.raw = raw
276+
}
277+
278+
private init(unchecked raw: RawSyntax) {
279+
self.raw = raw
280+
}
281+
282+
public init?(_ other: some RawSyntaxNodeProtocol) {
283+
guard Self.isKindOf(other.raw) else {
284+
return nil
285+
}
286+
self.init(unchecked: other.raw)
287+
}
288+
289+
public init(
290+
_ unexpectedBeforeDeclName: RawUnexpectedNodesSyntax? = nil,
291+
declName: RawDeclReferenceExprSyntax,
292+
_ unexpectedBetweenDeclNameAndLeftParen: RawUnexpectedNodesSyntax? = nil,
293+
leftParen: RawTokenSyntax,
294+
_ unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? = nil,
295+
arguments: RawLabeledExprListSyntax,
296+
_ unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? = nil,
297+
rightParen: RawTokenSyntax,
298+
_ unexpectedAfterRightParen: RawUnexpectedNodesSyntax? = nil,
299+
arena: __shared SyntaxArena
300+
) {
301+
let raw = RawSyntax.makeLayout(
302+
kind: .keyPathMethodComponent, uninitializedCount: 9, arena: arena) { layout in
303+
layout.initialize(repeating: nil)
304+
layout[0] = unexpectedBeforeDeclName?.raw
305+
layout[1] = declName.raw
306+
layout[2] = unexpectedBetweenDeclNameAndLeftParen?.raw
307+
layout[3] = leftParen.raw
308+
layout[4] = unexpectedBetweenLeftParenAndArguments?.raw
309+
layout[5] = arguments.raw
310+
layout[6] = unexpectedBetweenArgumentsAndRightParen?.raw
311+
layout[7] = rightParen.raw
312+
layout[8] = unexpectedAfterRightParen?.raw
313+
}
314+
self.init(unchecked: raw)
315+
}
316+
317+
public var unexpectedBeforeDeclName: RawUnexpectedNodesSyntax? {
318+
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
319+
}
320+
321+
public var declName: RawDeclReferenceExprSyntax {
322+
layoutView.children[1].map(RawDeclReferenceExprSyntax.init(raw:))!
323+
}
324+
325+
public var unexpectedBetweenDeclNameAndLeftParen: RawUnexpectedNodesSyntax? {
326+
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
327+
}
328+
329+
public var leftParen: RawTokenSyntax {
330+
layoutView.children[3].map(RawTokenSyntax.init(raw:))!
331+
}
332+
333+
public var unexpectedBetweenLeftParenAndArguments: RawUnexpectedNodesSyntax? {
334+
layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:))
335+
}
336+
337+
public var arguments: RawLabeledExprListSyntax {
338+
layoutView.children[5].map(RawLabeledExprListSyntax.init(raw:))!
339+
}
340+
341+
public var unexpectedBetweenArgumentsAndRightParen: RawUnexpectedNodesSyntax? {
342+
layoutView.children[6].map(RawUnexpectedNodesSyntax.init(raw:))
343+
}
344+
345+
public var rightParen: RawTokenSyntax {
346+
layoutView.children[7].map(RawTokenSyntax.init(raw:))!
347+
}
348+
349+
public var unexpectedAfterRightParen: RawUnexpectedNodesSyntax? {
350+
layoutView.children[8].map(RawUnexpectedNodesSyntax.init(raw:))
351+
}
352+
}
353+
250354
@_spi(RawSyntax)
251355
public struct RawKeyPathOptionalComponentSyntax: RawSyntaxNodeProtocol {
252356
@_spi(RawSyntax)

0 commit comments

Comments
 (0)