11
11
//===----------------------------------------------------------------------===//
12
12
13
13
#if compiler(>=6)
14
- @_spi ( RawSyntax) internal import SwiftSyntax
14
+ @_spi ( RawSyntax) @ _spi ( ExperimentalLanguageFeatures ) internal import SwiftSyntax
15
15
#else
16
- @_spi ( RawSyntax) import SwiftSyntax
16
+ @_spi ( RawSyntax) @ _spi ( ExperimentalLanguageFeatures ) import SwiftSyntax
17
17
#endif
18
18
19
19
extension TokenConsumer {
@@ -1127,11 +1127,54 @@ extension Parser {
1127
1127
continue
1128
1128
}
1129
1129
1130
- // Check for a .name or .1 suffix.
1130
+ // Check for a .name, .1, .name(), .name("Kiwi"), .name(fruit:),
1131
+ // .name(_:), .name(fruit: "Kiwi) suffix.
1131
1132
if self . at ( . period) {
1132
1133
let ( unexpectedPeriod, period, declName, generics) = parseDottedExpressionSuffix (
1133
1134
previousNode: components. last? . raw ?? rootType? . raw ?? backslash. raw
1134
1135
)
1136
+
1137
+ // If fully applied method component, parse as a keypath method.
1138
+ if self . experimentalFeatures. contains ( . keypathWithMethodMembers)
1139
+ && self . at ( . leftParen)
1140
+ {
1141
+ var ( unexpectedBeforeLParen, leftParen) = self . expect ( . leftParen)
1142
+ if let generics = generics {
1143
+ unexpectedBeforeLParen = RawUnexpectedNodesSyntax (
1144
+ ( unexpectedBeforeLParen? . elements ?? [ ] ) + [ RawSyntax ( generics) ] ,
1145
+ arena: self . arena
1146
+ )
1147
+ }
1148
+ let args = self . parseArgumentListElements (
1149
+ pattern: pattern,
1150
+ allowTrailingComma: true
1151
+ )
1152
+ let ( unexpectedBeforeRParen, rightParen) = self . expect ( . rightParen)
1153
+
1154
+ components. append (
1155
+ RawKeyPathComponentSyntax (
1156
+ unexpectedPeriod,
1157
+ period: period,
1158
+ component: . method(
1159
+ RawKeyPathMethodComponentSyntax (
1160
+ declName: declName,
1161
+ unexpectedBeforeLParen,
1162
+ leftParen: leftParen,
1163
+ arguments: RawLabeledExprListSyntax (
1164
+ elements: args,
1165
+ arena: self . arena
1166
+ ) ,
1167
+ unexpectedBeforeRParen,
1168
+ rightParen: rightParen,
1169
+ arena: self . arena
1170
+ )
1171
+ ) ,
1172
+ arena: self . arena
1173
+ )
1174
+ )
1175
+ continue
1176
+ }
1177
+ // Else, parse as a property.
1135
1178
components. append (
1136
1179
RawKeyPathComponentSyntax (
1137
1180
unexpectedPeriod,
@@ -1152,7 +1195,6 @@ extension Parser {
1152
1195
// No more postfix expressions.
1153
1196
break
1154
1197
}
1155
-
1156
1198
return RawKeyPathExprSyntax (
1157
1199
unexpectedBeforeBackslash,
1158
1200
backslash: backslash,
0 commit comments