From ac4228ac09ab092d0623a207b92907004b5a2655 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 6 Jan 2018 11:11:37 +0000 Subject: [PATCH] Display parse error messages to user --- app/Main.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index af2dfd6..43dbedd 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -12,6 +12,7 @@ import System.Console.Haskeline import System.Console.Haskeline.History import System.Environment import System.Random.Shuffle +import qualified Text.Megaparsec as Mega type Input = InputT IO @@ -200,10 +201,10 @@ fromFile :: FilePath -> Input () fromFile filepath = do time <- lift $ getCurrentTime content <- lift $ readFile filepath - let maybeElms = parseElementsMaybe time content - case maybeElms of - Nothing -> outputStrLn $ "Could not parse contents of " ++ show filepath ++ "." - Just elms -> do + let result = Mega.parse (parseElements time) filepath content + case result of + Left parseError -> outputStrLn $ Mega.parseErrorPretty parseError + Right elms -> do newElms <- run elms toFile filepath newElms