    {-# LANGUAGE ImportQualifiedPost #-}

    {- |
    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 (throwError)
    import Text.ParserCombinators.Parsec qualified as P

    import Data.Ini.Reader.Internals (IniParseResult, IniReaderError (..), buildConfig, iniParser)
    import Data.Ini.Types (Config)

    -- | Parser for a configuration contained in a 'String'.
    parse :: String -> IniParseResult Config
    parse :: String -> IniParseResult Config
    parse String
    s = case 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 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