@@ -68,22 +68,23 @@ extension Parser {
68
68
) -> RawIfConfigDeclSyntax {
69
69
var clauses = [ RawIfConfigClauseSyntax] ( )
70
70
do {
71
- var ( unexpectedBeforePoundIf , poundIf ) = self . expect ( . poundIfKeyword )
71
+ var firstIteration = true
72
72
var loopProgress = LoopProgressCondition ( )
73
- repeat {
73
+ while let poundIf = self . consume ( ifAny: firstIteration ? [ . poundIfKeyword] : [ . poundIfKeyword, . poundElseifKeyword, . poundElseKeyword] ) ,
74
+ loopProgress. evaluate ( self . currentToken) {
75
+ firstIteration = false
74
76
// Parse the condition.
77
+ let unexpectedBeforePoundIf : RawUnexpectedNodesSyntax ?
75
78
let condition : RawExprSyntax ?
76
- if let parsedElse = self . consume ( if: . poundElseKeyword) {
79
+ switch poundIf. tokenKind {
80
+ case . poundIfKeyword, . poundElseifKeyword:
77
81
unexpectedBeforePoundIf = nil
78
- poundIf = parsedElse
79
- condition = nil
80
- } else if let poundElseif = self . consume ( if: . poundElseifKeyword) {
81
- unexpectedBeforePoundIf = nil
82
- poundIf = poundElseif
83
- condition = RawExprSyntax ( self . parseSequenceExpression ( . basic, forDirective: true ) )
84
- } else {
85
- assert ( poundIf. tokenKind == . poundIfKeyword)
86
82
condition = RawExprSyntax ( self . parseSequenceExpression ( . basic, forDirective: true ) )
83
+ case . poundElseKeyword:
84
+ unexpectedBeforePoundIf = nil
85
+ condition = nil
86
+ default :
87
+ preconditionFailure ( " The loop condition should guarantee that we are at one of these tokens " )
87
88
}
88
89
89
90
var elements = [ Element] ( )
@@ -104,7 +105,7 @@ extension Parser {
104
105
condition: condition,
105
106
elements: syntax ( & self , elements) ,
106
107
arena: self . arena) )
107
- } while self . at ( any : [ . poundElseifKeyword , . poundElseKeyword ] ) && loopProgress . evaluate ( currentToken )
108
+ }
108
109
}
109
110
110
111
let ( unexpectedBeforePoundEndIf, poundEndIf) = self . expect ( . poundEndifKeyword)
0 commit comments