@@ -52,6 +52,16 @@ extension TokenConsumer {
5252 }
5353 }
5454
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.
5565 mutating func atStartOfDeclaration(
5666 allowInitDecl: Bool = true ,
5767 requiresDecl: Bool = false
@@ -111,7 +121,7 @@ extension TokenConsumer {
111121 var lookahead = subparser. lookahead ( )
112122 repeat {
113123 lookahead. consumeAnyToken ( )
114- } while lookahead. atStartOfDeclaration ( allowInitDecl: allowInitDecl)
124+ } while lookahead. atStartOfDeclaration ( allowInitDecl: allowInitDecl, requiresDecl : requiresDecl )
115125 return lookahead. at ( . identifier)
116126 case . lhs( . case) :
117127 // When 'case' appears inside a function, it's probably a switch
@@ -179,7 +189,7 @@ extension TokenConsumer {
179189 return true
180190 }
181191 }
182- // Special recovery 'try let/var'.
192+ // Special recovery for 'try let/var'.
183193 if subparser. at ( . keyword( . try ) ) ,
184194 subparser. peek ( isAtAnyIn: VariableDeclSyntax . BindingSpecifierOptions. self) != nil
185195 {
@@ -199,10 +209,6 @@ extension Parser {
199209 self . attributes = attributes
200210 self . modifiers = modifiers
201211 }
202-
203- var isEmpty : Bool {
204- attributes. isEmpty && modifiers. isEmpty
205- }
206212 }
207213
208214 /// Describes the context around a declaration in order to modify how it is parsed.
@@ -1010,7 +1016,7 @@ extension Parser {
10101016 var elements = [ RawMemberBlockItemSyntax] ( )
10111017 do {
10121018 var loopProgress = LoopProgressCondition ( )
1013- while !self . at ( . endOfFile) && !stopCondition ( & self ) && self . hasProgressed ( & loopProgress) {
1019+ while !stopCondition ( & self ) , ! self . at ( . endOfFile) , self . hasProgressed ( & loopProgress) {
10141020 let newItemAtStartOfLine = self . atStartOfLine
10151021 guard let newElement = self . parseMemberBlockItem ( until: stopCondition) else {
10161022 break
0 commit comments