@@ -52,6 +52,16 @@ extension TokenConsumer {
52
52
}
53
53
}
54
54
55
+ /// Check if the current token is at a start of any declaration.
56
+ ///
57
+ ///
58
+ /// - Parameters
59
+ /// - allowInitDecl: whether to consider 'init' a declaration in the context.
60
+ /// Only initializer bodies should use `false` for this.
61
+ /// - requiresDecl: Whether only declarations are expected in the context.
62
+ /// For example, in member blocks.
63
+ ///
64
+ /// - Note: this returns `false` for `#if` unless it's an attribute list.
55
65
mutating func atStartOfDeclaration(
56
66
allowInitDecl: Bool = true ,
57
67
requiresDecl: Bool = false
@@ -111,7 +121,7 @@ extension TokenConsumer {
111
121
var lookahead = subparser. lookahead ( )
112
122
repeat {
113
123
lookahead. consumeAnyToken ( )
114
- } while lookahead. atStartOfDeclaration ( allowInitDecl: allowInitDecl)
124
+ } while lookahead. atStartOfDeclaration ( allowInitDecl: allowInitDecl, requiresDecl : requiresDecl )
115
125
return lookahead. at ( . identifier)
116
126
case . lhs( . case) :
117
127
// When 'case' appears inside a function, it's probably a switch
@@ -179,7 +189,7 @@ extension TokenConsumer {
179
189
return true
180
190
}
181
191
}
182
- // Special recovery 'try let/var'.
192
+ // Special recovery for 'try let/var'.
183
193
if subparser. at ( . keyword( . try ) ) ,
184
194
subparser. peek ( isAtAnyIn: VariableDeclSyntax . BindingSpecifierOptions. self) != nil
185
195
{
@@ -199,10 +209,6 @@ extension Parser {
199
209
self . attributes = attributes
200
210
self . modifiers = modifiers
201
211
}
202
-
203
- var isEmpty : Bool {
204
- attributes. isEmpty && modifiers. isEmpty
205
- }
206
212
}
207
213
208
214
/// Describes the context around a declaration in order to modify how it is parsed.
@@ -1010,7 +1016,7 @@ extension Parser {
1010
1016
var elements = [ RawMemberBlockItemSyntax] ( )
1011
1017
do {
1012
1018
var loopProgress = LoopProgressCondition ( )
1013
- while !self . at ( . endOfFile) && !stopCondition ( & self ) && self . hasProgressed ( & loopProgress) {
1019
+ while !stopCondition ( & self ) , ! self . at ( . endOfFile) , self . hasProgressed ( & loopProgress) {
1014
1020
let newItemAtStartOfLine = self . atStartOfLine
1015
1021
guard let newElement = self . parseMemberBlockItem ( until: stopCondition) else {
1016
1022
break
0 commit comments