{-# LANGUAGE CPP #-}
module Streamly.Internal.Data.Parser.Type
(
Initial (..)
, Step (..)
, extractStep
, bimapOverrideCount
, Parser (..)
, ParseError (..)
, rmapM
, fromPure
, fromEffect
, splitWith
, split_
, die
, dieM
, splitSome
, splitMany
, splitManyPost
, alt
, concatMap
, lmap
, lmapM
, filter
, noErrorUnsafeSplitWith
, noErrorUnsafeSplit_
, noErrorUnsafeConcatMap
)
where
#include "inline.hs"
#include "assert.hs"
#if !MIN_VERSION_base(4,18,0)
import Control.Applicative (liftA2)
#endif
import Control.Applicative (Alternative(..))
import Control.Exception (Exception(..))
import Control.Monad ((>=>))
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Bifunctor (Bifunctor(..))
import Fusion.Plugin.Types (Fuse(..))
import Streamly.Internal.Data.Fold.Type (Fold(..), toList)
import qualified Control.Monad.Fail as Fail
import qualified Streamly.Internal.Data.Fold.Type as FL
import Prelude hiding (concatMap, filter)
#include "DocTestDataParser.hs"
{-# ANN type Initial Fuse #-}
data Initial s b
= IPartial !s
| IDone !b
| IError !String
instance Bifunctor Initial where
{-# INLINE bimap #-}
bimap :: forall a b c d. (a -> b) -> (c -> d) -> Initial a c -> Initial b d
bimap a -> b
f c -> d
_ (IPartial a
a) = b -> Initial b d
forall s b. s -> Initial s b
IPartial (a -> b
f a
a)
bimap a -> b
_ c -> d
g (IDone c
b) = d -> Initial b d
forall s b. b -> Initial s b
IDone (c -> d
g c
b)
bimap a -> b
_ c -> d
_ (IError String
err) = String -> Initial b d
forall s b. String -> Initial s b
IError String
err
instance Functor (Initial s) where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> Initial s a -> Initial s b
fmap = (a -> b) -> Initial s a -> Initial s b
forall b c a. (b -> c) -> Initial a b -> Initial a c
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second
{-# ANN type Step Fuse #-}
data Step s b =
Partial !Int !s
| Continue !Int !s
| Done !Int !b
| Error !String
instance Bifunctor Step where
{-# INLINE bimap #-}
bimap :: forall a b c d. (a -> b) -> (c -> d) -> Step a c -> Step b d
bimap a -> b
f c -> d
g Step a c
step =
case Step a c
step of
Partial Int
n a
s -> Int -> b -> Step b d
forall s b. Int -> s -> Step s b
Partial Int
n (a -> b
f a
s)
Continue Int
n a
s -> Int -> b -> Step b d
forall s b. Int -> s -> Step s b
Continue Int
n (a -> b
f a
s)
Done Int
n c
b -> Int -> d -> Step b d
forall s b. Int -> b -> Step s b
Done Int
n (c -> d
g c
b)
Error String
err -> String -> Step b d
forall s b. String -> Step s b
Error String
err
bimapOverrideCount :: Int -> (s -> s1) -> (b -> b1) -> Step s b -> Step s1 b1
bimapOverrideCount :: forall s s1 b b1.
Int -> (s -> s1) -> (b -> b1) -> Step s b -> Step s1 b1
bimapOverrideCount Int
n s -> s1
f b -> b1
g Step s b
step =
case Step s b
step of
Partial Int
_ s
s -> Int -> s1 -> Step s1 b1
forall s b. Int -> s -> Step s b
Partial Int
n (s -> s1
f s
s)
Continue Int
_ s
s -> Int -> s1 -> Step s1 b1
forall s b. Int -> s -> Step s b
Continue Int
n (s -> s1
f s
s)
Done Int
_ b
b -> Int -> b1 -> Step s1 b1
forall s b. Int -> b -> Step s b
Done Int
n (b -> b1
g b
b)
Error String
err -> String -> Step s1 b1
forall s b. String -> Step s b
Error String
err
instance Functor (Step s) where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> Step s a -> Step s b
fmap = (a -> b) -> Step s a -> Step s b
forall b c a. (b -> c) -> Step a b -> Step a c
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second
{-# INLINE assertStepCount #-}
assertStepCount :: Int -> Step s b -> Step s b
assertStepCount :: forall s b. Int -> Step s b -> Step s b
assertStepCount Int
i Step s b
step =
case Step s b
step of
Partial Int
n s
_ -> Bool -> Step s b -> Step s b
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n) Step s b
step
Continue Int
n s
_ -> Bool -> Step s b -> Step s b
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n) Step s b
step
Done Int
n b
_ -> Bool -> Step s b -> Step s b
forall a. (?callStack::CallStack) => Bool -> a -> a
assert (Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n) Step s b
step
Error String
_ -> Step s b
step
{-# INLINE extractStep #-}
extractStep :: Monad m => (s -> m (Step s1 b)) -> Step s b -> m (Step s1 b)
s -> m (Step s1 b)
f Step s b
res =
case Step s b
res of
Partial Int
n s
s1 -> Int -> Step s1 b -> Step s1 b
forall s b. Int -> Step s b -> Step s b
assertStepCount Int
n (Step s1 b -> Step s1 b) -> m (Step s1 b) -> m (Step s1 b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m (Step s1 b)
f s
s1
Done Int
n b
b -> Step s1 b -> m (Step s1 b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s1 b -> m (Step s1 b)) -> Step s1 b -> m (Step s1 b)
forall a b. (a -> b) -> a -> b
$ Int -> b -> Step s1 b
forall s b. Int -> b -> Step s b
Done Int
n b
b
Continue Int
n s
s1 -> Int -> Step s1 b -> Step s1 b
forall s b. Int -> Step s b -> Step s b
assertStepCount Int
n (Step s1 b -> Step s1 b) -> m (Step s1 b) -> m (Step s1 b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m (Step s1 b)
f s
s1
Error String
err -> Step s1 b -> m (Step s1 b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s1 b -> m (Step s1 b)) -> Step s1 b -> m (Step s1 b)
forall a b. (a -> b) -> a -> b
$ String -> Step s1 b
forall s b. String -> Step s b
Error String
err
{-# INLINE mapMStep #-}
mapMStep :: Applicative m => (a -> m b) -> Step s a -> m (Step s b)
mapMStep :: forall (m :: * -> *) a b s.
Applicative m =>
(a -> m b) -> Step s a -> m (Step s b)
mapMStep a -> m b
f Step s a
res =
case Step s a
res of
Partial Int
n s
s -> Step s b -> m (Step s b)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ Int -> s -> Step s b
forall s b. Int -> s -> Step s b
Partial Int
n s
s
Done Int
n a
b -> Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
n (b -> Step s b) -> m b -> m (Step s b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> m b
f a
b
Continue Int
n s
s -> Step s b -> m (Step s b)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ Int -> s -> Step s b
forall s b. Int -> s -> Step s b
Continue Int
n s
s
Error String
err -> Step s b -> m (Step s b)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ String -> Step s b
forall s b. String -> Step s b
Error String
err
data Parser a m b =
forall s. Parser
(s -> a -> m (Step s b))
(m (Initial s b))
(s -> m (Step s b))
newtype ParseError = ParseError String
deriving Int -> ParseError -> ShowS
[ParseError] -> ShowS
ParseError -> String
(Int -> ParseError -> ShowS)
-> (ParseError -> String)
-> ([ParseError] -> ShowS)
-> Show ParseError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ParseError -> ShowS
showsPrec :: Int -> ParseError -> ShowS
$cshow :: ParseError -> String
show :: ParseError -> String
$cshowList :: [ParseError] -> ShowS
showList :: [ParseError] -> ShowS
Show
instance Exception ParseError where
displayException :: ParseError -> String
displayException (ParseError String
err) = String
err
instance Functor m => Functor (Parser a m) where
{-# INLINE fmap #-}
fmap :: forall a b. (a -> b) -> Parser a m a -> Parser a m b
fmap a -> b
f (Parser s -> a -> m (Step s a)
step1 m (Initial s a)
initial1 s -> m (Step s a)
extract) =
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser s -> a -> m (Step s b)
step m (Initial s b)
initial ((a -> b) -> (s -> m (Step s a)) -> s -> m (Step s b)
forall {f :: * -> *} {f :: * -> *} {f :: * -> *} {a} {b}.
(Functor f, Functor f, Functor f) =>
(a -> b) -> f (f (f a)) -> f (f (f b))
fmap3 a -> b
f s -> m (Step s a)
extract)
where
initial :: m (Initial s b)
initial = (a -> b) -> m (Initial s a) -> m (Initial s b)
forall {f :: * -> *} {f :: * -> *} {a} {b}.
(Functor f, Functor f) =>
(a -> b) -> f (f a) -> f (f b)
fmap2 a -> b
f m (Initial s a)
initial1
step :: s -> a -> m (Step s b)
step s
s a
b = (a -> b) -> m (Step s a) -> m (Step s b)
forall {f :: * -> *} {f :: * -> *} {a} {b}.
(Functor f, Functor f) =>
(a -> b) -> f (f a) -> f (f b)
fmap2 a -> b
f (s -> a -> m (Step s a)
step1 s
s a
b)
fmap2 :: (a -> b) -> f (f a) -> f (f b)
fmap2 a -> b
g = (f a -> f b) -> f (f a) -> f (f b)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> f a -> f b
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
g)
fmap3 :: (a -> b) -> f (f (f a)) -> f (f (f b))
fmap3 a -> b
g = (f a -> f b) -> f (f (f a)) -> f (f (f b))
forall {f :: * -> *} {f :: * -> *} {a} {b}.
(Functor f, Functor f) =>
(a -> b) -> f (f a) -> f (f b)
fmap2 ((a -> b) -> f a -> f b
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
g)
{-# INLINE rmapM #-}
rmapM :: Monad m => (b -> m c) -> Parser a m b -> Parser a m c
rmapM :: forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> Parser a m b -> Parser a m c
rmapM b -> m c
f (Parser s -> a -> m (Step s b)
step m (Initial s b)
initial s -> m (Step s b)
extract) =
(s -> a -> m (Step s c))
-> m (Initial s c) -> (s -> m (Step s c)) -> Parser a m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser s -> a -> m (Step s c)
step1 m (Initial s c)
initial1 (s -> m (Step s b)
extract (s -> m (Step s b))
-> (Step s b -> m (Step s c)) -> s -> m (Step s c)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (b -> m c) -> Step s b -> m (Step s c)
forall (m :: * -> *) a b s.
Applicative m =>
(a -> m b) -> Step s a -> m (Step s b)
mapMStep b -> m c
f)
where
initial1 :: m (Initial s c)
initial1 = do
Initial s b
res <- m (Initial s b)
initial
case Initial s b
res of
IPartial s
x -> Initial s c -> m (Initial s c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial s c -> m (Initial s c)) -> Initial s c -> m (Initial s c)
forall a b. (a -> b) -> a -> b
$ s -> Initial s c
forall s b. s -> Initial s b
IPartial s
x
IDone b
a -> c -> Initial s c
forall s b. b -> Initial s b
IDone (c -> Initial s c) -> m c -> m (Initial s c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> m c
f b
a
IError String
err -> Initial s c -> m (Initial s c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial s c -> m (Initial s c)) -> Initial s c -> m (Initial s c)
forall a b. (a -> b) -> a -> b
$ String -> Initial s c
forall s b. String -> Initial s b
IError String
err
step1 :: s -> a -> m (Step s c)
step1 s
s a
a = s -> a -> m (Step s b)
step s
s a
a m (Step s b) -> (Step s b -> m (Step s c)) -> m (Step s c)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (b -> m c) -> Step s b -> m (Step s c)
forall (m :: * -> *) a b s.
Applicative m =>
(a -> m b) -> Step s a -> m (Step s b)
mapMStep b -> m c
f
{-# INLINE_NORMAL fromPure #-}
fromPure :: Monad m => b -> Parser a m b
fromPure :: forall (m :: * -> *) b a. Monad m => b -> Parser a m b
fromPure b
b = (Any -> a -> m (Step Any b))
-> m (Initial Any b) -> (Any -> m (Step Any b)) -> Parser a m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser Any -> a -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined (Initial Any b -> m (Initial Any b)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Initial Any b -> m (Initial Any b))
-> Initial Any b -> m (Initial Any b)
forall a b. (a -> b) -> a -> b
$ b -> Initial Any b
forall s b. b -> Initial s b
IDone b
b) Any -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined
{-# INLINE fromEffect #-}
fromEffect :: Monad m => m b -> Parser a m b
fromEffect :: forall (m :: * -> *) b a. Monad m => m b -> Parser a m b
fromEffect m b
b = (Any -> a -> m (Step Any b))
-> m (Initial Any b) -> (Any -> m (Step Any b)) -> Parser a m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser Any -> a -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined (b -> Initial Any b
forall s b. b -> Initial s b
IDone (b -> Initial Any b) -> m b -> m (Initial Any b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m b
b) Any -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined
{-# ANN type SeqParseState Fuse #-}
data SeqParseState sl f sr = SeqParseL !sl | SeqParseR !f !sr
{-# INLINE splitWith #-}
splitWith :: Monad m
=> (a -> b -> c) -> Parser x m a -> Parser x m b -> Parser x m c
splitWith :: forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Parser x m a -> Parser x m b -> Parser x m c
splitWith a -> b -> c
func (Parser s -> x -> m (Step s a)
stepL m (Initial s a)
initialL s -> m (Step s a)
extractL)
(Parser s -> x -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) =
(SeqParseState s (b -> c) s
-> x -> m (Step (SeqParseState s (b -> c) s) c))
-> m (Initial (SeqParseState s (b -> c) s) c)
-> (SeqParseState s (b -> c) s
-> m (Step (SeqParseState s (b -> c) s) c))
-> Parser x m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser SeqParseState s (b -> c) s
-> x -> m (Step (SeqParseState s (b -> c) s) c)
step m (Initial (SeqParseState s (b -> c) s) c)
initial SeqParseState s (b -> c) s
-> m (Step (SeqParseState s (b -> c) s) c)
extract
where
initial :: m (Initial (SeqParseState s (b -> c) s) c)
initial = do
Initial s a
resL <- m (Initial s a)
initialL
case Initial s a
resL of
IPartial s
sl -> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c))
-> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c
forall s b. s -> Initial s b
IPartial (SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c)
-> SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c
forall a b. (a -> b) -> a -> b
$ s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
sl
IDone a
bl -> do
Initial s b
resR <- m (Initial s b)
initialR
Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c))
-> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ case Initial s b
resR of
IPartial s
sr -> SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c
forall s b. s -> Initial s b
IPartial (SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c)
-> SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c
forall a b. (a -> b) -> a -> b
$ (b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR (a -> b -> c
func a
bl) s
sr
IDone b
br -> c -> Initial (SeqParseState s (b -> c) s) c
forall s b. b -> Initial s b
IDone (a -> b -> c
func a
bl b
br)
IError String
err -> String -> Initial (SeqParseState s (b -> c) s) c
forall s b. String -> Initial s b
IError String
err
IError String
err -> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c))
-> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ String -> Initial (SeqParseState s (b -> c) s) c
forall s b. String -> Initial s b
IError String
err
step :: SeqParseState s (b -> c) s
-> x -> m (Step (SeqParseState s (b -> c) s) c)
step (SeqParseL s
st) x
a = do
Step s a
resL <- s -> x -> m (Step s a)
stepL s
st x
a
case Step s a
resL of
Partial Int
n s
s -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
s)
Continue Int
n s
s -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
s)
Done Int
n a
b -> do
Initial s b
initR <- m (Initial s b)
initialR
Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ case Initial s b
initR of
IPartial s
sr -> Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Continue Int
n (SeqParseState s (b -> c) s -> Step (SeqParseState s (b -> c) s) c)
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall a b. (a -> b) -> a -> b
$ (b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR (a -> b -> c
func a
b) s
sr
IDone b
br -> Int -> c -> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> b -> Step s b
Done Int
n (a -> b -> c
func a
b b
br)
IError String
err -> String -> Step (SeqParseState s (b -> c) s) c
forall s b. String -> Step s b
Error String
err
Error String
err -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (SeqParseState s (b -> c) s) c
forall s b. String -> Step s b
Error String
err
step (SeqParseR b -> c
f s
st) x
a = (Step s b -> Step (SeqParseState s (b -> c) s) c)
-> m (Step s b) -> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> SeqParseState s (b -> c) s)
-> (b -> c) -> Step s b -> Step (SeqParseState s (b -> c) s) c
forall a b c d. (a -> b) -> (c -> d) -> Step a c -> Step b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ((b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR b -> c
f) b -> c
f) (s -> x -> m (Step s b)
stepR s
st x
a)
extract :: SeqParseState s (b -> c) s
-> m (Step (SeqParseState s (b -> c) s) c)
extract (SeqParseR b -> c
f s
sR) = (Step s b -> Step (SeqParseState s (b -> c) s) c)
-> m (Step s b) -> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> SeqParseState s (b -> c) s)
-> (b -> c) -> Step s b -> Step (SeqParseState s (b -> c) s) c
forall a b c d. (a -> b) -> (c -> d) -> Step a c -> Step b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ((b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR b -> c
f) b -> c
f) (s -> m (Step s b)
extractR s
sR)
extract (SeqParseL s
sL) = do
Step s a
rL <- s -> m (Step s a)
extractL s
sL
case Step s a
rL of
Done Int
n a
bL -> do
Initial s b
iR <- m (Initial s b)
initialR
case Initial s b
iR of
IPartial s
sR -> do
(Step s b -> Step (SeqParseState s (b -> c) s) c)
-> m (Step s b) -> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
((s -> SeqParseState s (b -> c) s)
-> (b -> c) -> Step s b -> Step (SeqParseState s (b -> c) s) c
forall a b c d. (a -> b) -> (c -> d) -> Step a c -> Step b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ((b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR (a -> b -> c
func a
bL)) (a -> b -> c
func a
bL))
(s -> m (Step s b)
extractR s
sR)
IDone b
bR -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> b -> Step s b
Done Int
n (c -> Step (SeqParseState s (b -> c) s) c)
-> c -> Step (SeqParseState s (b -> c) s) c
forall a b. (a -> b) -> a -> b
$ a -> b -> c
func a
bL b
bR
IError String
err -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (SeqParseState s (b -> c) s) c
forall s b. String -> Step s b
Error String
err
Error String
err -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (SeqParseState s (b -> c) s) c
forall s b. String -> Step s b
Error String
err
Partial Int
_ s
_ -> String -> m (Step (SeqParseState s (b -> c) s) c)
forall a. (?callStack::CallStack) => String -> a
error String
"Bug: splitWith extract 'Partial'"
Continue Int
n s
s -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
s)
{-# INLINE noErrorUnsafeSplitWith #-}
noErrorUnsafeSplitWith :: Monad m
=> (a -> b -> c) -> Parser x m a -> Parser x m b -> Parser x m c
noErrorUnsafeSplitWith :: forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Parser x m a -> Parser x m b -> Parser x m c
noErrorUnsafeSplitWith a -> b -> c
func (Parser s -> x -> m (Step s a)
stepL m (Initial s a)
initialL s -> m (Step s a)
extractL)
(Parser s -> x -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) =
(SeqParseState s (b -> c) s
-> x -> m (Step (SeqParseState s (b -> c) s) c))
-> m (Initial (SeqParseState s (b -> c) s) c)
-> (SeqParseState s (b -> c) s
-> m (Step (SeqParseState s (b -> c) s) c))
-> Parser x m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser SeqParseState s (b -> c) s
-> x -> m (Step (SeqParseState s (b -> c) s) c)
step m (Initial (SeqParseState s (b -> c) s) c)
initial SeqParseState s (b -> c) s
-> m (Step (SeqParseState s (b -> c) s) c)
extract
where
errMsg :: String -> a
errMsg String
e = String -> a
forall a. (?callStack::CallStack) => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"noErrorUnsafeSplitWith: unreachable: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
e
initial :: m (Initial (SeqParseState s (b -> c) s) c)
initial = do
Initial s a
resL <- m (Initial s a)
initialL
case Initial s a
resL of
IPartial s
sl -> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c))
-> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c
forall s b. s -> Initial s b
IPartial (SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c)
-> SeqParseState s (b -> c) s
-> Initial (SeqParseState s (b -> c) s) c
forall a b. (a -> b) -> a -> b
$ s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
sl
IDone a
bl -> do
Initial s b
resR <- m (Initial s b)
initialR
Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c))
-> Initial (SeqParseState s (b -> c) s) c
-> m (Initial (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ (s -> SeqParseState s (b -> c) s)
-> (b -> c)
-> Initial s b
-> Initial (SeqParseState s (b -> c) s) c
forall a b c d. (a -> b) -> (c -> d) -> Initial a c -> Initial b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ((b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR (a -> b -> c
func a
bl)) (a -> b -> c
func a
bl) Initial s b
resR
IError String
err -> String -> m (Initial (SeqParseState s (b -> c) s) c)
forall {a}. String -> a
errMsg String
err
step :: SeqParseState s (b -> c) s
-> x -> m (Step (SeqParseState s (b -> c) s) c)
step (SeqParseL s
st) x
a = do
Step s a
r <- s -> x -> m (Step s a)
stepL s
st x
a
case Step s a
r of
Partial Int
n s
s -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Partial Int
n (s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
s)
Continue Int
n s
s -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
s)
Done Int
n a
b -> do
Initial s b
res <- m (Initial s b)
initialR
Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ case Initial s b
res of
IPartial s
sr -> Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Partial Int
n (SeqParseState s (b -> c) s -> Step (SeqParseState s (b -> c) s) c)
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall a b. (a -> b) -> a -> b
$ (b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR (a -> b -> c
func a
b) s
sr
IDone b
br -> Int -> c -> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> b -> Step s b
Done Int
n (a -> b -> c
func a
b b
br)
IError String
err -> String -> Step (SeqParseState s (b -> c) s) c
forall {a}. String -> a
errMsg String
err
Error String
err -> String -> m (Step (SeqParseState s (b -> c) s) c)
forall {a}. String -> a
errMsg String
err
step (SeqParseR b -> c
f s
st) x
a = (Step s b -> Step (SeqParseState s (b -> c) s) c)
-> m (Step s b) -> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> SeqParseState s (b -> c) s)
-> (b -> c) -> Step s b -> Step (SeqParseState s (b -> c) s) c
forall a b c d. (a -> b) -> (c -> d) -> Step a c -> Step b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ((b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR b -> c
f) b -> c
f) (s -> x -> m (Step s b)
stepR s
st x
a)
extract :: SeqParseState s (b -> c) s
-> m (Step (SeqParseState s (b -> c) s) c)
extract (SeqParseR b -> c
f s
sR) = (Step s b -> Step (SeqParseState s (b -> c) s) c)
-> m (Step s b) -> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> SeqParseState s (b -> c) s)
-> (b -> c) -> Step s b -> Step (SeqParseState s (b -> c) s) c
forall a b c d. (a -> b) -> (c -> d) -> Step a c -> Step b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap ((b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR b -> c
f) b -> c
f) (s -> m (Step s b)
extractR s
sR)
extract (SeqParseL s
sL) = do
Step s a
rL <- s -> m (Step s a)
extractL s
sL
case Step s a
rL of
Done Int
n a
bL -> do
Initial s b
iR <- m (Initial s b)
initialR
case Initial s b
iR of
IPartial s
sR -> do
Step s b
rR <- s -> m (Step s b)
extractR s
sR
Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (s -> SeqParseState s (b -> c) s)
-> (b -> c)
-> Step s b
-> Step (SeqParseState s (b -> c) s) c
forall s s1 b b1.
Int -> (s -> s1) -> (b -> b1) -> Step s b -> Step s1 b1
bimapOverrideCount
Int
n ((b -> c) -> s -> SeqParseState s (b -> c) s
forall sl f sr. f -> sr -> SeqParseState sl f sr
SeqParseR (a -> b -> c
func a
bL)) (a -> b -> c
func a
bL) Step s b
rR
IDone b
bR -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> b -> Step s b
Done Int
n (c -> Step (SeqParseState s (b -> c) s) c)
-> c -> Step (SeqParseState s (b -> c) s) c
forall a b. (a -> b) -> a -> b
$ a -> b -> c
func a
bL b
bR
IError String
err -> String -> m (Step (SeqParseState s (b -> c) s) c)
forall {a}. String -> a
errMsg String
err
Error String
err -> String -> m (Step (SeqParseState s (b -> c) s) c)
forall {a}. String -> a
errMsg String
err
Partial Int
_ s
_ -> String -> m (Step (SeqParseState s (b -> c) s) c)
forall {a}. String -> a
errMsg String
"Partial"
Continue Int
n s
s -> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c))
-> Step (SeqParseState s (b -> c) s) c
-> m (Step (SeqParseState s (b -> c) s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> SeqParseState s (b -> c) s
-> Step (SeqParseState s (b -> c) s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqParseState s (b -> c) s
forall sl f sr. sl -> SeqParseState sl f sr
SeqParseL s
s)
{-# ANN type SeqAState Fuse #-}
data SeqAState sl sr = SeqAL !sl | SeqAR !sr
{-# INLINE split_ #-}
split_ :: Monad m => Parser x m a -> Parser x m b -> Parser x m b
split_ :: forall (m :: * -> *) x a b.
Monad m =>
Parser x m a -> Parser x m b -> Parser x m b
split_ (Parser s -> x -> m (Step s a)
stepL m (Initial s a)
initialL s -> m (Step s a)
extractL) (Parser s -> x -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) =
(SeqAState s s -> x -> m (Step (SeqAState s s) b))
-> m (Initial (SeqAState s s) b)
-> (SeqAState s s -> m (Step (SeqAState s s) b))
-> Parser x m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser SeqAState s s -> x -> m (Step (SeqAState s s) b)
step m (Initial (SeqAState s s) b)
initial SeqAState s s -> m (Step (SeqAState s s) b)
extract
where
initial :: m (Initial (SeqAState s s) b)
initial = do
Initial s a
resL <- m (Initial s a)
initialL
case Initial s a
resL of
IPartial s
sl -> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b))
-> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ SeqAState s s -> Initial (SeqAState s s) b
forall s b. s -> Initial s b
IPartial (SeqAState s s -> Initial (SeqAState s s) b)
-> SeqAState s s -> Initial (SeqAState s s) b
forall a b. (a -> b) -> a -> b
$ s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
sl
IDone a
_ -> do
Initial s b
resR <- m (Initial s b)
initialR
Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b))
-> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ (s -> SeqAState s s) -> Initial s b -> Initial (SeqAState s s) b
forall a b c. (a -> b) -> Initial a c -> Initial b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR Initial s b
resR
IError String
err -> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b))
-> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ String -> Initial (SeqAState s s) b
forall s b. String -> Initial s b
IError String
err
step :: SeqAState s s -> x -> m (Step (SeqAState s s) b)
step (SeqAL s
st) x
a = do
Step s a
resL <- s -> x -> m (Step s a)
stepL s
st x
a
case Step s a
resL of
Partial Int
n s
s -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
s)
Continue Int
n s
s -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
s)
Done Int
n a
_ -> do
Initial s b
initR <- m (Initial s b)
initialR
Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ case Initial s b
initR of
IPartial s
s -> Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR s
s)
IDone b
b -> Int -> b -> Step (SeqAState s s) b
forall s b. Int -> b -> Step s b
Done Int
n b
b
IError String
err -> String -> Step (SeqAState s s) b
forall s b. String -> Step s b
Error String
err
Error String
err -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (SeqAState s s) b
forall s b. String -> Step s b
Error String
err
step (SeqAR s
st) x
a = (s -> SeqAState s s) -> Step s b -> Step (SeqAState s s) b
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR (Step s b -> Step (SeqAState s s) b)
-> m (Step s b) -> m (Step (SeqAState s s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> x -> m (Step s b)
stepR s
st x
a
extract :: SeqAState s s -> m (Step (SeqAState s s) b)
extract (SeqAR s
sR) = (Step s b -> Step (SeqAState s s) b)
-> m (Step s b) -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> SeqAState s s) -> Step s b -> Step (SeqAState s s) b
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR) (s -> m (Step s b)
extractR s
sR)
extract (SeqAL s
sL) = do
Step s a
rL <- s -> m (Step s a)
extractL s
sL
case Step s a
rL of
Done Int
n a
_ -> do
Initial s b
iR <- m (Initial s b)
initialR
case Initial s b
iR of
IPartial s
sR ->
(Step s b -> Step (SeqAState s s) b)
-> m (Step s b) -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int
-> (s -> SeqAState s s)
-> (b -> b)
-> Step s b
-> Step (SeqAState s s) b
forall s s1 b b1.
Int -> (s -> s1) -> (b -> b1) -> Step s b -> Step s1 b1
bimapOverrideCount Int
n s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR b -> b
forall a. a -> a
id) (s -> m (Step s b)
extractR s
sR)
IDone b
bR -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> b -> Step (SeqAState s s) b
forall s b. Int -> b -> Step s b
Done Int
n b
bR
IError String
err -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (SeqAState s s) b
forall s b. String -> Step s b
Error String
err
Error String
err -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (SeqAState s s) b
forall s b. String -> Step s b
Error String
err
Partial Int
_ s
_ -> String -> m (Step (SeqAState s s) b)
forall a. (?callStack::CallStack) => String -> a
error String
"split_: Partial"
Continue Int
n s
s -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
s)
{-# INLINE noErrorUnsafeSplit_ #-}
noErrorUnsafeSplit_ :: Monad m => Parser x m a -> Parser x m b -> Parser x m b
noErrorUnsafeSplit_ :: forall (m :: * -> *) x a b.
Monad m =>
Parser x m a -> Parser x m b -> Parser x m b
noErrorUnsafeSplit_
(Parser s -> x -> m (Step s a)
stepL m (Initial s a)
initialL s -> m (Step s a)
extractL) (Parser s -> x -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) =
(SeqAState s s -> x -> m (Step (SeqAState s s) b))
-> m (Initial (SeqAState s s) b)
-> (SeqAState s s -> m (Step (SeqAState s s) b))
-> Parser x m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser SeqAState s s -> x -> m (Step (SeqAState s s) b)
step m (Initial (SeqAState s s) b)
initial SeqAState s s -> m (Step (SeqAState s s) b)
extract
where
errMsg :: String -> a
errMsg String
e = String -> a
forall a. (?callStack::CallStack) => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"noErrorUnsafeSplit_: unreachable: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
e
initial :: m (Initial (SeqAState s s) b)
initial = do
Initial s a
resL <- m (Initial s a)
initialL
case Initial s a
resL of
IPartial s
sl -> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b))
-> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ SeqAState s s -> Initial (SeqAState s s) b
forall s b. s -> Initial s b
IPartial (SeqAState s s -> Initial (SeqAState s s) b)
-> SeqAState s s -> Initial (SeqAState s s) b
forall a b. (a -> b) -> a -> b
$ s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
sl
IDone a
_ -> do
Initial s b
resR <- m (Initial s b)
initialR
Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b))
-> Initial (SeqAState s s) b -> m (Initial (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ (s -> SeqAState s s) -> Initial s b -> Initial (SeqAState s s) b
forall a b c. (a -> b) -> Initial a c -> Initial b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR Initial s b
resR
IError String
err -> String -> m (Initial (SeqAState s s) b)
forall {a}. String -> a
errMsg String
err
step :: SeqAState s s -> x -> m (Step (SeqAState s s) b)
step (SeqAL s
st) x
a = do
Step s a
resL <- s -> x -> m (Step s a)
stepL s
st x
a
case Step s a
resL of
Partial Int
n s
s -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Partial Int
n (s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
s)
Continue Int
n s
s -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
s)
Done Int
n a
_ -> do
Initial s b
initR <- m (Initial s b)
initialR
Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ case Initial s b
initR of
IPartial s
s -> Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Partial Int
n (s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR s
s)
IDone b
b -> Int -> b -> Step (SeqAState s s) b
forall s b. Int -> b -> Step s b
Done Int
n b
b
IError String
err -> String -> Step (SeqAState s s) b
forall {a}. String -> a
errMsg String
err
Error String
err -> String -> m (Step (SeqAState s s) b)
forall {a}. String -> a
errMsg String
err
step (SeqAR s
st) x
a = (s -> SeqAState s s) -> Step s b -> Step (SeqAState s s) b
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR (Step s b -> Step (SeqAState s s) b)
-> m (Step s b) -> m (Step (SeqAState s s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> x -> m (Step s b)
stepR s
st x
a
extract :: SeqAState s s -> m (Step (SeqAState s s) b)
extract (SeqAR s
sR) = (Step s b -> Step (SeqAState s s) b)
-> m (Step s b) -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> SeqAState s s) -> Step s b -> Step (SeqAState s s) b
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR) (s -> m (Step s b)
extractR s
sR)
extract (SeqAL s
sL) = do
Step s a
rL <- s -> m (Step s a)
extractL s
sL
case Step s a
rL of
Done Int
n a
_ -> do
Initial s b
iR <- m (Initial s b)
initialR
case Initial s b
iR of
IPartial s
sR -> do
(Step s b -> Step (SeqAState s s) b)
-> m (Step s b) -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int
-> (s -> SeqAState s s)
-> (b -> b)
-> Step s b
-> Step (SeqAState s s) b
forall s s1 b b1.
Int -> (s -> s1) -> (b -> b1) -> Step s b -> Step s1 b1
bimapOverrideCount Int
n s -> SeqAState s s
forall sl sr. sr -> SeqAState sl sr
SeqAR b -> b
forall a. a -> a
id) (s -> m (Step s b)
extractR s
sR)
IDone b
bR -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> b -> Step (SeqAState s s) b
forall s b. Int -> b -> Step s b
Done Int
n b
bR
IError String
err -> String -> m (Step (SeqAState s s) b)
forall {a}. String -> a
errMsg String
err
Error String
err -> String -> m (Step (SeqAState s s) b)
forall {a}. String -> a
errMsg String
err
Partial Int
_ s
_ -> String -> m (Step (SeqAState s s) b)
forall a. (?callStack::CallStack) => String -> a
error String
"split_: Partial"
Continue Int
n s
s -> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SeqAState s s) b -> m (Step (SeqAState s s) b))
-> Step (SeqAState s s) b -> m (Step (SeqAState s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> SeqAState s s -> Step (SeqAState s s) b
forall s b. Int -> s -> Step s b
Continue Int
n (s -> SeqAState s s
forall sl sr. sl -> SeqAState sl sr
SeqAL s
s)
instance Monad m => Applicative (Parser a m) where
{-# INLINE pure #-}
pure :: forall a. a -> Parser a m a
pure = a -> Parser a m a
forall (m :: * -> *) b a. Monad m => b -> Parser a m b
fromPure
{-# INLINE (<*>) #-}
<*> :: forall a b. Parser a m (a -> b) -> Parser a m a -> Parser a m b
(<*>) = ((a -> b) -> a -> b)
-> Parser a m (a -> b) -> Parser a m a -> Parser a m b
forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> c) -> Parser x m a -> Parser x m b -> Parser x m c
splitWith (a -> b) -> a -> b
forall a. a -> a
id
{-# INLINE (*>) #-}
*> :: forall a b. Parser a m a -> Parser a m b -> Parser a m b
(*>) = Parser a m a -> Parser a m b -> Parser a m b
forall (m :: * -> *) x a b.
Monad m =>
Parser x m a -> Parser x m b -> Parser x m b
split_
{-# INLINE liftA2 #-}
liftA2 :: forall a b c.
(a -> b -> c) -> Parser a m a -> Parser a m b -> Parser a m c
liftA2 a -> b -> c
f Parser a m a
x = Parser a m (b -> c) -> Parser a m b -> Parser a m c
forall a b. Parser a m (a -> b) -> Parser a m a -> Parser a m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
(<*>) ((a -> b -> c) -> Parser a m a -> Parser a m (b -> c)
forall a b. (a -> b) -> Parser a m a -> Parser a m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b -> c
f Parser a m a
x)
{-# ANN type AltParseState Fuse #-}
data AltParseState sl sr = AltParseL !Int !sl | AltParseR !sr
{-# INLINE alt #-}
alt :: Monad m => Parser x m a -> Parser x m a -> Parser x m a
alt :: forall (m :: * -> *) x a.
Monad m =>
Parser x m a -> Parser x m a -> Parser x m a
alt (Parser s -> x -> m (Step s a)
stepL m (Initial s a)
initialL s -> m (Step s a)
extractL) (Parser s -> x -> m (Step s a)
stepR m (Initial s a)
initialR s -> m (Step s a)
extractR) =
(AltParseState s s -> x -> m (Step (AltParseState s s) a))
-> m (Initial (AltParseState s s) a)
-> (AltParseState s s -> m (Step (AltParseState s s) a))
-> Parser x m a
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser AltParseState s s -> x -> m (Step (AltParseState s s) a)
step m (Initial (AltParseState s s) a)
initial AltParseState s s -> m (Step (AltParseState s s) a)
extract
where
initial :: m (Initial (AltParseState s s) a)
initial = do
Initial s a
resL <- m (Initial s a)
initialL
case Initial s a
resL of
IPartial s
sl -> Initial (AltParseState s s) a -> m (Initial (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (AltParseState s s) a
-> m (Initial (AltParseState s s) a))
-> Initial (AltParseState s s) a
-> m (Initial (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ AltParseState s s -> Initial (AltParseState s s) a
forall s b. s -> Initial s b
IPartial (AltParseState s s -> Initial (AltParseState s s) a)
-> AltParseState s s -> Initial (AltParseState s s) a
forall a b. (a -> b) -> a -> b
$ Int -> s -> AltParseState s s
forall sl sr. Int -> sl -> AltParseState sl sr
AltParseL Int
0 s
sl
IDone a
bl -> Initial (AltParseState s s) a -> m (Initial (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (AltParseState s s) a
-> m (Initial (AltParseState s s) a))
-> Initial (AltParseState s s) a
-> m (Initial (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ a -> Initial (AltParseState s s) a
forall s b. b -> Initial s b
IDone a
bl
IError String
_ -> do
Initial s a
resR <- m (Initial s a)
initialR
Initial (AltParseState s s) a -> m (Initial (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (AltParseState s s) a
-> m (Initial (AltParseState s s) a))
-> Initial (AltParseState s s) a
-> m (Initial (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ case Initial s a
resR of
IPartial s
sr -> AltParseState s s -> Initial (AltParseState s s) a
forall s b. s -> Initial s b
IPartial (AltParseState s s -> Initial (AltParseState s s) a)
-> AltParseState s s -> Initial (AltParseState s s) a
forall a b. (a -> b) -> a -> b
$ s -> AltParseState s s
forall sl sr. sr -> AltParseState sl sr
AltParseR s
sr
IDone a
br -> a -> Initial (AltParseState s s) a
forall s b. b -> Initial s b
IDone a
br
IError String
err -> String -> Initial (AltParseState s s) a
forall s b. String -> Initial s b
IError String
err
step :: AltParseState s s -> x -> m (Step (AltParseState s s) a)
step (AltParseL Int
cnt s
st) x
a = do
Step s a
r <- s -> x -> m (Step s a)
stepL s
st x
a
case Step s a
r of
Partial Int
n s
s -> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ Int -> AltParseState s s -> Step (AltParseState s s) a
forall s b. Int -> s -> Step s b
Partial Int
n (Int -> s -> AltParseState s s
forall sl sr. Int -> sl -> AltParseState sl sr
AltParseL Int
0 s
s)
Continue Int
n s
s -> do
assertM(Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ Int -> AltParseState s s -> Step (AltParseState s s) a
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> AltParseState s s
forall sl sr. Int -> sl -> AltParseState sl sr
AltParseL (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
s)
Done Int
n a
b -> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ Int -> a -> Step (AltParseState s s) a
forall s b. Int -> b -> Step s b
Done Int
n a
b
Error String
_ -> do
Initial s a
res <- m (Initial s a)
initialR
Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ case Initial s a
res of
IPartial s
rR -> Int -> AltParseState s s -> Step (AltParseState s s) a
forall s b. Int -> s -> Step s b
Continue (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (s -> AltParseState s s
forall sl sr. sr -> AltParseState sl sr
AltParseR s
rR)
IDone a
b -> Int -> a -> Step (AltParseState s s) a
forall s b. Int -> b -> Step s b
Done (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) a
b
IError String
err -> String -> Step (AltParseState s s) a
forall s b. String -> Step s b
Error String
err
step (AltParseR s
st) x
a = do
Step s a
r <- s -> x -> m (Step s a)
stepR s
st x
a
Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Partial Int
n s
s -> Int -> AltParseState s s -> Step (AltParseState s s) a
forall s b. Int -> s -> Step s b
Partial Int
n (s -> AltParseState s s
forall sl sr. sr -> AltParseState sl sr
AltParseR s
s)
Continue Int
n s
s -> Int -> AltParseState s s -> Step (AltParseState s s) a
forall s b. Int -> s -> Step s b
Continue Int
n (s -> AltParseState s s
forall sl sr. sr -> AltParseState sl sr
AltParseR s
s)
Done Int
n a
b -> Int -> a -> Step (AltParseState s s) a
forall s b. Int -> b -> Step s b
Done Int
n a
b
Error String
err -> String -> Step (AltParseState s s) a
forall s b. String -> Step s b
Error String
err
extract :: AltParseState s s -> m (Step (AltParseState s s) a)
extract (AltParseR s
sR) = (Step s a -> Step (AltParseState s s) a)
-> m (Step s a) -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> AltParseState s s) -> Step s a -> Step (AltParseState s s) a
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first s -> AltParseState s s
forall sl sr. sr -> AltParseState sl sr
AltParseR) (s -> m (Step s a)
extractR s
sR)
extract (AltParseL Int
cnt s
sL) = do
Step s a
rL <- s -> m (Step s a)
extractL s
sL
case Step s a
rL of
Done Int
n a
b -> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ Int -> a -> Step (AltParseState s s) a
forall s b. Int -> b -> Step s b
Done Int
n a
b
Error String
_ -> do
Initial s a
res <- m (Initial s a)
initialR
Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ case Initial s a
res of
IPartial s
rR -> Int -> AltParseState s s -> Step (AltParseState s s) a
forall s b. Int -> s -> Step s b
Continue Int
cnt (s -> AltParseState s s
forall sl sr. sr -> AltParseState sl sr
AltParseR s
rR)
IDone a
b -> Int -> a -> Step (AltParseState s s) a
forall s b. Int -> b -> Step s b
Done Int
cnt a
b
IError String
err -> String -> Step (AltParseState s s) a
forall s b. String -> Step s b
Error String
err
Partial Int
_ s
_ -> String -> m (Step (AltParseState s s) a)
forall a. (?callStack::CallStack) => String -> a
error String
"Bug: alt: extractL 'Partial'"
Continue Int
n s
s -> do
assertM(Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
cnt)
Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (AltParseState s s) a -> m (Step (AltParseState s s) a))
-> Step (AltParseState s s) a -> m (Step (AltParseState s s) a)
forall a b. (a -> b) -> a -> b
$ Int -> AltParseState s s -> Step (AltParseState s s) a
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> AltParseState s s
forall sl sr. Int -> sl -> AltParseState sl sr
AltParseL Int
0 s
s)
{-# ANN type Fused3 Fuse #-}
data Fused3 a b c = Fused3 !a !b !c
{-# INLINE splitMany #-}
splitMany :: Monad m => Parser a m b -> Fold m b c -> Parser a m c
splitMany :: forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
splitMany (Parser s -> a -> m (Step s b)
step1 m (Initial s b)
initial1 s -> m (Step s b)
extract1) (Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
_ s -> m c
ffinal) =
(Fused3 s Int s -> a -> m (Step (Fused3 s Int s) c))
-> m (Initial (Fused3 s Int s) c)
-> (Fused3 s Int s -> m (Step (Fused3 s Int s) c))
-> Parser a m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser Fused3 s Int s -> a -> m (Step (Fused3 s Int s) c)
step m (Initial (Fused3 s Int s) c)
initial Fused3 s Int s -> m (Step (Fused3 s Int s) c)
forall {b}. Num b => Fused3 s Int s -> m (Step (Fused3 s b s) c)
extract
where
handleCollect :: (Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s b s -> b
partial c -> b
done Step s c
fres =
case Step s c
fres of
FL.Partial s
fs -> do
Initial s b
pres <- m (Initial s b)
initial1
case Initial s b
pres of
IPartial s
ps -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$ Fused3 s b s -> b
partial (Fused3 s b s -> b) -> Fused3 s b s -> b
forall a b. (a -> b) -> a -> b
$ s -> b -> s -> Fused3 s b s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
ps b
0 s
fs
IDone b
pb ->
(Step s c -> m b) -> s -> b -> m b
forall {b}. (Step s c -> m b) -> s -> b -> m b
runCollectorWith ((Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s b s -> b
partial c -> b
done) s
fs b
pb
IError String
_ -> c -> b
done (c -> b) -> m c -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
ffinal s
fs
FL.Done c
fb -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$ c -> b
done c
fb
runCollectorWith :: (Step s c -> m b) -> s -> b -> m b
runCollectorWith Step s c -> m b
cont s
fs b
pb = s -> b -> m (Step s c)
fstep s
fs b
pb m (Step s c) -> (Step s c -> m b) -> m b
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Step s c -> m b
cont
initial :: m (Initial (Fused3 s Int s) c)
initial = m (Step s c)
finitial m (Step s c)
-> (Step s c -> m (Initial (Fused3 s Int s) c))
-> m (Initial (Fused3 s Int s) c)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Fused3 s Int s -> Initial (Fused3 s Int s) c)
-> (c -> Initial (Fused3 s Int s) c)
-> Step s c
-> m (Initial (Fused3 s Int s) c)
forall {b} {b}.
Num b =>
(Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s Int s -> Initial (Fused3 s Int s) c
forall s b. s -> Initial s b
IPartial c -> Initial (Fused3 s Int s) c
forall s b. b -> Initial s b
IDone
{-# INLINE step #-}
step :: Fused3 s Int s -> a -> m (Step (Fused3 s Int s) c)
step (Fused3 s
st Int
cnt s
fs) a
a = do
Step s b
r <- s -> a -> m (Step s b)
step1 s
st a
a
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
case Step s b
r of
Partial Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c))
-> Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a b. (a -> b) -> a -> b
$ Int -> Fused3 s Int s -> Step (Fused3 s Int s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> Int -> s -> Fused3 s Int s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs)
Continue Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c))
-> Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a b. (a -> b) -> a -> b
$ Int -> Fused3 s Int s -> Step (Fused3 s Int s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> Int -> s -> Fused3 s Int s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs)
Done Int
n b
b -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
s -> b -> m (Step s c)
fstep s
fs b
b m (Step s c)
-> (Step s c -> m (Step (Fused3 s Int s) c))
-> m (Step (Fused3 s Int s) c)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Fused3 s Int s -> Step (Fused3 s Int s) c)
-> (c -> Step (Fused3 s Int s) c)
-> Step s c
-> m (Step (Fused3 s Int s) c)
forall {b} {b}.
Num b =>
(Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect (Int -> Fused3 s Int s -> Step (Fused3 s Int s) c
forall s b. Int -> s -> Step s b
Partial Int
n) (Int -> c -> Step (Fused3 s Int s) c
forall s b. Int -> b -> Step s b
Done Int
n)
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c))
-> Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (Fused3 s Int s) c
forall s b. Int -> b -> Step s b
Done Int
cnt c
xs
extract :: Fused3 s Int s -> m (Step (Fused3 s b s) c)
extract (Fused3 s
_ Int
0 s
fs) = (c -> Step (Fused3 s b s) c) -> m c -> m (Step (Fused3 s b s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b s) c
forall s b. Int -> b -> Step s b
Done Int
0) (s -> m c
ffinal s
fs)
extract (Fused3 s
s Int
cnt s
fs) = do
Step s b
r <- s -> m (Step s b)
extract1 s
s
case Step s b
r of
Error String
_ -> (c -> Step (Fused3 s b s) c) -> m c -> m (Step (Fused3 s b s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b s) c
forall s b. Int -> b -> Step s b
Done Int
cnt) (s -> m c
ffinal s
fs)
Done Int
n b
b -> do
assertM(Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
cnt)
Step s c
fs1 <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fs1 of
FL.Partial s
s1 -> (c -> Step (Fused3 s b s) c) -> m c -> m (Step (Fused3 s b s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b s) c
forall s b. Int -> b -> Step s b
Done Int
n) (s -> m c
ffinal s
s1)
FL.Done c
b1 -> Step (Fused3 s b s) c -> m (Step (Fused3 s b s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step (Fused3 s b s) c
forall s b. Int -> b -> Step s b
Done Int
n c
b1)
Partial Int
_ s
_ -> String -> m (Step (Fused3 s b s) c)
forall a. (?callStack::CallStack) => String -> a
error String
"splitMany: Partial in extract"
Continue Int
n s
s1 -> do
assertM(Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
cnt)
Step (Fused3 s b s) c -> m (Step (Fused3 s b s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Fused3 s b s -> Step (Fused3 s b s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> b -> s -> Fused3 s b s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s1 b
0 s
fs))
{-# INLINE splitManyPost #-}
splitManyPost :: Monad m => Parser a m b -> Fold m b c -> Parser a m c
splitManyPost :: forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
splitManyPost (Parser s -> a -> m (Step s b)
step1 m (Initial s b)
initial1 s -> m (Step s b)
extract1) (Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
_ s -> m c
ffinal) =
(Fused3 s Int s -> a -> m (Step (Fused3 s Int s) c))
-> m (Initial (Fused3 s Int s) c)
-> (Fused3 s Int s -> m (Step (Fused3 s Int s) c))
-> Parser a m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser Fused3 s Int s -> a -> m (Step (Fused3 s Int s) c)
step m (Initial (Fused3 s Int s) c)
initial Fused3 s Int s -> m (Step (Fused3 s Int s) c)
forall {b}. Num b => Fused3 s Int s -> m (Step (Fused3 s b s) c)
extract
where
handleCollect :: (Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s b s -> b
partial c -> b
done Step s c
fres =
case Step s c
fres of
FL.Partial s
fs -> do
Initial s b
pres <- m (Initial s b)
initial1
case Initial s b
pres of
IPartial s
ps -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$ Fused3 s b s -> b
partial (Fused3 s b s -> b) -> Fused3 s b s -> b
forall a b. (a -> b) -> a -> b
$ s -> b -> s -> Fused3 s b s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
ps b
0 s
fs
IDone b
pb ->
(Step s c -> m b) -> s -> b -> m b
forall {b}. (Step s c -> m b) -> s -> b -> m b
runCollectorWith ((Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s b s -> b
partial c -> b
done) s
fs b
pb
IError String
_ -> c -> b
done (c -> b) -> m c -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
ffinal s
fs
FL.Done c
fb -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$ c -> b
done c
fb
runCollectorWith :: (Step s c -> m b) -> s -> b -> m b
runCollectorWith Step s c -> m b
cont s
fs b
pb = s -> b -> m (Step s c)
fstep s
fs b
pb m (Step s c) -> (Step s c -> m b) -> m b
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Step s c -> m b
cont
initial :: m (Initial (Fused3 s Int s) c)
initial = m (Step s c)
finitial m (Step s c)
-> (Step s c -> m (Initial (Fused3 s Int s) c))
-> m (Initial (Fused3 s Int s) c)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Fused3 s Int s -> Initial (Fused3 s Int s) c)
-> (c -> Initial (Fused3 s Int s) c)
-> Step s c
-> m (Initial (Fused3 s Int s) c)
forall {b} {b}.
Num b =>
(Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s Int s -> Initial (Fused3 s Int s) c
forall s b. s -> Initial s b
IPartial c -> Initial (Fused3 s Int s) c
forall s b. b -> Initial s b
IDone
{-# INLINE step #-}
step :: Fused3 s Int s -> a -> m (Step (Fused3 s Int s) c)
step (Fused3 s
st Int
cnt s
fs) a
a = do
Step s b
r <- s -> a -> m (Step s b)
step1 s
st a
a
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
case Step s b
r of
Partial Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c))
-> Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a b. (a -> b) -> a -> b
$ Int -> Fused3 s Int s -> Step (Fused3 s Int s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> Int -> s -> Fused3 s Int s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs)
Continue Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c))
-> Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a b. (a -> b) -> a -> b
$ Int -> Fused3 s Int s -> Step (Fused3 s Int s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> Int -> s -> Fused3 s Int s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs)
Done Int
n b
b -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
s -> b -> m (Step s c)
fstep s
fs b
b m (Step s c)
-> (Step s c -> m (Step (Fused3 s Int s) c))
-> m (Step (Fused3 s Int s) c)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Fused3 s Int s -> Step (Fused3 s Int s) c)
-> (c -> Step (Fused3 s Int s) c)
-> Step s c
-> m (Step (Fused3 s Int s) c)
forall {b} {b}.
Num b =>
(Fused3 s b s -> b) -> (c -> b) -> Step s c -> m b
handleCollect (Int -> Fused3 s Int s -> Step (Fused3 s Int s) c
forall s b. Int -> s -> Step s b
Partial Int
n) (Int -> c -> Step (Fused3 s Int s) c
forall s b. Int -> b -> Step s b
Done Int
n)
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c))
-> Step (Fused3 s Int s) c -> m (Step (Fused3 s Int s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (Fused3 s Int s) c
forall s b. Int -> b -> Step s b
Done Int
cnt1 c
xs
extract :: Fused3 s Int s -> m (Step (Fused3 s b s) c)
extract (Fused3 s
s Int
cnt s
fs) = do
Step s b
r <- s -> m (Step s b)
extract1 s
s
case Step s b
r of
Error String
_ -> (c -> Step (Fused3 s b s) c) -> m c -> m (Step (Fused3 s b s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b s) c
forall s b. Int -> b -> Step s b
Done Int
cnt) (s -> m c
ffinal s
fs)
Done Int
n b
b -> do
assertM(Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
cnt)
Step s c
fs1 <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fs1 of
FL.Partial s
s1 -> (c -> Step (Fused3 s b s) c) -> m c -> m (Step (Fused3 s b s) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b s) c
forall s b. Int -> b -> Step s b
Done Int
n) (s -> m c
ffinal s
s1)
FL.Done c
b1 -> Step (Fused3 s b s) c -> m (Step (Fused3 s b s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step (Fused3 s b s) c
forall s b. Int -> b -> Step s b
Done Int
n c
b1)
Partial Int
_ s
_ -> String -> m (Step (Fused3 s b s) c)
forall a. (?callStack::CallStack) => String -> a
error String
"splitMany: Partial in extract"
Continue Int
n s
s1 -> do
assertM(Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
cnt)
Step (Fused3 s b s) c -> m (Step (Fused3 s b s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Fused3 s b s -> Step (Fused3 s b s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> b -> s -> Fused3 s b s
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s1 b
0 s
fs))
{-# INLINE splitSome #-}
splitSome :: Monad m => Parser a m b -> Fold m b c -> Parser a m c
splitSome :: forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
splitSome (Parser s -> a -> m (Step s b)
step1 m (Initial s b)
initial1 s -> m (Step s b)
extract1) (Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
_ s -> m c
ffinal) =
(Fused3 s Int (Either s s)
-> a -> m (Step (Fused3 s Int (Either s s)) c))
-> m (Initial (Fused3 s Int (Either s s)) c)
-> (Fused3 s Int (Either s s)
-> m (Step (Fused3 s Int (Either s s)) c))
-> Parser a m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser Fused3 s Int (Either s s)
-> a -> m (Step (Fused3 s Int (Either s s)) c)
step m (Initial (Fused3 s Int (Either s s)) c)
initial Fused3 s Int (Either s s) -> m (Step (Fused3 s Int (Either s s)) c)
forall {b}.
Num b =>
Fused3 s Int (Either s s) -> m (Step (Fused3 s b (Either s s)) c)
extract
where
handleCollect :: (Fused3 s b (Either a s) -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s b (Either a s) -> b
partial c -> b
done Step s c
fres =
case Step s c
fres of
FL.Partial s
fs -> do
Initial s b
pres <- m (Initial s b)
initial1
case Initial s b
pres of
IPartial s
ps -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$ Fused3 s b (Either a s) -> b
partial (Fused3 s b (Either a s) -> b) -> Fused3 s b (Either a s) -> b
forall a b. (a -> b) -> a -> b
$ s -> b -> Either a s -> Fused3 s b (Either a s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
ps b
0 (Either a s -> Fused3 s b (Either a s))
-> Either a s -> Fused3 s b (Either a s)
forall a b. (a -> b) -> a -> b
$ s -> Either a s
forall a b. b -> Either a b
Right s
fs
IDone b
pb ->
(Step s c -> m b) -> s -> b -> m b
forall {b}. (Step s c -> m b) -> s -> b -> m b
runCollectorWith ((Fused3 s b (Either a s) -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s b (Either a s) -> b
partial c -> b
done) s
fs b
pb
IError String
_ -> c -> b
done (c -> b) -> m c -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
ffinal s
fs
FL.Done c
fb -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$ c -> b
done c
fb
runCollectorWith :: (Step s c -> m b) -> s -> b -> m b
runCollectorWith Step s c -> m b
cont s
fs b
pb = s -> b -> m (Step s c)
fstep s
fs b
pb m (Step s c) -> (Step s c -> m b) -> m b
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Step s c -> m b
cont
initial :: m (Initial (Fused3 s Int (Either s s)) c)
initial = do
Step s c
fres <- m (Step s c)
finitial
case Step s c
fres of
FL.Partial s
fs -> do
Initial s b
pres <- m (Initial s b)
initial1
case Initial s b
pres of
IPartial s
ps -> Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c))
-> Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ Fused3 s Int (Either s s) -> Initial (Fused3 s Int (Either s s)) c
forall s b. s -> Initial s b
IPartial (Fused3 s Int (Either s s)
-> Initial (Fused3 s Int (Either s s)) c)
-> Fused3 s Int (Either s s)
-> Initial (Fused3 s Int (Either s s)) c
forall a b. (a -> b) -> a -> b
$ s -> Int -> Either s s -> Fused3 s Int (Either s s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
ps Int
0 (Either s s -> Fused3 s Int (Either s s))
-> Either s s -> Fused3 s Int (Either s s)
forall a b. (a -> b) -> a -> b
$ s -> Either s s
forall a b. a -> Either a b
Left s
fs
IDone b
pb ->
(Step s c -> m (Initial (Fused3 s Int (Either s s)) c))
-> s -> b -> m (Initial (Fused3 s Int (Either s s)) c)
forall {b}. (Step s c -> m b) -> s -> b -> m b
runCollectorWith ((Fused3 s Int (Either s s)
-> Initial (Fused3 s Int (Either s s)) c)
-> (c -> Initial (Fused3 s Int (Either s s)) c)
-> Step s c
-> m (Initial (Fused3 s Int (Either s s)) c)
forall {b} {a} {b}.
Num b =>
(Fused3 s b (Either a s) -> b) -> (c -> b) -> Step s c -> m b
handleCollect Fused3 s Int (Either s s) -> Initial (Fused3 s Int (Either s s)) c
forall s b. s -> Initial s b
IPartial c -> Initial (Fused3 s Int (Either s s)) c
forall s b. b -> Initial s b
IDone) s
fs b
pb
IError String
err -> Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c))
-> Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ String -> Initial (Fused3 s Int (Either s s)) c
forall s b. String -> Initial s b
IError String
err
FL.Done c
_ ->
Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c))
-> Initial (Fused3 s Int (Either s s)) c
-> m (Initial (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ String -> Initial (Fused3 s Int (Either s s)) c
forall s b. String -> Initial s b
IError
(String -> Initial (Fused3 s Int (Either s s)) c)
-> String -> Initial (Fused3 s Int (Either s s)) c
forall a b. (a -> b) -> a -> b
$ String
"splitSome: The collecting fold terminated without"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" consuming any elements."
{-# INLINE step #-}
step :: Fused3 s Int (Either s s)
-> a -> m (Step (Fused3 s Int (Either s s)) c)
step (Fused3 s
st Int
cnt (Left s
fs)) a
a = do
Step s b
r <- s -> a -> m (Step s b)
step1 s
st a
a
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
case Step s b
r of
Partial Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c))
-> Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ Int
-> Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> Int -> Either s s -> Fused3 s Int (Either s s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (s -> Either s s
forall a b. a -> Either a b
Left s
fs))
Continue Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c))
-> Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ Int
-> Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> Int -> Either s s -> Fused3 s Int (Either s s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (s -> Either s s
forall a b. a -> Either a b
Left s
fs))
Done Int
n b
b -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
s -> b -> m (Step s c)
fstep s
fs b
b m (Step s c)
-> (Step s c -> m (Step (Fused3 s Int (Either s s)) c))
-> m (Step (Fused3 s Int (Either s s)) c)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c)
-> (c -> Step (Fused3 s Int (Either s s)) c)
-> Step s c
-> m (Step (Fused3 s Int (Either s s)) c)
forall {b} {a} {b}.
Num b =>
(Fused3 s b (Either a s) -> b) -> (c -> b) -> Step s c -> m b
handleCollect (Int
-> Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> s -> Step s b
Partial Int
n) (Int -> c -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
n)
Error String
err -> Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c))
-> Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (Fused3 s Int (Either s s)) c
forall s b. String -> Step s b
Error String
err
step (Fused3 s
st Int
cnt (Right s
fs)) a
a = do
Step s b
r <- s -> a -> m (Step s b)
step1 s
st a
a
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
case Step s b
r of
Partial Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c))
-> Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ Int
-> Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> s -> Step s b
Partial Int
n (s -> Int -> Either s s -> Fused3 s Int (Either s s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (s -> Either s s
forall a b. b -> Either a b
Right s
fs))
Continue Int
n s
s -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c))
-> Step (Fused3 s Int (Either s s)) c
-> m (Step (Fused3 s Int (Either s s)) c)
forall a b. (a -> b) -> a -> b
$ Int
-> Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> Int -> Either s s -> Fused3 s Int (Either s s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) (s -> Either s s
forall a b. b -> Either a b
Right s
fs))
Done Int
n b
b -> do
assertM(Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
s -> b -> m (Step s c)
fstep s
fs b
b m (Step s c)
-> (Step s c -> m (Step (Fused3 s Int (Either s s)) c))
-> m (Step (Fused3 s Int (Either s s)) c)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c)
-> (c -> Step (Fused3 s Int (Either s s)) c)
-> Step s c
-> m (Step (Fused3 s Int (Either s s)) c)
forall {b} {a} {b}.
Num b =>
(Fused3 s b (Either a s) -> b) -> (c -> b) -> Step s c -> m b
handleCollect (Int
-> Fused3 s Int (Either s s) -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> s -> Step s b
Partial Int
n) (Int -> c -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
n)
Error String
_ -> Int -> c -> Step (Fused3 s Int (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
cnt1 (c -> Step (Fused3 s Int (Either s s)) c)
-> m c -> m (Step (Fused3 s Int (Either s s)) c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
ffinal s
fs
extract :: Fused3 s Int (Either s s) -> m (Step (Fused3 s b (Either s s)) c)
extract (Fused3 s
s Int
cnt (Left s
fs)) = do
Step s b
r <- s -> m (Step s b)
extract1 s
s
case Step s b
r of
Error String
err -> Step (Fused3 s b (Either s s)) c
-> m (Step (Fused3 s b (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Step (Fused3 s b (Either s s)) c
forall s b. String -> Step s b
Error String
err)
Done Int
n b
b -> do
assertM(Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
cnt)
Step s c
fs1 <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fs1 of
FL.Partial s
s1 -> (c -> Step (Fused3 s b (Either s s)) c)
-> m c -> m (Step (Fused3 s b (Either s s)) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
n) (s -> m c
ffinal s
s1)
FL.Done c
b1 -> Step (Fused3 s b (Either s s)) c
-> m (Step (Fused3 s b (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step (Fused3 s b (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
n c
b1)
Partial Int
_ s
_ -> String -> m (Step (Fused3 s b (Either s s)) c)
forall a. (?callStack::CallStack) => String -> a
error String
"splitSome: Partial in extract"
Continue Int
n s
s1 -> do
assertM(Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
cnt)
Step (Fused3 s b (Either s s)) c
-> m (Step (Fused3 s b (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Fused3 s b (Either s s) -> Step (Fused3 s b (Either s s)) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> b -> Either s s -> Fused3 s b (Either s s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s1 b
0 (s -> Either s s
forall a b. a -> Either a b
Left s
fs)))
extract (Fused3 s
s Int
cnt (Right s
fs)) = do
Step s b
r <- s -> m (Step s b)
extract1 s
s
case Step s b
r of
Error String
_ -> (c -> Step (Fused3 s b (Either s s)) c)
-> m c -> m (Step (Fused3 s b (Either s s)) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
cnt) (s -> m c
ffinal s
fs)
Done Int
n b
b -> do
assertM(Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
cnt)
Step s c
fs1 <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fs1 of
FL.Partial s
s1 -> (c -> Step (Fused3 s b (Either s s)) c)
-> m c -> m (Step (Fused3 s b (Either s s)) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> c -> Step (Fused3 s b (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
n) (s -> m c
ffinal s
s1)
FL.Done c
b1 -> Step (Fused3 s b (Either s s)) c
-> m (Step (Fused3 s b (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step (Fused3 s b (Either s s)) c
forall s b. Int -> b -> Step s b
Done Int
n c
b1)
Partial Int
_ s
_ -> String -> m (Step (Fused3 s b (Either s s)) c)
forall a. (?callStack::CallStack) => String -> a
error String
"splitSome: Partial in extract"
Continue Int
n s
s1 -> do
assertM(Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
cnt)
Step (Fused3 s b (Either s s)) c
-> m (Step (Fused3 s b (Either s s)) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Fused3 s b (Either s s) -> Step (Fused3 s b (Either s s)) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> b -> Either s s -> Fused3 s b (Either s s)
forall a b c. a -> b -> c -> Fused3 a b c
Fused3 s
s1 b
0 (s -> Either s s
forall a b. b -> Either a b
Right s
fs)))
{-# INLINE_NORMAL die #-}
die :: Monad m => String -> Parser a m b
die :: forall (m :: * -> *) a b. Monad m => String -> Parser a m b
die String
err = (Any -> a -> m (Step Any b))
-> m (Initial Any b) -> (Any -> m (Step Any b)) -> Parser a m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser Any -> a -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined (Initial Any b -> m (Initial Any b)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> Initial Any b
forall s b. String -> Initial s b
IError String
err)) Any -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined
{-# INLINE dieM #-}
dieM :: Monad m => m String -> Parser a m b
dieM :: forall (m :: * -> *) a b. Monad m => m String -> Parser a m b
dieM m String
err = (Any -> a -> m (Step Any b))
-> m (Initial Any b) -> (Any -> m (Step Any b)) -> Parser a m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser Any -> a -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined (String -> Initial Any b
forall s b. String -> Initial s b
IError (String -> Initial Any b) -> m String -> m (Initial Any b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String
err) Any -> m (Step Any b)
forall a. (?callStack::CallStack) => a
undefined
instance Monad m => Alternative (Parser a m) where
{-# INLINE empty #-}
empty :: forall a. Parser a m a
empty = String -> Parser a m a
forall (m :: * -> *) a b. Monad m => String -> Parser a m b
die String
"empty"
{-# INLINE (<|>) #-}
<|> :: forall a. Parser a m a -> Parser a m a -> Parser a m a
(<|>) = Parser a m a -> Parser a m a -> Parser a m a
forall (m :: * -> *) x a.
Monad m =>
Parser x m a -> Parser x m a -> Parser x m a
alt
{-# INLINE many #-}
many :: forall a. Parser a m a -> Parser a m [a]
many = (Parser a m a -> Fold m a [a] -> Parser a m [a])
-> Fold m a [a] -> Parser a m a -> Parser a m [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip Parser a m a -> Fold m a [a] -> Parser a m [a]
forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
splitMany Fold m a [a]
forall (m :: * -> *) a. Monad m => Fold m a [a]
toList
{-# INLINE some #-}
some :: forall a. Parser a m a -> Parser a m [a]
some = (Parser a m a -> Fold m a [a] -> Parser a m [a])
-> Fold m a [a] -> Parser a m a -> Parser a m [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip Parser a m a -> Fold m a [a] -> Parser a m [a]
forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
splitSome Fold m a [a]
forall (m :: * -> *) a. Monad m => Fold m a [a]
toList
{-# ANN type ConcatParseState Fuse #-}
data ConcatParseState sl m a b =
ConcatParseL !sl
| forall s. ConcatParseR (s -> a -> m (Step s b)) s (s -> m (Step s b))
{-# INLINE concatMap #-}
concatMap :: Monad m =>
(b -> Parser a m c) -> Parser a m b -> Parser a m c
concatMap :: forall (m :: * -> *) b a c.
Monad m =>
(b -> Parser a m c) -> Parser a m b -> Parser a m c
concatMap b -> Parser a m c
func (Parser s -> a -> m (Step s b)
stepL m (Initial s b)
initialL s -> m (Step s b)
extractL) = (ConcatParseState s m a c
-> a -> m (Step (ConcatParseState s m a c) c))
-> m (Initial (ConcatParseState s m a c) c)
-> (ConcatParseState s m a c
-> m (Step (ConcatParseState s m a c) c))
-> Parser a m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser ConcatParseState s m a c
-> a -> m (Step (ConcatParseState s m a c) c)
step m (Initial (ConcatParseState s m a c) c)
initial ConcatParseState s m a c -> m (Step (ConcatParseState s m a c) c)
extract
where
{-# INLINE initializeR #-}
initializeR :: Parser a m b -> m (Initial (ConcatParseState sl m a b) b)
initializeR (Parser s -> a -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) = do
Initial s b
resR <- m (Initial s b)
initialR
Initial (ConcatParseState sl m a b) b
-> m (Initial (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (ConcatParseState sl m a b) b
-> m (Initial (ConcatParseState sl m a b) b))
-> Initial (ConcatParseState sl m a b) b
-> m (Initial (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> a -> b
$ case Initial s b
resR of
IPartial s
sr -> ConcatParseState sl m a b -> Initial (ConcatParseState sl m a b) b
forall s b. s -> Initial s b
IPartial (ConcatParseState sl m a b
-> Initial (ConcatParseState sl m a b) b)
-> ConcatParseState sl m a b
-> Initial (ConcatParseState sl m a b) b
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s b)
stepR s
sr s -> m (Step s b)
extractR
IDone b
br -> b -> Initial (ConcatParseState sl m a b) b
forall s b. b -> Initial s b
IDone b
br
IError String
err -> String -> Initial (ConcatParseState sl m a b) b
forall s b. String -> Initial s b
IError String
err
initial :: m (Initial (ConcatParseState s m a c) c)
initial = do
Initial s b
res <- m (Initial s b)
initialL
case Initial s b
res of
IPartial s
s -> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c))
-> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ ConcatParseState s m a c -> Initial (ConcatParseState s m a c) c
forall s b. s -> Initial s b
IPartial (ConcatParseState s m a c -> Initial (ConcatParseState s m a c) c)
-> ConcatParseState s m a c -> Initial (ConcatParseState s m a c) c
forall a b. (a -> b) -> a -> b
$ s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s
IDone b
b -> Parser a m c -> m (Initial (ConcatParseState s m a c) c)
forall {m :: * -> *} {a} {b} {sl}.
Monad m =>
Parser a m b -> m (Initial (ConcatParseState sl m a b) b)
initializeR (b -> Parser a m c
func b
b)
IError String
err -> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c))
-> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ String -> Initial (ConcatParseState s m a c) c
forall s b. String -> Initial s b
IError String
err
{-# INLINE initializeRL #-}
initializeRL :: Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
initializeRL Int
n (Parser s -> a -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) = do
Initial s b
resR <- m (Initial s b)
initialR
Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b))
-> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> a -> b
$ case Initial s b
resR of
IPartial s
sr -> Int
-> ConcatParseState sl m a b -> Step (ConcatParseState sl m a b) b
forall s b. Int -> s -> Step s b
Continue Int
n (ConcatParseState sl m a b -> Step (ConcatParseState sl m a b) b)
-> ConcatParseState sl m a b -> Step (ConcatParseState sl m a b) b
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s b)
stepR s
sr s -> m (Step s b)
extractR
IDone b
br -> Int -> b -> Step (ConcatParseState sl m a b) b
forall s b. Int -> b -> Step s b
Done Int
n b
br
IError String
err -> String -> Step (ConcatParseState sl m a b) b
forall s b. String -> Step s b
Error String
err
step :: ConcatParseState s m a c
-> a -> m (Step (ConcatParseState s m a c) c)
step (ConcatParseL s
st) a
a = do
Step s b
r <- s -> a -> m (Step s b)
stepL s
st a
a
case Step s b
r of
Partial Int
n s
s -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s)
Continue Int
n s
s -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s)
Done Int
n b
b -> Int -> Parser a m c -> m (Step (ConcatParseState s m a c) c)
forall {m :: * -> *} {a} {b} {sl}.
Monad m =>
Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
initializeRL Int
n (b -> Parser a m c
func b
b)
Error String
err -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (ConcatParseState s m a c) c
forall s b. String -> Step s b
Error String
err
step (ConcatParseR s -> a -> m (Step s c)
stepR s
st s -> m (Step s c)
extractR) a
a = do
Step s c
r <- s -> a -> m (Step s c)
stepR s
st a
a
Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ case Step s c
r of
Partial Int
n s
s -> Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Partial Int
n (ConcatParseState s m a c -> Step (ConcatParseState s m a c) c)
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s c))
-> s -> (s -> m (Step s c)) -> ConcatParseState s m a c
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s c)
stepR s
s s -> m (Step s c)
extractR
Continue Int
n s
s -> Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Continue Int
n (ConcatParseState s m a c -> Step (ConcatParseState s m a c) c)
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s c))
-> s -> (s -> m (Step s c)) -> ConcatParseState s m a c
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s c)
stepR s
s s -> m (Step s c)
extractR
Done Int
n c
b -> Int -> c -> Step (ConcatParseState s m a c) c
forall s b. Int -> b -> Step s b
Done Int
n c
b
Error String
err -> String -> Step (ConcatParseState s m a c) c
forall s b. String -> Step s b
Error String
err
{-# INLINE extractP #-}
extractP :: Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
extractP Int
n (Parser s -> a -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) = do
Initial s b
res <- m (Initial s b)
initialR
case Initial s b
res of
IPartial s
s ->
(Step s b -> Step (ConcatParseState sl m a b) b)
-> m (Step s b) -> m (Step (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
((s -> ConcatParseState sl m a b)
-> Step s b -> Step (ConcatParseState sl m a b) b
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (\s
s1 -> (s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s b)
stepR s
s1 s -> m (Step s b)
extractR))
(s -> m (Step s b)
extractR s
s)
IDone b
b -> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> b -> Step (ConcatParseState sl m a b) b
forall s b. Int -> b -> Step s b
Done Int
n b
b)
IError String
err -> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b))
-> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (ConcatParseState sl m a b) b
forall s b. String -> Step s b
Error String
err
extract :: ConcatParseState s m a c -> m (Step (ConcatParseState s m a c) c)
extract (ConcatParseR s -> a -> m (Step s c)
stepR s
s s -> m (Step s c)
extractR) =
(Step s c -> Step (ConcatParseState s m a c) c)
-> m (Step s c) -> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> ConcatParseState s m a c)
-> Step s c -> Step (ConcatParseState s m a c) c
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (\s
s1 -> (s -> a -> m (Step s c))
-> s -> (s -> m (Step s c)) -> ConcatParseState s m a c
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s c)
stepR s
s1 s -> m (Step s c)
extractR)) (s -> m (Step s c)
extractR s
s)
extract (ConcatParseL s
sL) = do
Step s b
rL <- s -> m (Step s b)
extractL s
sL
case Step s b
rL of
Error String
err -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (ConcatParseState s m a c) c
forall s b. String -> Step s b
Error String
err
Done Int
n b
b -> Int -> Parser a m c -> m (Step (ConcatParseState s m a c) c)
forall {m :: * -> *} {a} {b} {sl}.
Monad m =>
Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
extractP Int
n (Parser a m c -> m (Step (ConcatParseState s m a c) c))
-> Parser a m c -> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ b -> Parser a m c
func b
b
Partial Int
_ s
_ -> String -> m (Step (ConcatParseState s m a c) c)
forall a. (?callStack::CallStack) => String -> a
error String
"concatMap: extract Partial"
Continue Int
n s
s -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s)
{-# INLINE noErrorUnsafeConcatMap #-}
noErrorUnsafeConcatMap :: Monad m =>
(b -> Parser a m c) -> Parser a m b -> Parser a m c
noErrorUnsafeConcatMap :: forall (m :: * -> *) b a c.
Monad m =>
(b -> Parser a m c) -> Parser a m b -> Parser a m c
noErrorUnsafeConcatMap b -> Parser a m c
func (Parser s -> a -> m (Step s b)
stepL m (Initial s b)
initialL s -> m (Step s b)
extractL) =
(ConcatParseState s m a c
-> a -> m (Step (ConcatParseState s m a c) c))
-> m (Initial (ConcatParseState s m a c) c)
-> (ConcatParseState s m a c
-> m (Step (ConcatParseState s m a c) c))
-> Parser a m c
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser ConcatParseState s m a c
-> a -> m (Step (ConcatParseState s m a c) c)
step m (Initial (ConcatParseState s m a c) c)
initial ConcatParseState s m a c -> m (Step (ConcatParseState s m a c) c)
extract
where
{-# INLINE initializeR #-}
initializeR :: Parser a m b -> m (Initial (ConcatParseState sl m a b) b)
initializeR (Parser s -> a -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) = do
Initial s b
resR <- m (Initial s b)
initialR
Initial (ConcatParseState sl m a b) b
-> m (Initial (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (ConcatParseState sl m a b) b
-> m (Initial (ConcatParseState sl m a b) b))
-> Initial (ConcatParseState sl m a b) b
-> m (Initial (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> a -> b
$ case Initial s b
resR of
IPartial s
sr -> ConcatParseState sl m a b -> Initial (ConcatParseState sl m a b) b
forall s b. s -> Initial s b
IPartial (ConcatParseState sl m a b
-> Initial (ConcatParseState sl m a b) b)
-> ConcatParseState sl m a b
-> Initial (ConcatParseState sl m a b) b
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s b)
stepR s
sr s -> m (Step s b)
extractR
IDone b
br -> b -> Initial (ConcatParseState sl m a b) b
forall s b. b -> Initial s b
IDone b
br
IError String
err -> String -> Initial (ConcatParseState sl m a b) b
forall s b. String -> Initial s b
IError String
err
initial :: m (Initial (ConcatParseState s m a c) c)
initial = do
Initial s b
res <- m (Initial s b)
initialL
case Initial s b
res of
IPartial s
s -> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c))
-> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ ConcatParseState s m a c -> Initial (ConcatParseState s m a c) c
forall s b. s -> Initial s b
IPartial (ConcatParseState s m a c -> Initial (ConcatParseState s m a c) c)
-> ConcatParseState s m a c -> Initial (ConcatParseState s m a c) c
forall a b. (a -> b) -> a -> b
$ s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s
IDone b
b -> Parser a m c -> m (Initial (ConcatParseState s m a c) c)
forall {m :: * -> *} {a} {b} {sl}.
Monad m =>
Parser a m b -> m (Initial (ConcatParseState sl m a b) b)
initializeR (b -> Parser a m c
func b
b)
IError String
err -> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c))
-> Initial (ConcatParseState s m a c) c
-> m (Initial (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ String -> Initial (ConcatParseState s m a c) c
forall s b. String -> Initial s b
IError String
err
{-# INLINE initializeRL #-}
initializeRL :: Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
initializeRL Int
n (Parser s -> a -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) = do
Initial s b
resR <- m (Initial s b)
initialR
Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b))
-> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> a -> b
$ case Initial s b
resR of
IPartial s
sr -> Int
-> ConcatParseState sl m a b -> Step (ConcatParseState sl m a b) b
forall s b. Int -> s -> Step s b
Partial Int
n (ConcatParseState sl m a b -> Step (ConcatParseState sl m a b) b)
-> ConcatParseState sl m a b -> Step (ConcatParseState sl m a b) b
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s b)
stepR s
sr s -> m (Step s b)
extractR
IDone b
br -> Int -> b -> Step (ConcatParseState sl m a b) b
forall s b. Int -> b -> Step s b
Done Int
n b
br
IError String
err -> String -> Step (ConcatParseState sl m a b) b
forall s b. String -> Step s b
Error String
err
step :: ConcatParseState s m a c
-> a -> m (Step (ConcatParseState s m a c) c)
step (ConcatParseL s
st) a
a = do
Step s b
r <- s -> a -> m (Step s b)
stepL s
st a
a
case Step s b
r of
Partial Int
n s
s -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Partial Int
n (s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s)
Continue Int
n s
s -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s)
Done Int
n b
b -> Int -> Parser a m c -> m (Step (ConcatParseState s m a c) c)
forall {m :: * -> *} {a} {b} {sl}.
Monad m =>
Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
initializeRL Int
n (b -> Parser a m c
func b
b)
Error String
err -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (ConcatParseState s m a c) c
forall s b. String -> Step s b
Error String
err
step (ConcatParseR s -> a -> m (Step s c)
stepR s
st s -> m (Step s c)
extractR) a
a = do
Step s c
r <- s -> a -> m (Step s c)
stepR s
st a
a
Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ case Step s c
r of
Partial Int
n s
s -> Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Partial Int
n (ConcatParseState s m a c -> Step (ConcatParseState s m a c) c)
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s c))
-> s -> (s -> m (Step s c)) -> ConcatParseState s m a c
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s c)
stepR s
s s -> m (Step s c)
extractR
Continue Int
n s
s -> Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Continue Int
n (ConcatParseState s m a c -> Step (ConcatParseState s m a c) c)
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall a b. (a -> b) -> a -> b
$ (s -> a -> m (Step s c))
-> s -> (s -> m (Step s c)) -> ConcatParseState s m a c
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s c)
stepR s
s s -> m (Step s c)
extractR
Done Int
n c
b -> Int -> c -> Step (ConcatParseState s m a c) c
forall s b. Int -> b -> Step s b
Done Int
n c
b
Error String
err -> String -> Step (ConcatParseState s m a c) c
forall s b. String -> Step s b
Error String
err
{-# INLINE extractP #-}
extractP :: Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
extractP Int
n (Parser s -> a -> m (Step s b)
stepR m (Initial s b)
initialR s -> m (Step s b)
extractR) = do
Initial s b
res <- m (Initial s b)
initialR
case Initial s b
res of
IPartial s
s ->
(Step s b -> Step (ConcatParseState sl m a b) b)
-> m (Step s b) -> m (Step (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
((s -> ConcatParseState sl m a b)
-> Step s b -> Step (ConcatParseState sl m a b) b
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (\s
s1 -> (s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s b)
stepR s
s1 s -> m (Step s b)
extractR))
(s -> m (Step s b)
extractR s
s)
IDone b
b -> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> b -> Step (ConcatParseState sl m a b) b
forall s b. Int -> b -> Step s b
Done Int
n b
b)
IError String
err -> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b))
-> Step (ConcatParseState sl m a b) b
-> m (Step (ConcatParseState sl m a b) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (ConcatParseState sl m a b) b
forall s b. String -> Step s b
Error String
err
extract :: ConcatParseState s m a c -> m (Step (ConcatParseState s m a c) c)
extract (ConcatParseR s -> a -> m (Step s c)
stepR s
s s -> m (Step s c)
extractR) =
(Step s c -> Step (ConcatParseState s m a c) c)
-> m (Step s c) -> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((s -> ConcatParseState s m a c)
-> Step s c -> Step (ConcatParseState s m a c) c
forall a b c. (a -> b) -> Step a c -> Step b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (\s
s1 -> (s -> a -> m (Step s c))
-> s -> (s -> m (Step s c)) -> ConcatParseState s m a c
forall sl (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> s -> (s -> m (Step s b)) -> ConcatParseState sl m a b
ConcatParseR s -> a -> m (Step s c)
stepR s
s1 s -> m (Step s c)
extractR)) (s -> m (Step s c)
extractR s
s)
extract (ConcatParseL s
sL) = do
Step s b
rL <- s -> m (Step s b)
extractL s
sL
case Step s b
rL of
Error String
err -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (ConcatParseState s m a c) c
forall s b. String -> Step s b
Error String
err
Done Int
n b
b -> Int -> Parser a m c -> m (Step (ConcatParseState s m a c) c)
forall {m :: * -> *} {a} {b} {sl}.
Monad m =>
Int -> Parser a m b -> m (Step (ConcatParseState sl m a b) b)
extractP Int
n (Parser a m c -> m (Step (ConcatParseState s m a c) c))
-> Parser a m c -> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ b -> Parser a m c
func b
b
Partial Int
_ s
_ -> String -> m (Step (ConcatParseState s m a c) c)
forall a. (?callStack::CallStack) => String -> a
error String
"concatMap: extract Partial"
Continue Int
n s
s -> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c))
-> Step (ConcatParseState s m a c) c
-> m (Step (ConcatParseState s m a c) c)
forall a b. (a -> b) -> a -> b
$ Int
-> ConcatParseState s m a c -> Step (ConcatParseState s m a c) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> ConcatParseState s m a c
forall sl (m :: * -> *) a b. sl -> ConcatParseState sl m a b
ConcatParseL s
s)
instance Monad m => Monad (Parser a m) where
{-# INLINE return #-}
return :: forall a. a -> Parser a m a
return = a -> Parser a m a
forall a. a -> Parser a m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE (>>=) #-}
>>= :: forall a b. Parser a m a -> (a -> Parser a m b) -> Parser a m b
(>>=) = ((a -> Parser a m b) -> Parser a m a -> Parser a m b)
-> Parser a m a -> (a -> Parser a m b) -> Parser a m b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> Parser a m b) -> Parser a m a -> Parser a m b
forall (m :: * -> *) b a c.
Monad m =>
(b -> Parser a m c) -> Parser a m b -> Parser a m c
concatMap
{-# INLINE (>>) #-}
>> :: forall a b. Parser a m a -> Parser a m b -> Parser a m b
(>>) = Parser a m a -> Parser a m b -> Parser a m b
forall a b. Parser a m a -> Parser a m b -> Parser a m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
(*>)
instance Monad m => Fail.MonadFail (Parser a m) where
{-# INLINE fail #-}
fail :: forall a. String -> Parser a m a
fail = String -> Parser a m a
forall (m :: * -> *) a b. Monad m => String -> Parser a m b
die
instance (MonadIO m) => MonadIO (Parser a m) where
{-# INLINE liftIO #-}
liftIO :: forall a. IO a -> Parser a m a
liftIO = m a -> Parser a m a
forall (m :: * -> *) b a. Monad m => m b -> Parser a m b
fromEffect (m a -> Parser a m a) -> (IO a -> m a) -> IO a -> Parser a m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
{-# INLINE lmap #-}
lmap :: (a -> b) -> Parser b m r -> Parser a m r
lmap :: forall a b (m :: * -> *) r.
(a -> b) -> Parser b m r -> Parser a m r
lmap a -> b
f (Parser s -> b -> m (Step s r)
step m (Initial s r)
begin s -> m (Step s r)
done) = (s -> a -> m (Step s r))
-> m (Initial s r) -> (s -> m (Step s r)) -> Parser a m r
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser s -> a -> m (Step s r)
step1 m (Initial s r)
begin s -> m (Step s r)
done
where
step1 :: s -> a -> m (Step s r)
step1 s
x a
a = s -> b -> m (Step s r)
step s
x (a -> b
f a
a)
{-# INLINE lmapM #-}
lmapM :: Monad m => (a -> m b) -> Parser b m r -> Parser a m r
lmapM :: forall (m :: * -> *) a b r.
Monad m =>
(a -> m b) -> Parser b m r -> Parser a m r
lmapM a -> m b
f (Parser s -> b -> m (Step s r)
step m (Initial s r)
begin s -> m (Step s r)
done) = (s -> a -> m (Step s r))
-> m (Initial s r) -> (s -> m (Step s r)) -> Parser a m r
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser s -> a -> m (Step s r)
step1 m (Initial s r)
begin s -> m (Step s r)
done
where
step1 :: s -> a -> m (Step s r)
step1 s
x a
a = a -> m b
f a
a m b -> (b -> m (Step s r)) -> m (Step s r)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= s -> b -> m (Step s r)
step s
x
{-# INLINE filter #-}
filter :: Monad m => (a -> Bool) -> Parser a m b -> Parser a m b
filter :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Parser a m b -> Parser a m b
filter a -> Bool
f (Parser s -> a -> m (Step s b)
step m (Initial s b)
initial s -> m (Step s b)
extract) = (s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
forall a (m :: * -> *) b s.
(s -> a -> m (Step s b))
-> m (Initial s b) -> (s -> m (Step s b)) -> Parser a m b
Parser s -> a -> m (Step s b)
step1 m (Initial s b)
initial s -> m (Step s b)
extract
where
step1 :: s -> a -> m (Step s b)
step1 s
x a
a = if a -> Bool
f a
a then s -> a -> m (Step s b)
step s
x a
a else Step s b -> m (Step s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ Int -> s -> Step s b
forall s b. Int -> s -> Step s b
Partial Int
0 s
x