module Data.Ini.Reader (
parse,
IniReaderError (..),
IniParseResult,
) where
import Control.Monad.Except
import qualified Text.ParserCombinators.Parsec as P
import Data.Ini.Reader.Internals
import Data.Ini.Types
parse :: String -> IniParseResult Config
parse :: String -> IniParseResult Config
parse String
s =
let
pr :: Either ParseError [IniFile]
pr = Parsec String () [IniFile]
-> String -> String -> Either ParseError [IniFile]
forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
P.parse Parsec String () [IniFile]
iniParser String
"ini" String
s
in
case Either ParseError [IniFile]
pr of
Left ParseError
e -> IniReaderError -> IniParseResult Config
forall a. IniReaderError -> Either IniReaderError a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (IniReaderError -> IniParseResult Config)
-> (String -> IniReaderError) -> String -> IniParseResult Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IniReaderError
IniParserError (String -> IniParseResult Config)
-> String -> IniParseResult Config
forall a b. (a -> b) -> a -> b
$ ParseError -> String
forall a. Show a => a -> String
show ParseError
e
Right [IniFile]
is -> [IniFile] -> IniParseResult Config
buildConfig [IniFile]
is