mirror of
https://github.com/mrkkrp/megaparsec.git
synced 2024-11-24 12:04:23 +03:00
Added Control.Applicative.Alternative instance
This commit is contained in:
parent
4cc1a98ba9
commit
4de1647cc5
@ -16,15 +16,18 @@
|
||||
|
||||
module Text.Parsec.Prim where
|
||||
|
||||
import Control.Applicative
|
||||
import qualified Control.Applicative as Applicative ( Applicative(..), Alternative(..) )
|
||||
import Control.Monad
|
||||
import Control.Monad.Trans
|
||||
import Control.Monad.Identity
|
||||
|
||||
import Text.Parsec.Pos
|
||||
import Text.Parsec.Error
|
||||
|
||||
unknownError state = newErrorUnknown (statePos state)
|
||||
|
||||
sysUnExpectError msg pos = Error (newErrorMessage (SysUnExpect msg) pos)
|
||||
|
||||
unexpected :: (Stream s m t) => String -> ParsecT s u m a
|
||||
unexpected msg
|
||||
= ParsecT $ \s -> return $ Empty $ return $
|
||||
@ -65,9 +68,13 @@ parsecMap :: (Monad m) => (a -> b) -> ParsecT s u m a -> ParsecT s u m b
|
||||
parsecMap f p
|
||||
= ParsecT $ \s -> liftM (fmap (liftM (fmap f))) (runParsecT p s)
|
||||
|
||||
instance (Monad m) => Applicative (ParsecT s u m) where
|
||||
instance (Monad m) => Applicative.Applicative (ParsecT s u m) where
|
||||
pure = return
|
||||
(<*>) = ap
|
||||
(<*>) = ap -- TODO: Can this be optimized?
|
||||
|
||||
instance (Monad m) => Applicative.Alternative (ParsecT s u m) where
|
||||
empty = mzero
|
||||
(<|>) = mplus
|
||||
|
||||
instance (Monad m) => Monad (ParsecT s u m) where
|
||||
return x = parserReturn x
|
||||
@ -438,5 +445,6 @@ modifyState f = do updateParserState $ \s -> s { stateUser = f (stateUser s) }
|
||||
|
||||
setState :: (Monad m) => u -> ParsecT s u m ()
|
||||
setState = putState
|
||||
|
||||
updateState :: (Monad m) => (u -> u) -> ParsecT s u m ()
|
||||
updateState = modifyState
|
||||
|
Loading…
Reference in New Issue
Block a user