@@ -966,13 +966,9 @@ extension Parser {
966966 decl = self . parseDeclaration ( in: . memberDeclList)
967967 attachSemi = true
968968 } else {
969+ // Otherwise, eat the unexpected tokens into an "decl".
969970 decl = RawDeclSyntax (
970- self . parseUnexpectedCodeDeclaration (
971- allowInitDecl: true ,
972- requiresDecl: true ,
973- skipToDeclOnly: true ,
974- until: stopCondition
975- )
971+ self . parseUnexpectedCodeDeclaration ( allowInitDecl: true , requiresDecl: true , until: stopCondition)
976972 )
977973 attachSemi = true
978974 }
@@ -1009,7 +1005,7 @@ extension Parser {
10091005 }
10101006
10111007 mutating func parseMemberDeclList(
1012- until stopCondition: ( inout Parser ) -> Bool = { $0. at ( . rightBrace) }
1008+ until stopCondition: ( inout Parser ) -> Bool = { $0. at ( . rightBrace) || $0 . atEndOfIfConfigClauseBody ( ) }
10131009 ) -> RawMemberBlockItemListSyntax {
10141010 var elements = [ RawMemberBlockItemSyntax] ( )
10151011 do {
@@ -1765,7 +1761,7 @@ extension Parser {
17651761 // There can only be an implicit getter if no other accessors were
17661762 // seen before this one.
17671763 guard let accessorList else {
1768- let body = parseCodeBlockItemList ( until : { $0 . at ( . rightBrace ) } )
1764+ let body = parseCodeBlockItemList ( )
17691765
17701766 let ( unexpectedBeforeRBrace, rbrace) = self . expect ( . rightBrace)
17711767 return RawAccessorBlockSyntax (
@@ -2326,20 +2322,20 @@ extension Parser {
23262322 )
23272323 }
23282324
2329- /// Eat tokens until a start of decl, or if `skipToDeclOnly` is not set until
2330- /// a start of statement or expression.
2325+ /// Eats tokens until a start of decl, statement, or expression.
23312326 /// Returns consumed tokens as a `RawUnexpectedCodeDeclSyntax` declaration.
23322327 mutating func parseUnexpectedCodeDeclaration(
23332328 allowInitDecl: Bool ,
23342329 requiresDecl: Bool ,
2335- skipToDeclOnly: Bool ,
23362330 until stopCondition: ( inout Parser ) -> Bool
23372331 ) -> RawUnexpectedCodeDeclSyntax {
23382332 var unexpectedTokens = [ RawSyntax] ( )
2339- while !self . at ( . endOfFile, . semicolon) && !stopCondition( & self ) {
2340- let numTokensToSkip = self . withLookahead ( {
2341- $0. skipSingle ( ) ; return $0. tokensConsumed
2342- } )
2333+ var loopProgress = LoopProgressCondition ( )
2334+ while !self . at ( . endOfFile, . semicolon) , !stopCondition( & self ) , self . hasProgressed ( & loopProgress) {
2335+ let numTokensToSkip = self . withLookahead {
2336+ $0. skipSingle ( )
2337+ return $0. tokensConsumed
2338+ }
23432339 for _ in 0 ..< numTokensToSkip {
23442340 unexpectedTokens. append ( RawSyntax ( self . consumeAnyTokenWithoutAdjustingNestingLevel ( ) ) )
23452341 }
@@ -2354,13 +2350,14 @@ extension Parser {
23542350 break
23552351 }
23562352
2357- if skipToDeclOnly {
2353+ // If a declaration is expected, ignore statements and expressions.
2354+ if requiresDecl {
23582355 continue
23592356 }
23602357 if self . atStartOfStatement ( preferExpr: false ) {
23612358 break
23622359 }
2363- // Recover to an expression only if it's on the next line.
2360+ // Recover to an expression only if it's on a new line.
23642361 if self . currentToken. isAtStartOfLine && self . atStartOfExpression ( ) {
23652362 break
23662363 }
0 commit comments