module Text.ParserCombinators.Parsely.Class where
import Control.Monad
import qualified Text.ParserCombinators.Parsec as P
infix 0 <?>
infixr 1 <|>
(<|>) :: Parsely m => m a -> m a -> m a
(<|>) = mplus
class (Functor m, MonadPlus m) => Parsely m where
(<?>) :: m a -> String -> m a
(<?>) = const
unexpected :: String -> m a
unexpected _ = mzero
many :: m a -> m [a]
many p = go []
where
go xs = do x <- p; go (x:xs)
<|> return (reverse xs)
skipMany :: m a -> m ()
skipMany p = (p >> skipMany p)
<|> return ()
class Parsely m => ParselyTry m where
try :: m a -> m a
class ParselyTry m => MonadParsec m tok pos
| m -> tok, m -> pos where
token :: (tok -> String) -> (tok -> pos) -> (tok -> Maybe a) -> m a
tokenPrim
:: (tok -> String) -> (pos -> tok -> [tok] -> pos)
-> (tok -> Maybe a) -> m a
tokens
:: Eq tok => ([tok] -> String) -> (pos -> [tok] -> pos) -> [tok] -> m [tok]
lookAhead :: m a -> m a
instance Parsely (P.GenParser tok st) where
(<?>) = P.label
unexpected = P.unexpected
many = P.many
skipMany = P.skipMany
instance ParselyTry (P.GenParser tok st) where
try = P.try
instance MonadParsec (P.GenParser tok st) tok P.SourcePos where
token = P.token
tokenPrim = P.tokenPrim
tokens = P.tokens
lookAhead = P.lookAhead