@@ -7,16 +7,17 @@ module Text.Parsing.Parser
7
7
, Parser
8
8
, runParser
9
9
, runParserT
10
+ , hoistParserT
10
11
, consume
11
12
, fail
12
13
) where
13
14
14
15
import Prelude
15
16
import Control.Alt (class Alt )
16
17
import Control.Lazy (defer , class Lazy )
17
- import Control.Monad.Except (class MonadError , ExceptT (..), throwError , runExceptT )
18
+ import Control.Monad.Except (class MonadError , ExceptT (..), throwError , runExceptT , mapExceptT )
18
19
import Control.Monad.Rec.Class (class MonadRec )
19
- import Control.Monad.State (runStateT , class MonadState , StateT (..), gets , evalStateT , modify )
20
+ import Control.Monad.State (runStateT , class MonadState , StateT (..), gets , evalStateT , mapStateT , modify )
20
21
import Control.Monad.Trans.Class (lift , class MonadTrans )
21
22
import Control.MonadPlus (class Alternative , class MonadZero , class MonadPlus , class Plus )
22
23
import Data.Either (Either (..))
@@ -58,12 +59,15 @@ runParserT s p = evalStateT (runExceptT (unwrap p)) initialState where
58
59
initialState = ParseState s initialPos false
59
60
60
61
-- | The `Parser` monad is a synonym for the parser monad transformer applied to the `Identity` monad.
61
- type Parser s a = ParserT s Identity a
62
+ type Parser s = ParserT s Identity
62
63
63
64
-- | Apply a parser, keeping only the parsed result.
64
65
runParser :: forall s a . s -> Parser s a -> Either ParseError a
65
66
runParser s = unwrap <<< runParserT s
66
67
68
+ hoistParserT :: forall s m n a . (m ~> n ) -> ParserT s m a -> ParserT s n a
69
+ hoistParserT f (ParserT m) = ParserT (mapExceptT (mapStateT f) m)
70
+
67
71
instance lazyParserT :: Lazy (ParserT s m a ) where
68
72
defer f = ParserT (ExceptT (defer (runExceptT <<< unwrap <<< f)))
69
73
0 commit comments