@@ -106,7 +106,7 @@ extension TokenConsumer {
106
106
declStartKeyword = subparser. at ( anyIn: DeclarationKeyword . self) ? . 0
107
107
}
108
108
switch declStartKeyword {
109
- case . actor :
109
+ case . lhs ( . actor ) :
110
110
// actor Foo {}
111
111
if subparser. peek ( ) . rawTokenKind == . identifier {
112
112
return true
@@ -119,16 +119,16 @@ extension TokenConsumer {
119
119
lookahead. consumeAnyToken ( )
120
120
} while lookahead. atStartOfDeclaration ( isAtTopLevel: isAtTopLevel, allowInitDecl: allowInitDecl)
121
121
return lookahead. at ( . identifier)
122
- case . case:
122
+ case . lhs ( . case) :
123
123
// When 'case' appears inside a function, it's probably a switch
124
124
// case, not an enum case declaration.
125
125
return false
126
- case . `init`:
126
+ case . lhs ( . `init`) :
127
127
return allowInitDecl
128
- case . macro:
128
+ case . lhs ( . macro) :
129
129
// macro Foo ...
130
130
return subparser. peek ( ) . rawTokenKind == . identifier
131
- case . pound:
131
+ case . lhs ( . pound) :
132
132
// Force parsing '#<identifier>' after attributes as a macro expansion decl.
133
133
if hasAttribute || hasModifier {
134
134
return true
@@ -210,81 +210,99 @@ extension Parser {
210
210
// while recovering to the declaration start.
211
211
let recoveryPrecedence = inMemberDeclList ? TokenPrecedence . closingBrace : nil
212
212
213
- switch self . canRecoverTo ( anyIn: DeclarationKeyword . self, overrideRecoveryPrecedence: recoveryPrecedence) {
214
- case ( . import, let handle) ? :
213
+ CanRecoverToSwitch: switch self . canRecoverTo ( anyIn: DeclarationKeyword . self, overrideRecoveryPrecedence: recoveryPrecedence) {
214
+ case ( . lhs ( . import) , let handle) ? :
215
215
return RawDeclSyntax ( self . parseImportDeclaration ( attrs, handle) )
216
- case ( . class, let handle) ? :
216
+ case ( . lhs ( . class) , let handle) ? :
217
217
return RawDeclSyntax ( self . parseNominalTypeDeclaration ( for: RawClassDeclSyntax . self, attrs: attrs, introucerHandle: handle) )
218
- case ( . enum, let handle) ? :
218
+ case ( . lhs ( . enum) , let handle) ? :
219
219
return RawDeclSyntax ( self . parseNominalTypeDeclaration ( for: RawEnumDeclSyntax . self, attrs: attrs, introucerHandle: handle) )
220
- case ( . case, let handle) ? :
220
+ case ( . lhs ( . case) , let handle) ? :
221
221
return RawDeclSyntax ( self . parseEnumCaseDeclaration ( attrs, handle) )
222
- case ( . struct, let handle) ? :
222
+ case ( . lhs ( . struct) , let handle) ? :
223
223
return RawDeclSyntax ( self . parseNominalTypeDeclaration ( for: RawStructDeclSyntax . self, attrs: attrs, introucerHandle: handle) )
224
- case ( . protocol, let handle) ? :
224
+ case ( . lhs ( . protocol) , let handle) ? :
225
225
return RawDeclSyntax ( self . parseNominalTypeDeclaration ( for: RawProtocolDeclSyntax . self, attrs: attrs, introucerHandle: handle) )
226
- case ( . associatedtype, let handle) ? :
226
+ case ( . lhs ( . associatedtype) , let handle) ? :
227
227
return RawDeclSyntax ( self . parseAssociatedTypeDeclaration ( attrs, handle) )
228
- case ( . typealias, let handle) ? :
228
+ case ( . lhs ( . typealias) , let handle) ? :
229
229
return RawDeclSyntax ( self . parseTypealiasDeclaration ( attrs, handle) )
230
- case ( . extension, let handle) ? :
230
+ case ( . lhs ( . extension) , let handle) ? :
231
231
return RawDeclSyntax ( self . parseExtensionDeclaration ( attrs, handle) )
232
- case ( . func, let handle) ? :
232
+ case ( . lhs ( . func) , let handle) ? :
233
233
return RawDeclSyntax ( self . parseFuncDeclaration ( attrs, handle) )
234
- case ( . subscript, let handle) ? :
234
+ case ( . lhs ( . subscript) , let handle) ? :
235
235
return RawDeclSyntax ( self . parseSubscriptDeclaration ( attrs, handle) )
236
- case ( . let, let handle) ? , ( . var, let handle) ? ,
237
- ( . inout, let handle) ? :
238
- return RawDeclSyntax ( self . parseBindingDeclaration ( attrs, handle, inMemberDeclList: inMemberDeclList) )
239
- case ( . `init`, let handle) ? :
236
+ case ( . lhs( . `init`) , let handle) ? :
240
237
return RawDeclSyntax ( self . parseInitializerDeclaration ( attrs, handle) )
241
- case ( . deinit, let handle) ? :
238
+ case ( . lhs ( . deinit) , let handle) ? :
242
239
return RawDeclSyntax ( self . parseDeinitializerDeclaration ( attrs, handle) )
243
- case ( . operator, let handle) ? :
240
+ case ( . lhs ( . operator) , let handle) ? :
244
241
return RawDeclSyntax ( self . parseOperatorDeclaration ( attrs, handle) )
245
- case ( . precedencegroup, let handle) ? :
242
+ case ( . lhs ( . precedencegroup) , let handle) ? :
246
243
return RawDeclSyntax ( self . parsePrecedenceGroupDeclaration ( attrs, handle) )
247
- case ( . actor , let handle) ? :
244
+ case ( . lhs ( . actor ) , let handle) ? :
248
245
return RawDeclSyntax ( self . parseNominalTypeDeclaration ( for: RawActorDeclSyntax . self, attrs: attrs, introucerHandle: handle) )
249
- case ( . macro, let handle) ? :
246
+ case ( . lhs ( . macro) , let handle) ? :
250
247
return RawDeclSyntax ( self . parseMacroDeclaration ( attrs: attrs, introducerHandle: handle) )
251
- case ( . pound, let handle) ? :
248
+ case ( . lhs ( . pound) , let handle) ? :
252
249
return RawDeclSyntax ( self . parseMacroExpansionDeclaration ( attrs, handle) )
250
+ case ( . rhs( let binding) , let handle) ? :
251
+ switch binding {
252
+ case . _mutating:
253
+ fallthrough
254
+ case . _borrowing:
255
+ fallthrough
256
+ case . _consuming:
257
+ guard experimentalFeatures. contains ( . referenceBindings) else {
258
+ break CanRecoverToSwitch
259
+ }
260
+ fallthrough
261
+ case . let:
262
+ fallthrough
263
+ case . var:
264
+ fallthrough
265
+ case . inout:
266
+ // Handle all cases of `ValueBindingPatternSyntax.BindingSpecifierOptions` in the same way.
267
+ return RawDeclSyntax ( self . parseBindingDeclaration ( attrs, handle, inMemberDeclList: inMemberDeclList) )
268
+ }
253
269
case nil :
254
- if inMemberDeclList {
255
- let isProbablyVarDecl = self . at ( . identifier, . wildcard) && self . peek ( isAt: . colon, . equal, . comma)
256
- let isProbablyTupleDecl = self . at ( . leftParen) && self . peek ( isAt: . identifier, . wildcard)
270
+ break
271
+ }
257
272
258
- if isProbablyVarDecl || isProbablyTupleDecl {
259
- return RawDeclSyntax ( self . parseBindingDeclaration ( attrs , . missing ( . keyword ( . var ) ) ) )
260
- }
273
+ if inMemberDeclList {
274
+ let isProbablyVarDecl = self . at ( . identifier , . wildcard ) && self . peek ( isAt : . colon , . equal , . comma )
275
+ let isProbablyTupleDecl = self . at ( . leftParen ) && self . peek ( isAt : . identifier , . wildcard )
261
276
262
- if self . currentToken. isEditorPlaceholder {
263
- let placeholder = self . consumeAnyToken ( )
264
- return RawDeclSyntax (
265
- RawEditorPlaceholderDeclSyntax (
266
- attributes: attrs. attributes,
267
- modifiers: attrs. modifiers,
268
- placeholder: placeholder,
269
- arena: self . arena
270
- )
277
+ if isProbablyVarDecl || isProbablyTupleDecl {
278
+ return RawDeclSyntax ( self . parseBindingDeclaration ( attrs, . missing( . keyword( . var) ) ) )
279
+ }
280
+
281
+ if self . currentToken. isEditorPlaceholder {
282
+ let placeholder = self . consumeAnyToken ( )
283
+ return RawDeclSyntax (
284
+ RawEditorPlaceholderDeclSyntax (
285
+ attributes: attrs. attributes,
286
+ modifiers: attrs. modifiers,
287
+ placeholder: placeholder,
288
+ arena: self . arena
271
289
)
272
- }
290
+ )
291
+ }
273
292
274
- let isProbablyFuncDecl = self . at ( . identifier, . wildcard) || self . at ( anyIn: Operator . self) != nil
293
+ let isProbablyFuncDecl = self . at ( . identifier, . wildcard) || self . at ( anyIn: Operator . self) != nil
275
294
276
- if isProbablyFuncDecl {
277
- return RawDeclSyntax ( self . parseFuncDeclaration ( attrs, . missing( . keyword( . func) ) ) )
278
- }
295
+ if isProbablyFuncDecl {
296
+ return RawDeclSyntax ( self . parseFuncDeclaration ( attrs, . missing( . keyword( . func) ) ) )
279
297
}
280
- return RawDeclSyntax (
281
- RawMissingDeclSyntax (
282
- attributes: attrs. attributes,
283
- modifiers: attrs. modifiers,
284
- arena: self . arena
285
- )
286
- )
287
298
}
299
+ return RawDeclSyntax (
300
+ RawMissingDeclSyntax (
301
+ attributes: attrs. attributes,
302
+ modifiers: attrs. modifiers,
303
+ arena: self . arena
304
+ )
305
+ )
288
306
}
289
307
}
290
308
0 commit comments