Skip to content

Commit c061f83

Browse files
committed
NFC: Move parseIfStatement into Expressions.swift
1 parent fecc81c commit c061f83

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
@@ -2524,6 +2524,47 @@ extension Parser.Lookahead {
25242524
}
25252525
}
25262526

2527+
extension Parser {
2528+
/// Parse an if statement.
2529+
///
2530+
/// Grammar
2531+
/// =======
2532+
///
2533+
/// if-statement → 'if' condition-list code-block else-clause?
2534+
/// else-clause → 'else' code-block | else if-statement
2535+
@_spi(RawSyntax)
2536+
public mutating func parseIfStatement(ifHandle: RecoveryConsumptionHandle) -> RawIfStmtSyntax {
2537+
let (unexpectedBeforeIfKeyword, ifKeyword) = self.eat(ifHandle)
2538+
// A scope encloses the condition and true branch for any variables bound
2539+
// by a conditional binding. The else branch does *not* see these variables.
2540+
let conditions = self.parseConditionList()
2541+
let body = self.parseCodeBlock(introducer: ifKeyword)
2542+
2543+
// The else branch, if any, is outside of the scope of the condition.
2544+
let elseKeyword = self.consume(if: .elseKeyword)
2545+
let elseBody: RawIfStmtSyntax.ElseBody?
2546+
if elseKeyword != nil {
2547+
if self.at(.ifKeyword) {
2548+
elseBody = .ifStmt(self.parseIfStatement(ifHandle: .constant(.ifKeyword)))
2549+
} else {
2550+
elseBody = .codeBlock(self.parseCodeBlock(introducer: ifKeyword))
2551+
}
2552+
} else {
2553+
elseBody = nil
2554+
}
2555+
2556+
return RawIfStmtSyntax(
2557+
unexpectedBeforeIfKeyword,
2558+
ifKeyword: ifKeyword,
2559+
conditions: conditions,
2560+
body: body,
2561+
elseKeyword: elseKeyword,
2562+
elseBody: elseBody,
2563+
arena: self.arena
2564+
)
2565+
}
2566+
}
2567+
25272568
// MARK: Lookahead
25282569

25292570
extension Parser.Lookahead {

Sources/SwiftParser/Statements.swift

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

131131
// MARK: Conditional Statements
132132

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

0 commit comments

Comments
 (0)