Skip to content

Commit 43dc7a5

Browse files
committed
NFC: Move parseIfStatement into Expressions.swift
1 parent 7b2b829 commit 43dc7a5

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

Sources/SwiftParser/Expressions.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,47 @@ extension Parser.Lookahead {
20992099
}
21002100
}
21012101

2102+
extension Parser {
2103+
/// Parse an if statement.
2104+
///
2105+
/// Grammar
2106+
/// =======
2107+
///
2108+
/// if-statement → 'if' condition-list code-block else-clause?
2109+
/// else-clause → 'else' code-block | else if-statement
2110+
@_spi(RawSyntax)
2111+
public mutating func parseIfStatement(ifHandle: RecoveryConsumptionHandle) -> RawIfStmtSyntax {
2112+
let (unexpectedBeforeIfKeyword, ifKeyword) = self.eat(ifHandle)
2113+
// A scope encloses the condition and true branch for any variables bound
2114+
// by a conditional binding. The else branch does *not* see these variables.
2115+
let conditions = self.parseConditionList()
2116+
let body = self.parseCodeBlock(introducer: ifKeyword)
2117+
2118+
// The else branch, if any, is outside of the scope of the condition.
2119+
let elseKeyword = self.consume(if: .keyword(.else))
2120+
let elseBody: RawIfStmtSyntax.ElseBody?
2121+
if elseKeyword != nil {
2122+
if self.at(.keyword(.if)) {
2123+
elseBody = .ifStmt(self.parseIfStatement(ifHandle: .constant(.keyword(.if))))
2124+
} else {
2125+
elseBody = .codeBlock(self.parseCodeBlock(introducer: ifKeyword))
2126+
}
2127+
} else {
2128+
elseBody = nil
2129+
}
2130+
2131+
return RawIfStmtSyntax(
2132+
unexpectedBeforeIfKeyword,
2133+
ifKeyword: ifKeyword,
2134+
conditions: conditions,
2135+
body: body,
2136+
elseKeyword: elseKeyword,
2137+
elseBody: elseBody,
2138+
arena: self.arena
2139+
)
2140+
}
2141+
}
2142+
21022143
// MARK: Lookahead
21032144

21042145
extension Parser.Lookahead {

Sources/SwiftParser/Statements.swift

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -132,47 +132,6 @@ extension Parser {
132132

133133
// MARK: Conditional Statements
134134

135-
extension Parser {
136-
/// Parse an if statement.
137-
///
138-
/// Grammar
139-
/// =======
140-
///
141-
/// if-statement → 'if' condition-list code-block else-clause?
142-
/// else-clause → 'else' code-block | else if-statement
143-
@_spi(RawSyntax)
144-
public mutating func parseIfStatement(ifHandle: RecoveryConsumptionHandle) -> RawIfStmtSyntax {
145-
let (unexpectedBeforeIfKeyword, ifKeyword) = self.eat(ifHandle)
146-
// A scope encloses the condition and true branch for any variables bound
147-
// by a conditional binding. The else branch does *not* see these variables.
148-
let conditions = self.parseConditionList()
149-
let body = self.parseCodeBlock(introducer: ifKeyword)
150-
151-
// The else branch, if any, is outside of the scope of the condition.
152-
let elseKeyword = self.consume(if: .keyword(.else))
153-
let elseBody: RawIfStmtSyntax.ElseBody?
154-
if elseKeyword != nil {
155-
if self.at(.keyword(.if)) {
156-
elseBody = .ifStmt(self.parseIfStatement(ifHandle: .constant(.keyword(.if))))
157-
} else {
158-
elseBody = .codeBlock(self.parseCodeBlock(introducer: ifKeyword))
159-
}
160-
} else {
161-
elseBody = nil
162-
}
163-
164-
return RawIfStmtSyntax(
165-
unexpectedBeforeIfKeyword,
166-
ifKeyword: ifKeyword,
167-
conditions: conditions,
168-
body: body,
169-
elseKeyword: elseKeyword,
170-
elseBody: elseBody,
171-
arena: self.arena
172-
)
173-
}
174-
}
175-
176135
extension Parser {
177136
/// Parse a guard statement.
178137
///

0 commit comments

Comments
 (0)