module SimpleParser.Throw
( EmptyParseError (..)
, runParserThrow
, runParserEnd
) where
import Control.Exception (Exception)
import Control.Monad.Catch (MonadThrow (throwM))
import Data.Typeable (Typeable)
import SimpleParser.Input (matchEnd)
import SimpleParser.Parser (Parser, runParser)
import SimpleParser.Result (ParseResult (..), ParseSuccess (..))
import SimpleParser.Stream (Chunk, Stream, Token)
data EmptyParseError = EmptyParseError
deriving stock (EmptyParseError -> EmptyParseError -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EmptyParseError -> EmptyParseError -> Bool
$c/= :: EmptyParseError -> EmptyParseError -> Bool
== :: EmptyParseError -> EmptyParseError -> Bool
$c== :: EmptyParseError -> EmptyParseError -> Bool
Eq, Int -> EmptyParseError -> ShowS
[EmptyParseError] -> ShowS
EmptyParseError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EmptyParseError] -> ShowS
$cshowList :: [EmptyParseError] -> ShowS
show :: EmptyParseError -> String
$cshow :: EmptyParseError -> String
showsPrec :: Int -> EmptyParseError -> ShowS
$cshowsPrec :: Int -> EmptyParseError -> ShowS
Show)
instance Exception EmptyParseError
runParserThrow :: (
Typeable l, Typeable s, Typeable e, Typeable (Token s), Typeable (Chunk s),
Show l, Show s, Show e, Show (Token s), Show (Chunk s),
MonadThrow m) => Parser l s e a -> s -> m (ParseSuccess s a)
runParserThrow :: forall l s e (m :: * -> *) a.
(Typeable l, Typeable s, Typeable e, Typeable (Token s),
Typeable (Chunk s), Show l, Show s, Show e, Show (Token s),
Show (Chunk s), MonadThrow m) =>
Parser l s e a -> s -> m (ParseSuccess s a)
runParserThrow Parser l s e a
parser s
s =
case forall l s e a. Parser l s e a -> s -> Maybe (ParseResult l s e a)
runParser Parser l s e a
parser s
s of
Maybe (ParseResult l s e a)
Nothing -> forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM EmptyParseError
EmptyParseError
Just ParseResult l s e a
res ->
case ParseResult l s e a
res of
ParseResultError ParseErrorBundle l s e
errs -> forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM ParseErrorBundle l s e
errs
ParseResultSuccess ParseSuccess s a
success -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ParseSuccess s a
success
runParserEnd :: (
Typeable l, Typeable s, Typeable e, Typeable (Token s), Typeable (Chunk s),
Show l, Show s, Show e, Show (Token s), Show (Chunk s),
Stream s, MonadThrow m) => Parser l s e a -> s -> m a
runParserEnd :: forall l s e (m :: * -> *) a.
(Typeable l, Typeable s, Typeable e, Typeable (Token s),
Typeable (Chunk s), Show l, Show s, Show e, Show (Token s),
Show (Chunk s), Stream s, MonadThrow m) =>
Parser l s e a -> s -> m a
runParserEnd Parser l s e a
parser s
s = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. ParseSuccess s a -> a
psValue (forall l s e (m :: * -> *) a.
(Typeable l, Typeable s, Typeable e, Typeable (Token s),
Typeable (Chunk s), Show l, Show s, Show e, Show (Token s),
Show (Chunk s), MonadThrow m) =>
Parser l s e a -> s -> m (ParseSuccess s a)
runParserThrow (Parser l s e a
parser forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) l e.
(Stream s, Monad m) =>
ParserT l s e m ()
matchEnd) s
s)