mirror of
https://github.com/khibino/haskell-relational-record.git
synced 2024-12-01 13:52:12 +03:00
switch to Except type of transformers-compat.
This commit is contained in:
parent
599b247ebc
commit
554211d933
@ -8,27 +8,26 @@ module Text.Parser.List
|
|||||||
import Control.Applicative (pure)
|
import Control.Applicative (pure)
|
||||||
import Control.Monad (guard)
|
import Control.Monad (guard)
|
||||||
import Control.Monad.Trans.State.Strict (StateT (..), evalStateT, get, put)
|
import Control.Monad.Trans.State.Strict (StateT (..), evalStateT, get, put)
|
||||||
|
import Control.Monad.Trans.Except (Except, runExcept, withExcept, throwE)
|
||||||
import Data.Monoid (Last (..))
|
import Data.Monoid (Last (..))
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
import Control.Monad.Either.Plus (EitherP (..), emap, leftP)
|
|
||||||
|
|
||||||
|
|
||||||
type Error = Last String
|
type Error = Last String
|
||||||
|
|
||||||
unError :: String -> Error -> String
|
unError :: String -> Error -> String
|
||||||
unError s = fromMaybe s . getLast
|
unError s = fromMaybe s . getLast
|
||||||
|
|
||||||
type Parser t = StateT [t] (EitherP Error)
|
type Parser t = StateT [t] (Except Error)
|
||||||
|
|
||||||
runParser :: Parser t a -> [t] -> Either String (a, [t])
|
runParser :: Parser t a -> [t] -> Either String (a, [t])
|
||||||
runParser p = unEitherP . emap (unError "runParser: parse error.") . runStateT p
|
runParser p = runExcept . withExcept (unError "runParser: parse error.") . runStateT p
|
||||||
|
|
||||||
evalParser :: Parser t a -> [t] -> Either String a
|
evalParser :: Parser t a -> [t] -> Either String a
|
||||||
evalParser p = unEitherP . emap (unError "evalParser: parse error.") . evalStateT p
|
evalParser p = runExcept . withExcept (unError "evalParser: parse error.") . evalStateT p
|
||||||
|
|
||||||
errorE :: String -> EitherP Error a
|
errorE :: String -> Except Error a
|
||||||
errorE = leftP . Last . Just
|
errorE = throwE . Last . Just
|
||||||
|
|
||||||
errorP :: String -> Parser t a
|
errorP :: String -> Parser t a
|
||||||
errorP = StateT . const . errorE
|
errorP = StateT . const . errorE
|
||||||
|
@ -32,6 +32,7 @@ library
|
|||||||
|
|
||||||
build-depends: base <5
|
build-depends: base <5
|
||||||
, transformers
|
, transformers
|
||||||
|
, transformers-compat
|
||||||
, dlist
|
, dlist
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
Loading…
Reference in New Issue
Block a user