on master help sign in
Merge pull request #1084 from elm-lang/dev
8a2e85dEvan Czaplicki
src/Parse/Expression.hs+12−6
@@ -2,7 +2,7 @@ module Parse.Expression (term, typeAnnotation, definition, expr) where
2
2
3import qualified Data.List as List
3import qualified Data.List as List
4import Text.Parsec hiding (newline, spaces)
4import Text.Parsec hiding (newline, spaces)
5−import Text.Parsec.Indent (block, withPos)
5+import qualified Text.Parsec.Indent as Indent
6
6
7import qualified Parse.Binop as Binop
7import qualified Parse.Binop as Binop
8import Parse.Helpers
8import Parse.Helpers
@@ -245,12 +245,18 @@ lambdaExpr =
245caseExpr :: IParser Source.Expr'
245caseExpr :: IParser Source.Expr'
246caseExpr =
246caseExpr =
247 do try (reserved "case")
247 do try (reserved "case")
248− e <- padded expr
248+ exp <- padded expr
249 reserved "of"
249 reserved "of"
250 whitespace
250 whitespace
251− E.Case e <$> block (do c <- case_ ; whitespace ; return c)
251+ Indent.withPos $
252+ do firstBranch <- branch
253+ branches <-
254+ many $ do
255+ try (whitespace >> Indent.checkIndent)
256+ branch
257+ return $ E.Case exp (firstBranch : branches)
252 where
258 where
253− case_ =
259+ branch =
254 do p <- Pattern.expr
260 do p <- Pattern.expr
255 padded rightArrow
261 padded rightArrow
256 (,) p <$> expr
262 (,) p <$> expr
@@ -263,7 +269,7 @@ letExpr =
263 do try (reserved "let")
269 do try (reserved "let")
264 whitespace
270 whitespace
265 defs <-
271 defs <-
266− block $
272+ Indent.block $
267 do def <- typeAnnotation <|> definition
273 do def <- typeAnnotation <|> definition
268 whitespace
274 whitespace
269 return def
275 return def
@@ -288,7 +294,7 @@ typeAnnotation =
288definition :: IParser Source.Def
294definition :: IParser Source.Def
289definition =
295definition =
290 addLocation $
296 addLocation $
291− withPos $
297+ Indent.withPos $
292 do (name, args) <- defStart
298 do (name, args) <- defStart
293 padded equals
299 padded equals
294 body <- expr
300 body <- expr