Display parse error messages to user
This commit is contained in:
parent
596f3b9bde
commit
ac4228ac09
1 changed files with 5 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ import System.Console.Haskeline
|
||||||
import System.Console.Haskeline.History
|
import System.Console.Haskeline.History
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Random.Shuffle
|
import System.Random.Shuffle
|
||||||
|
import qualified Text.Megaparsec as Mega
|
||||||
|
|
||||||
type Input = InputT IO
|
type Input = InputT IO
|
||||||
|
|
||||||
|
|
@ -200,10 +201,10 @@ fromFile :: FilePath -> Input ()
|
||||||
fromFile filepath = do
|
fromFile filepath = do
|
||||||
time <- lift $ getCurrentTime
|
time <- lift $ getCurrentTime
|
||||||
content <- lift $ readFile filepath
|
content <- lift $ readFile filepath
|
||||||
let maybeElms = parseElementsMaybe time content
|
let result = Mega.parse (parseElements time) filepath content
|
||||||
case maybeElms of
|
case result of
|
||||||
Nothing -> outputStrLn $ "Could not parse contents of " ++ show filepath ++ "."
|
Left parseError -> outputStrLn $ Mega.parseErrorPretty parseError
|
||||||
Just elms -> do
|
Right elms -> do
|
||||||
newElms <- run elms
|
newElms <- run elms
|
||||||
toFile filepath newElms
|
toFile filepath newElms
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue