Skip to content

Commit

Permalink
add mapParserT (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
safareli authored and paf31 committed Apr 24, 2017
1 parent a1adc35 commit 47ced07
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Text/Parsing/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Control.MonadPlus (class Alternative, class MonadZero, class MonadPlus, c
import Data.Either (Either(..))
import Data.Identity (Identity)
import Data.Monoid (class Monoid, mempty)
import Data.Newtype (class Newtype, unwrap)
import Data.Newtype (class Newtype, unwrap, over)
import Data.Tuple (Tuple(..))
import Text.Parsing.Parser.Pos (Position, initialPos)

Expand Down Expand Up @@ -69,7 +69,14 @@ runParser :: forall s a. s -> Parser s a -> Either ParseError a
runParser s = unwrap <<< runParserT s

hoistParserT :: forall s m n a. (m ~> n) -> ParserT s m a -> ParserT s n a
hoistParserT f (ParserT m) = ParserT (mapExceptT (mapStateT f) m)
hoistParserT = mapParserT

-- | Change the underlying monad action and data type in a ParserT monad action.
mapParserT :: forall b n s a m.
( m (Tuple (Either ParseError a) (ParseState s))
-> n (Tuple (Either ParseError b) (ParseState s))
) -> ParserT s m a -> ParserT s n b
mapParserT = over ParserT <<< mapExceptT <<< mapStateT

instance lazyParserT :: Lazy (ParserT s m a) where
defer f = ParserT (ExceptT (defer (runExceptT <<< unwrap <<< f)))
Expand Down

0 comments on commit 47ced07

Please sign in to comment.