Create utility function for loading and parsing files

This commit is contained in:
Joscha 2019-11-13 07:58:41 +00:00
parent f1d097094d
commit 1b8680004e
2 changed files with 22 additions and 9 deletions

17
src/Mima/IO.hs Normal file
View file

@ -0,0 +1,17 @@
module Mima.IO
( parseFile
) where
import qualified Data.Text.IO as T
import Text.Megaparsec
import Mima.Parser.Common
parseFile :: Parser a -> FilePath -> IO (Maybe a)
parseFile parser filepath = do
content <- T.readFile filepath
case parse parser filepath content of
Right a -> pure $ Just a
Left errorBundle -> do
putStrLn $ errorBundlePretty errorBundle
pure Nothing