{-# LANGUAGE FlexibleContexts #-} module Postdelay.Utils ( hoistParsecT ) where import Control.Monad.Error.Class import Data.Functor import Data.Either import Data.Functor.Identity import Text.Parsec.Prim import Text.Parsec.Error hoistParsecT :: (Monad m, Stream s Identity t, Stream s m t) => ParsecT s u Identity a -> ParsecT s u m a hoistParsecT p = do st <- getParserState let res = runParser p' undefined "" undefined p' = setParserState st >> ((,) <$> getState <*> p) either (fail . show) (\(st', res) -> putState st' $> res) $ res