@@ -18,8 +18,6 @@ import qualified AST.Literal as L
1818import qualified AST.Pattern as P
1919import qualified AST.Variable as Var
2020import qualified Reporting.Annotation as A
21−import qualified Reporting.Crash as Crash
22−import qualified Reporting.Region as R
2321
2422
2523-------- Basic Terms --------
@@ -197,8 +195,7 @@ appExpr =
197195
198196expr :: IParser Source.Expr
199197expr =
200− addLocation (choice [ letExpr, caseExpr ])
201− <|> ifExpr
198+ addLocation (choice [ letExpr, caseExpr, ifExpr ])
202199 <|> lambdaExpr
203200 <|> binaryExpr
204201 <?> "an expression"
@@ -209,45 +206,23 @@ binaryExpr =
209206 Binop.binops appExpr lastExpr anyOp
210207 where
211208 lastExpr =
212− addLocation (choice [ letExpr, caseExpr ])
213− <|> ifExpr
209+ addLocation (choice [ letExpr, caseExpr, ifExpr ])
214210 <|> lambdaExpr
215211 <?> "an expression"
216212
217213
218−ifExpr :: IParser Source.Expr
214+ifExpr :: IParser Source.Expr'
219215ifExpr =
220− do start <- getMyPosition
221− try (reserved "if")
216+ do try (reserved "if")
222217 whitespace
223− makeExpr <- normal <|> multiIf
224− end <- getMyPosition
225− return (makeExpr (R.Region start end))
226− where
227− normal =
228− do condition <- expr
229− padded (reserved "then")
230− thenBranch <- expr
231− whitespace <?> "an 'else' branch"
232− reserved "else" <?> "an 'else' branch"
233− whitespace
234− elseBranch <- expr
235− return $ \region -> A.A region (E.MultiIf [(condition, thenBranch)] elseBranch)
236−
237− multiIf =
238− do branches <- spaceSep1 multiBranch
239− return $ \region -> A.A region (E.MultiIf branches (crash region))
240−
241− crash region =
242− A.A region (E.Crash (Crash.IncompleteMultiIf region))
243−
244− multiBranch =
245− do string "|"
246− whitespace
247− condition <- expr
248− padded rightArrow
249− branch <- expr
250− return (condition, branch)
218+ condition <- expr
219+ padded (reserved "then")
220+ thenBranch <- expr
221+ whitespace <?> "an 'else' branch"
222+ reserved "else" <?> "an 'else' branch"
223+ whitespace
224+ elseBranch <- expr
225+ return (E.If [(condition, thenBranch)] elseBranch)
251226
252227
253228lambdaExpr :: IParser Source.Expr