{- |
Module    : Data.Ini.Reader
Copyright : 2011-2014 Magnus Therning
License   : BSD3

Parser for configurations.
-}
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

-- | Parser for a configuration contained in a 'String'.
parse :: String -> IniParseResult Config
parse :: String -> IniParseResult Config
parse String
s =
    let
        pr :: Either ParseError [IniFile]
pr = forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
P.parse Parser [IniFile]
iniParser String
"ini" String
s
     in
        case Either ParseError [IniFile]
pr of
            Left ParseError
e -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IniReaderError
IniParserError forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show ParseError
e
            Right [IniFile]
is -> [IniFile] -> IniParseResult Config
buildConfig [IniFile]
is