module Distribution.ReadE (
ReadE(..), succeedReadE, failReadE,
parseReadE, readEOrFail,
readP_to_E
) where
import Distribution.Compat.ReadP
import Data.Char ( isSpace )
newtype runReadE :: String -> Either ErrorMsg aReadE a = ReadE {runReadE :: String -> Either ErrorMsg a}
type ErrorMsg = String
instance D:Functor ::
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a)
-> T:Functor fFunctor ReadE where
fmap f (ReadE p) = ReadE :: (String -> Either ErrorMsg a) -> ReadE aReadE ($) :: (a -> b) -> a -> b$ \txt -> case p :: String -> Either ErrorMsg ap txt :: Stringtxt of
Right a -> Right :: b -> Either a bRight (f :: a -> bf a :: aa)
Left err -> Left :: a -> Either a bLeft err :: ErrorMsgerr
succeedReadE :: (String -> a) -> ReadE a
succeedReadE f = ReadE :: (String -> Either ErrorMsg a) -> ReadE aReadE (Right :: b -> Either a bRight (.) :: (b -> c) -> (a -> b) -> a -> c. f :: a -> bf)
failReadE :: ErrorMsg -> ReadE a
failReadE = ReadE :: (String -> Either ErrorMsg a) -> ReadE aReadE (.) :: (b -> c) -> (a -> b) -> a -> c. const :: a -> b -> aconst Left :: a -> Either a bLeft
parseReadE :: ReadE a -> ReadP r a
parseReadE (ReadE p) = do
txt <- look :: ReadP r Stringlook
either :: (a -> c) -> (b -> c) -> Either a b -> ceither fail :: Monad m => forall a. String -> m afail return :: Monad m => forall a. a -> m areturn (p :: String -> Either ErrorMsg ap txt :: Stringtxt)
readEOrFail :: ReadE a -> (String -> a)
readEOrFail r = either :: (a -> c) -> (b -> c) -> Either a b -> ceither error :: [Char] -> aerror id :: a -> aid (.) :: (b -> c) -> (a -> b) -> a -> c. runReadE :: ReadE a -> String -> Either ErrorMsg arunReadE r :: ReadE ar
readP_to_E :: (String -> ErrorMsg) -> ReadP a a -> ReadE a
readP_to_E err r =
ReadE :: (String -> Either ErrorMsg a) -> ReadE aReadE ($) :: (a -> b) -> a -> b$ \txt -> case [ p :: String -> Either ErrorMsg ap | (p, s) <- readP_to_S :: ReadP a a -> ReadS areadP_to_S r :: ReadE ar txt :: Stringtxt
, all :: (a -> Bool) -> [a] -> Boolall isSpace :: Char -> BoolisSpace s :: Strings ]
of [] -> Left :: a -> Either a bLeft (err :: ErrorMsgerr txt :: Stringtxt)
(p:_) -> Right :: b -> Either a bRight p :: String -> Either ErrorMsg ap