{-# LANGUAGE CPP #-}
module Streamly.Internal.Data.Parser
(
module Streamly.Internal.Data.Parser.Type
, Parser (..)
, ParseError (..)
, Step (..)
, Initial (..)
, toFold
, fromFold
, fromFoldMaybe
, postscan
, peek
, one
, oneEq
, oneNotEq
, oneOf
, noneOf
, eof
, satisfy
, maybe
, either
, lookAhead
, takeBetween
, takeEQ
, takeGE
, takeP
, listEq
, listEqBy
, streamEqBy
, subsequenceBy
, takeWhile
, takeWhileP
, takeWhile1
, dropWhile
, takeEndBy
, takeEndBy_
, takeEndByEsc
, takeStartBy
, takeStartBy_
, takeEitherSepBy
, wordBy
, groupBy
, groupByRolling
, groupByRollingEither
, wordFramedBy
, wordWithQuotes
, wordKeepQuotes
, wordProcessQuotes
, takeFramedBy_
, takeFramedByEsc_
, takeFramedByGeneric
, blockWithQuotes
, span
, spanBy
, spanByRolling
, sequence
, count
, countBetween
, manyP
, many
, some
, deintercalate
, deintercalate1
, deintercalateAll
, sepBy1
, sepBy
, sepByAll
, manyTillP
, manyTill
, manyThen
, roundRobin
, retryMaxTotal
, retryMaxSuccessive
, retry
, zipWithM
, zip
, indexed
, makeIndexFilter
, sampleFromthen
, next
)
where
#include "inline.hs"
#include "assert.hs"
import Control.Monad (when)
import Data.Bifunctor (first)
import Fusion.Plugin.Types (Fuse(..))
import Streamly.Internal.Data.Fold.Type (Fold(..))
import Streamly.Internal.Data.SVar.Type (defState)
import Streamly.Internal.Data.Either.Strict (Either'(..))
import Streamly.Internal.Data.Maybe.Strict (Maybe'(..))
import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
import Streamly.Internal.Data.Stream.Type (Stream)
import qualified Data.Foldable as Foldable
import qualified Streamly.Internal.Data.Fold.Type as FL
import qualified Streamly.Internal.Data.Stream.Type as D
import qualified Streamly.Internal.Data.Stream.Generate as D
import Streamly.Internal.Data.Parser.Type
import Prelude hiding
(any, all, take, takeWhile, sequence, concatMap, maybe, either, span
, zip, filter, dropWhile)
#include "DocTestDataParser.hs"
{-# INLINE toFold #-}
toFold :: Monad m => Parser a m b -> Fold m a b
toFold :: forall (m :: * -> *) a b. Monad m => Parser a m b -> Fold m a b
toFold (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinitial s -> m (Step s b)
pextract) = (s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> (s -> m b) -> Fold m a b
forall (m :: * -> *) a b s.
(s -> a -> m (Step s b))
-> m (Step s b) -> (s -> m b) -> (s -> m b) -> Fold m a b
Fold s -> a -> m (Step s b)
step m (Step s b)
initial s -> m b
forall {a}. a
extract s -> m b
final
where
initial :: m (Step s b)
initial = do
Initial s b
r <- m (Initial s b)
pinitial
case Initial s b
r of
IPartial s
s -> 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
$ s -> Step s b
forall s b. s -> Step s b
FL.Partial s
s
IDone b
b -> 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
$ b -> Step s b
forall s b. b -> Step s b
FL.Done b
b
IError String
err ->
String -> m (Step s b)
forall a. HasCallStack => String -> a
error (String -> m (Step s b)) -> String -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ String
"toFold: parser throws error in initial" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err
perror :: a -> a
perror a
n = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"toFold: parser backtracks in Partial: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n
cerror :: a -> a
cerror a
n = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"toFold: parser backtracks in Continue: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n
derror :: a -> a
derror a
n = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"toFold: parser backtracks in Done: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n
eerror :: String -> a
eerror String
err = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"toFold: parser throws error: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err
step :: s -> a -> m (Step s b)
step s
st a
a = do
Step s b
r <- s -> a -> m (Step s b)
pstep s
st a
a
case Step s b
r of
Partial Int
0 s
s -> 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
$ s -> Step s b
forall s b. s -> Step s b
FL.Partial s
s
Continue Int
0 s
s -> 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
$ s -> Step s b
forall s b. s -> Step s b
FL.Partial s
s
Done Int
0 b
b -> 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
$ b -> Step s b
forall s b. b -> Step s b
FL.Done b
b
Partial Int
n s
_ -> Int -> m (Step s b)
forall {a} {a}. Show a => a -> a
perror Int
n
Continue Int
n s
_ -> Int -> m (Step s b)
forall {a} {a}. Show a => a -> a
cerror Int
n
Done Int
n b
_ -> Int -> m (Step s b)
forall {a} {a}. Show a => a -> a
derror Int
n
Error String
err -> String -> m (Step s b)
forall {a}. String -> a
eerror String
err
extract :: a
extract = String -> a
forall a. HasCallStack => String -> a
error String
"toFold: parser cannot be used for scanning"
final :: s -> m b
final s
st = do
Step s b
r <- s -> m (Step s b)
pextract s
st
case Step s b
r of
Done Int
0 b
b -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
Partial Int
n s
_ -> Int -> m b
forall {a} {a}. Show a => a -> a
perror Int
n
Continue Int
n s
_ -> Int -> m b
forall {a} {a}. Show a => a -> a
cerror Int
n
Done Int
n b
_ -> Int -> m b
forall {a} {a}. Show a => a -> a
derror Int
n
Error String
err -> String -> m b
forall {a}. String -> a
eerror String
err
{-# INLINE fromFold #-}
fromFold :: Monad m => Fold m a b -> Parser a m b
fromFold :: forall (m :: * -> *) a b. Monad m => Fold m a b -> Parser a m b
fromFold (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) = (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 s -> m (Step s b)
forall {s}. s -> m (Step s b)
extract
where
initial :: m (Initial s b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial s b -> m (Initial s b)) -> Initial s b -> m (Initial s b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> s -> Initial s b
forall s b. s -> Initial s b
IPartial s
s1
FL.Done b
b -> b -> Initial s b
forall s b. b -> Initial s b
IDone b
b
step :: s -> a -> m (Step s b)
step s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
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
$ case Step s b
res of
FL.Partial s
s1 -> Int -> s -> Step s b
forall s b. Int -> s -> Step s b
Partial Int
0 s
s1
FL.Done b
b -> Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
extract :: s -> m (Step s b)
extract = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> (s -> m b) -> s -> m (Step s b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m b
ffinal
{-# INLINE fromFoldMaybe #-}
fromFoldMaybe :: Monad m => String -> Fold m a (Maybe b) -> Parser a m b
fromFoldMaybe :: forall (m :: * -> *) a b.
Monad m =>
String -> Fold m a (Maybe b) -> Parser a m b
fromFoldMaybe String
errMsg (Fold s -> a -> m (Step s (Maybe b))
fstep m (Step s (Maybe b))
finitial s -> m (Maybe b)
_ s -> m (Maybe b)
ffinal) =
(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 s -> m (Step s b)
forall {s}. s -> m (Step s b)
extract
where
initial :: m (Initial s b)
initial = do
Step s (Maybe b)
res <- m (Step s (Maybe b))
finitial
Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial s b -> m (Initial s b)) -> Initial s b -> m (Initial s b)
forall a b. (a -> b) -> a -> b
$ case Step s (Maybe b)
res of
FL.Partial s
s1 -> s -> Initial s b
forall s b. s -> Initial s b
IPartial s
s1
FL.Done Maybe b
b ->
case Maybe b
b of
Just b
x -> b -> Initial s b
forall s b. b -> Initial s b
IDone b
x
Maybe b
Nothing -> String -> Initial s b
forall s b. String -> Initial s b
IError String
errMsg
step :: s -> a -> m (Step s b)
step s
s a
a = do
Step s (Maybe b)
res <- s -> a -> m (Step s (Maybe b))
fstep s
s a
a
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
$ case Step s (Maybe b)
res of
FL.Partial s
s1 -> Int -> s -> Step s b
forall s b. Int -> s -> Step s b
Partial Int
0 s
s1
FL.Done Maybe b
b ->
case Maybe b
b of
Just b
x -> Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
x
Maybe b
Nothing -> String -> Step s b
forall s b. String -> Step s b
Error String
errMsg
extract :: s -> m (Step s b)
extract s
s = do
Maybe b
res <- s -> m (Maybe b)
ffinal s
s
case Maybe b
res of
Just b
x -> 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
x
Maybe b
Nothing -> 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
errMsg
{-# INLINE peek #-}
peek :: Monad m => Parser a m a
peek :: forall (m :: * -> *) a. Monad m => Parser a m a
peek = (() -> a -> m (Step () a))
-> m (Initial () a) -> (() -> m (Step () a)) -> Parser a 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 () -> a -> m (Step () a)
forall {m :: * -> *} {b} {s}. Monad m => () -> b -> m (Step s b)
step m (Initial () a)
forall {b}. m (Initial () b)
initial () -> m (Step () a)
forall {m :: * -> *} {s} {b}. Monad m => () -> m (Step s b)
extract
where
initial :: m (Initial () b)
initial = Initial () b -> m (Initial () b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial () b -> m (Initial () b))
-> Initial () b -> m (Initial () b)
forall a b. (a -> b) -> a -> b
$ () -> Initial () b
forall s b. s -> Initial s b
IPartial ()
step :: () -> b -> m (Step s b)
step () b
a = 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
1 b
a
extract :: () -> m (Step s b)
extract () = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"peek: end of input"
{-# INLINE eof #-}
eof :: Monad m => Parser a m ()
eof :: forall (m :: * -> *) a. Monad m => Parser a m ()
eof = (() -> a -> m (Step () ()))
-> m (Initial () ()) -> (() -> m (Step () ())) -> Parser a m ()
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 () -> a -> m (Step () ())
forall {m :: * -> *} {p} {s} {b}.
Monad m =>
() -> p -> m (Step s b)
step m (Initial () ())
forall {b}. m (Initial () b)
initial () -> m (Step () ())
forall {m :: * -> *} {s}. Monad m => () -> m (Step s ())
extract
where
initial :: m (Initial () b)
initial = Initial () b -> m (Initial () b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial () b -> m (Initial () b))
-> Initial () b -> m (Initial () b)
forall a b. (a -> b) -> a -> b
$ () -> Initial () b
forall s b. s -> Initial s b
IPartial ()
step :: () -> p -> m (Step s b)
step () p
_ = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"eof: not at end of input"
extract :: () -> m (Step s ())
extract () = Step s () -> m (Step s ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s () -> m (Step s ())) -> Step s () -> m (Step s ())
forall a b. (a -> b) -> a -> b
$ Int -> () -> Step s ()
forall s b. Int -> b -> Step s b
Done Int
0 ()
{-# DEPRECATED next "Please use \"fromFold Fold.one\" instead" #-}
{-# INLINE next #-}
next :: Monad m => Parser a m (Maybe a)
next :: forall (m :: * -> *) a. Monad m => Parser a m (Maybe a)
next = (() -> a -> m (Step () (Maybe a)))
-> m (Initial () (Maybe a))
-> (() -> m (Step () (Maybe a)))
-> Parser a m (Maybe 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 () -> a -> m (Step () (Maybe a))
forall {f :: * -> *} {a} {s}.
Applicative f =>
() -> a -> f (Step s (Maybe a))
step m (Initial () (Maybe a))
forall {b}. m (Initial () b)
initial () -> m (Step () (Maybe a))
forall {f :: * -> *} {s} {a}.
Applicative f =>
() -> f (Step s (Maybe a))
extract
where
initial :: m (Initial () b)
initial = Initial () b -> m (Initial () b)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Initial () b -> m (Initial () b))
-> Initial () b -> m (Initial () b)
forall a b. (a -> b) -> a -> b
$ () -> Initial () b
forall s b. s -> Initial s b
IPartial ()
step :: () -> a -> f (Step s (Maybe a))
step () a
a = Step s (Maybe a) -> f (Step s (Maybe a))
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Step s (Maybe a) -> f (Step s (Maybe a)))
-> Step s (Maybe a) -> f (Step s (Maybe a))
forall a b. (a -> b) -> a -> b
$ Int -> Maybe a -> Step s (Maybe a)
forall s b. Int -> b -> Step s b
Done Int
0 (a -> Maybe a
forall a. a -> Maybe a
Just a
a)
extract :: () -> f (Step s (Maybe a))
extract () = Step s (Maybe a) -> f (Step s (Maybe a))
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Step s (Maybe a) -> f (Step s (Maybe a)))
-> Step s (Maybe a) -> f (Step s (Maybe a))
forall a b. (a -> b) -> a -> b
$ Int -> Maybe a -> Step s (Maybe a)
forall s b. Int -> b -> Step s b
Done Int
0 Maybe a
forall a. Maybe a
Nothing
{-# INLINE either #-}
either :: Monad m => (a -> Either String b) -> Parser a m b
either :: forall (m :: * -> *) a b.
Monad m =>
(a -> Either String b) -> Parser a m b
either a -> Either String b
f = (() -> a -> m (Step () b))
-> m (Initial () b) -> (() -> m (Step () 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 () -> a -> m (Step () b)
forall {m :: * -> *} {s}. Monad m => () -> a -> m (Step s b)
step m (Initial () b)
forall {b}. m (Initial () b)
initial () -> m (Step () b)
forall {m :: * -> *} {s} {b}. Monad m => () -> m (Step s b)
extract
where
initial :: m (Initial () b)
initial = Initial () b -> m (Initial () b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial () b -> m (Initial () b))
-> Initial () b -> m (Initial () b)
forall a b. (a -> b) -> a -> b
$ () -> Initial () b
forall s b. s -> Initial s b
IPartial ()
step :: () -> a -> m (Step s b)
step () a
a = 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
$
case a -> Either String b
f a
a of
Right b
b -> Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
Left String
err -> String -> Step s b
forall s b. String -> Step s b
Error String
err
extract :: () -> m (Step s b)
extract () = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"end of input"
{-# INLINE maybe #-}
maybe :: Monad m => (a -> Maybe b) -> Parser a m b
maybe :: forall (m :: * -> *) a b. Monad m => (a -> Maybe b) -> Parser a m b
maybe a -> Maybe b
parserF = (() -> a -> m (Step () b))
-> m (Initial () b) -> (() -> m (Step () 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 () -> a -> m (Step () b)
forall {m :: * -> *} {s}. Monad m => () -> a -> m (Step s b)
step m (Initial () b)
forall {b}. m (Initial () b)
initial () -> m (Step () b)
forall {m :: * -> *} {s} {b}. Monad m => () -> m (Step s b)
extract
where
initial :: m (Initial () b)
initial = Initial () b -> m (Initial () b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial () b -> m (Initial () b))
-> Initial () b -> m (Initial () b)
forall a b. (a -> b) -> a -> b
$ () -> Initial () b
forall s b. s -> Initial s b
IPartial ()
step :: () -> a -> m (Step s b)
step () a
a = 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
$
case a -> Maybe b
parserF a
a of
Just b
b -> Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
Maybe b
Nothing -> String -> Step s b
forall s b. String -> Step s b
Error String
"maybe: predicate failed"
extract :: () -> m (Step s b)
extract () = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"maybe: end of input"
{-# INLINE satisfy #-}
satisfy :: Monad m => (a -> Bool) -> Parser a m a
satisfy :: forall (m :: * -> *) a. Monad m => (a -> Bool) -> Parser a m a
satisfy a -> Bool
predicate = (() -> a -> m (Step () a))
-> m (Initial () a) -> (() -> m (Step () a)) -> Parser a 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 () -> a -> m (Step () a)
forall {m :: * -> *} {s}. Monad m => () -> a -> m (Step s a)
step m (Initial () a)
forall {b}. m (Initial () b)
initial () -> m (Step () a)
forall {m :: * -> *} {s} {b}. Monad m => () -> m (Step s b)
extract
where
initial :: m (Initial () b)
initial = Initial () b -> m (Initial () b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial () b -> m (Initial () b))
-> Initial () b -> m (Initial () b)
forall a b. (a -> b) -> a -> b
$ () -> Initial () b
forall s b. s -> Initial s b
IPartial ()
step :: () -> a -> m (Step s a)
step () a
a = Step s a -> m (Step s a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$
if a -> Bool
predicate a
a
then Int -> a -> Step s a
forall s b. Int -> b -> Step s b
Done Int
0 a
a
else String -> Step s a
forall s b. String -> Step s b
Error String
"satisfy: predicate failed"
extract :: () -> m (Step s b)
extract () = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"satisfy: end of input"
{-# INLINE one #-}
one :: Monad m => Parser a m a
one :: forall (m :: * -> *) a. Monad m => Parser a m a
one = (a -> Bool) -> Parser a m a
forall (m :: * -> *) a. Monad m => (a -> Bool) -> Parser a m a
satisfy ((a -> Bool) -> Parser a m a) -> (a -> Bool) -> Parser a m a
forall a b. (a -> b) -> a -> b
$ Bool -> a -> Bool
forall a b. a -> b -> a
const Bool
True
{-# INLINE oneEq #-}
oneEq :: (Monad m, Eq a) => a -> Parser a m a
oneEq :: forall (m :: * -> *) a. (Monad m, Eq a) => a -> Parser a m a
oneEq a
x = (a -> Bool) -> Parser a m a
forall (m :: * -> *) a. Monad m => (a -> Bool) -> Parser a m a
satisfy (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x)
{-# INLINE oneNotEq #-}
oneNotEq :: (Monad m, Eq a) => a -> Parser a m a
oneNotEq :: forall (m :: * -> *) a. (Monad m, Eq a) => a -> Parser a m a
oneNotEq a
x = (a -> Bool) -> Parser a m a
forall (m :: * -> *) a. Monad m => (a -> Bool) -> Parser a m a
satisfy (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
x)
{-# INLINE oneOf #-}
oneOf :: (Monad m, Eq a, Foldable f) => f a -> Parser a m a
oneOf :: forall (m :: * -> *) a (f :: * -> *).
(Monad m, Eq a, Foldable f) =>
f a -> Parser a m a
oneOf f a
xs = (a -> Bool) -> Parser a m a
forall (m :: * -> *) a. Monad m => (a -> Bool) -> Parser a m a
satisfy (a -> f a -> Bool
forall a. Eq a => a -> f a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`Foldable.elem` f a
xs)
{-# INLINE noneOf #-}
noneOf :: (Monad m, Eq a, Foldable f) => f a -> Parser a m a
noneOf :: forall (m :: * -> *) a (f :: * -> *).
(Monad m, Eq a, Foldable f) =>
f a -> Parser a m a
noneOf f a
xs = (a -> Bool) -> Parser a m a
forall (m :: * -> *) a. Monad m => (a -> Bool) -> Parser a m a
satisfy (a -> f a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`Foldable.notElem` f a
xs)
{-# ANN type Tuple'Fused Fuse #-}
data Tuple'Fused a b = Tuple'Fused !a !b deriving Int -> Tuple'Fused a b -> String -> String
[Tuple'Fused a b] -> String -> String
Tuple'Fused a b -> String
(Int -> Tuple'Fused a b -> String -> String)
-> (Tuple'Fused a b -> String)
-> ([Tuple'Fused a b] -> String -> String)
-> Show (Tuple'Fused a b)
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
forall a b.
(Show a, Show b) =>
Int -> Tuple'Fused a b -> String -> String
forall a b.
(Show a, Show b) =>
[Tuple'Fused a b] -> String -> String
forall a b. (Show a, Show b) => Tuple'Fused a b -> String
$cshowsPrec :: forall a b.
(Show a, Show b) =>
Int -> Tuple'Fused a b -> String -> String
showsPrec :: Int -> Tuple'Fused a b -> String -> String
$cshow :: forall a b. (Show a, Show b) => Tuple'Fused a b -> String
show :: Tuple'Fused a b -> String
$cshowList :: forall a b.
(Show a, Show b) =>
[Tuple'Fused a b] -> String -> String
showList :: [Tuple'Fused a b] -> String -> String
Show
{-# INLINE takeBetween #-}
takeBetween :: Monad m => Int -> Int -> Fold m a b -> Parser a m b
takeBetween :: forall (m :: * -> *) a b.
Monad m =>
Int -> Int -> Fold m a b -> Parser a m b
takeBetween Int
low Int
high (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b))
-> m (Initial (Tuple'Fused Int s) b)
-> (Tuple'Fused Int s -> m (Step (Tuple'Fused Int 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 Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b)
step m (Initial (Tuple'Fused Int s) b)
initial ((Int -> String)
-> Tuple'Fused Int s -> m (Step (Tuple'Fused Int s) b)
forall {s}. (Int -> String) -> Tuple'Fused Int s -> m (Step s b)
extract Int -> String
forall a. Show a => a -> String
streamErr)
where
streamErr :: a -> String
streamErr a
i =
String
"takeBetween: Expecting alteast " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
low
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements, got " String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
i
invalidRange :: String
invalidRange =
String
"takeBetween: lower bound - " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
low
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" is greater than higher bound - " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
high
foldErr :: Int -> String
foldErr :: Int -> String
foldErr Int
i =
String
"takeBetween: the collecting fold terminated after"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" consuming" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" minimum" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
low String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements needed"
{-# INLINE inext #-}
inext :: Int -> Step s b -> m (Initial (Tuple'Fused Int s) b)
inext Int
i Step s b
res =
let i1 :: Int
i1 = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case Step s b
res of
FL.Partial s
s -> do
let s1 :: Tuple'Fused Int s
s1 = Int -> s -> Tuple'Fused Int s
forall a b. a -> b -> Tuple'Fused a b
Tuple'Fused Int
i1 s
s
if Int
i1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
high
then Initial (Tuple'Fused Int s) b -> m (Initial (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b))
-> Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ Tuple'Fused Int s -> Initial (Tuple'Fused Int s) b
forall s b. s -> Initial s b
IPartial Tuple'Fused Int s
s1
else (Int -> String)
-> Tuple'Fused Int s -> m (Initial (Tuple'Fused Int s) b)
forall {s}. (Int -> String) -> Tuple'Fused Int s -> m (Initial s b)
iextract Int -> String
foldErr Tuple'Fused Int s
s1
FL.Done b
b ->
Initial (Tuple'Fused Int s) b -> m (Initial (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b))
-> Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ if Int
i1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
low
then b -> Initial (Tuple'Fused Int s) b
forall s b. b -> Initial s b
IDone b
b
else String -> Initial (Tuple'Fused Int s) b
forall s b. String -> Initial s b
IError (Int -> String
foldErr Int
i1)
initial :: m (Initial (Tuple'Fused Int s) b)
initial = do
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
low Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
high Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
low Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
high)
(m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ String -> m ()
forall a. HasCallStack => String -> a
error String
invalidRange
m (Step s b)
finitial m (Step s b)
-> (Step s b -> m (Initial (Tuple'Fused Int s) b))
-> m (Initial (Tuple'Fused Int s) b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Step s b -> m (Initial (Tuple'Fused Int s) b)
inext (-Int
1)
{-# INLINE snext #-}
snext :: Int -> Step s b -> m (Step (Tuple'Fused Int s) b)
snext Int
i Step s b
res =
let i1 :: Int
i1 = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case Step s b
res of
FL.Partial s
s -> do
let s1 :: Tuple'Fused Int s
s1 = Int -> s -> Tuple'Fused Int s
forall a b. a -> b -> Tuple'Fused a b
Tuple'Fused Int
i1 s
s
if Int
i1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
low
then Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b))
-> Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ Int -> Tuple'Fused Int s -> Step (Tuple'Fused Int s) b
forall s b. Int -> s -> Step s b
Continue Int
0 Tuple'Fused Int s
s1
else if Int
i1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
high
then Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b))
-> Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ Int -> Tuple'Fused Int s -> Step (Tuple'Fused Int s) b
forall s b. Int -> s -> Step s b
Partial Int
0 Tuple'Fused Int s
s1
else (b -> Step (Tuple'Fused Int s) b)
-> m b -> m (Step (Tuple'Fused Int 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 -> b -> Step (Tuple'Fused Int s) b
forall s b. Int -> b -> Step s b
Done Int
0) (s -> m b
ffinal s
s)
FL.Done b
b ->
Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b))
-> Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ if Int
i1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
low
then Int -> b -> Step (Tuple'Fused Int s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
else String -> Step (Tuple'Fused Int s) b
forall s b. String -> Step s b
Error (Int -> String
foldErr Int
i1)
step :: Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b)
step (Tuple'Fused Int
i s
s) a
a = s -> a -> m (Step s b)
fstep s
s a
a m (Step s b)
-> (Step s b -> m (Step (Tuple'Fused Int s) b))
-> m (Step (Tuple'Fused Int s) b)
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Int -> Step s b -> m (Step (Tuple'Fused Int s) b)
snext Int
i
extract :: (Int -> String) -> Tuple'Fused Int s -> m (Step s b)
extract Int -> String
f (Tuple'Fused Int
i s
s)
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
low Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
high = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (s -> m b
ffinal s
s)
| Bool
otherwise = 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
$ String -> Step s b
forall s b. String -> Step s b
Error (Int -> String
f Int
i)
iextract :: (Int -> String) -> Tuple'Fused Int s -> m (Initial s b)
iextract Int -> String
f (Tuple'Fused Int
i s
s)
| Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
low Bool -> Bool -> Bool
&& Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
high = (b -> Initial s b) -> m b -> m (Initial s b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Initial s b
forall s b. b -> Initial s b
IDone (s -> m b
ffinal s
s)
| Bool
otherwise = Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial s b -> m (Initial s b)) -> Initial s b -> m (Initial s b)
forall a b. (a -> b) -> a -> b
$ String -> Initial s b
forall s b. String -> Initial s b
IError (Int -> String
f Int
i)
{-# INLINE takeEQ #-}
takeEQ :: Monad m => Int -> Fold m a b -> Parser a m b
takeEQ :: forall (m :: * -> *) a b.
Monad m =>
Int -> Fold m a b -> Parser a m b
takeEQ Int
n (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) = (Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b))
-> m (Initial (Tuple'Fused Int s) b)
-> (Tuple'Fused Int s -> m (Step (Tuple'Fused Int 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 Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b)
step m (Initial (Tuple'Fused Int s) b)
initial Tuple'Fused Int s -> m (Step (Tuple'Fused Int s) b)
forall {m :: * -> *} {a} {b} {s} {b}.
(Monad m, Show a, Num a) =>
Tuple'Fused a b -> m (Step s b)
extract
where
initial :: m (Initial (Tuple'Fused Int s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
case Step s b
res of
FL.Partial s
s ->
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then Initial (Tuple'Fused Int s) b -> m (Initial (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b))
-> Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ Tuple'Fused Int s -> Initial (Tuple'Fused Int s) b
forall s b. s -> Initial s b
IPartial (Tuple'Fused Int s -> Initial (Tuple'Fused Int s) b)
-> Tuple'Fused Int s -> Initial (Tuple'Fused Int s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> Tuple'Fused Int s
forall a b. a -> b -> Tuple'Fused a b
Tuple'Fused Int
1 s
s
else (b -> Initial (Tuple'Fused Int s) b)
-> m b -> m (Initial (Tuple'Fused Int s) b)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Initial (Tuple'Fused Int s) b
forall s b. b -> Initial s b
IDone (s -> m b
ffinal s
s)
FL.Done b
b -> Initial (Tuple'Fused Int s) b -> m (Initial (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b))
-> Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then String -> Initial (Tuple'Fused Int s) b
forall s b. String -> Initial s b
IError
(String -> Initial (Tuple'Fused Int s) b)
-> String -> Initial (Tuple'Fused Int s) b
forall a b. (a -> b) -> a -> b
$ String
"takeEQ: Expecting exactly " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements, fold terminated without"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" consuming any elements"
else b -> Initial (Tuple'Fused Int s) b
forall s b. b -> Initial s b
IDone b
b
step :: Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b)
step (Tuple'Fused Int
i1 s
r) a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
r a
a
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
i1
then
Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b))
-> Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> Int -> Tuple'Fused Int s -> Step (Tuple'Fused Int s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (Tuple'Fused Int s -> Step (Tuple'Fused Int s) b)
-> Tuple'Fused Int s -> Step (Tuple'Fused Int s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> Tuple'Fused Int s
forall a b. a -> b -> Tuple'Fused a b
Tuple'Fused (Int
i1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) s
s
FL.Done b
_ ->
String -> Step (Tuple'Fused Int s) b
forall s b. String -> Step s b
Error
(String -> Step (Tuple'Fused Int s) b)
-> String -> Step (Tuple'Fused Int s) b
forall a b. (a -> b) -> a -> b
$ String
"takeEQ: Expecting exactly " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements, fold terminated on " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i1
else
Int -> b -> Step (Tuple'Fused Int s) b
forall s b. Int -> b -> Step s b
Done Int
0
(b -> Step (Tuple'Fused Int s) b)
-> m b -> m (Step (Tuple'Fused Int s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Step s b
res of
FL.Partial s
s -> s -> m b
ffinal s
s
FL.Done b
b -> b -> m b
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return b
b
extract :: Tuple'Fused a b -> m (Step s b)
extract (Tuple'Fused a
i b
_) =
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
$ String -> Step s b
forall s b. String -> Step s b
Error
(String -> Step s b) -> String -> Step s b
forall a b. (a -> b) -> a -> b
$ String
"takeEQ: Expecting exactly " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements, input terminated on " String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show (a
i a -> a -> a
forall a. Num a => a -> a -> a
- a
1)
{-# ANN type TakeGEState Fuse #-}
data TakeGEState s =
TakeGELT !Int !s
| TakeGEGE !s
{-# INLINE takeGE #-}
takeGE :: Monad m => Int -> Fold m a b -> Parser a m b
takeGE :: forall (m :: * -> *) a b.
Monad m =>
Int -> Fold m a b -> Parser a m b
takeGE Int
n (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) = (TakeGEState s -> a -> m (Step (TakeGEState s) b))
-> m (Initial (TakeGEState s) b)
-> (TakeGEState s -> m (Step (TakeGEState 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 TakeGEState s -> a -> m (Step (TakeGEState s) b)
step m (Initial (TakeGEState s) b)
initial TakeGEState s -> m (Step (TakeGEState s) b)
forall {s}. TakeGEState s -> m (Step s b)
extract
where
initial :: m (Initial (TakeGEState s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
case Step s b
res of
FL.Partial s
s ->
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b))
-> Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b)
forall a b. (a -> b) -> a -> b
$ TakeGEState s -> Initial (TakeGEState s) b
forall s b. s -> Initial s b
IPartial (TakeGEState s -> Initial (TakeGEState s) b)
-> TakeGEState s -> Initial (TakeGEState s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> TakeGEState s
forall s. Int -> s -> TakeGEState s
TakeGELT Int
1 s
s
else Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b))
-> Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b)
forall a b. (a -> b) -> a -> b
$ TakeGEState s -> Initial (TakeGEState s) b
forall s b. s -> Initial s b
IPartial (TakeGEState s -> Initial (TakeGEState s) b)
-> TakeGEState s -> Initial (TakeGEState s) b
forall a b. (a -> b) -> a -> b
$ s -> TakeGEState s
forall s. s -> TakeGEState s
TakeGEGE s
s
FL.Done b
b -> Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b))
-> Initial (TakeGEState s) b -> m (Initial (TakeGEState s) b)
forall a b. (a -> b) -> a -> b
$
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then String -> Initial (TakeGEState s) b
forall s b. String -> Initial s b
IError
(String -> Initial (TakeGEState s) b)
-> String -> Initial (TakeGEState s) b
forall a b. (a -> b) -> a -> b
$ String
"takeGE: Expecting at least " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements, fold terminated without"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" consuming any elements"
else b -> Initial (TakeGEState s) b
forall s b. b -> Initial s b
IDone b
b
step :: TakeGEState s -> a -> m (Step (TakeGEState s) b)
step (TakeGELT Int
i1 s
r) a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
r a
a
if Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
i1
then
Step (TakeGEState s) b -> m (Step (TakeGEState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (TakeGEState s) b -> m (Step (TakeGEState s) b))
-> Step (TakeGEState s) b -> m (Step (TakeGEState s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> Int -> TakeGEState s -> Step (TakeGEState s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (TakeGEState s -> Step (TakeGEState s) b)
-> TakeGEState s -> Step (TakeGEState s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> TakeGEState s
forall s. Int -> s -> TakeGEState s
TakeGELT (Int
i1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) s
s
FL.Done b
_ ->
String -> Step (TakeGEState s) b
forall s b. String -> Step s b
Error
(String -> Step (TakeGEState s) b)
-> String -> Step (TakeGEState s) b
forall a b. (a -> b) -> a -> b
$ String
"takeGE: Expecting at least " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements, fold terminated on " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
i1
else
Step (TakeGEState s) b -> m (Step (TakeGEState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (TakeGEState s) b -> m (Step (TakeGEState s) b))
-> Step (TakeGEState s) b -> m (Step (TakeGEState s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> Int -> TakeGEState s -> Step (TakeGEState s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (TakeGEState s -> Step (TakeGEState s) b)
-> TakeGEState s -> Step (TakeGEState s) b
forall a b. (a -> b) -> a -> b
$ s -> TakeGEState s
forall s. s -> TakeGEState s
TakeGEGE s
s
FL.Done b
b -> Int -> b -> Step (TakeGEState s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step (TakeGEGE s
r) a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
r a
a
Step (TakeGEState s) b -> m (Step (TakeGEState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (TakeGEState s) b -> m (Step (TakeGEState s) b))
-> Step (TakeGEState s) b -> m (Step (TakeGEState s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> Int -> TakeGEState s -> Step (TakeGEState s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (TakeGEState s -> Step (TakeGEState s) b)
-> TakeGEState s -> Step (TakeGEState s) b
forall a b. (a -> b) -> a -> b
$ s -> TakeGEState s
forall s. s -> TakeGEState s
TakeGEGE s
s
FL.Done b
b -> Int -> b -> Step (TakeGEState s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
extract :: TakeGEState s -> m (Step s b)
extract (TakeGELT Int
i s
_) =
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
$ String -> Step s b
forall s b. String -> Step s b
Error
(String -> Step s b) -> String -> Step s b
forall a b. (a -> b) -> a -> b
$ String
"takeGE: Expecting at least " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements, input terminated on " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
extract (TakeGEGE s
r) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
r
{-# INLINE takeWhileP #-}
takeWhileP :: Monad m => (a -> Bool) -> Parser a m b -> Parser a m b
takeWhileP :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Parser a m b -> Parser a m b
takeWhileP a -> Bool
predicate (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinitial s -> m (Step s b)
pextract) =
(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)
pinitial s -> m (Step s b)
pextract
where
step :: s -> a -> m (Step s b)
step s
s a
a =
if a -> Bool
predicate a
a
then s -> a -> m (Step s b)
pstep s
s a
a
else do
Step s b
r <- s -> m (Step s b)
pextract s
s
case Step s b
r of
Error String
err -> 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
err
Done Int
n b
s1 -> 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) b
s1
Partial Int
_ s
_ -> String -> m (Step s b)
forall a. HasCallStack => String -> a
error String
"Bug: takeWhileP: Partial in extract"
Continue Int
n s
s1 -> 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
Continue (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) s
s1
{-# INLINE takeWhile #-}
takeWhile :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
takeWhile :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Parser a m b
takeWhile a -> Bool
predicate (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(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 s -> m (Step s b)
forall {s}. s -> m (Step s b)
extract
where
initial :: m (Initial s b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial s b -> m (Initial s b)) -> Initial s b -> m (Initial s b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> s -> Initial s b
forall s b. s -> Initial s b
IPartial s
s
FL.Done b
b -> b -> Initial s b
forall s b. b -> Initial s b
IDone b
b
step :: s -> a -> m (Step s b)
step s
s a
a =
if a -> Bool
predicate a
a
then do
Step s b
fres <- s -> a -> m (Step s b)
fstep s
s a
a
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
$ case Step s b
fres of
FL.Partial s
s1 -> Int -> s -> Step s b
forall s b. Int -> s -> Step s b
Partial Int
0 s
s1
FL.Done b
b -> Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
else Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
1 (b -> Step s b) -> m b -> m (Step s b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
extract :: s -> m (Step s b)
extract s
s = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (s -> m b
ffinal s
s)
{-# INLINE takeWhile1 #-}
takeWhile1 :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
takeWhile1 :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Parser a m b
takeWhile1 a -> Bool
predicate (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(Either' s s -> a -> m (Step (Either' s s) b))
-> m (Initial (Either' s s) b)
-> (Either' s s -> m (Step (Either' s 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 Either' s s -> a -> m (Step (Either' s s) b)
forall {a}. Either' s s -> a -> m (Step (Either' a s) b)
step m (Initial (Either' s s) b)
forall {b} {b}. m (Initial (Either' s b) b)
initial Either' s s -> m (Step (Either' s s) b)
forall {a} {s}. Either' a s -> m (Step s b)
extract
where
initial :: m (Initial (Either' s b) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (Either' s b) b -> m (Initial (Either' s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Either' s b) b -> m (Initial (Either' s b) b))
-> Initial (Either' s b) b -> m (Initial (Either' s b) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> Either' s b -> Initial (Either' s b) b
forall s b. s -> Initial s b
IPartial (s -> Either' s b
forall a b. a -> Either' a b
Left' s
s)
FL.Done b
_ ->
String -> Initial (Either' s b) b
forall s b. String -> Initial s b
IError
(String -> Initial (Either' s b) b)
-> String -> Initial (Either' s b) b
forall a b. (a -> b) -> a -> b
$ String
"takeWhile1: fold terminated without consuming:"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" any element"
{-# INLINE process #-}
process :: s -> a -> m (Step (Either' a s) b)
process s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (Either' a s) b -> m (Step (Either' a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (Either' a s) b -> m (Step (Either' a s) b))
-> Step (Either' a s) b -> m (Step (Either' a s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> Either' a s -> Step (Either' a s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (s -> Either' a s
forall a b. b -> Either' a b
Right' s
s1)
FL.Done b
b -> Int -> b -> Step (Either' a s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step :: Either' s s -> a -> m (Step (Either' a s) b)
step (Left' s
s) a
a =
if a -> Bool
predicate a
a
then s -> a -> m (Step (Either' a s) b)
forall {a}. s -> a -> m (Step (Either' a s) b)
process s
s a
a
else Step (Either' a s) b -> m (Step (Either' a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either' a s) b -> m (Step (Either' a s) b))
-> Step (Either' a s) b -> m (Step (Either' a s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (Either' a s) b
forall s b. String -> Step s b
Error String
"takeWhile1: predicate failed on first element"
step (Right' s
s) a
a =
if a -> Bool
predicate a
a
then s -> a -> m (Step (Either' a s) b)
forall {a}. s -> a -> m (Step (Either' a s) b)
process s
s a
a
else do
b
b <- s -> m b
ffinal s
s
Step (Either' a s) b -> m (Step (Either' a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either' a s) b -> m (Step (Either' a s) b))
-> Step (Either' a s) b -> m (Step (Either' a s) b)
forall a b. (a -> b) -> a -> b
$ Int -> b -> Step (Either' a s) b
forall s b. Int -> b -> Step s b
Done Int
1 b
b
extract :: Either' a s -> m (Step s b)
extract (Left' a
_) = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"takeWhile1: end of input"
extract (Right' s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (s -> m b
ffinal s
s)
{-# INLINE dropWhile #-}
dropWhile :: Monad m => (a -> Bool) -> Parser a m ()
dropWhile :: forall (m :: * -> *) a. Monad m => (a -> Bool) -> Parser a m ()
dropWhile a -> Bool
p = (a -> Bool) -> Fold m a () -> Parser a m ()
forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Parser a m b
takeWhile a -> Bool
p Fold m a ()
forall (m :: * -> *) a. Monad m => Fold m a ()
FL.drain
{-# ANN type FramedEscState Fuse #-}
data FramedEscState s =
FrameEscInit !s | FrameEscGo !s !Int | FrameEscEsc !s !Int
{-# INLINE takeFramedByGeneric #-}
takeFramedByGeneric :: Monad m =>
Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Fold m a b
-> Parser a m b
takeFramedByGeneric :: forall (m :: * -> *) a b.
Monad m =>
Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Fold m a b
-> Parser a m b
takeFramedByGeneric Maybe (a -> Bool)
esc Maybe (a -> Bool)
begin Maybe (a -> Bool)
end (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(FramedEscState s -> a -> m (Step (FramedEscState s) b))
-> m (Initial (FramedEscState s) b)
-> (FramedEscState s -> m (Step (FramedEscState 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 FramedEscState s -> a -> m (Step (FramedEscState s) b)
step m (Initial (FramedEscState s) b)
forall {b}. m (Initial (FramedEscState s) b)
initial FramedEscState s -> m (Step (FramedEscState s) b)
forall {s}. FramedEscState s -> m (Step s b)
extract
where
initial :: m (Initial (FramedEscState s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (FramedEscState s) b -> m (Initial (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (FramedEscState s) b -> m (Initial (FramedEscState s) b))
-> Initial (FramedEscState s) b -> m (Initial (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$
case Step s b
res of
FL.Partial s
s -> FramedEscState s -> Initial (FramedEscState s) b
forall s b. s -> Initial s b
IPartial (s -> FramedEscState s
forall s. s -> FramedEscState s
FrameEscInit s
s)
FL.Done b
_ ->
String -> Initial (FramedEscState s) b
forall a. HasCallStack => String -> a
error String
"takeFramedByGeneric: fold done without input"
{-# INLINE process #-}
process :: s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> FramedEscState s -> Step (FramedEscState s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> Int -> FramedEscState s
forall s. s -> Int -> FramedEscState s
FrameEscGo s
s1 Int
n)
FL.Done b
b -> Int -> b -> Step (FramedEscState s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
{-# INLINE processNoEsc #-}
processNoEsc :: s -> a -> Int -> m (Step (FramedEscState s) b)
processNoEsc s
s a
a Int
n =
case Maybe (a -> Bool)
end of
Just a -> Bool
isEnd ->
case Maybe (a -> Bool)
begin of
Just a -> Bool
isBegin ->
if a -> Bool
isEnd a
a
then
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Int -> b -> Step (FramedEscState s) b
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Step (FramedEscState s) b)
-> m b -> m (Step (FramedEscState s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
else s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
else
let n1 :: Int
n1 = if a -> Bool
isBegin a
a then Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 else Int
n
in s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n1
Maybe (a -> Bool)
Nothing ->
if a -> Bool
isEnd a
a
then Int -> b -> Step (FramedEscState s) b
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Step (FramedEscState s) b)
-> m b -> m (Step (FramedEscState s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
else s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n
Maybe (a -> Bool)
Nothing ->
case Maybe (a -> Bool)
begin of
Just a -> Bool
isBegin ->
if a -> Bool
isBegin a
a
then Int -> b -> Step (FramedEscState s) b
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Step (FramedEscState s) b)
-> m b -> m (Step (FramedEscState s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
else s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n
Maybe (a -> Bool)
Nothing ->
String -> m (Step (FramedEscState s) b)
forall a. HasCallStack => String -> a
error (String -> m (Step (FramedEscState s) b))
-> String -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ String
"takeFramedByGeneric: "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"Both begin and end frame predicate missing"
{-# INLINE processCheckEsc #-}
processCheckEsc :: s -> a -> Int -> m (Step (FramedEscState s) b)
processCheckEsc s
s a
a Int
n =
case Maybe (a -> Bool)
esc of
Just a -> Bool
isEsc ->
if a -> Bool
isEsc a
a
then Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ Int -> FramedEscState s -> Step (FramedEscState s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (FramedEscState s -> Step (FramedEscState s) b)
-> FramedEscState s -> Step (FramedEscState s) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> FramedEscState s
forall s. s -> Int -> FramedEscState s
FrameEscEsc s
s Int
n
else s -> a -> Int -> m (Step (FramedEscState s) b)
processNoEsc s
s a
a Int
n
Maybe (a -> Bool)
Nothing -> s -> a -> Int -> m (Step (FramedEscState s) b)
processNoEsc s
s a
a Int
n
step :: FramedEscState s -> a -> m (Step (FramedEscState s) b)
step (FrameEscInit s
s) a
a =
case Maybe (a -> Bool)
begin of
Just a -> Bool
isBegin ->
if a -> Bool
isBegin a
a
then Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ Int -> FramedEscState s -> Step (FramedEscState s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (s -> Int -> FramedEscState s
forall s. s -> Int -> FramedEscState s
FrameEscGo s
s Int
0)
else Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (FramedEscState s) b
forall s b. String -> Step s b
Error String
"takeFramedByGeneric: missing frame start"
Maybe (a -> Bool)
Nothing ->
case Maybe (a -> Bool)
end of
Just a -> Bool
isEnd ->
if a -> Bool
isEnd a
a
then Int -> b -> Step (FramedEscState s) b
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Step (FramedEscState s) b)
-> m b -> m (Step (FramedEscState s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
else s -> a -> Int -> m (Step (FramedEscState s) b)
processCheckEsc s
s a
a Int
0
Maybe (a -> Bool)
Nothing ->
String -> m (Step (FramedEscState s) b)
forall a. HasCallStack => String -> a
error String
"Both begin and end frame predicate missing"
step (FrameEscGo s
s Int
n) a
a = s -> a -> Int -> m (Step (FramedEscState s) b)
processCheckEsc s
s a
a Int
n
step (FrameEscEsc s
s Int
n) a
a = s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n
err :: String -> m (Step s b)
err = 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))
-> (String -> Step s b) -> String -> m (Step s b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Step s b
forall s b. String -> Step s b
Error
extract :: FramedEscState s -> m (Step s b)
extract (FrameEscInit s
_) =
String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedByGeneric: empty token"
extract (FrameEscGo s
s Int
_) =
case Maybe (a -> Bool)
begin of
Just a -> Bool
_ ->
case Maybe (a -> Bool)
end of
Maybe (a -> Bool)
Nothing -> (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
Just a -> Bool
_ -> String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedByGeneric: missing frame end"
Maybe (a -> Bool)
Nothing -> String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedByGeneric: missing closing frame"
extract (FrameEscEsc s
_ Int
_) = String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedByGeneric: trailing escape"
data BlockParseState s =
BlockInit !s
| BlockUnquoted !Int !s
| BlockQuoted !Int !s
| BlockQuotedEsc !Int !s
{-# INLINE blockWithQuotes #-}
blockWithQuotes :: (Monad m, Eq a) =>
(a -> Bool)
-> (a -> Bool)
-> a
-> a
-> Fold m a b
-> Parser a m b
blockWithQuotes :: forall (m :: * -> *) a b.
(Monad m, Eq a) =>
(a -> Bool) -> (a -> Bool) -> a -> a -> Fold m a b -> Parser a m b
blockWithQuotes a -> Bool
isEsc a -> Bool
isQuote a
bopen a
bclose
(Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(BlockParseState s -> a -> m (Step (BlockParseState s) b))
-> m (Initial (BlockParseState s) b)
-> (BlockParseState s -> m (Step (BlockParseState 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 BlockParseState s -> a -> m (Step (BlockParseState s) b)
step m (Initial (BlockParseState s) b)
forall {b}. m (Initial (BlockParseState s) b)
initial BlockParseState s -> m (Step (BlockParseState s) b)
forall {s}. BlockParseState s -> m (Step s b)
extract
where
initial :: m (Initial (BlockParseState s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (BlockParseState s) b -> m (Initial (BlockParseState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (BlockParseState s) b
-> m (Initial (BlockParseState s) b))
-> Initial (BlockParseState s) b
-> m (Initial (BlockParseState s) b)
forall a b. (a -> b) -> a -> b
$
case Step s b
res of
FL.Partial s
s -> BlockParseState s -> Initial (BlockParseState s) b
forall s b. s -> Initial s b
IPartial (s -> BlockParseState s
forall s. s -> BlockParseState s
BlockInit s
s)
FL.Done b
_ ->
String -> Initial (BlockParseState s) b
forall a. HasCallStack => String -> a
error String
"blockWithQuotes: fold finished without input"
{-# INLINE process #-}
process :: s -> a -> (s -> s) -> m (Step s b)
process s
s a
a s -> s
nextState = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
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
$ case Step s b
res of
FL.Partial s
s1 -> Int -> s -> Step s b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> s
nextState s
s1)
FL.Done b
b -> Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step :: BlockParseState s -> a -> m (Step (BlockParseState s) b)
step (BlockInit s
s) a
a =
Step (BlockParseState s) b -> m (Step (BlockParseState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (BlockParseState s) b -> m (Step (BlockParseState s) b))
-> Step (BlockParseState s) b -> m (Step (BlockParseState s) b)
forall a b. (a -> b) -> a -> b
$ if a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
bopen
then Int -> BlockParseState s -> Step (BlockParseState s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (BlockParseState s -> Step (BlockParseState s) b)
-> BlockParseState s -> Step (BlockParseState s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockUnquoted Int
1 s
s
else String -> Step (BlockParseState s) b
forall s b. String -> Step s b
Error String
"blockWithQuotes: missing block start"
step (BlockUnquoted Int
level s
s) a
a
| a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
bopen = s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockUnquoted (Int
level Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1))
| a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
bclose =
if Int
level Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then (b -> Step (BlockParseState s) b)
-> m b -> m (Step (BlockParseState 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 -> b -> Step (BlockParseState s) b
forall s b. Int -> b -> Step s b
Done Int
0) (s -> m b
ffinal s
s)
else s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockUnquoted (Int
level Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
| a -> Bool
isQuote a
a = s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockQuoted Int
level)
| Bool
otherwise = s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockUnquoted Int
level)
step (BlockQuoted Int
level s
s) a
a
| a -> Bool
isEsc a
a = s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockQuotedEsc Int
level)
| Bool
otherwise =
if a -> Bool
isQuote a
a
then s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockUnquoted Int
level)
else s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockQuoted Int
level)
step (BlockQuotedEsc Int
level s
s) a
a = s
-> a -> (s -> BlockParseState s) -> m (Step (BlockParseState s) b)
forall {s}. s -> a -> (s -> s) -> m (Step s b)
process s
s a
a (Int -> s -> BlockParseState s
forall s. Int -> s -> BlockParseState s
BlockQuoted Int
level)
err :: String -> m (Step s b)
err = 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))
-> (String -> Step s b) -> String -> m (Step s b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Step s b
forall s b. String -> Step s b
Error
extract :: BlockParseState s -> m (Step s b)
extract (BlockInit s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (BlockUnquoted Int
level s
_) =
String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err (String -> m (Step s b)) -> String -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ String
"blockWithQuotes: finished at block nest level " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
level
extract (BlockQuoted Int
level s
_) =
String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err (String -> m (Step s b)) -> String -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ String
"blockWithQuotes: finished, inside an unfinished quote, "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"at block nest level " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
level
extract (BlockQuotedEsc Int
level s
_) =
String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err (String -> m (Step s b)) -> String -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ String
"blockWithQuotes: finished, inside an unfinished quote, "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"after an escape char, at block nest level " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
level
{-# INLINE takeEndBy #-}
takeEndBy :: Monad m => (a -> Bool) -> Parser a m b -> Parser a m b
takeEndBy :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Parser a m b -> Parser a m b
takeEndBy a -> Bool
cond (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinitial s -> m (Step s b)
pextract) =
(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 s -> m (Step s b)
pextract
where
initial :: m (Initial s b)
initial = m (Initial s b)
pinitial
step :: s -> a -> m (Step s b)
step s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
pstep s
s a
a
if Bool -> Bool
not (a -> Bool
cond a
a)
then Step s b -> m (Step s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Step s b
res
else (s -> m (Step s b)) -> Step s b -> m (Step s b)
forall (m :: * -> *) s s1 b.
Monad m =>
(s -> m (Step s1 b)) -> Step s b -> m (Step s1 b)
extractStep s -> m (Step s b)
pextract Step s b
res
{-# INLINE takeEndByEsc #-}
takeEndByEsc :: Monad m =>
(a -> Bool) -> (a -> Bool) -> Parser a m b -> Parser a m b
takeEndByEsc :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> (a -> Bool) -> Parser a m b -> Parser a m b
takeEndByEsc a -> Bool
isEsc a -> Bool
isSep (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinitial s -> m (Step s b)
pextract) =
(Either' s s -> a -> m (Step (Either' s s) b))
-> m (Initial (Either' s s) b)
-> (Either' s s -> m (Step (Either' s 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 Either' s s -> a -> m (Step (Either' s s) b)
step m (Initial (Either' s s) b)
forall {b}. m (Initial (Either' s b) b)
initial Either' s s -> m (Step (Either' s s) b)
forall {b} {b}. Either' s b -> m (Step (Either' s b) b)
extract
where
initial :: m (Initial (Either' s b) b)
initial = (s -> Either' s b) -> Initial s b -> Initial (Either' s b) 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 -> Either' s b
forall a b. a -> Either' a b
Left' (Initial s b -> Initial (Either' s b) b)
-> m (Initial s b) -> m (Initial (Either' s b) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (Initial s b)
pinitial
step :: Either' s s -> a -> m (Step (Either' s s) b)
step (Left' s
s) a
a = do
if a -> Bool
isEsc a
a
then Step (Either' s s) b -> m (Step (Either' s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either' s s) b -> m (Step (Either' s s) b))
-> Step (Either' s s) b -> m (Step (Either' s s) b)
forall a b. (a -> b) -> a -> b
$ Int -> Either' s s -> Step (Either' s s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (Either' s s -> Step (Either' s s) b)
-> Either' s s -> Step (Either' s s) b
forall a b. (a -> b) -> a -> b
$ s -> Either' s s
forall a b. b -> Either' a b
Right' s
s
else do
Step s b
res <- s -> a -> m (Step s b)
pstep s
s a
a
if Bool -> Bool
not (a -> Bool
isSep a
a)
then Step (Either' s s) b -> m (Step (Either' s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either' s s) b -> m (Step (Either' s s) b))
-> Step (Either' s s) b -> m (Step (Either' s s) b)
forall a b. (a -> b) -> a -> b
$ (s -> Either' s s) -> Step s b -> Step (Either' 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 -> Either' s s
forall a b. a -> Either' a b
Left' Step s b
res
else (Step s b -> Step (Either' s s) b)
-> m (Step s b) -> m (Step (Either' 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 -> Either' s s) -> Step s b -> Step (Either' 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 -> Either' s s
forall a b. a -> Either' a b
Left') (m (Step s b) -> m (Step (Either' s s) b))
-> m (Step s b) -> m (Step (Either' s s) b)
forall a b. (a -> b) -> a -> b
$ (s -> m (Step s b)) -> Step s b -> m (Step s b)
forall (m :: * -> *) s s1 b.
Monad m =>
(s -> m (Step s1 b)) -> Step s b -> m (Step s1 b)
extractStep s -> m (Step s b)
pextract Step s b
res
step (Right' s
s) a
a = do
Step s b
res <- s -> a -> m (Step s b)
pstep s
s a
a
Step (Either' s s) b -> m (Step (Either' s s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either' s s) b -> m (Step (Either' s s) b))
-> Step (Either' s s) b -> m (Step (Either' s s) b)
forall a b. (a -> b) -> a -> b
$ (s -> Either' s s) -> Step s b -> Step (Either' 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 -> Either' s s
forall a b. a -> Either' a b
Left' Step s b
res
extract :: Either' s b -> m (Step (Either' s b) b)
extract (Left' s
s) = (Step s b -> Step (Either' s b) b)
-> m (Step s b) -> m (Step (Either' s 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 -> Either' s b) -> Step s b -> Step (Either' s 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 -> Either' s b
forall a b. a -> Either' a b
Left') (m (Step s b) -> m (Step (Either' s b) b))
-> m (Step s b) -> m (Step (Either' s b) b)
forall a b. (a -> b) -> a -> b
$ s -> m (Step s b)
pextract s
s
extract (Right' b
_) =
Step (Either' s b) b -> m (Step (Either' s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either' s b) b -> m (Step (Either' s b) b))
-> Step (Either' s b) b -> m (Step (Either' s b) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (Either' s b) b
forall s b. String -> Step s b
Error String
"takeEndByEsc: trailing escape"
{-# INLINE takeEndBy_ #-}
takeEndBy_ :: (a -> Bool) -> Parser a m b -> Parser a m b
takeEndBy_ :: forall a (m :: * -> *) b.
(a -> Bool) -> Parser a m b -> Parser a m b
takeEndBy_ a -> Bool
cond (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinitial s -> m (Step s b)
pextract) =
(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)
pinitial s -> m (Step s b)
pextract
where
step :: s -> a -> m (Step s b)
step s
s a
a =
if a -> Bool
cond a
a
then s -> m (Step s b)
pextract s
s
else s -> a -> m (Step s b)
pstep s
s a
a
{-# INLINE takeEitherSepBy #-}
takeEitherSepBy ::
(a -> Bool) -> Fold m (Either a b) c -> Parser a m c
takeEitherSepBy :: forall a (m :: * -> *) b c.
(a -> Bool) -> Fold m (Either a b) c -> Parser a m c
takeEitherSepBy a -> Bool
_cond = Fold m (Either a b) c -> Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE takeStartBy #-}
takeStartBy :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
takeStartBy :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Parser a m b
takeStartBy a -> Bool
cond (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(Either' s s -> a -> m (Step (Either' s s) b))
-> m (Initial (Either' s s) b)
-> (Either' s s -> m (Step (Either' s 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 Either' s s -> a -> m (Step (Either' s s) b)
forall {a}. Either' s s -> a -> m (Step (Either' a s) b)
step m (Initial (Either' s s) b)
forall {b} {b}. m (Initial (Either' s b) b)
initial Either' s s -> m (Step (Either' s s) b)
forall {s}. Either' s s -> m (Step s b)
extract
where
initial :: m (Initial (Either' s b) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (Either' s b) b -> m (Initial (Either' s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Either' s b) b -> m (Initial (Either' s b) b))
-> Initial (Either' s b) b -> m (Initial (Either' s b) b)
forall a b. (a -> b) -> a -> b
$
case Step s b
res of
FL.Partial s
s -> Either' s b -> Initial (Either' s b) b
forall s b. s -> Initial s b
IPartial (s -> Either' s b
forall a b. a -> Either' a b
Left' s
s)
FL.Done b
_ -> String -> Initial (Either' s b) b
forall s b. String -> Initial s b
IError String
"takeStartBy: fold done without input"
{-# INLINE process #-}
process :: s -> a -> m (Step (Either' a s) b)
process s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (Either' a s) b -> m (Step (Either' a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (Either' a s) b -> m (Step (Either' a s) b))
-> Step (Either' a s) b -> m (Step (Either' a s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> Either' a s -> Step (Either' a s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (s -> Either' a s
forall a b. b -> Either' a b
Right' s
s1)
FL.Done b
b -> Int -> b -> Step (Either' a s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step :: Either' s s -> a -> m (Step (Either' a s) b)
step (Left' s
s) a
a =
if a -> Bool
cond a
a
then s -> a -> m (Step (Either' a s) b)
forall {a}. s -> a -> m (Step (Either' a s) b)
process s
s a
a
else Step (Either' a s) b -> m (Step (Either' a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either' a s) b -> m (Step (Either' a s) b))
-> Step (Either' a s) b -> m (Step (Either' a s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (Either' a s) b
forall s b. String -> Step s b
Error String
"takeStartBy: missing frame start"
step (Right' s
s) a
a =
if Bool -> Bool
not (a -> Bool
cond a
a)
then s -> a -> m (Step (Either' a s) b)
forall {a}. s -> a -> m (Step (Either' a s) b)
process s
s a
a
else Int -> b -> Step (Either' a s) b
forall s b. Int -> b -> Step s b
Done Int
1 (b -> Step (Either' a s) b) -> m b -> m (Step (Either' a s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
extract :: Either' s s -> m (Step s b)
extract (Left' s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (Right' s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
{-# INLINE takeStartBy_ #-}
takeStartBy_ :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
takeStartBy_ :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Parser a m b
takeStartBy_ a -> Bool
isBegin = Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Fold m a b
-> Parser a m b
forall (m :: * -> *) a b.
Monad m =>
Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Maybe (a -> Bool)
-> Fold m a b
-> Parser a m b
takeFramedByGeneric Maybe (a -> Bool)
forall a. Maybe a
Nothing ((a -> Bool) -> Maybe (a -> Bool)
forall a. a -> Maybe a
Just a -> Bool
isBegin) Maybe (a -> Bool)
forall a. Maybe a
Nothing
{-# INLINE takeFramedByEsc_ #-}
takeFramedByEsc_ :: Monad m =>
(a -> Bool) -> (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
takeFramedByEsc_ :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool)
-> (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
takeFramedByEsc_ a -> Bool
isEsc a -> Bool
isBegin a -> Bool
isEnd (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal ) =
(FramedEscState s -> a -> m (Step (FramedEscState s) b))
-> m (Initial (FramedEscState s) b)
-> (FramedEscState s -> m (Step (FramedEscState 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 FramedEscState s -> a -> m (Step (FramedEscState s) b)
step m (Initial (FramedEscState s) b)
forall {b}. m (Initial (FramedEscState s) b)
initial FramedEscState s -> m (Step (FramedEscState s) b)
forall {s} {s} {b}. FramedEscState s -> m (Step s b)
extract
where
initial :: m (Initial (FramedEscState s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (FramedEscState s) b -> m (Initial (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (FramedEscState s) b -> m (Initial (FramedEscState s) b))
-> Initial (FramedEscState s) b -> m (Initial (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$
case Step s b
res of
FL.Partial s
s -> FramedEscState s -> Initial (FramedEscState s) b
forall s b. s -> Initial s b
IPartial (s -> FramedEscState s
forall s. s -> FramedEscState s
FrameEscInit s
s)
FL.Done b
_ ->
String -> Initial (FramedEscState s) b
forall a. HasCallStack => String -> a
error String
"takeFramedByEsc_: fold done without input"
{-# INLINE process #-}
process :: s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> FramedEscState s -> Step (FramedEscState s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> Int -> FramedEscState s
forall s. s -> Int -> FramedEscState s
FrameEscGo s
s1 Int
n)
FL.Done b
b -> Int -> b -> Step (FramedEscState s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step :: FramedEscState s -> a -> m (Step (FramedEscState s) b)
step (FrameEscInit s
s) a
a =
if a -> Bool
isBegin a
a
then Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ Int -> FramedEscState s -> Step (FramedEscState s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (s -> Int -> FramedEscState s
forall s. s -> Int -> FramedEscState s
FrameEscGo s
s Int
0)
else Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (FramedEscState s) b
forall s b. String -> Step s b
Error String
"takeFramedByEsc_: missing frame start"
step (FrameEscGo s
s Int
n) a
a =
if a -> Bool
isEsc a
a
then Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedEscState s) b -> m (Step (FramedEscState s) b))
-> Step (FramedEscState s) b -> m (Step (FramedEscState s) b)
forall a b. (a -> b) -> a -> b
$ Int -> FramedEscState s -> Step (FramedEscState s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (FramedEscState s -> Step (FramedEscState s) b)
-> FramedEscState s -> Step (FramedEscState s) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> FramedEscState s
forall s. s -> Int -> FramedEscState s
FrameEscEsc s
s Int
n
else do
if Bool -> Bool
not (a -> Bool
isEnd a
a)
then
let n1 :: Int
n1 = if a -> Bool
isBegin a
a then Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 else Int
n
in s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n1
else
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Int -> b -> Step (FramedEscState s) b
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Step (FramedEscState s) b)
-> m b -> m (Step (FramedEscState s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
else s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
step (FrameEscEsc s
s Int
n) a
a = s -> a -> Int -> m (Step (FramedEscState s) b)
process s
s a
a Int
n
err :: String -> m (Step s b)
err = 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))
-> (String -> Step s b) -> String -> m (Step s b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Step s b
forall s b. String -> Step s b
Error
extract :: FramedEscState s -> m (Step s b)
extract (FrameEscInit s
_) = String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedByEsc_: empty token"
extract (FrameEscGo s
_ Int
_) = String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedByEsc_: missing frame end"
extract (FrameEscEsc s
_ Int
_) = String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedByEsc_: trailing escape"
data FramedState s = FrameInit !s | FrameGo !s Int
{-# INLINE takeFramedBy_ #-}
takeFramedBy_ :: Monad m =>
(a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
takeFramedBy_ :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser a m b
takeFramedBy_ a -> Bool
isBegin a -> Bool
isEnd (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(FramedState s -> a -> m (Step (FramedState s) b))
-> m (Initial (FramedState s) b)
-> (FramedState s -> m (Step (FramedState 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 FramedState s -> a -> m (Step (FramedState s) b)
step m (Initial (FramedState s) b)
forall {b}. m (Initial (FramedState s) b)
initial FramedState s -> m (Step (FramedState s) b)
forall {s} {s} {b}. FramedState s -> m (Step s b)
extract
where
initial :: m (Initial (FramedState s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (FramedState s) b -> m (Initial (FramedState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (FramedState s) b -> m (Initial (FramedState s) b))
-> Initial (FramedState s) b -> m (Initial (FramedState s) b)
forall a b. (a -> b) -> a -> b
$
case Step s b
res of
FL.Partial s
s -> FramedState s -> Initial (FramedState s) b
forall s b. s -> Initial s b
IPartial (s -> FramedState s
forall s. s -> FramedState s
FrameInit s
s)
FL.Done b
_ ->
String -> Initial (FramedState s) b
forall a. HasCallStack => String -> a
error String
"takeFramedBy_: fold done without input"
{-# INLINE process #-}
process :: s -> a -> Int -> m (Step (FramedState s) b)
process s
s a
a Int
n = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (FramedState s) b -> m (Step (FramedState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (FramedState s) b -> m (Step (FramedState s) b))
-> Step (FramedState s) b -> m (Step (FramedState s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> FramedState s -> Step (FramedState s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> Int -> FramedState s
forall s. s -> Int -> FramedState s
FrameGo s
s1 Int
n)
FL.Done b
b -> Int -> b -> Step (FramedState s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step :: FramedState s -> a -> m (Step (FramedState s) b)
step (FrameInit s
s) a
a =
if a -> Bool
isBegin a
a
then Step (FramedState s) b -> m (Step (FramedState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedState s) b -> m (Step (FramedState s) b))
-> Step (FramedState s) b -> m (Step (FramedState s) b)
forall a b. (a -> b) -> a -> b
$ Int -> FramedState s -> Step (FramedState s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> Int -> FramedState s
forall s. s -> Int -> FramedState s
FrameGo s
s Int
0)
else Step (FramedState s) b -> m (Step (FramedState s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (FramedState s) b -> m (Step (FramedState s) b))
-> Step (FramedState s) b -> m (Step (FramedState s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (FramedState s) b
forall s b. String -> Step s b
Error String
"takeFramedBy_: missing frame start"
step (FrameGo s
s Int
n) a
a
| Bool -> Bool
not (a -> Bool
isEnd a
a) =
let n1 :: Int
n1 = if a -> Bool
isBegin a
a then Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 else Int
n
in s -> a -> Int -> m (Step (FramedState s) b)
process s
s a
a Int
n1
| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Int -> b -> Step (FramedState s) b
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Step (FramedState s) b) -> m b -> m (Step (FramedState s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
| Bool
otherwise = s -> a -> Int -> m (Step (FramedState s) b)
process s
s a
a (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
err :: String -> m (Step s b)
err = 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))
-> (String -> Step s b) -> String -> m (Step s b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Step s b
forall s b. String -> Step s b
Error
extract :: FramedState s -> m (Step s b)
extract (FrameInit s
_) = String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedBy_: empty token"
extract (FrameGo s
_ Int
_) = String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"takeFramedBy_: missing frame end"
data WordByState s b = WBLeft !s | WBWord !s | WBRight !b
{-# INLINE wordBy #-}
wordBy :: Monad m => (a -> Bool) -> Fold m a b -> Parser a m b
wordBy :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Parser a m b
wordBy a -> Bool
predicate (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) = (WordByState s b -> a -> m (Step (WordByState s b) b))
-> m (Initial (WordByState s b) b)
-> (WordByState s b -> m (Step (WordByState s b) 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 WordByState s b -> a -> m (Step (WordByState s b) b)
step m (Initial (WordByState s b) b)
forall {b}. m (Initial (WordByState s b) b)
initial WordByState s b -> m (Step (WordByState s b) b)
forall {s}. WordByState s b -> m (Step s b)
extract
where
{-# INLINE worder #-}
worder :: s -> a -> m (Step (WordByState s b) b)
worder s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (WordByState s b) b -> m (Step (WordByState s b) b))
-> Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> WordByState s b -> Step (WordByState s b) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordByState s b -> Step (WordByState s b) b)
-> WordByState s b -> Step (WordByState s b) b
forall a b. (a -> b) -> a -> b
$ s -> WordByState s b
forall s b. s -> WordByState s b
WBWord s
s1
FL.Done b
b -> Int -> b -> Step (WordByState s b) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
initial :: m (Initial (WordByState s b) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (WordByState s b) b -> m (Initial (WordByState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial (WordByState s b) b -> m (Initial (WordByState s b) b))
-> Initial (WordByState s b) b -> m (Initial (WordByState s b) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> WordByState s b -> Initial (WordByState s b) b
forall s b. s -> Initial s b
IPartial (WordByState s b -> Initial (WordByState s b) b)
-> WordByState s b -> Initial (WordByState s b) b
forall a b. (a -> b) -> a -> b
$ s -> WordByState s b
forall s b. s -> WordByState s b
WBLeft s
s
FL.Done b
b -> b -> Initial (WordByState s b) b
forall s b. b -> Initial s b
IDone b
b
step :: WordByState s b -> a -> m (Step (WordByState s b) b)
step (WBLeft s
s) a
a =
if Bool -> Bool
not (a -> Bool
predicate a
a)
then s -> a -> m (Step (WordByState s b) b)
forall {b}. s -> a -> m (Step (WordByState s b) b)
worder s
s a
a
else Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordByState s b) b -> m (Step (WordByState s b) b))
-> Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordByState s b -> Step (WordByState s b) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordByState s b -> Step (WordByState s b) b)
-> WordByState s b -> Step (WordByState s b) b
forall a b. (a -> b) -> a -> b
$ s -> WordByState s b
forall s b. s -> WordByState s b
WBLeft s
s
step (WBWord s
s) a
a =
if Bool -> Bool
not (a -> Bool
predicate a
a)
then s -> a -> m (Step (WordByState s b) b)
forall {b}. s -> a -> m (Step (WordByState s b) b)
worder s
s a
a
else do
b
b <- s -> m b
ffinal s
s
Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordByState s b) b -> m (Step (WordByState s b) b))
-> Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordByState s b -> Step (WordByState s b) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordByState s b -> Step (WordByState s b) b)
-> WordByState s b -> Step (WordByState s b) b
forall a b. (a -> b) -> a -> b
$ b -> WordByState s b
forall s b. b -> WordByState s b
WBRight b
b
step (WBRight b
b) a
a =
Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (WordByState s b) b -> m (Step (WordByState s b) b))
-> Step (WordByState s b) b -> m (Step (WordByState s b) b)
forall a b. (a -> b) -> a -> b
$ if Bool -> Bool
not (a -> Bool
predicate a
a)
then Int -> b -> Step (WordByState s b) b
forall s b. Int -> b -> Step s b
Done Int
1 b
b
else Int -> WordByState s b -> Step (WordByState s b) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordByState s b -> Step (WordByState s b) b)
-> WordByState s b -> Step (WordByState s b) b
forall a b. (a -> b) -> a -> b
$ b -> WordByState s b
forall s b. b -> WordByState s b
WBRight b
b
extract :: WordByState s b -> m (Step s b)
extract (WBLeft s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (WBWord s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (WBRight b
b) = Step s b -> m (Step s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b)
data WordFramedState s b =
WordFramedSkipPre !s
| WordFramedWord !s !Int
| WordFramedEsc !s !Int
| WordFramedSkipPost !b
{-# INLINE wordFramedBy #-}
wordFramedBy :: Monad m =>
(a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordFramedBy :: forall (m :: * -> *) a b.
Monad m =>
(a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordFramedBy a -> Bool
isEsc a -> Bool
isBegin a -> Bool
isEnd a -> Bool
isSep
(Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(WordFramedState s b -> a -> m (Step (WordFramedState s b) b))
-> m (Initial (WordFramedState s b) b)
-> (WordFramedState s b -> m (Step (WordFramedState s b) 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 WordFramedState s b -> a -> m (Step (WordFramedState s b) b)
step m (Initial (WordFramedState s b) b)
forall {b} {b}. m (Initial (WordFramedState s b) b)
initial WordFramedState s b -> m (Step (WordFramedState s b) b)
forall {s}. WordFramedState s b -> m (Step s b)
extract
where
initial :: m (Initial (WordFramedState s b) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (WordFramedState s b) b
-> m (Initial (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (WordFramedState s b) b
-> m (Initial (WordFramedState s b) b))
-> Initial (WordFramedState s b) b
-> m (Initial (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$
case Step s b
res of
FL.Partial s
s -> WordFramedState s b -> Initial (WordFramedState s b) b
forall s b. s -> Initial s b
IPartial (s -> WordFramedState s b
forall s b. s -> WordFramedState s b
WordFramedSkipPre s
s)
FL.Done b
_ ->
String -> Initial (WordFramedState s b) b
forall a. HasCallStack => String -> a
error String
"wordFramedBy: fold done without input"
{-# INLINE process #-}
process :: s -> a -> Int -> m (Step (WordFramedState s b) b)
process s
s a
a Int
n = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> Int -> WordFramedState s b
forall s b. s -> Int -> WordFramedState s b
WordFramedWord s
s1 Int
n)
FL.Done b
b -> Int -> b -> Step (WordFramedState s b) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step :: WordFramedState s b -> a -> m (Step (WordFramedState s b) b)
step (WordFramedSkipPre s
s) a
a
| a -> Bool
isEsc a
a = Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> WordFramedState s b
forall s b. s -> Int -> WordFramedState s b
WordFramedEsc s
s Int
0
| a -> Bool
isSep a
a = Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ s -> WordFramedState s b
forall s b. s -> WordFramedState s b
WordFramedSkipPre s
s
| a -> Bool
isBegin a
a = Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> WordFramedState s b
forall s b. s -> Int -> WordFramedState s b
WordFramedWord s
s Int
1
| a -> Bool
isEnd a
a =
Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (WordFramedState s b) b
forall s b. String -> Step s b
Error String
"wordFramedBy: missing frame start"
| Bool
otherwise = s -> a -> Int -> m (Step (WordFramedState s b) b)
forall {b}. s -> a -> Int -> m (Step (WordFramedState s b) b)
process s
s a
a Int
0
step (WordFramedWord s
s Int
n) a
a
| a -> Bool
isEsc a
a = Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> WordFramedState s b
forall s b. s -> Int -> WordFramedState s b
WordFramedEsc s
s Int
n
| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& a -> Bool
isSep a
a = do
b
b <- s -> m b
ffinal s
s
Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ b -> WordFramedState s b
forall s b. b -> WordFramedState s b
WordFramedSkipPost b
b
| Bool
otherwise = do
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then
if a -> Bool
isBegin a
a
then Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> WordFramedState s b
forall s b. s -> Int -> WordFramedState s b
WordFramedWord s
s Int
1
else if a -> Bool
isEnd a
a
then Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (WordFramedState s b) b
forall s b. String -> Step s b
Error String
"wordFramedBy: missing frame start"
else s -> a -> Int -> m (Step (WordFramedState s b) b)
forall {b}. s -> a -> Int -> m (Step (WordFramedState s b) b)
process s
s a
a Int
n
else
if a -> Bool
isEnd a
a
then
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> WordFramedState s b
forall s b. s -> Int -> WordFramedState s b
WordFramedWord s
s Int
0
else s -> a -> Int -> m (Step (WordFramedState s b) b)
forall {b}. s -> a -> Int -> m (Step (WordFramedState s b) b)
process s
s a
a (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
else if a -> Bool
isBegin a
a
then s -> a -> Int -> m (Step (WordFramedState s b) b)
forall {b}. s -> a -> Int -> m (Step (WordFramedState s b) b)
process s
s a
a (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
else s -> a -> Int -> m (Step (WordFramedState s b) b)
forall {b}. s -> a -> Int -> m (Step (WordFramedState s b) b)
process s
s a
a Int
n
step (WordFramedEsc s
s Int
n) a
a = s -> a -> Int -> m (Step (WordFramedState s b) b)
forall {b}. s -> a -> Int -> m (Step (WordFramedState s b) b)
process s
s a
a Int
n
step (WordFramedSkipPost b
b) a
a =
Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b))
-> Step (WordFramedState s b) b -> m (Step (WordFramedState s b) b)
forall a b. (a -> b) -> a -> b
$ if Bool -> Bool
not (a -> Bool
isSep a
a)
then Int -> b -> Step (WordFramedState s b) b
forall s b. Int -> b -> Step s b
Done Int
1 b
b
else Int -> WordFramedState s b -> Step (WordFramedState s b) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordFramedState s b -> Step (WordFramedState s b) b)
-> WordFramedState s b -> Step (WordFramedState s b) b
forall a b. (a -> b) -> a -> b
$ b -> WordFramedState s b
forall s b. b -> WordFramedState s b
WordFramedSkipPost b
b
err :: String -> m (Step s b)
err = 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))
-> (String -> Step s b) -> String -> m (Step s b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Step s b
forall s b. String -> Step s b
Error
extract :: WordFramedState s b -> m (Step s b)
extract (WordFramedSkipPre s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (WordFramedWord s
s Int
n) =
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
else String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"wordFramedBy: missing frame end"
extract (WordFramedEsc s
_ Int
_) =
String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"wordFramedBy: trailing escape"
extract (WordFramedSkipPost b
b) = Step s b -> m (Step s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b)
data WordQuotedState s b a =
WordQuotedSkipPre !s
| WordUnquotedWord !s
| WordQuotedWord !s !Int !a !a
| WordUnquotedEsc !s
| WordQuotedEsc !s !Int !a !a
| WordQuotedSkipPost !b
{-# INLINE wordWithQuotes #-}
wordWithQuotes :: (Monad m, Eq a) =>
Bool
-> (a -> a -> Maybe a)
-> a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordWithQuotes :: forall (m :: * -> *) a b.
(Monad m, Eq a) =>
Bool
-> (a -> a -> Maybe a)
-> a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordWithQuotes Bool
keepQuotes a -> a -> Maybe a
tr a
escChar a -> Maybe a
toRight a -> Bool
isSep
(Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) =
(WordQuotedState s b a -> a -> m (Step (WordQuotedState s b a) b))
-> m (Initial (WordQuotedState s b a) b)
-> (WordQuotedState s b a -> m (Step (WordQuotedState s b a) 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 WordQuotedState s b a -> a -> m (Step (WordQuotedState s b a) b)
step m (Initial (WordQuotedState s b a) b)
forall {b} {a} {b}. m (Initial (WordQuotedState s b a) b)
initial WordQuotedState s b a -> m (Step (WordQuotedState s b a) b)
forall {a} {s}. WordQuotedState s b a -> m (Step s b)
extract
where
isInvalid :: b -> Bool
isInvalid = Bool -> b -> Bool
forall a b. a -> b -> a
const Bool
False
isEsc :: a -> Bool
isEsc = (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
escChar)
initial :: m (Initial (WordQuotedState s b a) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (WordQuotedState s b a) b
-> m (Initial (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (WordQuotedState s b a) b
-> m (Initial (WordQuotedState s b a) b))
-> Initial (WordQuotedState s b a) b
-> m (Initial (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$
case Step s b
res of
FL.Partial s
s -> WordQuotedState s b a -> Initial (WordQuotedState s b a) b
forall s b. s -> Initial s b
IPartial (s -> WordQuotedState s b a
forall s b a. s -> WordQuotedState s b a
WordQuotedSkipPre s
s)
FL.Done b
_ ->
String -> Initial (WordQuotedState s b a) b
forall a. HasCallStack => String -> a
error String
"wordKeepQuotes: fold done without input"
{-# INLINE processQuoted #-}
processQuoted :: s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s a
a Int
n a
ql a
qr = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> Int -> a -> a -> WordQuotedState s b a
forall s b a. s -> Int -> a -> a -> WordQuotedState s b a
WordQuotedWord s
s1 Int
n a
ql a
qr)
FL.Done b
b -> Int -> b -> Step (WordQuotedState s b a) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
{-# INLINE processUnquoted #-}
processUnquoted :: s -> a -> m (Step (WordQuotedState s b a) b)
processUnquoted s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s1 -> Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (s -> WordQuotedState s b a
forall s b a. s -> WordQuotedState s b a
WordUnquotedWord s
s1)
FL.Done b
b -> Int -> b -> Step (WordQuotedState s b a) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
step :: WordQuotedState s b a -> a -> m (Step (WordQuotedState s b a) b)
step (WordQuotedSkipPre s
s) a
a
| a -> Bool
isEsc a
a = Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ s -> WordQuotedState s b a
forall s b a. s -> WordQuotedState s b a
WordUnquotedEsc s
s
| a -> Bool
isSep a
a = Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ s -> WordQuotedState s b a
forall s b a. s -> WordQuotedState s b a
WordQuotedSkipPre s
s
| Bool
otherwise =
case a -> Maybe a
toRight a
a of
Just a
qr ->
if Bool
keepQuotes
then s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
forall {a} {b}.
s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s a
a Int
1 a
a a
qr
else Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> a -> a -> WordQuotedState s b a
forall s b a. s -> Int -> a -> a -> WordQuotedState s b a
WordQuotedWord s
s Int
1 a
a a
qr
Maybe a
Nothing
| a -> Bool
forall {b}. b -> Bool
isInvalid a
a ->
Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (WordQuotedState s b a) b
forall s b. String -> Step s b
Error String
"wordKeepQuotes: invalid unquoted char"
| Bool
otherwise -> s -> a -> m (Step (WordQuotedState s b a) b)
forall {b} {a}. s -> a -> m (Step (WordQuotedState s b a) b)
processUnquoted s
s a
a
step (WordUnquotedWord s
s) a
a
| a -> Bool
isEsc a
a = Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ s -> WordQuotedState s b a
forall s b a. s -> WordQuotedState s b a
WordUnquotedEsc s
s
| a -> Bool
isSep a
a = do
b
b <- s -> m b
ffinal s
s
Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ b -> WordQuotedState s b a
forall s b a. b -> WordQuotedState s b a
WordQuotedSkipPost b
b
| Bool
otherwise = do
case a -> Maybe a
toRight a
a of
Just a
qr ->
if Bool
keepQuotes
then s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
forall {a} {b}.
s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s a
a Int
1 a
a a
qr
else Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> a -> a -> WordQuotedState s b a
forall s b a. s -> Int -> a -> a -> WordQuotedState s b a
WordQuotedWord s
s Int
1 a
a a
qr
Maybe a
Nothing ->
if a -> Bool
forall {b}. b -> Bool
isInvalid a
a
then Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (WordQuotedState s b a) b
forall s b. String -> Step s b
Error String
"wordKeepQuotes: invalid unquoted char"
else s -> a -> m (Step (WordQuotedState s b a) b)
forall {b} {a}. s -> a -> m (Step (WordQuotedState s b a) b)
processUnquoted s
s a
a
step (WordQuotedWord s
s Int
n a
ql a
qr) a
a
| a -> Bool
isEsc a
a = Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ s -> Int -> a -> a -> WordQuotedState s b a
forall s b a. s -> Int -> a -> a -> WordQuotedState s b a
WordQuotedEsc s
s Int
n a
ql a
qr
| Bool
otherwise = do
if a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
qr
then
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
then if Bool
keepQuotes
then s -> a -> m (Step (WordQuotedState s b a) b)
forall {b} {a}. s -> a -> m (Step (WordQuotedState s b a) b)
processUnquoted s
s a
a
else Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Continue Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ s -> WordQuotedState s b a
forall s b a. s -> WordQuotedState s b a
WordUnquotedWord s
s
else s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
forall {a} {b}.
s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s a
a (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
ql a
qr
else if a
a a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
ql
then s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
forall {a} {b}.
s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s a
a (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) a
ql a
qr
else s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
forall {a} {b}.
s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s a
a Int
n a
ql a
qr
step (WordUnquotedEsc s
s) a
a = s -> a -> m (Step (WordQuotedState s b a) b)
forall {b} {a}. s -> a -> m (Step (WordQuotedState s b a) b)
processUnquoted s
s a
a
step (WordQuotedEsc s
s Int
n a
ql a
qr) a
a =
case a -> a -> Maybe a
tr a
ql a
a of
Maybe a
Nothing -> do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
escChar
case Step s b
res of
FL.Partial s
s1 -> s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
forall {a} {b}.
s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s1 a
a Int
n a
ql a
qr
FL.Done b
b -> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ Int -> b -> Step (WordQuotedState s b a) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
Just a
x -> s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
forall {a} {b}.
s -> a -> Int -> a -> a -> m (Step (WordQuotedState s b a) b)
processQuoted s
s a
x Int
n a
ql a
qr
step (WordQuotedSkipPost b
b) a
a =
Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b))
-> Step (WordQuotedState s b a) b
-> m (Step (WordQuotedState s b a) b)
forall a b. (a -> b) -> a -> b
$ if Bool -> Bool
not (a -> Bool
isSep a
a)
then Int -> b -> Step (WordQuotedState s b a) b
forall s b. Int -> b -> Step s b
Done Int
1 b
b
else Int -> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall s b. Int -> s -> Step s b
Partial Int
0 (WordQuotedState s b a -> Step (WordQuotedState s b a) b)
-> WordQuotedState s b a -> Step (WordQuotedState s b a) b
forall a b. (a -> b) -> a -> b
$ b -> WordQuotedState s b a
forall s b a. b -> WordQuotedState s b a
WordQuotedSkipPost b
b
err :: String -> m (Step s b)
err = 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))
-> (String -> Step s b) -> String -> m (Step s b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Step s b
forall s b. String -> Step s b
Error
extract :: WordQuotedState s b a -> m (Step s b)
extract (WordQuotedSkipPre s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (WordUnquotedWord s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (WordQuotedWord s
s Int
n a
_ a
_) =
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
else String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"wordWithQuotes: missing frame end"
extract WordQuotedEsc {} =
String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"wordWithQuotes: trailing escape"
extract (WordUnquotedEsc s
_) =
String -> m (Step s b)
forall {s} {b}. String -> m (Step s b)
err String
"wordWithQuotes: trailing escape"
extract (WordQuotedSkipPost b
b) = Step s b -> m (Step s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0 b
b)
{-# INLINE wordKeepQuotes #-}
wordKeepQuotes :: (Monad m, Eq a) =>
a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordKeepQuotes :: forall (m :: * -> *) a b.
(Monad m, Eq a) =>
a -> (a -> Maybe a) -> (a -> Bool) -> Fold m a b -> Parser a m b
wordKeepQuotes =
Bool
-> (a -> a -> Maybe a)
-> a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
forall (m :: * -> *) a b.
(Monad m, Eq a) =>
Bool
-> (a -> a -> Maybe a)
-> a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordWithQuotes Bool
True (\a
q a
x -> if a
q a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x then a -> Maybe a
forall a. a -> Maybe a
Just a
x else Maybe a
forall a. Maybe a
Nothing)
{-# INLINE wordProcessQuotes #-}
wordProcessQuotes :: (Monad m, Eq a) =>
a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordProcessQuotes :: forall (m :: * -> *) a b.
(Monad m, Eq a) =>
a -> (a -> Maybe a) -> (a -> Bool) -> Fold m a b -> Parser a m b
wordProcessQuotes =
Bool
-> (a -> a -> Maybe a)
-> a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
forall (m :: * -> *) a b.
(Monad m, Eq a) =>
Bool
-> (a -> a -> Maybe a)
-> a
-> (a -> Maybe a)
-> (a -> Bool)
-> Fold m a b
-> Parser a m b
wordWithQuotes Bool
False (\a
q a
x -> if a
q a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x then a -> Maybe a
forall a. a -> Maybe a
Just a
x else Maybe a
forall a. Maybe a
Nothing)
{-# ANN type GroupByState Fuse #-}
data GroupByState a s
= GroupByInit !s
| GroupByGrouping !a !s
{-# INLINE groupBy #-}
groupBy :: Monad m => (a -> a -> Bool) -> Fold m a b -> Parser a m b
groupBy :: forall (m :: * -> *) a b.
Monad m =>
(a -> a -> Bool) -> Fold m a b -> Parser a m b
groupBy a -> a -> Bool
eq (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) = (GroupByState a s -> a -> m (Step (GroupByState a s) b))
-> m (Initial (GroupByState a s) b)
-> (GroupByState a s -> m (Step (GroupByState a 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 GroupByState a s -> a -> m (Step (GroupByState a s) b)
step m (Initial (GroupByState a s) b)
forall {a}. m (Initial (GroupByState a s) b)
initial GroupByState a s -> m (Step (GroupByState a s) b)
forall {a} {s}. GroupByState a s -> m (Step s b)
extract
where
{-# INLINE grouper #-}
grouper :: s -> a -> a -> m (Step (GroupByState a s) b)
grouper s
s a
a0 a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (GroupByState a s) b -> m (Step (GroupByState a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (GroupByState a s) b -> m (Step (GroupByState a s) b))
-> Step (GroupByState a s) b -> m (Step (GroupByState a s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Done b
b -> Int -> b -> Step (GroupByState a s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
FL.Partial s
s1 -> Int -> GroupByState a s -> Step (GroupByState a s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (a -> s -> GroupByState a s
forall a s. a -> s -> GroupByState a s
GroupByGrouping a
a0 s
s1)
initial :: m (Initial (GroupByState a s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (GroupByState a s) b -> m (Initial (GroupByState a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial (GroupByState a s) b -> m (Initial (GroupByState a s) b))
-> Initial (GroupByState a s) b -> m (Initial (GroupByState a s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> GroupByState a s -> Initial (GroupByState a s) b
forall s b. s -> Initial s b
IPartial (GroupByState a s -> Initial (GroupByState a s) b)
-> GroupByState a s -> Initial (GroupByState a s) b
forall a b. (a -> b) -> a -> b
$ s -> GroupByState a s
forall a s. s -> GroupByState a s
GroupByInit s
s
FL.Done b
b -> b -> Initial (GroupByState a s) b
forall s b. b -> Initial s b
IDone b
b
step :: GroupByState a s -> a -> m (Step (GroupByState a s) b)
step (GroupByInit s
s) a
a = s -> a -> a -> m (Step (GroupByState a s) b)
forall {a}. s -> a -> a -> m (Step (GroupByState a s) b)
grouper s
s a
a a
a
step (GroupByGrouping a
a0 s
s) a
a =
if a -> a -> Bool
eq a
a0 a
a
then s -> a -> a -> m (Step (GroupByState a s) b)
forall {a}. s -> a -> a -> m (Step (GroupByState a s) b)
grouper s
s a
a0 a
a
else Int -> b -> Step (GroupByState a s) b
forall s b. Int -> b -> Step s b
Done Int
1 (b -> Step (GroupByState a s) b)
-> m b -> m (Step (GroupByState a s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
extract :: GroupByState a s -> m (Step s b)
extract (GroupByInit s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (GroupByGrouping a
_ s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
{-# INLINE groupByRolling #-}
groupByRolling :: Monad m => (a -> a -> Bool) -> Fold m a b -> Parser a m b
groupByRolling :: forall (m :: * -> *) a b.
Monad m =>
(a -> a -> Bool) -> Fold m a b -> Parser a m b
groupByRolling a -> a -> Bool
eq (Fold s -> a -> m (Step s b)
fstep m (Step s b)
finitial s -> m b
_ s -> m b
ffinal) = (GroupByState a s -> a -> m (Step (GroupByState a s) b))
-> m (Initial (GroupByState a s) b)
-> (GroupByState a s -> m (Step (GroupByState a 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 GroupByState a s -> a -> m (Step (GroupByState a s) b)
step m (Initial (GroupByState a s) b)
forall {a}. m (Initial (GroupByState a s) b)
initial GroupByState a s -> m (Step (GroupByState a s) b)
forall {a} {s}. GroupByState a s -> m (Step s b)
extract
where
{-# INLINE grouper #-}
grouper :: s -> a -> m (Step (GroupByState a s) b)
grouper s
s a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep s
s a
a
Step (GroupByState a s) b -> m (Step (GroupByState a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (GroupByState a s) b -> m (Step (GroupByState a s) b))
-> Step (GroupByState a s) b -> m (Step (GroupByState a s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Done b
b -> Int -> b -> Step (GroupByState a s) b
forall s b. Int -> b -> Step s b
Done Int
0 b
b
FL.Partial s
s1 -> Int -> GroupByState a s -> Step (GroupByState a s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (a -> s -> GroupByState a s
forall a s. a -> s -> GroupByState a s
GroupByGrouping a
a s
s1)
initial :: m (Initial (GroupByState a s) b)
initial = do
Step s b
res <- m (Step s b)
finitial
Initial (GroupByState a s) b -> m (Initial (GroupByState a s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial (GroupByState a s) b -> m (Initial (GroupByState a s) b))
-> Initial (GroupByState a s) b -> m (Initial (GroupByState a s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Partial s
s -> GroupByState a s -> Initial (GroupByState a s) b
forall s b. s -> Initial s b
IPartial (GroupByState a s -> Initial (GroupByState a s) b)
-> GroupByState a s -> Initial (GroupByState a s) b
forall a b. (a -> b) -> a -> b
$ s -> GroupByState a s
forall a s. s -> GroupByState a s
GroupByInit s
s
FL.Done b
b -> b -> Initial (GroupByState a s) b
forall s b. b -> Initial s b
IDone b
b
step :: GroupByState a s -> a -> m (Step (GroupByState a s) b)
step (GroupByInit s
s) a
a = s -> a -> m (Step (GroupByState a s) b)
grouper s
s a
a
step (GroupByGrouping a
a0 s
s) a
a =
if a -> a -> Bool
eq a
a0 a
a
then s -> a -> m (Step (GroupByState a s) b)
grouper s
s a
a
else Int -> b -> Step (GroupByState a s) b
forall s b. Int -> b -> Step s b
Done Int
1 (b -> Step (GroupByState a s) b)
-> m b -> m (Step (GroupByState a s) b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal s
s
extract :: GroupByState a s -> m (Step s b)
extract (GroupByInit s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
extract (GroupByGrouping a
_ s
s) = (b -> Step s b) -> m b -> m (Step 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
0) (m b -> m (Step s b)) -> m b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> m b
ffinal s
s
{-# ANN type GroupByStatePair Fuse #-}
data GroupByStatePair a s1 s2
= GroupByInitPair !s1 !s2
| GroupByGroupingPair !a !s1 !s2
| GroupByGroupingPairL !a !s1 !s2
| GroupByGroupingPairR !a !s1 !s2
{-# INLINE groupByRollingEither #-}
groupByRollingEither :: Monad m =>
(a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (Either b c)
groupByRollingEither :: forall (m :: * -> *) a b c.
Monad m =>
(a -> a -> Bool)
-> Fold m a b -> Fold m a c -> Parser a m (Either b c)
groupByRollingEither
a -> a -> Bool
eq
(Fold s -> a -> m (Step s b)
fstep1 m (Step s b)
finitial1 s -> m b
_ s -> m b
ffinal1)
(Fold s -> a -> m (Step s c)
fstep2 m (Step s c)
finitial2 s -> m c
_ s -> m c
ffinal2) = (GroupByStatePair a s s
-> a -> m (Step (GroupByStatePair a s s) (Either b c)))
-> m (Initial (GroupByStatePair a s s) (Either b c))
-> (GroupByStatePair a s s
-> m (Step (GroupByStatePair a s s) (Either b c)))
-> Parser a m (Either b 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 GroupByStatePair a s s
-> a -> m (Step (GroupByStatePair a s s) (Either b c))
step m (Initial (GroupByStatePair a s s) (Either b c))
forall {a}. m (Initial (GroupByStatePair a s s) (Either b c))
initial GroupByStatePair a s s
-> m (Step (GroupByStatePair a s s) (Either b c))
forall {s}. GroupByStatePair a s s -> m (Step s (Either b c))
extract
where
{-# INLINE grouper #-}
grouper :: s1 -> s2 -> a -> m (Step (GroupByStatePair a s1 s2) b)
grouper s1
s1 s2
s2 a
a = do
Step (GroupByStatePair a s1 s2) b
-> m (Step (GroupByStatePair a s1 s2) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (GroupByStatePair a s1 s2) b
-> m (Step (GroupByStatePair a s1 s2) b))
-> Step (GroupByStatePair a s1 s2) b
-> m (Step (GroupByStatePair a s1 s2) b)
forall a b. (a -> b) -> a -> b
$ Int
-> GroupByStatePair a s1 s2 -> Step (GroupByStatePair a s1 s2) b
forall s b. Int -> s -> Step s b
Continue Int
0 (a -> s1 -> s2 -> GroupByStatePair a s1 s2
forall a s1 s2. a -> s1 -> s2 -> GroupByStatePair a s1 s2
GroupByGroupingPair a
a s1
s1 s2
s2)
{-# INLINE grouperL2 #-}
grouperL2 :: s -> s2 -> a -> m (Step (GroupByStatePair a s s2) (Either b b))
grouperL2 s
s1 s2
s2 a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep1 s
s1 a
a
Step (GroupByStatePair a s s2) (Either b b)
-> m (Step (GroupByStatePair a s s2) (Either b b))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (GroupByStatePair a s s2) (Either b b)
-> m (Step (GroupByStatePair a s s2) (Either b b)))
-> Step (GroupByStatePair a s s2) (Either b b)
-> m (Step (GroupByStatePair a s s2) (Either b b))
forall a b. (a -> b) -> a -> b
$ case Step s b
res of
FL.Done b
b -> Int -> Either b b -> Step (GroupByStatePair a s s2) (Either b b)
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Either b b
forall a b. a -> Either a b
Left b
b)
FL.Partial s
s11 -> Int
-> GroupByStatePair a s s2
-> Step (GroupByStatePair a s s2) (Either b b)
forall s b. Int -> s -> Step s b
Partial Int
0 (a -> s -> s2 -> GroupByStatePair a s s2
forall a s1 s2. a -> s1 -> s2 -> GroupByStatePair a s1 s2
GroupByGroupingPairL a
a s
s11 s2
s2)
{-# INLINE grouperL #-}
grouperL :: s
-> s2 -> a -> a -> m (Step (GroupByStatePair a s s2) (Either b b))
grouperL s
s1 s2
s2 a
a0 a
a = do
Step s b
res <- s -> a -> m (Step s b)
fstep1 s
s1 a
a0
case Step s b
res of
FL.Done b
b -> Step (GroupByStatePair a s s2) (Either b b)
-> m (Step (GroupByStatePair a s s2) (Either b b))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (GroupByStatePair a s s2) (Either b b)
-> m (Step (GroupByStatePair a s s2) (Either b b)))
-> Step (GroupByStatePair a s s2) (Either b b)
-> m (Step (GroupByStatePair a s s2) (Either b b))
forall a b. (a -> b) -> a -> b
$ Int -> Either b b -> Step (GroupByStatePair a s s2) (Either b b)
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Either b b
forall a b. a -> Either a b
Left b
b)
FL.Partial s
s11 -> s -> s2 -> a -> m (Step (GroupByStatePair a s s2) (Either b b))
forall {s2} {b}.
s -> s2 -> a -> m (Step (GroupByStatePair a s s2) (Either b b))
grouperL2 s
s11 s2
s2 a
a
{-# INLINE grouperR2 #-}
grouperR2 :: s1 -> s -> a -> m (Step (GroupByStatePair a s1 s) (Either a c))
grouperR2 s1
s1 s
s2 a
a = do
Step s c
res <- s -> a -> m (Step s c)
fstep2 s
s2 a
a
Step (GroupByStatePair a s1 s) (Either a c)
-> m (Step (GroupByStatePair a s1 s) (Either a c))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (GroupByStatePair a s1 s) (Either a c)
-> m (Step (GroupByStatePair a s1 s) (Either a c)))
-> Step (GroupByStatePair a s1 s) (Either a c)
-> m (Step (GroupByStatePair a s1 s) (Either a c))
forall a b. (a -> b) -> a -> b
$ case Step s c
res of
FL.Done c
b -> Int -> Either a c -> Step (GroupByStatePair a s1 s) (Either a c)
forall s b. Int -> b -> Step s b
Done Int
0 (c -> Either a c
forall a b. b -> Either a b
Right c
b)
FL.Partial s
s21 -> Int
-> GroupByStatePair a s1 s
-> Step (GroupByStatePair a s1 s) (Either a c)
forall s b. Int -> s -> Step s b
Partial Int
0 (a -> s1 -> s -> GroupByStatePair a s1 s
forall a s1 s2. a -> s1 -> s2 -> GroupByStatePair a s1 s2
GroupByGroupingPairR a
a s1
s1 s
s21)
{-# INLINE grouperR #-}
grouperR :: s1
-> s -> a -> a -> m (Step (GroupByStatePair a s1 s) (Either a c))
grouperR s1
s1 s
s2 a
a0 a
a = do
Step s c
res <- s -> a -> m (Step s c)
fstep2 s
s2 a
a0
case Step s c
res of
FL.Done c
b -> Step (GroupByStatePair a s1 s) (Either a c)
-> m (Step (GroupByStatePair a s1 s) (Either a c))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (GroupByStatePair a s1 s) (Either a c)
-> m (Step (GroupByStatePair a s1 s) (Either a c)))
-> Step (GroupByStatePair a s1 s) (Either a c)
-> m (Step (GroupByStatePair a s1 s) (Either a c))
forall a b. (a -> b) -> a -> b
$ Int -> Either a c -> Step (GroupByStatePair a s1 s) (Either a c)
forall s b. Int -> b -> Step s b
Done Int
0 (c -> Either a c
forall a b. b -> Either a b
Right c
b)
FL.Partial s
s21 -> s1 -> s -> a -> m (Step (GroupByStatePair a s1 s) (Either a c))
forall {s1} {a}.
s1 -> s -> a -> m (Step (GroupByStatePair a s1 s) (Either a c))
grouperR2 s1
s1 s
s21 a
a
initial :: m (Initial (GroupByStatePair a s s) (Either b c))
initial = do
Step s b
res1 <- m (Step s b)
finitial1
Step s c
res2 <- m (Step s c)
finitial2
Initial (GroupByStatePair a s s) (Either b c)
-> m (Initial (GroupByStatePair a s s) (Either b c))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Initial (GroupByStatePair a s s) (Either b c)
-> m (Initial (GroupByStatePair a s s) (Either b c)))
-> Initial (GroupByStatePair a s s) (Either b c)
-> m (Initial (GroupByStatePair a s s) (Either b c))
forall a b. (a -> b) -> a -> b
$ case Step s b
res1 of
FL.Partial s
s1 ->
case Step s c
res2 of
FL.Partial s
s2 -> GroupByStatePair a s s
-> Initial (GroupByStatePair a s s) (Either b c)
forall s b. s -> Initial s b
IPartial (GroupByStatePair a s s
-> Initial (GroupByStatePair a s s) (Either b c))
-> GroupByStatePair a s s
-> Initial (GroupByStatePair a s s) (Either b c)
forall a b. (a -> b) -> a -> b
$ s -> s -> GroupByStatePair a s s
forall a s1 s2. s1 -> s2 -> GroupByStatePair a s1 s2
GroupByInitPair s
s1 s
s2
FL.Done c
b -> Either b c -> Initial (GroupByStatePair a s s) (Either b c)
forall s b. b -> Initial s b
IDone (c -> Either b c
forall a b. b -> Either a b
Right c
b)
FL.Done b
b -> Either b c -> Initial (GroupByStatePair a s s) (Either b c)
forall s b. b -> Initial s b
IDone (b -> Either b c
forall a b. a -> Either a b
Left b
b)
step :: GroupByStatePair a s s
-> a -> m (Step (GroupByStatePair a s s) (Either b c))
step (GroupByInitPair s
s1 s
s2) a
a = s -> s -> a -> m (Step (GroupByStatePair a s s) (Either b c))
forall {m :: * -> *} {s1} {s2} {a} {b}.
Monad m =>
s1 -> s2 -> a -> m (Step (GroupByStatePair a s1 s2) b)
grouper s
s1 s
s2 a
a
step (GroupByGroupingPair a
a0 s
s1 s
s2) a
a =
if Bool -> Bool
not (a -> a -> Bool
eq a
a0 a
a)
then s -> s -> a -> a -> m (Step (GroupByStatePair a s s) (Either b c))
forall {s2} {b}.
s
-> s2 -> a -> a -> m (Step (GroupByStatePair a s s2) (Either b b))
grouperL s
s1 s
s2 a
a0 a
a
else s -> s -> a -> a -> m (Step (GroupByStatePair a s s) (Either b c))
forall {s1} {a}.
s1
-> s -> a -> a -> m (Step (GroupByStatePair a s1 s) (Either a c))
grouperR s
s1 s
s2 a
a0 a
a
step (GroupByGroupingPairL a
a0 s
s1 s
s2) a
a =
if Bool -> Bool
not (a -> a -> Bool
eq a
a0 a
a)
then s -> s -> a -> m (Step (GroupByStatePair a s s) (Either b c))
forall {s2} {b}.
s -> s2 -> a -> m (Step (GroupByStatePair a s s2) (Either b b))
grouperL2 s
s1 s
s2 a
a
else Int -> Either b c -> Step (GroupByStatePair a s s) (Either b c)
forall s b. Int -> b -> Step s b
Done Int
1 (Either b c -> Step (GroupByStatePair a s s) (Either b c))
-> (b -> Either b c)
-> b
-> Step (GroupByStatePair a s s) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either b c
forall a b. a -> Either a b
Left (b -> Step (GroupByStatePair a s s) (Either b c))
-> m b -> m (Step (GroupByStatePair a s s) (Either b c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal1 s
s1
step (GroupByGroupingPairR a
a0 s
s1 s
s2) a
a =
if a -> a -> Bool
eq a
a0 a
a
then s -> s -> a -> m (Step (GroupByStatePair a s s) (Either b c))
forall {s1} {a}.
s1 -> s -> a -> m (Step (GroupByStatePair a s1 s) (Either a c))
grouperR2 s
s1 s
s2 a
a
else Int -> Either b c -> Step (GroupByStatePair a s s) (Either b c)
forall s b. Int -> b -> Step s b
Done Int
1 (Either b c -> Step (GroupByStatePair a s s) (Either b c))
-> (c -> Either b c)
-> c
-> Step (GroupByStatePair a s s) (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> Either b c
forall a b. b -> Either a b
Right (c -> Step (GroupByStatePair a s s) (Either b c))
-> m c -> m (Step (GroupByStatePair a s s) (Either b c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
ffinal2 s
s2
extract :: GroupByStatePair a s s -> m (Step s (Either b c))
extract (GroupByInitPair s
s1 s
_) = Int -> Either b c -> Step s (Either b c)
forall s b. Int -> b -> Step s b
Done Int
0 (Either b c -> Step s (Either b c))
-> (b -> Either b c) -> b -> Step s (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either b c
forall a b. a -> Either a b
Left (b -> Step s (Either b c)) -> m b -> m (Step s (Either b c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal1 s
s1
extract (GroupByGroupingPairL a
_ s
s1 s
_) = Int -> Either b c -> Step s (Either b c)
forall s b. Int -> b -> Step s b
Done Int
0 (Either b c -> Step s (Either b c))
-> (b -> Either b c) -> b -> Step s (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either b c
forall a b. a -> Either a b
Left (b -> Step s (Either b c)) -> m b -> m (Step s (Either b c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal1 s
s1
extract (GroupByGroupingPairR a
_ s
_ s
s2) = Int -> Either b c -> Step s (Either b c)
forall s b. Int -> b -> Step s b
Done Int
0 (Either b c -> Step s (Either b c))
-> (c -> Either b c) -> c -> Step s (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> Either b c
forall a b. b -> Either a b
Right (c -> Step s (Either b c)) -> m c -> m (Step s (Either b c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
ffinal2 s
s2
extract (GroupByGroupingPair a
a s
s1 s
_) = do
Step s b
res <- s -> a -> m (Step s b)
fstep1 s
s1 a
a
case Step s b
res of
FL.Done b
b -> Step s (Either b c) -> m (Step s (Either b c))
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s (Either b c) -> m (Step s (Either b c)))
-> Step s (Either b c) -> m (Step s (Either b c))
forall a b. (a -> b) -> a -> b
$ Int -> Either b c -> Step s (Either b c)
forall s b. Int -> b -> Step s b
Done Int
0 (b -> Either b c
forall a b. a -> Either a b
Left b
b)
FL.Partial s
s11 -> Int -> Either b c -> Step s (Either b c)
forall s b. Int -> b -> Step s b
Done Int
0 (Either b c -> Step s (Either b c))
-> (b -> Either b c) -> b -> Step s (Either b c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Either b c
forall a b. a -> Either a b
Left (b -> Step s (Either b c)) -> m b -> m (Step s (Either b c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m b
ffinal1 s
s11
{-# INLINE listEqBy #-}
listEqBy :: Monad m => (a -> a -> Bool) -> [a] -> Parser a m [a]
listEqBy :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> [a] -> Parser a m [a]
listEqBy a -> a -> Bool
cmp [a]
xs = (a -> a -> Bool) -> Stream m a -> Parser a m ()
forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> Stream m a -> Parser a m ()
streamEqByInternal a -> a -> Bool
cmp ([a] -> Stream m a
forall (m :: * -> *) a. Applicative m => [a] -> Stream m a
D.fromList [a]
xs) Parser a m () -> Parser a m [a] -> Parser a m [a]
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
*> [a] -> Parser a m [a]
forall (m :: * -> *) b a. Monad m => b -> Parser a m b
fromPure [a]
xs
{-# INLINE streamEqByInternal #-}
streamEqByInternal :: Monad m => (a -> a -> Bool) -> D.Stream m a -> Parser a m ()
streamEqByInternal :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> Stream m a -> Parser a m ()
streamEqByInternal a -> a -> Bool
cmp (D.Stream State StreamK m a -> s -> m (Step s a)
sstep s
state) = ((Maybe' a, s) -> a -> m (Step (Maybe' a, s) ()))
-> m (Initial (Maybe' a, s) ())
-> ((Maybe' a, s) -> m (Step (Maybe' a, s) ()))
-> Parser a m ()
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 (Maybe' a, s) -> a -> m (Step (Maybe' a, s) ())
step m (Initial (Maybe' a, s) ())
initial (Maybe' a, s) -> m (Step (Maybe' a, s) ())
forall {m :: * -> *} {p} {s} {b}. Monad m => p -> m (Step s b)
extract
where
initial :: m (Initial (Maybe' a, s) ())
initial = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
sstep State StreamK m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState s
state
case Step s a
r of
D.Yield a
x s
s -> Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ()))
-> Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ())
forall a b. (a -> b) -> a -> b
$ (Maybe' a, s) -> Initial (Maybe' a, s) ()
forall s b. s -> Initial s b
IPartial (a -> Maybe' a
forall a. a -> Maybe' a
Just' a
x, s
s)
Step s a
D.Stop -> Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ()))
-> Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ())
forall a b. (a -> b) -> a -> b
$ () -> Initial (Maybe' a, s) ()
forall s b. b -> Initial s b
IDone ()
D.Skip s
s -> Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ()))
-> Initial (Maybe' a, s) () -> m (Initial (Maybe' a, s) ())
forall a b. (a -> b) -> a -> b
$ (Maybe' a, s) -> Initial (Maybe' a, s) ()
forall s b. s -> Initial s b
IPartial (Maybe' a
forall a. Maybe' a
Nothing', s
s)
step :: (Maybe' a, s) -> a -> m (Step (Maybe' a, s) ())
step (Just' a
x, s
st) a
a =
if a
x a -> a -> Bool
`cmp` a
a
then do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
sstep State StreamK m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState s
st
Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ()))
-> Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ())
forall a b. (a -> b) -> a -> b
$ case Step s a
r of
D.Yield a
x1 s
s -> Int -> (Maybe' a, s) -> Step (Maybe' a, s) ()
forall s b. Int -> s -> Step s b
Continue Int
0 (a -> Maybe' a
forall a. a -> Maybe' a
Just' a
x1, s
s)
Step s a
D.Stop -> Int -> () -> Step (Maybe' a, s) ()
forall s b. Int -> b -> Step s b
Done Int
0 ()
D.Skip s
s -> Int -> (Maybe' a, s) -> Step (Maybe' a, s) ()
forall s b. Int -> s -> Step s b
Continue Int
1 (Maybe' a
forall a. Maybe' a
Nothing', s
s)
else Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ()))
-> Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ())
forall a b. (a -> b) -> a -> b
$ String -> Step (Maybe' a, s) ()
forall s b. String -> Step s b
Error String
"streamEqBy: mismtach occurred"
step (Maybe' a
Nothing', s
st) a
a = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
sstep State StreamK m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState s
st
Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ())
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ()))
-> Step (Maybe' a, s) () -> m (Step (Maybe' a, s) ())
forall a b. (a -> b) -> a -> b
$ case Step s a
r of
D.Yield a
x s
s -> do
if a
x a -> a -> Bool
`cmp` a
a
then Int -> (Maybe' a, s) -> Step (Maybe' a, s) ()
forall s b. Int -> s -> Step s b
Continue Int
0 (Maybe' a
forall a. Maybe' a
Nothing', s
s)
else String -> Step (Maybe' a, s) ()
forall s b. String -> Step s b
Error String
"streamEqBy: mismatch occurred"
Step s a
D.Stop -> Int -> () -> Step (Maybe' a, s) ()
forall s b. Int -> b -> Step s b
Done Int
1 ()
D.Skip s
s -> Int -> (Maybe' a, s) -> Step (Maybe' a, s) ()
forall s b. Int -> s -> Step s b
Continue Int
1 (Maybe' a
forall a. Maybe' a
Nothing', s
s)
extract :: p -> m (Step s b)
extract p
_ = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"streamEqBy: end of input"
{-# INLINE streamEqBy #-}
streamEqBy :: Monad m => (a -> a -> Bool) -> D.Stream m a -> Parser a m ()
streamEqBy :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> Stream m a -> Parser a m ()
streamEqBy a -> a -> Bool
cmp Stream m a
stream = (a -> a -> Bool) -> Stream m a -> Parser a m ()
forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> Stream m a -> Parser a m ()
streamEqByInternal a -> a -> Bool
cmp Stream m a
stream Parser a m () -> Parser a m () -> Parser a m ()
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
*> () -> Parser a m ()
forall (m :: * -> *) b a. Monad m => b -> Parser a m b
fromPure ()
{-# INLINE listEq #-}
listEq :: (Monad m, Eq a) => [a] -> Parser a m [a]
listEq :: forall (m :: * -> *) a. (Monad m, Eq a) => [a] -> Parser a m [a]
listEq = (a -> a -> Bool) -> [a] -> Parser a m [a]
forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> [a] -> Parser a m [a]
listEqBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINE subsequenceBy #-}
subsequenceBy ::
(a -> a -> Bool) -> Stream m a -> Parser a m ()
subsequenceBy :: forall a (m :: * -> *).
(a -> a -> Bool) -> Stream m a -> Parser a m ()
subsequenceBy = (a -> a -> Bool) -> Stream m a -> Parser a m ()
forall a. HasCallStack => a
undefined
{-# INLINE postscan #-}
postscan ::
Fold m a b -> Parser b m c -> Parser a m c
postscan :: forall (m :: * -> *) a b c.
Fold m a b -> Parser b m c -> Parser a m c
postscan = Fold m a b -> Parser b m c -> Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE zipWithM #-}
zipWithM :: Monad m =>
(a -> b -> m c) -> D.Stream m a -> Fold m c x -> Parser b m x
zipWithM :: forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> m c) -> Stream m a -> Fold m c x -> Parser b m x
zipWithM a -> b -> m c
zf (D.Stream State StreamK m a -> s -> m (Step s a)
sstep s
state) (Fold s -> c -> m (Step s x)
fstep m (Step s x)
finitial s -> m x
_ s -> m x
ffinal) =
((Maybe' a, s, s) -> b -> m (Step (Maybe' a, s, s) x))
-> m (Initial (Maybe' a, s, s) x)
-> ((Maybe' a, s, s) -> m (Step (Maybe' a, s, s) x))
-> Parser b m x
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 (Maybe' a, s, s) -> b -> m (Step (Maybe' a, s, s) x)
step m (Initial (Maybe' a, s, s) x)
initial (Maybe' a, s, s) -> m (Step (Maybe' a, s, s) x)
forall {m :: * -> *} {p} {s} {b}. Monad m => p -> m (Step s b)
extract
where
initial :: m (Initial (Maybe' a, s, s) x)
initial = do
Step s x
fres <- m (Step s x)
finitial
case Step s x
fres of
FL.Partial s
fs -> do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
sstep State StreamK m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState s
state
case Step s a
r of
D.Yield a
x s
s -> Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x))
-> Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ (Maybe' a, s, s) -> Initial (Maybe' a, s, s) x
forall s b. s -> Initial s b
IPartial (a -> Maybe' a
forall a. a -> Maybe' a
Just' a
x, s
s, s
fs)
Step s a
D.Stop -> do
x
x <- s -> m x
ffinal s
fs
Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x))
-> Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ x -> Initial (Maybe' a, s, s) x
forall s b. b -> Initial s b
IDone x
x
D.Skip s
s -> Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x))
-> Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ (Maybe' a, s, s) -> Initial (Maybe' a, s, s) x
forall s b. s -> Initial s b
IPartial (Maybe' a
forall a. Maybe' a
Nothing', s
s, s
fs)
FL.Done x
x -> Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x))
-> Initial (Maybe' a, s, s) x -> m (Initial (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ x -> Initial (Maybe' a, s, s) x
forall s b. b -> Initial s b
IDone x
x
step :: (Maybe' a, s, s) -> b -> m (Step (Maybe' a, s, s) x)
step (Just' a
a, s
st, s
fs) b
b = do
c
c <- a -> b -> m c
zf a
a b
b
Step s x
fres <- s -> c -> m (Step s x)
fstep s
fs c
c
case Step s x
fres of
FL.Partial s
fs1 -> do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
sstep State StreamK m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState s
st
case Step s a
r of
D.Yield a
x1 s
s -> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> (Maybe' a, s, s) -> Step (Maybe' a, s, s) x
forall s b. Int -> s -> Step s b
Continue Int
0 (a -> Maybe' a
forall a. a -> Maybe' a
Just' a
x1, s
s, s
fs1)
Step s a
D.Stop -> do
x
x <- s -> m x
ffinal s
fs1
Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> x -> Step (Maybe' a, s, s) x
forall s b. Int -> b -> Step s b
Done Int
0 x
x
D.Skip s
s -> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> (Maybe' a, s, s) -> Step (Maybe' a, s, s) x
forall s b. Int -> s -> Step s b
Continue Int
1 (Maybe' a
forall a. Maybe' a
Nothing', s
s, s
fs1)
FL.Done x
x -> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> x -> Step (Maybe' a, s, s) x
forall s b. Int -> b -> Step s b
Done Int
0 x
x
step (Maybe' a
Nothing', s
st, s
fs) b
b = do
Step s a
r <- State StreamK m a -> s -> m (Step s a)
sstep State StreamK m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState s
st
case Step s a
r of
D.Yield a
a s
s -> do
c
c <- a -> b -> m c
zf a
a b
b
Step s x
fres <- s -> c -> m (Step s x)
fstep s
fs c
c
case Step s x
fres of
FL.Partial s
fs1 ->
Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> (Maybe' a, s, s) -> Step (Maybe' a, s, s) x
forall s b. Int -> s -> Step s b
Continue Int
0 (Maybe' a
forall a. Maybe' a
Nothing', s
s, s
fs1)
FL.Done x
x -> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> x -> Step (Maybe' a, s, s) x
forall s b. Int -> b -> Step s b
Done Int
0 x
x
Step s a
D.Stop -> do
x
x <- s -> m x
ffinal s
fs
Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> x -> Step (Maybe' a, s, s) x
forall s b. Int -> b -> Step s b
Done Int
1 x
x
D.Skip s
s -> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x))
-> Step (Maybe' a, s, s) x -> m (Step (Maybe' a, s, s) x)
forall a b. (a -> b) -> a -> b
$ Int -> (Maybe' a, s, s) -> Step (Maybe' a, s, s) x
forall s b. Int -> s -> Step s b
Continue Int
1 (Maybe' a
forall a. Maybe' a
Nothing', s
s, s
fs)
extract :: p -> m (Step s b)
extract p
_ = 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
$ String -> Step s b
forall s b. String -> Step s b
Error String
"zipWithM: end of input"
{-# INLINE zip #-}
zip :: Monad m => D.Stream m a -> Fold m (a, b) x -> Parser b m x
zip :: forall (m :: * -> *) a b x.
Monad m =>
Stream m a -> Fold m (a, b) x -> Parser b m x
zip = (a -> b -> m (a, b))
-> Stream m a -> Fold m (a, b) x -> Parser b m x
forall (m :: * -> *) a b c x.
Monad m =>
(a -> b -> m c) -> Stream m a -> Fold m c x -> Parser b m x
zipWithM (((a, b) -> m (a, b)) -> a -> b -> m (a, b)
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (a, b) -> m (a, b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return)
{-# INLINE indexed #-}
indexed :: forall m a b. Monad m => Fold m (Int, a) b -> Parser a m b
indexed :: forall (m :: * -> *) a b.
Monad m =>
Fold m (Int, a) b -> Parser a m b
indexed = Stream m Int -> Fold m (Int, a) b -> Parser a m b
forall (m :: * -> *) a b x.
Monad m =>
Stream m a -> Fold m (a, b) x -> Parser b m x
zip (Int -> Stream m Int
forall (m :: * -> *) a.
(Monad m, Integral a, Bounded a) =>
a -> Stream m a
D.enumerateFromIntegral Int
0 :: D.Stream m Int)
{-# INLINE makeIndexFilter #-}
makeIndexFilter ::
(Fold m (s, a) b -> Parser a m b)
-> (((s, a) -> Bool) -> Fold m (s, a) b -> Fold m (s, a) b)
-> (((s, a) -> Bool) -> Fold m a b -> Parser a m b)
makeIndexFilter :: forall (m :: * -> *) s a b.
(Fold m (s, a) b -> Parser a m b)
-> (((s, a) -> Bool) -> Fold m (s, a) b -> Fold m (s, a) b)
-> ((s, a) -> Bool)
-> Fold m a b
-> Parser a m b
makeIndexFilter Fold m (s, a) b -> Parser a m b
f ((s, a) -> Bool) -> Fold m (s, a) b -> Fold m (s, a) b
comb (s, a) -> Bool
g = Fold m (s, a) b -> Parser a m b
f (Fold m (s, a) b -> Parser a m b)
-> (Fold m a b -> Fold m (s, a) b) -> Fold m a b -> Parser a m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((s, a) -> Bool) -> Fold m (s, a) b -> Fold m (s, a) b
comb (s, a) -> Bool
g (Fold m (s, a) b -> Fold m (s, a) b)
-> (Fold m a b -> Fold m (s, a) b) -> Fold m a b -> Fold m (s, a) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((s, a) -> a) -> Fold m a b -> Fold m (s, a) b
forall a b (m :: * -> *) r. (a -> b) -> Fold m b r -> Fold m a r
FL.lmap (s, a) -> a
forall a b. (a, b) -> b
snd
{-# INLINE sampleFromthen #-}
sampleFromthen :: Monad m => Int -> Int -> Fold m a b -> Parser a m b
sampleFromthen :: forall (m :: * -> *) a b.
Monad m =>
Int -> Int -> Fold m a b -> Parser a m b
sampleFromthen Int
offset Int
size =
(Fold m (Int, a) b -> Parser a m b)
-> (((Int, a) -> Bool) -> Fold m (Int, a) b -> Fold m (Int, a) b)
-> ((Int, a) -> Bool)
-> Fold m a b
-> Parser a m b
forall (m :: * -> *) s a b.
(Fold m (s, a) b -> Parser a m b)
-> (((s, a) -> Bool) -> Fold m (s, a) b -> Fold m (s, a) b)
-> ((s, a) -> Bool)
-> Fold m a b
-> Parser a m b
makeIndexFilter Fold m (Int, a) b -> Parser a m b
forall (m :: * -> *) a b.
Monad m =>
Fold m (Int, a) b -> Parser a m b
indexed ((Int, a) -> Bool) -> Fold m (Int, a) b -> Fold m (Int, a) b
forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Fold m a r -> Fold m a r
FL.filter (\(Int
i, a
_) -> (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
offset) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
size Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0)
{-# INLINE span #-}
span :: Monad m => (a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (b, c)
span :: forall (m :: * -> *) a b c.
Monad m =>
(a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (b, c)
span a -> Bool
p Fold m a b
f1 Fold m a c
f2 = (b -> c -> (b, c))
-> Parser a m b -> Parser a m c -> Parser a m (b, c)
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 -> Bool) -> Fold m a b -> Parser a m b
forall (m :: * -> *) a b.
Monad m =>
(a -> Bool) -> Fold m a b -> Parser a m b
takeWhile a -> Bool
p Fold m a b
f1) (Fold m a c -> Parser a m c
forall (m :: * -> *) a b. Monad m => Fold m a b -> Parser a m b
fromFold Fold m a c
f2)
{-# INLINE spanBy #-}
spanBy ::
Monad m
=> (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (b, c)
spanBy :: forall (m :: * -> *) a b c.
Monad m =>
(a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (b, c)
spanBy a -> a -> Bool
eq Fold m a b
f1 Fold m a c
f2 = (b -> c -> (b, c))
-> Parser a m b -> Parser a m c -> Parser a m (b, c)
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 -> a -> Bool) -> Fold m a b -> Parser a m b
forall (m :: * -> *) a b.
Monad m =>
(a -> a -> Bool) -> Fold m a b -> Parser a m b
groupBy a -> a -> Bool
eq Fold m a b
f1) (Fold m a c -> Parser a m c
forall (m :: * -> *) a b. Monad m => Fold m a b -> Parser a m b
fromFold Fold m a c
f2)
{-# INLINE spanByRolling #-}
spanByRolling ::
Monad m
=> (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (b, c)
spanByRolling :: forall (m :: * -> *) a b c.
Monad m =>
(a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser a m (b, c)
spanByRolling a -> a -> Bool
eq Fold m a b
f1 Fold m a c
f2 =
(b -> c -> (b, c))
-> Parser a m b -> Parser a m c -> Parser a m (b, c)
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 -> a -> Bool) -> Fold m a b -> Parser a m b
forall (m :: * -> *) a b.
Monad m =>
(a -> a -> Bool) -> Fold m a b -> Parser a m b
groupByRolling a -> a -> Bool
eq Fold m a b
f1) (Fold m a c -> Parser a m c
forall (m :: * -> *) a b. Monad m => Fold m a b -> Parser a m b
fromFold Fold m a c
f2)
{-# INLINE takeP #-}
takeP :: Monad m => Int -> Parser a m b -> Parser a m b
takeP :: forall (m :: * -> *) a b.
Monad m =>
Int -> Parser a m b -> Parser a m b
takeP Int
lim (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinitial s -> m (Step s b)
pextract) = (Tuple' Int s -> a -> m (Step (Tuple' Int s) b))
-> m (Initial (Tuple' Int s) b)
-> (Tuple' Int s -> m (Step (Tuple' Int 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 Tuple' Int s -> a -> m (Step (Tuple' Int s) b)
step m (Initial (Tuple' Int s) b)
initial Tuple' Int s -> m (Step (Tuple' Int s) b)
extract
where
initial :: m (Initial (Tuple' Int s) b)
initial = do
Initial s b
res <- m (Initial s b)
pinitial
case Initial s b
res of
IPartial s
s ->
if Int
lim Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b))
-> Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ Tuple' Int s -> Initial (Tuple' Int s) b
forall s b. s -> Initial s b
IPartial (Tuple' Int s -> Initial (Tuple' Int s) b)
-> Tuple' Int s -> Initial (Tuple' Int s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' Int
0 s
s
else s -> m (Initial (Tuple' Int s) b)
forall {s}. s -> m (Initial s b)
iextract s
s
IDone b
b -> Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b))
-> Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ b -> Initial (Tuple' Int s) b
forall s b. b -> Initial s b
IDone b
b
IError String
e -> Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b))
-> Initial (Tuple' Int s) b -> m (Initial (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ String -> Initial (Tuple' Int s) b
forall s b. String -> Initial s b
IError String
e
step :: Tuple' Int s -> a -> m (Step (Tuple' Int s) b)
step (Tuple' Int
cnt s
r) a
a = do
assertM(Int
cnt Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
lim)
Step s b
res <- s -> a -> m (Step s b)
pstep s
r a
a
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
case Step s b
res of
Partial Int
0 s
s -> do
assertM(Int
cnt1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
if Int
cnt1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
lim
then Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ Int -> Tuple' Int s -> Step (Tuple' Int s) b
forall s b. Int -> s -> Step s b
Partial Int
0 (Tuple' Int s -> Step (Tuple' Int s) b)
-> Tuple' Int s -> Step (Tuple' Int s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' Int
cnt1 s
s
else do
Step s b
r1 <- s -> m (Step s b)
pextract s
s
Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
r1 of
Done Int
n b
b -> Int -> b -> Step (Tuple' Int s) b
forall s b. Int -> b -> Step s b
Done Int
n b
b
Continue Int
n s
s1 -> Int -> Tuple' Int s -> Step (Tuple' Int s) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
s1)
Error String
err -> String -> Step (Tuple' Int s) b
forall s b. String -> Step s b
Error String
err
Partial Int
_ s
_ -> String -> Step (Tuple' Int s) b
forall a. HasCallStack => String -> a
error String
"takeP: Partial in extract"
Continue Int
0 s
s -> do
assertM(Int
cnt1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
if Int
cnt1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
lim
then Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ Int -> Tuple' Int s -> Step (Tuple' Int s) b
forall s b. Int -> s -> Step s b
Continue Int
0 (Tuple' Int s -> Step (Tuple' Int s) b)
-> Tuple' Int s -> Step (Tuple' Int s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' Int
cnt1 s
s
else do
Step s b
r1 <- s -> m (Step s b)
pextract s
s
Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
r1 of
Done Int
n b
b -> Int -> b -> Step (Tuple' Int s) b
forall s b. Int -> b -> Step s b
Done Int
n b
b
Continue Int
n s
s1 -> Int -> Tuple' Int s -> Step (Tuple' Int s) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
s1)
Error String
err -> String -> Step (Tuple' Int s) b
forall s b. String -> Step s b
Error String
err
Partial Int
_ s
_ -> String -> Step (Tuple' Int s) b
forall a. HasCallStack => String -> a
error String
"takeP: Partial in extract"
Partial Int
n s
s -> do
let taken :: Int
taken = Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n
assertM(Int
taken Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ Int -> Tuple' Int s -> Step (Tuple' Int s) b
forall s b. Int -> s -> Step s b
Partial Int
n (Tuple' Int s -> Step (Tuple' Int s) b)
-> Tuple' Int s -> Step (Tuple' Int s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' Int
taken s
s
Continue Int
n s
s -> do
let taken :: Int
taken = Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n
assertM(Int
taken Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0)
Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ Int -> Tuple' Int s -> Step (Tuple' Int s) b
forall s b. Int -> s -> Step s b
Continue Int
n (Tuple' Int s -> Step (Tuple' Int s) b)
-> Tuple' Int s -> Step (Tuple' Int s) b
forall a b. (a -> b) -> a -> b
$ Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' Int
taken s
s
Done Int
n b
b -> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ Int -> b -> Step (Tuple' Int s) b
forall s b. Int -> b -> Step s b
Done Int
n b
b
Error String
str -> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ String -> Step (Tuple' Int s) b
forall s b. String -> Step s b
Error String
str
extract :: Tuple' Int s -> m (Step (Tuple' Int s) b)
extract (Tuple' Int
cnt s
r) = do
Step s b
r1 <- s -> m (Step s b)
pextract s
r
Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b))
-> Step (Tuple' Int s) b -> m (Step (Tuple' Int s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
r1 of
Done Int
n b
b -> Int -> b -> Step (Tuple' Int s) b
forall s b. Int -> b -> Step s b
Done Int
n b
b
Continue Int
n s
s1 -> Int -> Tuple' Int s -> Step (Tuple' Int s) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> Tuple' Int s
forall a b. a -> b -> Tuple' a b
Tuple' (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
s1)
Error String
err -> String -> Step (Tuple' Int s) b
forall s b. String -> Step s b
Error String
err
Partial Int
_ s
_ -> String -> Step (Tuple' Int s) b
forall a. HasCallStack => String -> a
error String
"takeP: Partial in extract"
iextract :: s -> m (Initial s b)
iextract s
s = do
Step s b
r <- s -> m (Step s b)
pextract s
s
Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial s b -> m (Initial s b)) -> Initial s b -> m (Initial s b)
forall a b. (a -> b) -> a -> b
$ case Step s b
r of
Done Int
_ b
b -> b -> Initial s b
forall s b. b -> Initial s b
IDone b
b
Error String
err -> String -> Initial s b
forall s b. String -> Initial s b
IError String
err
Step s b
_ -> String -> Initial s b
forall a. HasCallStack => String -> a
error String
"Bug: takeP invalid state in initial"
{-# INLINE lookAhead #-}
lookAhead :: Monad m => Parser a m b -> Parser a m b
lookAhead :: forall (m :: * -> *) a b. Monad m => Parser a m b -> Parser a m b
lookAhead (Parser s -> a -> m (Step s b)
step1 m (Initial s b)
initial1 s -> m (Step s b)
_) = (Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b))
-> m (Initial (Tuple'Fused Int s) b)
-> (Tuple'Fused Int s -> m (Step (Tuple'Fused Int 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 Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b)
step m (Initial (Tuple'Fused Int s) b)
initial Tuple'Fused Int s -> m (Step (Tuple'Fused Int s) b)
forall {m :: * -> *} {a} {b} {s} {b}.
(Monad m, Show a) =>
Tuple'Fused a b -> m (Step s b)
extract
where
initial :: m (Initial (Tuple'Fused Int s) b)
initial = do
Initial s b
res <- m (Initial s b)
initial1
Initial (Tuple'Fused Int s) b -> m (Initial (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b))
-> Initial (Tuple'Fused Int s) b
-> m (Initial (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ case Initial s b
res of
IPartial s
s -> Tuple'Fused Int s -> Initial (Tuple'Fused Int s) b
forall s b. s -> Initial s b
IPartial (Int -> s -> Tuple'Fused Int s
forall a b. a -> b -> Tuple'Fused a b
Tuple'Fused Int
0 s
s)
IDone b
b -> b -> Initial (Tuple'Fused Int s) b
forall s b. b -> Initial s b
IDone b
b
IError String
e -> String -> Initial (Tuple'Fused Int s) b
forall s b. String -> Initial s b
IError String
e
step :: Tuple'Fused Int s -> a -> m (Step (Tuple'Fused Int s) b)
step (Tuple'Fused Int
cnt s
st) 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
Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b))
-> Step (Tuple'Fused Int s) b -> m (Step (Tuple'Fused Int s) b)
forall a b. (a -> b) -> a -> b
$ case Step s b
r of
Partial Int
n s
s -> Int -> Tuple'Fused Int s -> Step (Tuple'Fused Int s) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> Tuple'Fused Int s
forall a b. a -> b -> Tuple'Fused a b
Tuple'Fused (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
s)
Continue Int
n s
s -> Int -> Tuple'Fused Int s -> Step (Tuple'Fused Int s) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> Tuple'Fused Int s
forall a b. a -> b -> Tuple'Fused a b
Tuple'Fused (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
s)
Done Int
_ b
b -> Int -> b -> Step (Tuple'Fused Int s) b
forall s b. Int -> b -> Step s b
Done Int
cnt1 b
b
Error String
err -> String -> Step (Tuple'Fused Int s) b
forall s b. String -> Step s b
Error String
err
extract :: Tuple'Fused a b -> m (Step s b)
extract (Tuple'Fused a
n b
_) =
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
$ String -> Step s b
forall s b. String -> Step s b
Error
(String -> Step s b) -> String -> Step s b
forall a b. (a -> b) -> a -> b
$ String
"lookAhead: end of input after consuming "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" elements"
{-# ANN type DeintercalateAllState Fuse #-}
data DeintercalateAllState fs sp ss =
DeintercalateAllInitL !fs
| DeintercalateAllL !fs !sp
| DeintercalateAllInitR !fs
| DeintercalateAllR !fs !ss
{-# INLINE deintercalateAll #-}
deintercalateAll :: Monad m =>
Parser a m x
-> Parser a m y
-> Fold m (Either x y) z
-> Parser a m z
deintercalateAll :: forall (m :: * -> *) a x y z.
Monad m =>
Parser a m x
-> Parser a m y -> Fold m (Either x y) z -> Parser a m z
deintercalateAll
(Parser s -> a -> m (Step s x)
stepL m (Initial s x)
initialL s -> m (Step s x)
extractL)
(Parser s -> a -> m (Step s y)
stepR m (Initial s y)
initialR s -> m (Step s y)
_)
(Fold s -> Either x y -> m (Step s z)
fstep m (Step s z)
finitial s -> m z
_ s -> m z
ffinal) = (DeintercalateAllState s s s
-> a -> m (Step (DeintercalateAllState s s s) z))
-> m (Initial (DeintercalateAllState s s s) z)
-> (DeintercalateAllState s s s
-> m (Step (DeintercalateAllState s s s) z))
-> Parser a m z
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 DeintercalateAllState s s s
-> a -> m (Step (DeintercalateAllState s s s) z)
step m (Initial (DeintercalateAllState s s s) z)
forall {sp} {ss}. m (Initial (DeintercalateAllState s sp ss) z)
initial DeintercalateAllState s s s
-> m (Step (DeintercalateAllState s s s) z)
forall {ss} {ss}.
DeintercalateAllState s s ss
-> m (Step (DeintercalateAllState s s ss) z)
extract
where
errMsg :: String -> String -> a
errMsg String
p String
status =
String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"deintercalate: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
p String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" parser cannot "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
status String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" without input"
initial :: m (Initial (DeintercalateAllState s sp ss) z)
initial = do
Step s z
res <- m (Step s z)
finitial
case Step s z
res of
FL.Partial s
fs -> Initial (DeintercalateAllState s sp ss) z
-> m (Initial (DeintercalateAllState s sp ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (DeintercalateAllState s sp ss) z
-> m (Initial (DeintercalateAllState s sp ss) z))
-> Initial (DeintercalateAllState s sp ss) z
-> m (Initial (DeintercalateAllState s sp ss) z)
forall a b. (a -> b) -> a -> b
$ DeintercalateAllState s sp ss
-> Initial (DeintercalateAllState s sp ss) z
forall s b. s -> Initial s b
IPartial (DeintercalateAllState s sp ss
-> Initial (DeintercalateAllState s sp ss) z)
-> DeintercalateAllState s sp ss
-> Initial (DeintercalateAllState s sp ss) z
forall a b. (a -> b) -> a -> b
$ s -> DeintercalateAllState s sp ss
forall fs sp ss. fs -> DeintercalateAllState fs sp ss
DeintercalateAllInitL s
fs
FL.Done z
c -> Initial (DeintercalateAllState s sp ss) z
-> m (Initial (DeintercalateAllState s sp ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (DeintercalateAllState s sp ss) z
-> m (Initial (DeintercalateAllState s sp ss) z))
-> Initial (DeintercalateAllState s sp ss) z
-> m (Initial (DeintercalateAllState s sp ss) z)
forall a b. (a -> b) -> a -> b
$ z -> Initial (DeintercalateAllState s sp ss) z
forall s b. b -> Initial s b
IDone z
c
{-# INLINE processL #-}
processL :: m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL m (Step t b)
foldAction Int
n t -> s
nextState = do
Step t b
fres <- m (Step t b)
foldAction
case Step t b
fres of
FL.Partial t
fs1 -> 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
n (t -> s
nextState t
fs1)
FL.Done b
c -> 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
n b
c
{-# INLINE runStepL #-}
runStepL :: s -> s -> a -> m (Step (DeintercalateAllState s s ss) z)
runStepL s
fs s
sL a
a = do
Step s x
r <- s -> a -> m (Step s x)
stepL s
sL a
a
case Step s x
r of
Partial Int
n s
s -> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z))
-> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateAllState s s ss
-> Step (DeintercalateAllState s s ss) z
forall s b. Int -> s -> Step s b
Partial Int
n (s -> s -> DeintercalateAllState s s ss
forall fs sp ss. fs -> sp -> DeintercalateAllState fs sp ss
DeintercalateAllL s
fs s
s)
Continue Int
n s
s -> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z))
-> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateAllState s s ss
-> Step (DeintercalateAllState s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (s -> s -> DeintercalateAllState s s ss
forall fs sp ss. fs -> sp -> DeintercalateAllState fs sp ss
DeintercalateAllL s
fs s
s)
Done Int
n x
b ->
m (Step s z)
-> Int
-> (s -> DeintercalateAllState s s ss)
-> m (Step (DeintercalateAllState s s ss) z)
forall {m :: * -> *} {t} {b} {s}.
Monad m =>
m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL (s -> Either x y -> m (Step s z)
fstep s
fs (x -> Either x y
forall a b. a -> Either a b
Left x
b)) Int
n s -> DeintercalateAllState s s ss
forall fs sp ss. fs -> DeintercalateAllState fs sp ss
DeintercalateAllInitR
Error String
err -> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z))
-> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ String -> Step (DeintercalateAllState s s ss) z
forall s b. String -> Step s b
Error String
err
{-# INLINE processR #-}
processR :: m (Step fs b) -> Int -> m (Step (DeintercalateAllState fs s ss) b)
processR m (Step fs b)
foldAction Int
n = do
Step fs b
fres <- m (Step fs b)
foldAction
case Step fs b
fres of
FL.Partial fs
fs1 -> do
Initial s x
res <- m (Initial s x)
initialL
case Initial s x
res of
IPartial s
ps -> Step (DeintercalateAllState fs s ss) b
-> m (Step (DeintercalateAllState fs s ss) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState fs s ss) b
-> m (Step (DeintercalateAllState fs s ss) b))
-> Step (DeintercalateAllState fs s ss) b
-> m (Step (DeintercalateAllState fs s ss) b)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateAllState fs s ss
-> Step (DeintercalateAllState fs s ss) b
forall s b. Int -> s -> Step s b
Partial Int
n (fs -> s -> DeintercalateAllState fs s ss
forall fs sp ss. fs -> sp -> DeintercalateAllState fs sp ss
DeintercalateAllL fs
fs1 s
ps)
IDone x
_ -> String -> String -> m (Step (DeintercalateAllState fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (DeintercalateAllState fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
FL.Done b
c -> Step (DeintercalateAllState fs s ss) b
-> m (Step (DeintercalateAllState fs s ss) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState fs s ss) b
-> m (Step (DeintercalateAllState fs s ss) b))
-> Step (DeintercalateAllState fs s ss) b
-> m (Step (DeintercalateAllState fs s ss) b)
forall a b. (a -> b) -> a -> b
$ Int -> b -> Step (DeintercalateAllState fs s ss) b
forall s b. Int -> b -> Step s b
Done Int
n b
c
{-# INLINE runStepR #-}
runStepR :: s -> s -> a -> m (Step (DeintercalateAllState s s s) z)
runStepR s
fs s
sR a
a = do
Step s y
r <- s -> a -> m (Step s y)
stepR s
sR a
a
case Step s y
r of
Partial Int
n s
s -> Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z))
-> Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateAllState s s s
-> Step (DeintercalateAllState s s s) z
forall s b. Int -> s -> Step s b
Partial Int
n (s -> s -> DeintercalateAllState s s s
forall fs sp ss. fs -> ss -> DeintercalateAllState fs sp ss
DeintercalateAllR s
fs s
s)
Continue Int
n s
s -> Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z))
-> Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateAllState s s s
-> Step (DeintercalateAllState s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (s -> s -> DeintercalateAllState s s s
forall fs sp ss. fs -> ss -> DeintercalateAllState fs sp ss
DeintercalateAllR s
fs s
s)
Done Int
n y
b -> m (Step s z) -> Int -> m (Step (DeintercalateAllState s s s) z)
forall {fs} {b} {ss}.
m (Step fs b) -> Int -> m (Step (DeintercalateAllState fs s ss) b)
processR (s -> Either x y -> m (Step s z)
fstep s
fs (y -> Either x y
forall a b. b -> Either a b
Right y
b)) Int
n
Error String
err -> Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z))
-> Step (DeintercalateAllState s s s) z
-> m (Step (DeintercalateAllState s s s) z)
forall a b. (a -> b) -> a -> b
$ String -> Step (DeintercalateAllState s s s) z
forall s b. String -> Step s b
Error String
err
step :: DeintercalateAllState s s s
-> a -> m (Step (DeintercalateAllState s s s) z)
step (DeintercalateAllInitL s
fs) a
a = do
Initial s x
res <- m (Initial s x)
initialL
case Initial s x
res of
IPartial s
s -> s -> s -> a -> m (Step (DeintercalateAllState s s s) z)
forall {ss}.
s -> s -> a -> m (Step (DeintercalateAllState s s ss) z)
runStepL s
fs s
s a
a
IDone x
_ -> String -> String -> m (Step (DeintercalateAllState s s s) z)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (DeintercalateAllState s s s) z)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
step (DeintercalateAllL s
fs s
sL) a
a = s -> s -> a -> m (Step (DeintercalateAllState s s s) z)
forall {ss}.
s -> s -> a -> m (Step (DeintercalateAllState s s ss) z)
runStepL s
fs s
sL a
a
step (DeintercalateAllInitR s
fs) a
a = do
Initial s y
res <- m (Initial s y)
initialR
case Initial s y
res of
IPartial s
s -> s -> s -> a -> m (Step (DeintercalateAllState s s s) z)
runStepR s
fs s
s a
a
IDone y
_ -> String -> String -> m (Step (DeintercalateAllState s s s) z)
forall {a}. String -> String -> a
errMsg String
"right" String
"succeed"
IError String
_ -> String -> String -> m (Step (DeintercalateAllState s s s) z)
forall {a}. String -> String -> a
errMsg String
"right" String
"fail"
step (DeintercalateAllR s
fs s
sR) a
a = s -> s -> a -> m (Step (DeintercalateAllState s s s) z)
runStepR s
fs s
sR a
a
{-# INLINE extractResult #-}
extractResult :: Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs Either x y
r = do
Step s z
res <- s -> Either x y -> m (Step s z)
fstep s
fs Either x y
r
case Step s z
res of
FL.Partial s
fs1 -> (z -> Step s z) -> m z -> m (Step s z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step s z
forall s b. Int -> b -> Step s b
Done Int
n) (m z -> m (Step s z)) -> m z -> m (Step s z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs1
FL.Done z
c -> Step s z -> m (Step s z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> z -> Step s z
forall s b. Int -> b -> Step s b
Done Int
n z
c)
extract :: DeintercalateAllState s s ss
-> m (Step (DeintercalateAllState s s ss) z)
extract (DeintercalateAllInitL s
fs) = (z -> Step (DeintercalateAllState s s ss) z)
-> m z -> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step (DeintercalateAllState s s ss) z
forall s b. Int -> b -> Step s b
Done Int
0) (m z -> m (Step (DeintercalateAllState s s ss) z))
-> m z -> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs
extract (DeintercalateAllL s
fs s
sL) = do
Step s x
r <- s -> m (Step s x)
extractL s
sL
case Step s x
r of
Done Int
n x
b -> Int -> s -> Either x y -> m (Step (DeintercalateAllState s s ss) z)
forall {s}. Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs (x -> Either x y
forall a b. a -> Either a b
Left x
b)
Error String
err -> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z))
-> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ String -> Step (DeintercalateAllState s s ss) z
forall s b. String -> Step s b
Error String
err
Continue Int
n s
s -> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z))
-> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateAllState s s ss
-> Step (DeintercalateAllState s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (s -> s -> DeintercalateAllState s s ss
forall fs sp ss. fs -> sp -> DeintercalateAllState fs sp ss
DeintercalateAllL s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (DeintercalateAllState s s ss) z)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
extract (DeintercalateAllInitR s
fs) = (z -> Step (DeintercalateAllState s s ss) z)
-> m z -> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step (DeintercalateAllState s s ss) z
forall s b. Int -> b -> Step s b
Done Int
0) (m z -> m (Step (DeintercalateAllState s s ss) z))
-> m z -> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs
extract (DeintercalateAllR s
_ ss
_) =
Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z))
-> Step (DeintercalateAllState s s ss) z
-> m (Step (DeintercalateAllState s s ss) z)
forall a b. (a -> b) -> a -> b
$ String -> Step (DeintercalateAllState s s ss) z
forall s b. String -> Step s b
Error String
"deintercalateAll: input ended at 'Right' value"
{-# ANN type DeintercalateState Fuse #-}
data DeintercalateState b fs sp ss =
DeintercalateInitL !fs
| DeintercalateL !Int !fs !sp
| DeintercalateInitR !fs
| DeintercalateR !Int !fs !ss
| DeintercalateRL !Int !b !fs !sp
{-# INLINE deintercalate #-}
deintercalate :: Monad m =>
Parser a m x
-> Parser a m y
-> Fold m (Either x y) z
-> Parser a m z
deintercalate :: forall (m :: * -> *) a x y z.
Monad m =>
Parser a m x
-> Parser a m y -> Fold m (Either x y) z -> Parser a m z
deintercalate
(Parser s -> a -> m (Step s x)
stepL m (Initial s x)
initialL s -> m (Step s x)
extractL)
(Parser s -> a -> m (Step s y)
stepR m (Initial s y)
initialR s -> m (Step s y)
_)
(Fold s -> Either x y -> m (Step s z)
fstep m (Step s z)
finitial s -> m z
_ s -> m z
ffinal) = (DeintercalateState y s s s
-> a -> m (Step (DeintercalateState y s s s) z))
-> m (Initial (DeintercalateState y s s s) z)
-> (DeintercalateState y s s s
-> m (Step (DeintercalateState y s s s) z))
-> Parser a m z
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 DeintercalateState y s s s
-> a -> m (Step (DeintercalateState y s s s) z)
step m (Initial (DeintercalateState y s s s) z)
forall {b} {sp} {ss}. m (Initial (DeintercalateState b s sp ss) z)
initial DeintercalateState y s s s
-> m (Step (DeintercalateState y s s s) z)
forall {ss} {ss}.
DeintercalateState y s s ss
-> m (Step (DeintercalateState y s s ss) z)
extract
where
errMsg :: String -> String -> a
errMsg String
p String
status =
String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"deintercalate: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
p String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" parser cannot "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
status String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" without input"
initial :: m (Initial (DeintercalateState b s sp ss) z)
initial = do
Step s z
res <- m (Step s z)
finitial
case Step s z
res of
FL.Partial s
fs -> Initial (DeintercalateState b s sp ss) z
-> m (Initial (DeintercalateState b s sp ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (DeintercalateState b s sp ss) z
-> m (Initial (DeintercalateState b s sp ss) z))
-> Initial (DeintercalateState b s sp ss) z
-> m (Initial (DeintercalateState b s sp ss) z)
forall a b. (a -> b) -> a -> b
$ DeintercalateState b s sp ss
-> Initial (DeintercalateState b s sp ss) z
forall s b. s -> Initial s b
IPartial (DeintercalateState b s sp ss
-> Initial (DeintercalateState b s sp ss) z)
-> DeintercalateState b s sp ss
-> Initial (DeintercalateState b s sp ss) z
forall a b. (a -> b) -> a -> b
$ s -> DeintercalateState b s sp ss
forall b fs sp ss. fs -> DeintercalateState b fs sp ss
DeintercalateInitL s
fs
FL.Done z
c -> Initial (DeintercalateState b s sp ss) z
-> m (Initial (DeintercalateState b s sp ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (DeintercalateState b s sp ss) z
-> m (Initial (DeintercalateState b s sp ss) z))
-> Initial (DeintercalateState b s sp ss) z
-> m (Initial (DeintercalateState b s sp ss) z)
forall a b. (a -> b) -> a -> b
$ z -> Initial (DeintercalateState b s sp ss) z
forall s b. b -> Initial s b
IDone z
c
{-# INLINE processL #-}
processL :: m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL m (Step t b)
foldAction Int
n t -> s
nextState = do
Step t b
fres <- m (Step t b)
foldAction
case Step t b
fres of
FL.Partial t
fs1 -> 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
n (t -> s
nextState t
fs1)
FL.Done b
c -> 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
n b
c
{-# INLINE runStepL #-}
runStepL :: Int -> s -> s -> a -> m (Step (DeintercalateState b s s ss) z)
runStepL Int
cnt s
fs s
sL a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s x
r <- s -> a -> m (Step s x)
stepL s
sL a
a
case Step s x
r of
Partial Int
n s
s -> Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z))
-> Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState b s s ss
-> Step (DeintercalateState b s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> DeintercalateState b s s ss
forall b fs sp ss. Int -> fs -> sp -> DeintercalateState b fs sp ss
DeintercalateL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z))
-> Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState b s s ss
-> Step (DeintercalateState b s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> DeintercalateState b s s ss
forall b fs sp ss. Int -> fs -> sp -> DeintercalateState b fs sp ss
DeintercalateL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n x
b ->
m (Step s z)
-> Int
-> (s -> DeintercalateState b s s ss)
-> m (Step (DeintercalateState b s s ss) z)
forall {m :: * -> *} {t} {b} {s}.
Monad m =>
m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL (s -> Either x y -> m (Step s z)
fstep s
fs (x -> Either x y
forall a b. a -> Either a b
Left x
b)) Int
n s -> DeintercalateState b s s ss
forall b fs sp ss. fs -> DeintercalateState b fs sp ss
DeintercalateInitR
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z))
-> Step (DeintercalateState b s s ss) z
-> m (Step (DeintercalateState b s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (DeintercalateState b s s ss) z
forall s b. Int -> b -> Step s b
Done Int
cnt1 z
xs
{-# INLINE processR #-}
processR :: Int -> b -> fs -> Int -> m (Step (DeintercalateState b fs s ss) b)
processR Int
cnt b
b fs
fs Int
n = do
Initial s x
res <- m (Initial s x)
initialL
case Initial s x
res of
IPartial s
ps -> Step (DeintercalateState b fs s ss) b
-> m (Step (DeintercalateState b fs s ss) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState b fs s ss) b
-> m (Step (DeintercalateState b fs s ss) b))
-> Step (DeintercalateState b fs s ss) b
-> m (Step (DeintercalateState b fs s ss) b)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState b fs s ss
-> Step (DeintercalateState b fs s ss) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> b -> fs -> s -> DeintercalateState b fs s ss
forall b fs sp ss.
Int -> b -> fs -> sp -> DeintercalateState b fs sp ss
DeintercalateRL Int
cnt b
b fs
fs s
ps)
IDone x
_ -> String -> String -> m (Step (DeintercalateState b fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (DeintercalateState b fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
{-# INLINE runStepR #-}
runStepR :: Int -> s -> s -> a -> m (Step (DeintercalateState y s s s) z)
runStepR Int
cnt s
fs s
sR a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s y
r <- s -> a -> m (Step s y)
stepR s
sR a
a
case Step s y
r of
Partial Int
n s
s -> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState y s s s
-> Step (DeintercalateState y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> DeintercalateState y s s s
forall b fs sp ss. Int -> fs -> ss -> DeintercalateState b fs sp ss
DeintercalateR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState y s s s
-> Step (DeintercalateState y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> DeintercalateState y s s s
forall b fs sp ss. Int -> fs -> ss -> DeintercalateState b fs sp ss
DeintercalateR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n y
b -> Int -> y -> s -> Int -> m (Step (DeintercalateState y s s s) z)
forall {b} {fs} {ss} {b}.
Int -> b -> fs -> Int -> m (Step (DeintercalateState b fs s ss) b)
processR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
b s
fs Int
n
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (DeintercalateState y s s s) z
forall s b. Int -> b -> Step s b
Done Int
cnt1 z
xs
step :: DeintercalateState y s s s
-> a -> m (Step (DeintercalateState y s s s) z)
step (DeintercalateInitL s
fs) a
a = do
Initial s x
res <- m (Initial s x)
initialL
case Initial s x
res of
IPartial s
s -> Int -> s -> s -> a -> m (Step (DeintercalateState y s s s) z)
forall {b} {ss}.
Int -> s -> s -> a -> m (Step (DeintercalateState b s s ss) z)
runStepL Int
0 s
fs s
s a
a
IDone x
_ -> String -> String -> m (Step (DeintercalateState y s s s) z)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (DeintercalateState y s s s) z)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
step (DeintercalateL Int
cnt s
fs s
sL) a
a = Int -> s -> s -> a -> m (Step (DeintercalateState y s s s) z)
forall {b} {ss}.
Int -> s -> s -> a -> m (Step (DeintercalateState b s s ss) z)
runStepL Int
cnt s
fs s
sL a
a
step (DeintercalateInitR s
fs) a
a = do
Initial s y
res <- m (Initial s y)
initialR
case Initial s y
res of
IPartial s
s -> Int -> s -> s -> a -> m (Step (DeintercalateState y s s s) z)
runStepR Int
0 s
fs s
s a
a
IDone y
_ -> String -> String -> m (Step (DeintercalateState y s s s) z)
forall {a}. String -> String -> a
errMsg String
"right" String
"succeed"
IError String
_ -> String -> String -> m (Step (DeintercalateState y s s s) z)
forall {a}. String -> String -> a
errMsg String
"right" String
"fail"
step (DeintercalateR Int
cnt s
fs s
sR) a
a = Int -> s -> s -> a -> m (Step (DeintercalateState y s s s) z)
runStepR Int
cnt s
fs s
sR a
a
step (DeintercalateRL Int
cnt y
bR s
fs s
sL) a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s x
r <- s -> a -> m (Step s x)
stepL s
sL a
a
case Step s x
r of
Partial Int
n s
s -> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState y s s s
-> Step (DeintercalateState y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> y -> s -> s -> DeintercalateState y s s s
forall b fs sp ss.
Int -> b -> fs -> sp -> DeintercalateState b fs sp ss
DeintercalateRL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
bR s
fs s
s)
Continue Int
n s
s -> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState y s s s
-> Step (DeintercalateState y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> y -> s -> s -> DeintercalateState y s s s
forall b fs sp ss.
Int -> b -> fs -> sp -> DeintercalateState b fs sp ss
DeintercalateRL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
bR s
fs s
s)
Done Int
n x
bL -> do
Step s z
res <- s -> Either x y -> m (Step s z)
fstep s
fs (y -> Either x y
forall a b. b -> Either a b
Right y
bR)
case Step s z
res of
FL.Partial s
fs1 -> do
Step s z
fres <- s -> Either x y -> m (Step s z)
fstep s
fs1 (x -> Either x y
forall a b. a -> Either a b
Left x
bL)
case Step s z
fres of
FL.Partial s
fs2 ->
Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState y s s s
-> Step (DeintercalateState y s s s) z
forall s b. Int -> s -> Step s b
Partial Int
n (s -> DeintercalateState y s s s
forall b fs sp ss. fs -> DeintercalateState b fs sp ss
DeintercalateInitR s
fs2)
FL.Done z
c -> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (DeintercalateState y s s s) z
forall s b. Int -> b -> Step s b
Done Int
n z
c
FL.Done z
_ -> String -> m (Step (DeintercalateState y s s s) z)
forall a. HasCallStack => String -> a
error String
"Fold terminated consuming partial input"
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z))
-> Step (DeintercalateState y s s s) z
-> m (Step (DeintercalateState y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (DeintercalateState y s s s) z
forall s b. Int -> b -> Step s b
Done Int
cnt1 z
xs
{-# INLINE extractResult #-}
extractResult :: Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs Either x y
r = do
Step s z
res <- s -> Either x y -> m (Step s z)
fstep s
fs Either x y
r
case Step s z
res of
FL.Partial s
fs1 -> (z -> Step s z) -> m z -> m (Step s z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step s z
forall s b. Int -> b -> Step s b
Done Int
n) (m z -> m (Step s z)) -> m z -> m (Step s z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs1
FL.Done z
c -> Step s z -> m (Step s z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> z -> Step s z
forall s b. Int -> b -> Step s b
Done Int
n z
c)
extract :: DeintercalateState y s s ss
-> m (Step (DeintercalateState y s s ss) z)
extract (DeintercalateInitL s
fs) = (z -> Step (DeintercalateState y s s ss) z)
-> m z -> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step (DeintercalateState y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
0) (m z -> m (Step (DeintercalateState y s s ss) z))
-> m z -> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs
extract (DeintercalateL Int
cnt s
fs s
sL) = do
Step s x
r <- s -> m (Step s x)
extractL s
sL
case Step s x
r of
Done Int
n x
b -> Int -> s -> Either x y -> m (Step (DeintercalateState y s s ss) z)
forall {s}. Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs (x -> Either x y
forall a b. a -> Either a b
Left x
b)
Continue Int
n s
s -> Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z))
-> Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState y s s ss
-> Step (DeintercalateState y s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> DeintercalateState y s s ss
forall b fs sp ss. Int -> fs -> sp -> DeintercalateState b fs sp ss
DeintercalateL (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (DeintercalateState y s s ss) z)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z))
-> Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (DeintercalateState y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
cnt z
xs
extract (DeintercalateInitR s
fs) = (z -> Step (DeintercalateState y s s ss) z)
-> m z -> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step (DeintercalateState y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
0) (m z -> m (Step (DeintercalateState y s s ss) z))
-> m z -> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs
extract (DeintercalateR Int
cnt s
fs ss
_) = (z -> Step (DeintercalateState y s s ss) z)
-> m z -> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step (DeintercalateState y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
cnt) (m z -> m (Step (DeintercalateState y s s ss) z))
-> m z -> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs
extract (DeintercalateRL Int
cnt y
bR s
fs s
sL) = do
Step s x
r <- s -> m (Step s x)
extractL s
sL
case Step s x
r of
Done Int
n x
bL -> do
Step s z
res <- s -> Either x y -> m (Step s z)
fstep s
fs (y -> Either x y
forall a b. b -> Either a b
Right y
bR)
case Step s z
res of
FL.Partial s
fs1 -> Int -> s -> Either x y -> m (Step (DeintercalateState y s s ss) z)
forall {s}. Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs1 (x -> Either x y
forall a b. a -> Either a b
Left x
bL)
FL.Done z
_ -> String -> m (Step (DeintercalateState y s s ss) z)
forall a. HasCallStack => String -> a
error String
"Fold terminated consuming partial input"
Continue Int
n s
s -> Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z))
-> Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> DeintercalateState y s s ss
-> Step (DeintercalateState y s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> y -> s -> s -> DeintercalateState y s s ss
forall b fs sp ss.
Int -> b -> fs -> sp -> DeintercalateState b fs sp ss
DeintercalateRL (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
bR s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (DeintercalateState y s s ss) z)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z))
-> Step (DeintercalateState y s s ss) z
-> m (Step (DeintercalateState y s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (DeintercalateState y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
cnt z
xs
{-# ANN type Deintercalate1State Fuse #-}
data Deintercalate1State b fs sp ss =
Deintercalate1InitL !Int !fs !sp
| Deintercalate1InitR !fs
| Deintercalate1R !Int !fs !ss
| Deintercalate1RL !Int !b !fs !sp
{-# INLINE deintercalate1 #-}
deintercalate1 :: Monad m =>
Parser a m x
-> Parser a m y
-> Fold m (Either x y) z
-> Parser a m z
deintercalate1 :: forall (m :: * -> *) a x y z.
Monad m =>
Parser a m x
-> Parser a m y -> Fold m (Either x y) z -> Parser a m z
deintercalate1
(Parser s -> a -> m (Step s x)
stepL m (Initial s x)
initialL s -> m (Step s x)
extractL)
(Parser s -> a -> m (Step s y)
stepR m (Initial s y)
initialR s -> m (Step s y)
_)
(Fold s -> Either x y -> m (Step s z)
fstep m (Step s z)
finitial s -> m z
_ s -> m z
ffinal) = (Deintercalate1State y s s s
-> a -> m (Step (Deintercalate1State y s s s) z))
-> m (Initial (Deintercalate1State y s s s) z)
-> (Deintercalate1State y s s s
-> m (Step (Deintercalate1State y s s s) z))
-> Parser a m z
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 Deintercalate1State y s s s
-> a -> m (Step (Deintercalate1State y s s s) z)
step m (Initial (Deintercalate1State y s s s) z)
forall {b} {ss}. m (Initial (Deintercalate1State b s s ss) z)
initial Deintercalate1State y s s s
-> m (Step (Deintercalate1State y s s s) z)
forall {ss} {ss}.
Deintercalate1State y s s ss
-> m (Step (Deintercalate1State y s s ss) z)
extract
where
errMsg :: String -> String -> a
errMsg String
p String
status =
String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"deintercalate: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
p String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" parser cannot "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
status String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" without input"
initial :: m (Initial (Deintercalate1State b s s ss) z)
initial = do
Step s z
res <- m (Step s z)
finitial
case Step s z
res of
FL.Partial s
fs -> do
Initial s x
pres <- m (Initial s x)
initialL
case Initial s x
pres of
IPartial s
s -> Initial (Deintercalate1State b s s ss) z
-> m (Initial (Deintercalate1State b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Deintercalate1State b s s ss) z
-> m (Initial (Deintercalate1State b s s ss) z))
-> Initial (Deintercalate1State b s s ss) z
-> m (Initial (Deintercalate1State b s s ss) z)
forall a b. (a -> b) -> a -> b
$ Deintercalate1State b s s ss
-> Initial (Deintercalate1State b s s ss) z
forall s b. s -> Initial s b
IPartial (Deintercalate1State b s s ss
-> Initial (Deintercalate1State b s s ss) z)
-> Deintercalate1State b s s ss
-> Initial (Deintercalate1State b s s ss) z
forall a b. (a -> b) -> a -> b
$ Int -> s -> s -> Deintercalate1State b s s ss
forall b fs sp ss.
Int -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1InitL Int
0 s
fs s
s
IDone x
_ -> String -> String -> m (Initial (Deintercalate1State b s s ss) z)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Initial (Deintercalate1State b s s ss) z)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
FL.Done z
c -> Initial (Deintercalate1State b s s ss) z
-> m (Initial (Deintercalate1State b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Deintercalate1State b s s ss) z
-> m (Initial (Deintercalate1State b s s ss) z))
-> Initial (Deintercalate1State b s s ss) z
-> m (Initial (Deintercalate1State b s s ss) z)
forall a b. (a -> b) -> a -> b
$ z -> Initial (Deintercalate1State b s s ss) z
forall s b. b -> Initial s b
IDone z
c
{-# INLINE processL #-}
processL :: m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL m (Step t b)
foldAction Int
n t -> s
nextState = do
Step t b
fres <- m (Step t b)
foldAction
case Step t b
fres of
FL.Partial t
fs1 -> 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
n (t -> s
nextState t
fs1)
FL.Done b
c -> 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
n b
c
{-# INLINE runStepInitL #-}
runStepInitL :: Int -> s -> s -> a -> m (Step (Deintercalate1State b s s ss) z)
runStepInitL Int
cnt s
fs s
sL a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s x
r <- s -> a -> m (Step s x)
stepL s
sL a
a
case Step s x
r of
Partial Int
n s
s -> Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z))
-> Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State b s s ss
-> Step (Deintercalate1State b s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> Deintercalate1State b s s ss
forall b fs sp ss.
Int -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1InitL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z))
-> Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State b s s ss
-> Step (Deintercalate1State b s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> Deintercalate1State b s s ss
forall b fs sp ss.
Int -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1InitL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n x
b ->
m (Step s z)
-> Int
-> (s -> Deintercalate1State b s s ss)
-> m (Step (Deintercalate1State b s s ss) z)
forall {m :: * -> *} {t} {b} {s}.
Monad m =>
m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL (s -> Either x y -> m (Step s z)
fstep s
fs (x -> Either x y
forall a b. a -> Either a b
Left x
b)) Int
n s -> Deintercalate1State b s s ss
forall b fs sp ss. fs -> Deintercalate1State b fs sp ss
Deintercalate1InitR
Error String
err -> Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z))
-> Step (Deintercalate1State b s s ss) z
-> m (Step (Deintercalate1State b s s ss) z)
forall a b. (a -> b) -> a -> b
$ String -> Step (Deintercalate1State b s s ss) z
forall s b. String -> Step s b
Error String
err
{-# INLINE processR #-}
processR :: Int -> b -> fs -> Int -> m (Step (Deintercalate1State b fs s ss) b)
processR Int
cnt b
b fs
fs Int
n = do
Initial s x
res <- m (Initial s x)
initialL
case Initial s x
res of
IPartial s
ps -> Step (Deintercalate1State b fs s ss) b
-> m (Step (Deintercalate1State b fs s ss) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State b fs s ss) b
-> m (Step (Deintercalate1State b fs s ss) b))
-> Step (Deintercalate1State b fs s ss) b
-> m (Step (Deintercalate1State b fs s ss) b)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State b fs s ss
-> Step (Deintercalate1State b fs s ss) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> b -> fs -> s -> Deintercalate1State b fs s ss
forall b fs sp ss.
Int -> b -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1RL Int
cnt b
b fs
fs s
ps)
IDone x
_ -> String -> String -> m (Step (Deintercalate1State b fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (Deintercalate1State b fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
{-# INLINE runStepR #-}
runStepR :: Int -> s -> s -> a -> m (Step (Deintercalate1State y s s s) z)
runStepR Int
cnt s
fs s
sR a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s y
r <- s -> a -> m (Step s y)
stepR s
sR a
a
case Step s y
r of
Partial Int
n s
s -> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State y s s s
-> Step (Deintercalate1State y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> Deintercalate1State y s s s
forall b fs sp ss.
Int -> fs -> ss -> Deintercalate1State b fs sp ss
Deintercalate1R (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State y s s s
-> Step (Deintercalate1State y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> Deintercalate1State y s s s
forall b fs sp ss.
Int -> fs -> ss -> Deintercalate1State b fs sp ss
Deintercalate1R (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n y
b -> Int -> y -> s -> Int -> m (Step (Deintercalate1State y s s s) z)
forall {b} {fs} {ss} {b}.
Int -> b -> fs -> Int -> m (Step (Deintercalate1State b fs s ss) b)
processR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
b s
fs Int
n
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (Deintercalate1State y s s s) z
forall s b. Int -> b -> Step s b
Done Int
cnt1 z
xs
step :: Deintercalate1State y s s s
-> a -> m (Step (Deintercalate1State y s s s) z)
step (Deintercalate1InitL Int
cnt s
fs s
sL) a
a = Int -> s -> s -> a -> m (Step (Deintercalate1State y s s s) z)
forall {b} {ss}.
Int -> s -> s -> a -> m (Step (Deintercalate1State b s s ss) z)
runStepInitL Int
cnt s
fs s
sL a
a
step (Deintercalate1InitR s
fs) a
a = do
Initial s y
res <- m (Initial s y)
initialR
case Initial s y
res of
IPartial s
s -> Int -> s -> s -> a -> m (Step (Deintercalate1State y s s s) z)
runStepR Int
0 s
fs s
s a
a
IDone y
_ -> String -> String -> m (Step (Deintercalate1State y s s s) z)
forall {a}. String -> String -> a
errMsg String
"right" String
"succeed"
IError String
_ -> String -> String -> m (Step (Deintercalate1State y s s s) z)
forall {a}. String -> String -> a
errMsg String
"right" String
"fail"
step (Deintercalate1R Int
cnt s
fs s
sR) a
a = Int -> s -> s -> a -> m (Step (Deintercalate1State y s s s) z)
runStepR Int
cnt s
fs s
sR a
a
step (Deintercalate1RL Int
cnt y
bR s
fs s
sL) a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s x
r <- s -> a -> m (Step s x)
stepL s
sL a
a
case Step s x
r of
Partial Int
n s
s -> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State y s s s
-> Step (Deintercalate1State y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> y -> s -> s -> Deintercalate1State y s s s
forall b fs sp ss.
Int -> b -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1RL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
bR s
fs s
s)
Continue Int
n s
s -> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State y s s s
-> Step (Deintercalate1State y s s s) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> y -> s -> s -> Deintercalate1State y s s s
forall b fs sp ss.
Int -> b -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1RL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
bR s
fs s
s)
Done Int
n x
bL -> do
Step s z
res <- s -> Either x y -> m (Step s z)
fstep s
fs (y -> Either x y
forall a b. b -> Either a b
Right y
bR)
case Step s z
res of
FL.Partial s
fs1 -> do
Step s z
fres <- s -> Either x y -> m (Step s z)
fstep s
fs1 (x -> Either x y
forall a b. a -> Either a b
Left x
bL)
case Step s z
fres of
FL.Partial s
fs2 ->
Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State y s s s
-> Step (Deintercalate1State y s s s) z
forall s b. Int -> s -> Step s b
Partial Int
n (s -> Deintercalate1State y s s s
forall b fs sp ss. fs -> Deintercalate1State b fs sp ss
Deintercalate1InitR s
fs2)
FL.Done z
c -> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (Deintercalate1State y s s s) z
forall s b. Int -> b -> Step s b
Done Int
n z
c
FL.Done z
_ -> String -> m (Step (Deintercalate1State y s s s) z)
forall a. HasCallStack => String -> a
error String
"Fold terminated consuming partial input"
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z))
-> Step (Deintercalate1State y s s s) z
-> m (Step (Deintercalate1State y s s s) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (Deintercalate1State y s s s) z
forall s b. Int -> b -> Step s b
Done Int
cnt1 z
xs
{-# INLINE extractResult #-}
extractResult :: Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs Either x y
r = do
Step s z
res <- s -> Either x y -> m (Step s z)
fstep s
fs Either x y
r
case Step s z
res of
FL.Partial s
fs1 -> (z -> Step s z) -> m z -> m (Step s z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step s z
forall s b. Int -> b -> Step s b
Done Int
n) (m z -> m (Step s z)) -> m z -> m (Step s z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs1
FL.Done z
c -> Step s z -> m (Step s z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> z -> Step s z
forall s b. Int -> b -> Step s b
Done Int
n z
c)
extract :: Deintercalate1State y s s ss
-> m (Step (Deintercalate1State y s s ss) z)
extract (Deintercalate1InitL Int
cnt s
fs s
sL) = do
Step s x
r <- s -> m (Step s x)
extractL s
sL
case Step s x
r of
Done Int
n x
b -> Int -> s -> Either x y -> m (Step (Deintercalate1State y s s ss) z)
forall {s}. Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs (x -> Either x y
forall a b. a -> Either a b
Left x
b)
Continue Int
n s
s -> Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z))
-> Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State y s s ss
-> Step (Deintercalate1State y s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> Deintercalate1State y s s ss
forall b fs sp ss.
Int -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1InitL (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (Deintercalate1State y s s ss) z)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
Error String
err -> Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z))
-> Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> a -> b
$ String -> Step (Deintercalate1State y s s ss) z
forall s b. String -> Step s b
Error String
err
extract (Deintercalate1InitR s
fs) = (z -> Step (Deintercalate1State y s s ss) z)
-> m z -> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step (Deintercalate1State y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
0) (m z -> m (Step (Deintercalate1State y s s ss) z))
-> m z -> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs
extract (Deintercalate1R Int
cnt s
fs ss
_) = (z -> Step (Deintercalate1State y s s ss) z)
-> m z -> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> z -> Step (Deintercalate1State y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
cnt) (m z -> m (Step (Deintercalate1State y s s ss) z))
-> m z -> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> a -> b
$ s -> m z
ffinal s
fs
extract (Deintercalate1RL Int
cnt y
bR s
fs s
sL) = do
Step s x
r <- s -> m (Step s x)
extractL s
sL
case Step s x
r of
Done Int
n x
bL -> do
Step s z
res <- s -> Either x y -> m (Step s z)
fstep s
fs (y -> Either x y
forall a b. b -> Either a b
Right y
bR)
case Step s z
res of
FL.Partial s
fs1 -> Int -> s -> Either x y -> m (Step (Deintercalate1State y s s ss) z)
forall {s}. Int -> s -> Either x y -> m (Step s z)
extractResult Int
n s
fs1 (x -> Either x y
forall a b. a -> Either a b
Left x
bL)
FL.Done z
_ -> String -> m (Step (Deintercalate1State y s s ss) z)
forall a. HasCallStack => String -> a
error String
"Fold terminated consuming partial input"
Continue Int
n s
s -> Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z))
-> Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int
-> Deintercalate1State y s s ss
-> Step (Deintercalate1State y s s ss) z
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> y -> s -> s -> Deintercalate1State y s s ss
forall b fs sp ss.
Int -> b -> fs -> sp -> Deintercalate1State b fs sp ss
Deintercalate1RL (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) y
bR s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (Deintercalate1State y s s ss) z)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
Error String
_ -> do
z
xs <- s -> m z
ffinal s
fs
Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z))
-> Step (Deintercalate1State y s s ss) z
-> m (Step (Deintercalate1State y s s ss) z)
forall a b. (a -> b) -> a -> b
$ Int -> z -> Step (Deintercalate1State y s s ss) z
forall s b. Int -> b -> Step s b
Done Int
cnt z
xs
{-# ANN type SepByState Fuse #-}
data SepByState fs sp ss =
SepByInitL !fs
| SepByL !Int !fs !sp
| SepByInitR !fs
| SepByR !Int !fs !ss
{-# INLINE sepBy #-}
sepBy :: Monad m =>
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
sepBy :: forall (m :: * -> *) a b x c.
Monad m =>
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
sepBy
(Parser s -> a -> m (Step s b)
stepL m (Initial s b)
initialL s -> m (Step s b)
extractL)
(Parser s -> a -> m (Step s x)
stepR m (Initial s x)
initialR s -> m (Step s x)
_)
(Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
_ s -> m c
ffinal) = (SepByState s s s -> a -> m (Step (SepByState s s s) c))
-> m (Initial (SepByState s s s) c)
-> (SepByState s s s -> m (Step (SepByState s 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 SepByState s s s -> a -> m (Step (SepByState s s s) c)
step m (Initial (SepByState s s s) c)
forall {sp} {ss}. m (Initial (SepByState s sp ss) c)
initial SepByState s s s -> m (Step (SepByState s s s) c)
forall {ss} {ss}.
SepByState s s ss -> m (Step (SepByState s s ss) c)
extract
where
errMsg :: String -> String -> a
errMsg String
p String
status =
String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"sepBy: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
p String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" parser cannot "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
status String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" without input"
initial :: m (Initial (SepByState s sp ss) c)
initial = do
Step s c
res <- m (Step s c)
finitial
case Step s c
res of
FL.Partial s
fs -> Initial (SepByState s sp ss) c
-> m (Initial (SepByState s sp ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SepByState s sp ss) c
-> m (Initial (SepByState s sp ss) c))
-> Initial (SepByState s sp ss) c
-> m (Initial (SepByState s sp ss) c)
forall a b. (a -> b) -> a -> b
$ SepByState s sp ss -> Initial (SepByState s sp ss) c
forall s b. s -> Initial s b
IPartial (SepByState s sp ss -> Initial (SepByState s sp ss) c)
-> SepByState s sp ss -> Initial (SepByState s sp ss) c
forall a b. (a -> b) -> a -> b
$ s -> SepByState s sp ss
forall fs sp ss. fs -> SepByState fs sp ss
SepByInitL s
fs
FL.Done c
c -> Initial (SepByState s sp ss) c
-> m (Initial (SepByState s sp ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SepByState s sp ss) c
-> m (Initial (SepByState s sp ss) c))
-> Initial (SepByState s sp ss) c
-> m (Initial (SepByState s sp ss) c)
forall a b. (a -> b) -> a -> b
$ c -> Initial (SepByState s sp ss) c
forall s b. b -> Initial s b
IDone c
c
{-# INLINE processL #-}
processL :: m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL m (Step t b)
foldAction Int
n t -> s
nextState = do
Step t b
fres <- m (Step t b)
foldAction
case Step t b
fres of
FL.Partial t
fs1 -> 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
n (t -> s
nextState t
fs1)
FL.Done b
c -> 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
n b
c
{-# INLINE runStepL #-}
runStepL :: Int -> s -> s -> a -> m (Step (SepByState s s ss) c)
runStepL Int
cnt s
fs s
sL a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s b
r <- s -> a -> m (Step s b)
stepL s
sL a
a
case Step s b
r of
Partial Int
n s
s -> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c))
-> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepByState s s ss -> Step (SepByState s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepByState s s ss
forall fs sp ss. Int -> fs -> sp -> SepByState fs sp ss
SepByL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c))
-> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepByState s s ss -> Step (SepByState s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepByState s s ss
forall fs sp ss. Int -> fs -> sp -> SepByState fs sp ss
SepByL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n b
b ->
m (Step s c)
-> Int
-> (s -> SepByState s s ss)
-> m (Step (SepByState s s ss) c)
forall {m :: * -> *} {t} {b} {s}.
Monad m =>
m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL (s -> b -> m (Step s c)
fstep s
fs b
b) Int
n s -> SepByState s s ss
forall fs sp ss. fs -> SepByState fs sp ss
SepByInitR
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c))
-> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SepByState s s ss) c
forall s b. Int -> b -> Step s b
Done Int
cnt1 c
xs
{-# INLINE processR #-}
processR :: Int -> fs -> Int -> m (Step (SepByState fs s ss) b)
processR Int
cnt fs
fs Int
n = do
Initial s b
res <- m (Initial s b)
initialL
case Initial s b
res of
IPartial s
ps -> Step (SepByState fs s ss) b -> m (Step (SepByState fs s ss) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState fs s ss) b -> m (Step (SepByState fs s ss) b))
-> Step (SepByState fs s ss) b -> m (Step (SepByState fs s ss) b)
forall a b. (a -> b) -> a -> b
$ Int -> SepByState fs s ss -> Step (SepByState fs s ss) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> fs -> s -> SepByState fs s ss
forall fs sp ss. Int -> fs -> sp -> SepByState fs sp ss
SepByL Int
cnt fs
fs s
ps)
IDone b
_ -> String -> String -> m (Step (SepByState fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (SepByState fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
{-# INLINE runStepR #-}
runStepR :: Int -> s -> s -> a -> m (Step (SepByState s s s) c)
runStepR Int
cnt s
fs s
sR a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s x
r <- s -> a -> m (Step s x)
stepR s
sR a
a
case Step s x
r of
Partial Int
n s
s -> Step (SepByState s s s) c -> m (Step (SepByState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s s) c -> m (Step (SepByState s s s) c))
-> Step (SepByState s s s) c -> m (Step (SepByState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepByState s s s -> Step (SepByState s s s) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepByState s s s
forall fs sp ss. Int -> fs -> ss -> SepByState fs sp ss
SepByR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (SepByState s s s) c -> m (Step (SepByState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s s) c -> m (Step (SepByState s s s) c))
-> Step (SepByState s s s) c -> m (Step (SepByState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepByState s s s -> Step (SepByState s s s) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepByState s s s
forall fs sp ss. Int -> fs -> ss -> SepByState fs sp ss
SepByR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n x
_ -> Int -> s -> Int -> m (Step (SepByState s s s) c)
forall {fs} {ss} {b}.
Int -> fs -> Int -> m (Step (SepByState fs s ss) b)
processR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs Int
n
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (SepByState s s s) c -> m (Step (SepByState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s s) c -> m (Step (SepByState s s s) c))
-> Step (SepByState s s s) c -> m (Step (SepByState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SepByState s s s) c
forall s b. Int -> b -> Step s b
Done Int
cnt1 c
xs
step :: SepByState s s s -> a -> m (Step (SepByState s s s) c)
step (SepByInitL s
fs) a
a = do
Initial s b
res <- m (Initial s b)
initialL
case Initial s b
res of
IPartial s
s -> Int -> s -> s -> a -> m (Step (SepByState s s s) c)
forall {ss}. Int -> s -> s -> a -> m (Step (SepByState s s ss) c)
runStepL Int
0 s
fs s
s a
a
IDone b
_ -> String -> String -> m (Step (SepByState s s s) c)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (SepByState s s s) c)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
step (SepByL Int
cnt s
fs s
sL) a
a = Int -> s -> s -> a -> m (Step (SepByState s s s) c)
forall {ss}. Int -> s -> s -> a -> m (Step (SepByState s s ss) c)
runStepL Int
cnt s
fs s
sL a
a
step (SepByInitR s
fs) a
a = do
Initial s x
res <- m (Initial s x)
initialR
case Initial s x
res of
IPartial s
s -> Int -> s -> s -> a -> m (Step (SepByState s s s) c)
runStepR Int
0 s
fs s
s a
a
IDone x
_ -> String -> String -> m (Step (SepByState s s s) c)
forall {a}. String -> String -> a
errMsg String
"right" String
"succeed"
IError String
_ -> String -> String -> m (Step (SepByState s s s) c)
forall {a}. String -> String -> a
errMsg String
"right" String
"fail"
step (SepByR Int
cnt s
fs s
sR) a
a = Int -> s -> s -> a -> m (Step (SepByState s s s) c)
runStepR Int
cnt s
fs s
sR a
a
{-# INLINE extractResult #-}
extractResult :: Int -> s -> b -> m (Step s c)
extractResult Int
n s
fs b
r = do
Step s c
res <- s -> b -> m (Step s c)
fstep s
fs b
r
case Step s c
res of
FL.Partial s
fs1 -> (c -> Step s c) -> m c -> m (Step 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 s c
forall s b. Int -> b -> Step s b
Done Int
n) (m c -> m (Step s c)) -> m c -> m (Step s c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs1
FL.Done c
c -> Step s c -> m (Step s c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step s c
forall s b. Int -> b -> Step s b
Done Int
n c
c)
extract :: SepByState s s ss -> m (Step (SepByState s s ss) c)
extract (SepByInitL s
fs) = (c -> Step (SepByState s s ss) c)
-> m c -> m (Step (SepByState s s ss) 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 (SepByState s s ss) c
forall s b. Int -> b -> Step s b
Done Int
0) (m c -> m (Step (SepByState s s ss) c))
-> m c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs
extract (SepByL Int
cnt s
fs s
sL) = do
Step s b
r <- s -> m (Step s b)
extractL s
sL
case Step s b
r of
Done Int
n b
b -> Int -> s -> b -> m (Step (SepByState s s ss) c)
forall {s}. Int -> s -> b -> m (Step s c)
extractResult Int
n s
fs b
b
Continue Int
n s
s -> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c))
-> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepByState s s ss -> Step (SepByState s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepByState s s ss
forall fs sp ss. Int -> fs -> sp -> SepByState fs sp ss
SepByL (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (SepByState s s ss) c)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c))
-> Step (SepByState s s ss) c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SepByState s s ss) c
forall s b. Int -> b -> Step s b
Done Int
cnt c
xs
extract (SepByInitR s
fs) = (c -> Step (SepByState s s ss) c)
-> m c -> m (Step (SepByState s s ss) 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 (SepByState s s ss) c
forall s b. Int -> b -> Step s b
Done Int
0) (m c -> m (Step (SepByState s s ss) c))
-> m c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs
extract (SepByR Int
cnt s
fs ss
_) = (c -> Step (SepByState s s ss) c)
-> m c -> m (Step (SepByState s s ss) 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 (SepByState s s ss) c
forall s b. Int -> b -> Step s b
Done Int
cnt) (m c -> m (Step (SepByState s s ss) c))
-> m c -> m (Step (SepByState s s ss) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs
{-# INLINE sepByAll #-}
sepByAll :: Monad m =>
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
sepByAll :: forall (m :: * -> *) a b x c.
Monad m =>
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
sepByAll Parser a m b
p1 Parser a m x
p2 Fold m b c
f = Parser a m b
-> Parser a m x -> Fold m (Either b x) c -> Parser a m c
forall (m :: * -> *) a x y z.
Monad m =>
Parser a m x
-> Parser a m y -> Fold m (Either x y) z -> Parser a m z
deintercalateAll Parser a m b
p1 Parser a m x
p2 (Fold m b c -> Fold m (Either b x) c
forall (m :: * -> *) a c b.
Monad m =>
Fold m a c -> Fold m (Either a b) c
FL.catLefts Fold m b c
f)
{-# ANN type SepBy1State Fuse #-}
data SepBy1State fs sp ss =
SepBy1InitL !Int !fs sp
| SepBy1L !Int !fs !sp
| SepBy1InitR !fs
| SepBy1R !Int !fs !ss
{-# INLINE sepBy1 #-}
sepBy1 :: Monad m =>
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
sepBy1 :: forall (m :: * -> *) a b x c.
Monad m =>
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
sepBy1
(Parser s -> a -> m (Step s b)
stepL m (Initial s b)
initialL s -> m (Step s b)
extractL)
(Parser s -> a -> m (Step s x)
stepR m (Initial s x)
initialR s -> m (Step s x)
_)
(Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
_ s -> m c
ffinal) = (SepBy1State s s s -> a -> m (Step (SepBy1State s s s) c))
-> m (Initial (SepBy1State s s s) c)
-> (SepBy1State s s s -> m (Step (SepBy1State s 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 SepBy1State s s s -> a -> m (Step (SepBy1State s s s) c)
step m (Initial (SepBy1State s s s) c)
forall {ss}. m (Initial (SepBy1State s s ss) c)
initial SepBy1State s s s -> m (Step (SepBy1State s s s) c)
forall {ss} {ss}.
SepBy1State s s ss -> m (Step (SepBy1State s s ss) c)
extract
where
errMsg :: String -> String -> a
errMsg String
p String
status =
String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"sepBy: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
p String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" parser cannot "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
status String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" without input"
initial :: m (Initial (SepBy1State s s ss) c)
initial = do
Step s c
res <- m (Step s c)
finitial
case Step s c
res of
FL.Partial s
fs -> do
Initial s b
pres <- m (Initial s b)
initialL
case Initial s b
pres of
IPartial s
s -> Initial (SepBy1State s s ss) c
-> m (Initial (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SepBy1State s s ss) c
-> m (Initial (SepBy1State s s ss) c))
-> Initial (SepBy1State s s ss) c
-> m (Initial (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ SepBy1State s s ss -> Initial (SepBy1State s s ss) c
forall s b. s -> Initial s b
IPartial (SepBy1State s s ss -> Initial (SepBy1State s s ss) c)
-> SepBy1State s s ss -> Initial (SepBy1State s s ss) c
forall a b. (a -> b) -> a -> b
$ Int -> s -> s -> SepBy1State s s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1InitL Int
0 s
fs s
s
IDone b
_ -> String -> String -> m (Initial (SepBy1State s s ss) c)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Initial (SepBy1State s s ss) c)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
FL.Done c
c -> Initial (SepBy1State s s ss) c
-> m (Initial (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (SepBy1State s s ss) c
-> m (Initial (SepBy1State s s ss) c))
-> Initial (SepBy1State s s ss) c
-> m (Initial (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ c -> Initial (SepBy1State s s ss) c
forall s b. b -> Initial s b
IDone c
c
{-# INLINE processL #-}
processL :: m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL m (Step t b)
foldAction Int
n t -> s
nextState = do
Step t b
fres <- m (Step t b)
foldAction
case Step t b
fres of
FL.Partial t
fs1 -> 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
n (t -> s
nextState t
fs1)
FL.Done b
c -> 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 -> b -> Step s b
forall s b. Int -> b -> Step s b
Done Int
n b
c
{-# INLINE runStepInitL #-}
runStepInitL :: Int -> s -> s -> a -> m (Step (SepBy1State s s ss) c)
runStepInitL Int
cnt s
fs s
sL a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s b
r <- s -> a -> m (Step s b)
stepL s
sL a
a
case Step s b
r of
Partial Int
n s
s -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s ss -> Step (SepBy1State s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1InitL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s ss -> Step (SepBy1State s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1InitL (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n b
b ->
m (Step s c)
-> Int
-> (s -> SepBy1State s s ss)
-> m (Step (SepBy1State s s ss) c)
forall {m :: * -> *} {t} {b} {s}.
Monad m =>
m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL (s -> b -> m (Step s c)
fstep s
fs b
b) Int
n s -> SepBy1State s s ss
forall fs sp ss. fs -> SepBy1State fs sp ss
SepBy1InitR
Error String
err -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (SepBy1State s s ss) c
forall s b. String -> Step s b
Error String
err
{-# INLINE runStepL #-}
runStepL :: Int -> s -> s -> a -> m (Step (SepBy1State s s ss) c)
runStepL Int
cnt s
fs s
sL a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s b
r <- s -> a -> m (Step s b)
stepL s
sL a
a
case Step s b
r of
Partial Int
n s
s -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s ss -> Step (SepBy1State s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1L (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s ss -> Step (SepBy1State s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1L (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n b
b ->
m (Step s c)
-> Int
-> (s -> SepBy1State s s ss)
-> m (Step (SepBy1State s s ss) c)
forall {m :: * -> *} {t} {b} {s}.
Monad m =>
m (Step t b) -> Int -> (t -> s) -> m (Step s b)
processL (s -> b -> m (Step s c)
fstep s
fs b
b) Int
n s -> SepBy1State s s ss
forall fs sp ss. fs -> SepBy1State fs sp ss
SepBy1InitR
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SepBy1State s s ss) c
forall s b. Int -> b -> Step s b
Done Int
cnt1 c
xs
{-# INLINE processR #-}
processR :: Int -> fs -> Int -> m (Step (SepBy1State fs s ss) b)
processR Int
cnt fs
fs Int
n = do
Initial s b
res <- m (Initial s b)
initialL
case Initial s b
res of
IPartial s
ps -> Step (SepBy1State fs s ss) b -> m (Step (SepBy1State fs s ss) b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State fs s ss) b -> m (Step (SepBy1State fs s ss) b))
-> Step (SepBy1State fs s ss) b -> m (Step (SepBy1State fs s ss) b)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State fs s ss -> Step (SepBy1State fs s ss) b
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> fs -> s -> SepBy1State fs s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1L Int
cnt fs
fs s
ps)
IDone b
_ -> String -> String -> m (Step (SepBy1State fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"succeed"
IError String
_ -> String -> String -> m (Step (SepBy1State fs s ss) b)
forall {a}. String -> String -> a
errMsg String
"left" String
"fail"
{-# INLINE runStepR #-}
runStepR :: Int -> s -> s -> a -> m (Step (SepBy1State s s s) c)
runStepR Int
cnt s
fs s
sR a
a = do
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Step s x
r <- s -> a -> m (Step s x)
stepR s
sR a
a
case Step s x
r of
Partial Int
n s
s -> Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c))
-> Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s s -> Step (SepBy1State s s s) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s s
forall fs sp ss. Int -> fs -> ss -> SepBy1State fs sp ss
SepBy1R (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Continue Int
n s
s -> Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c))
-> Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s s -> Step (SepBy1State s s s) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s s
forall fs sp ss. Int -> fs -> ss -> SepBy1State fs sp ss
SepBy1R (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Done Int
n x
_ -> Int -> s -> Int -> m (Step (SepBy1State s s s) c)
forall {fs} {ss} {b}.
Int -> fs -> Int -> m (Step (SepBy1State fs s ss) b)
processR (Int
cnt1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs Int
n
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c))
-> Step (SepBy1State s s s) c -> m (Step (SepBy1State s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SepBy1State s s s) c
forall s b. Int -> b -> Step s b
Done Int
cnt1 c
xs
step :: SepBy1State s s s -> a -> m (Step (SepBy1State s s s) c)
step (SepBy1InitL Int
cnt s
fs s
sL) a
a = Int -> s -> s -> a -> m (Step (SepBy1State s s s) c)
forall {ss}. Int -> s -> s -> a -> m (Step (SepBy1State s s ss) c)
runStepInitL Int
cnt s
fs s
sL a
a
step (SepBy1L Int
cnt s
fs s
sL) a
a = Int -> s -> s -> a -> m (Step (SepBy1State s s s) c)
forall {ss}. Int -> s -> s -> a -> m (Step (SepBy1State s s ss) c)
runStepL Int
cnt s
fs s
sL a
a
step (SepBy1InitR s
fs) a
a = do
Initial s x
res <- m (Initial s x)
initialR
case Initial s x
res of
IPartial s
s -> Int -> s -> s -> a -> m (Step (SepBy1State s s s) c)
runStepR Int
0 s
fs s
s a
a
IDone x
_ -> String -> String -> m (Step (SepBy1State s s s) c)
forall {a}. String -> String -> a
errMsg String
"right" String
"succeed"
IError String
_ -> String -> String -> m (Step (SepBy1State s s s) c)
forall {a}. String -> String -> a
errMsg String
"right" String
"fail"
step (SepBy1R Int
cnt s
fs s
sR) a
a = Int -> s -> s -> a -> m (Step (SepBy1State s s s) c)
runStepR Int
cnt s
fs s
sR a
a
{-# INLINE extractResult #-}
extractResult :: Int -> s -> b -> m (Step s c)
extractResult Int
n s
fs b
r = do
Step s c
res <- s -> b -> m (Step s c)
fstep s
fs b
r
case Step s c
res of
FL.Partial s
fs1 -> (c -> Step s c) -> m c -> m (Step 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 s c
forall s b. Int -> b -> Step s b
Done Int
n) (m c -> m (Step s c)) -> m c -> m (Step s c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs1
FL.Done c
c -> Step s c -> m (Step s c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step s c
forall s b. Int -> b -> Step s b
Done Int
n c
c)
extract :: SepBy1State s s ss -> m (Step (SepBy1State s s ss) c)
extract (SepBy1InitL Int
cnt s
fs s
sL) = do
Step s b
r <- s -> m (Step s b)
extractL s
sL
case Step s b
r of
Done Int
n b
b -> Int -> s -> b -> m (Step (SepBy1State s s ss) c)
forall {s}. Int -> s -> b -> m (Step s c)
extractResult Int
n s
fs b
b
Continue Int
n s
s -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s ss -> Step (SepBy1State s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1InitL (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (SepBy1State s s ss) c)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
Error String
err -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (SepBy1State s s ss) c
forall s b. String -> Step s b
Error String
err
extract (SepBy1L Int
cnt s
fs s
sL) = do
Step s b
r <- s -> m (Step s b)
extractL s
sL
case Step s b
r of
Done Int
n b
b -> Int -> s -> b -> m (Step (SepBy1State s s ss) c)
forall {s}. Int -> s -> b -> m (Step s c)
extractResult Int
n s
fs b
b
Continue Int
n s
s -> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> SepBy1State s s ss -> Step (SepBy1State s s ss) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> SepBy1State s s ss
forall fs sp ss. Int -> fs -> sp -> SepBy1State fs sp ss
SepBy1L (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (SepBy1State s s ss) c)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
Error String
_ -> do
c
xs <- s -> m c
ffinal s
fs
Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c))
-> Step (SepBy1State s s ss) c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (SepBy1State s s ss) c
forall s b. Int -> b -> Step s b
Done Int
cnt c
xs
extract (SepBy1InitR s
fs) = (c -> Step (SepBy1State s s ss) c)
-> m c -> m (Step (SepBy1State s s ss) 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 (SepBy1State s s ss) c
forall s b. Int -> b -> Step s b
Done Int
0) (m c -> m (Step (SepBy1State s s ss) c))
-> m c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs
extract (SepBy1R Int
cnt s
fs ss
_) = (c -> Step (SepBy1State s s ss) c)
-> m c -> m (Step (SepBy1State s s ss) 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 (SepBy1State s s ss) c
forall s b. Int -> b -> Step s b
Done Int
cnt) (m c -> m (Step (SepBy1State s s ss) c))
-> m c -> m (Step (SepBy1State s s ss) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs
{-# INLINE roundRobin #-}
roundRobin ::
t (Parser a m b) -> Fold m b c -> Parser a m c
roundRobin :: forall (t :: * -> *) a (m :: * -> *) b c.
t (Parser a m b) -> Fold m b c -> Parser a m c
roundRobin t (Parser a m b)
_ps Fold m b c
_f = Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE sequence #-}
sequence :: Monad m =>
D.Stream m (Parser a m b) -> Fold m b c -> Parser a m c
sequence :: forall (m :: * -> *) a b c.
Monad m =>
Stream m (Parser a m b) -> Fold m b c -> Parser a m c
sequence (D.Stream State StreamK m (Parser a m b) -> s -> m (Step s (Parser a m b))
sstep s
sstate) (Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
_ s -> m c
ffinal) =
((Maybe' (Parser a m b), s, s)
-> a -> m (Step (Maybe' (Parser a m b), s, s) c))
-> m (Initial (Maybe' (Parser a m b), s, s) c)
-> ((Maybe' (Parser a m b), s, s)
-> m (Step (Maybe' (Parser a m b), 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 (Maybe' (Parser a m b), s, s)
-> a -> m (Step (Maybe' (Parser a m b), s, s) c)
step m (Initial (Maybe' (Parser a m b), s, s) c)
forall {a}. m (Initial (Maybe' a, s, s) c)
initial (Maybe' (Parser a m b), s, s)
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall {a} {b}.
(Maybe' (Parser a m b), b, s)
-> m (Step (Maybe' (Parser a m b), b, s) c)
extract
where
initial :: m (Initial (Maybe' a, s, s) c)
initial = do
Step s c
fres <- m (Step s c)
finitial
case Step s c
fres of
FL.Partial s
fs -> Initial (Maybe' a, s, s) c -> m (Initial (Maybe' a, s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s, s) c -> m (Initial (Maybe' a, s, s) c))
-> Initial (Maybe' a, s, s) c -> m (Initial (Maybe' a, s, s) c)
forall a b. (a -> b) -> a -> b
$ (Maybe' a, s, s) -> Initial (Maybe' a, s, s) c
forall s b. s -> Initial s b
IPartial (Maybe' a
forall a. Maybe' a
Nothing', s
sstate, s
fs)
FL.Done c
c -> Initial (Maybe' a, s, s) c -> m (Initial (Maybe' a, s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (Maybe' a, s, s) c -> m (Initial (Maybe' a, s, s) c))
-> Initial (Maybe' a, s, s) c -> m (Initial (Maybe' a, s, s) c)
forall a b. (a -> b) -> a -> b
$ c -> Initial (Maybe' a, s, s) c
forall s b. b -> Initial s b
IDone c
c
step :: (Maybe' (Parser a m b), s, s)
-> a -> m (Step (Maybe' (Parser a m b), s, s) c)
step (Maybe' (Parser a m b)
Nothing', s
ss, s
fs) a
_ = do
Step s (Parser a m b)
sres <- State StreamK m (Parser a m b) -> s -> m (Step s (Parser a m b))
sstep State StreamK m (Parser a m b)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. State t m a
defState s
ss
case Step s (Parser a m b)
sres of
D.Yield Parser a m b
p s
ss1 -> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (Maybe' (Parser a m b), s, s)
-> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> s -> Step s b
Continue Int
1 (Parser a m b -> Maybe' (Parser a m b)
forall a. a -> Maybe' a
Just' Parser a m b
p, s
ss1, s
fs)
Step s (Parser a m b)
D.Stop -> do
c
c <- s -> m c
ffinal s
fs
Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> b -> Step s b
Done Int
1 c
c
D.Skip s
ss1 -> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (Maybe' (Parser a m b), s, s)
-> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> s -> Step s b
Continue Int
1 (Maybe' (Parser a m b)
forall a. Maybe' a
Nothing', s
ss1, s
fs)
step (Just' (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinit s -> m (Step s b)
pextr), s
ss, s
fs) a
a = do
Initial s b
ps <- m (Initial s b)
pinit
case Initial s b
ps of
IPartial s
ps1 -> do
Step s b
pres <- s -> a -> m (Step s b)
pstep s
ps1 a
a
case Step s b
pres of
Partial Int
n s
ps2 ->
let newP :: Maybe' (Parser a m b)
newP =
Parser a m b -> Maybe' (Parser a m b)
forall a. a -> Maybe' a
Just' (Parser a m b -> Maybe' (Parser a m b))
-> Parser a m b -> Maybe' (Parser a m b)
forall a b. (a -> b) -> a -> b
$ (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)
pstep (Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial s b -> m (Initial s b)) -> Initial s b -> m (Initial s b)
forall a b. (a -> b) -> a -> b
$ s -> Initial s b
forall s b. s -> Initial s b
IPartial s
ps2) s -> m (Step s b)
pextr
in Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (Maybe' (Parser a m b), s, s)
-> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> s -> Step s b
Partial Int
n (Maybe' (Parser a m b)
newP, s
ss, s
fs)
Continue Int
n s
ps2 ->
let newP :: Maybe' (Parser a m b)
newP =
Parser a m b -> Maybe' (Parser a m b)
forall a. a -> Maybe' a
Just' (Parser a m b -> Maybe' (Parser a m b))
-> Parser a m b -> Maybe' (Parser a m b)
forall a b. (a -> b) -> a -> b
$ (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)
pstep (Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial s b -> m (Initial s b)) -> Initial s b -> m (Initial s b)
forall a b. (a -> b) -> a -> b
$ s -> Initial s b
forall s b. s -> Initial s b
IPartial s
ps2) s -> m (Step s b)
pextr
in Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (Maybe' (Parser a m b), s, s)
-> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> s -> Step s b
Continue Int
n (Maybe' (Parser a m b)
newP, s
ss, s
fs)
Done Int
n b
b -> do
Step s c
fres <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fres of
FL.Partial s
fs1 ->
Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (Maybe' (Parser a m b), s, s)
-> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> s -> Step s b
Partial Int
n (Maybe' (Parser a m b)
forall a. Maybe' a
Nothing', s
ss, s
fs1)
FL.Done c
c -> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> b -> Step s b
Done Int
n c
c
Error String
msg -> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (Maybe' (Parser a m b), s, s) c
forall s b. String -> Step s b
Error String
msg
IDone b
b -> do
Step s c
fres <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fres of
FL.Partial s
fs1 ->
Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (Maybe' (Parser a m b), s, s)
-> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> s -> Step s b
Partial Int
1 (Maybe' (Parser a m b)
forall a. Maybe' a
Nothing', s
ss, s
fs1)
FL.Done c
c -> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (Maybe' (Parser a m b), s, s) c
forall s b. Int -> b -> Step s b
Done Int
1 c
c
IError String
err -> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c))
-> Step (Maybe' (Parser a m b), s, s) c
-> m (Step (Maybe' (Parser a m b), s, s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (Maybe' (Parser a m b), s, s) c
forall s b. String -> Step s b
Error String
err
extract :: (Maybe' (Parser a m b), b, s)
-> m (Step (Maybe' (Parser a m b), b, s) c)
extract (Maybe' (Parser a m b)
Nothing', b
_, s
fs) = (c -> Step (Maybe' (Parser a m b), b, s) c)
-> m c -> m (Step (Maybe' (Parser a m b), 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 (Maybe' (Parser a m b), b, s) c
forall s b. Int -> b -> Step s b
Done Int
0) (m c -> m (Step (Maybe' (Parser a m b), b, s) c))
-> m c -> m (Step (Maybe' (Parser a m b), b, s) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs
extract (Just' (Parser s -> a -> m (Step s b)
pstep m (Initial s b)
pinit s -> m (Step s b)
pextr), b
ss, s
fs) = do
Initial s b
ps <- m (Initial s b)
pinit
case Initial s b
ps of
IPartial s
ps1 -> do
Step s b
r <- s -> m (Step s b)
pextr s
ps1
case Step s b
r of
Done Int
n b
b -> do
Step s c
res <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
res of
FL.Partial s
fs1 -> (c -> Step (Maybe' (Parser a m b), b, s) c)
-> m c -> m (Step (Maybe' (Parser a m b), 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 (Maybe' (Parser a m b), b, s) c
forall s b. Int -> b -> Step s b
Done Int
n) (m c -> m (Step (Maybe' (Parser a m b), b, s) c))
-> m c -> m (Step (Maybe' (Parser a m b), b, s) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs1
FL.Done c
c -> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step (Maybe' (Parser a m b), b, s) c
forall s b. Int -> b -> Step s b
Done Int
n c
c)
Error String
err -> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c))
-> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (Maybe' (Parser a m b), b, s) c
forall s b. String -> Step s b
Error String
err
Continue Int
n s
s -> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c))
-> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a b. (a -> b) -> a -> b
$ Int
-> (Maybe' (Parser a m b), b, s)
-> Step (Maybe' (Parser a m b), b, s) c
forall s b. Int -> s -> Step s b
Continue Int
n (Parser a m b -> Maybe' (Parser a m b)
forall a. a -> Maybe' a
Just' ((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)
pstep (Initial s b -> m (Initial s b)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (s -> Initial s b
forall s b. s -> Initial s b
IPartial s
s)) s -> m (Step s b)
pextr), b
ss, s
fs)
Partial Int
_ s
_ -> String -> m (Step (Maybe' (Parser a m b), b, s) c)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
IDone b
b -> do
Step s c
fres <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fres of
FL.Partial s
fs1 -> (c -> Step (Maybe' (Parser a m b), b, s) c)
-> m c -> m (Step (Maybe' (Parser a m b), 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 (Maybe' (Parser a m b), b, s) c
forall s b. Int -> b -> Step s b
Done Int
0) (m c -> m (Step (Maybe' (Parser a m b), b, s) c))
-> m c -> m (Step (Maybe' (Parser a m b), b, s) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs1
FL.Done c
c -> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step (Maybe' (Parser a m b), b, s) c
forall s b. Int -> b -> Step s b
Done Int
0 c
c)
IError String
err -> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c))
-> Step (Maybe' (Parser a m b), b, s) c
-> m (Step (Maybe' (Parser a m b), b, s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (Maybe' (Parser a m b), b, s) c
forall s b. String -> Step s b
Error String
err
{-# INLINE manyP #-}
manyP ::
Parser a m b -> Parser b m c -> Parser a m c
manyP :: forall a (m :: * -> *) b c.
Parser a m b -> Parser b m c -> Parser a m c
manyP Parser a m b
_p Parser b m c
_f = Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE many #-}
many :: Monad m => Parser a m b -> Fold m b c -> Parser a m c
many :: forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
many = Parser a m b -> Fold m b c -> Parser a m c
forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
splitMany
{-# INLINE some #-}
some :: Monad m => Parser a m b -> Fold m b c -> Parser a m c
some :: forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
some = Parser a m b -> Fold m b c -> Parser a m c
forall (m :: * -> *) a b c.
Monad m =>
Parser a m b -> Fold m b c -> Parser a m c
splitSome
{-# INLINE countBetween #-}
countBetween ::
Int -> Int -> Parser a m b -> Fold m b c -> Parser a m c
countBetween :: forall a (m :: * -> *) b c.
Int -> Int -> Parser a m b -> Fold m b c -> Parser a m c
countBetween Int
_m Int
_n Parser a m b
_p = Fold m b c -> Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE count #-}
count ::
Int -> Parser a m b -> Fold m b c -> Parser a m c
count :: forall a (m :: * -> *) b c.
Int -> Parser a m b -> Fold m b c -> Parser a m c
count Int
n = Int -> Int -> Parser a m b -> Fold m b c -> Parser a m c
forall a (m :: * -> *) b c.
Int -> Int -> Parser a m b -> Fold m b c -> Parser a m c
countBetween Int
n Int
n
{-# INLINE manyTillP #-}
manyTillP ::
Parser a m b -> Parser a m x -> Parser b m c -> Parser a m c
manyTillP :: forall a (m :: * -> *) b x c.
Parser a m b -> Parser a m x -> Parser b m c -> Parser a m c
manyTillP Parser a m b
_p1 Parser a m x
_p2 Parser b m c
_f = Parser a m c
forall a. HasCallStack => a
undefined
{-# ANN type ManyTillState Fuse #-}
data ManyTillState fs sr sl
= ManyTillR !Int !fs !sr
| ManyTillL !fs !sl
{-# INLINE manyTill #-}
manyTill :: Monad m
=> Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
manyTill :: forall (m :: * -> *) a b x c.
Monad m =>
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
manyTill (Parser s -> a -> m (Step s b)
stepL m (Initial s b)
initialL s -> m (Step s b)
extractL)
(Parser s -> a -> m (Step s x)
stepR m (Initial s x)
initialR s -> m (Step s x)
_)
(Fold s -> b -> m (Step s c)
fstep m (Step s c)
finitial s -> m c
_ s -> m c
ffinal) =
(ManyTillState s s s -> a -> m (Step (ManyTillState s s s) c))
-> m (Initial (ManyTillState s s s) c)
-> (ManyTillState s s s -> m (Step (ManyTillState s 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 ManyTillState s s s -> a -> m (Step (ManyTillState s s s) c)
step m (Initial (ManyTillState s s s) c)
initial ManyTillState s s s -> m (Step (ManyTillState s s s) c)
forall {sr} {sr}.
ManyTillState s sr s -> m (Step (ManyTillState s sr s) c)
extract
where
scrutL :: s
-> (ManyTillState s s sl -> b)
-> (ManyTillState s sr s -> b)
-> (c -> b)
-> (String -> b)
-> m b
scrutL s
fs ManyTillState s s sl -> b
p ManyTillState s sr s -> b
c c -> b
d String -> b
e = do
Initial s b
resL <- m (Initial s b)
initialL
case Initial s b
resL of
IPartial s
sl -> 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
$ ManyTillState s sr s -> b
c (s -> s -> ManyTillState s sr s
forall fs sr sl. fs -> sl -> ManyTillState fs sr sl
ManyTillL s
fs s
sl)
IDone b
bl -> do
Step s c
fr <- s -> b -> m (Step s c)
fstep s
fs b
bl
case Step s c
fr of
FL.Partial s
fs1 -> s
-> (ManyTillState s s sl -> b)
-> (ManyTillState s sr s -> b)
-> (c -> b)
-> (String -> b)
-> m b
scrutR s
fs1 ManyTillState s s sl -> b
p ManyTillState s sr s -> b
c c -> b
d String -> b
e
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
d c
fb
IError String
err -> 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
$ String -> b
e String
err
scrutR :: s
-> (ManyTillState s s sl -> b)
-> (ManyTillState s sr s -> b)
-> (c -> b)
-> (String -> b)
-> m b
scrutR s
fs ManyTillState s s sl -> b
p ManyTillState s sr s -> b
c c -> b
d String -> b
e = do
Initial s x
resR <- m (Initial s x)
initialR
case Initial s x
resR of
IPartial s
sr -> 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
$ ManyTillState s s sl -> b
p (Int -> s -> s -> ManyTillState s s sl
forall fs sr sl. Int -> fs -> sr -> ManyTillState fs sr sl
ManyTillR Int
0 s
fs s
sr)
IDone x
_ -> c -> b
d (c -> b) -> m c -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> s -> m c
ffinal s
fs
IError String
_ -> s
-> (ManyTillState s s sl -> b)
-> (ManyTillState s sr s -> b)
-> (c -> b)
-> (String -> b)
-> m b
scrutL s
fs ManyTillState s s sl -> b
p ManyTillState s sr s -> b
c c -> b
d String -> b
e
initial :: m (Initial (ManyTillState s s s) c)
initial = do
Step s c
res <- m (Step s c)
finitial
case Step s c
res of
FL.Partial s
fs -> s
-> (ManyTillState s s s -> Initial (ManyTillState s s s) c)
-> (ManyTillState s s s -> Initial (ManyTillState s s s) c)
-> (c -> Initial (ManyTillState s s s) c)
-> (String -> Initial (ManyTillState s s s) c)
-> m (Initial (ManyTillState s s s) c)
forall {sl} {b} {sr}.
s
-> (ManyTillState s s sl -> b)
-> (ManyTillState s sr s -> b)
-> (c -> b)
-> (String -> b)
-> m b
scrutR s
fs ManyTillState s s s -> Initial (ManyTillState s s s) c
forall s b. s -> Initial s b
IPartial ManyTillState s s s -> Initial (ManyTillState s s s) c
forall s b. s -> Initial s b
IPartial c -> Initial (ManyTillState s s s) c
forall s b. b -> Initial s b
IDone String -> Initial (ManyTillState s s s) c
forall s b. String -> Initial s b
IError
FL.Done c
b -> Initial (ManyTillState s s s) c
-> m (Initial (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Initial (ManyTillState s s s) c
-> m (Initial (ManyTillState s s s) c))
-> Initial (ManyTillState s s s) c
-> m (Initial (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ c -> Initial (ManyTillState s s s) c
forall s b. b -> Initial s b
IDone c
b
step :: ManyTillState s s s -> a -> m (Step (ManyTillState s s s) c)
step (ManyTillR Int
cnt s
fs s
st) a
a = do
Step s x
r <- s -> a -> m (Step s x)
stepR s
st a
a
case Step s x
r of
Partial Int
n s
s -> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Partial Int
n (Int -> s -> s -> ManyTillState s s s
forall fs sr sl. Int -> fs -> sr -> ManyTillState fs sr sl
ManyTillR Int
0 s
fs 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 (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Continue Int
n (Int -> s -> s -> ManyTillState s s s
forall fs sr sl. Int -> fs -> sr -> ManyTillState fs sr sl
ManyTillR (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
fs s
s)
Done Int
n x
_ -> do
c
b <- s -> m c
ffinal s
fs
Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (ManyTillState s s s) c
forall s b. Int -> b -> Step s b
Done Int
n c
b
Error String
_ -> do
Initial s b
resL <- m (Initial s b)
initialL
case Initial s b
resL of
IPartial s
sl ->
Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Continue (Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (s -> s -> ManyTillState s s s
forall fs sr sl. fs -> sl -> ManyTillState fs sr sl
ManyTillL s
fs s
sl)
IDone b
bl -> do
Step s c
fr <- s -> b -> m (Step s c)
fstep s
fs b
bl
let cnt1 :: Int
cnt1 = Int
cnt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
case Step s c
fr of
FL.Partial s
fs1 ->
s
-> (ManyTillState s s s -> Step (ManyTillState s s s) c)
-> (ManyTillState s s s -> Step (ManyTillState s s s) c)
-> (c -> Step (ManyTillState s s s) c)
-> (String -> Step (ManyTillState s s s) c)
-> m (Step (ManyTillState s s s) c)
forall {sl} {b} {sr}.
s
-> (ManyTillState s s sl -> b)
-> (ManyTillState s sr s -> b)
-> (c -> b)
-> (String -> b)
-> m b
scrutR
s
fs1
(Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Partial Int
cnt1)
(Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Continue Int
cnt1)
(Int -> c -> Step (ManyTillState s s s) c
forall s b. Int -> b -> Step s b
Done Int
cnt1)
String -> Step (ManyTillState s s s) c
forall s b. String -> Step s b
Error
FL.Done c
fb -> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (ManyTillState s s s) c
forall s b. Int -> b -> Step s b
Done Int
cnt1 c
fb
IError String
err -> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (ManyTillState s s s) c
forall s b. String -> Step s b
Error String
err
step (ManyTillL s
fs 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 (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Partial Int
n (s -> s -> ManyTillState s s s
forall fs sr sl. fs -> sl -> ManyTillState fs sr sl
ManyTillL s
fs s
s)
Continue Int
n s
s -> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> s -> ManyTillState s s s
forall fs sr sl. fs -> sl -> ManyTillState fs sr sl
ManyTillL s
fs s
s)
Done Int
n b
b -> do
Step s c
fs1 <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
fs1 of
FL.Partial s
s ->
s
-> (ManyTillState s s s -> Step (ManyTillState s s s) c)
-> (ManyTillState s s s -> Step (ManyTillState s s s) c)
-> (c -> Step (ManyTillState s s s) c)
-> (String -> Step (ManyTillState s s s) c)
-> m (Step (ManyTillState s s s) c)
forall {sl} {b} {sr}.
s
-> (ManyTillState s s sl -> b)
-> (ManyTillState s sr s -> b)
-> (c -> b)
-> (String -> b)
-> m b
scrutR s
s (Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Partial Int
n) (Int -> ManyTillState s s s -> Step (ManyTillState s s s) c
forall s b. Int -> s -> Step s b
Continue Int
n) (Int -> c -> Step (ManyTillState s s s) c
forall s b. Int -> b -> Step s b
Done Int
n) String -> Step (ManyTillState s s s) c
forall s b. String -> Step s b
Error
FL.Done c
b1 -> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ Int -> c -> Step (ManyTillState s s s) c
forall s b. Int -> b -> Step s b
Done Int
n c
b1
Error String
err -> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c))
-> Step (ManyTillState s s s) c -> m (Step (ManyTillState s s s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (ManyTillState s s s) c
forall s b. String -> Step s b
Error String
err
extract :: ManyTillState s sr s -> m (Step (ManyTillState s sr s) c)
extract (ManyTillL s
fs s
sR) = do
Step s b
res <- s -> m (Step s b)
extractL s
sR
case Step s b
res of
Done Int
n b
b -> do
Step s c
r <- s -> b -> m (Step s c)
fstep s
fs b
b
case Step s c
r of
FL.Partial s
fs1 -> (c -> Step (ManyTillState s sr s) c)
-> m c -> m (Step (ManyTillState s sr 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 (ManyTillState s sr s) c
forall s b. Int -> b -> Step s b
Done Int
n) (m c -> m (Step (ManyTillState s sr s) c))
-> m c -> m (Step (ManyTillState s sr s) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs1
FL.Done c
c -> Step (ManyTillState s sr s) c -> m (Step (ManyTillState s sr s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> c -> Step (ManyTillState s sr s) c
forall s b. Int -> b -> Step s b
Done Int
n c
c)
Error String
err -> Step (ManyTillState s sr s) c -> m (Step (ManyTillState s sr s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s sr s) c
-> m (Step (ManyTillState s sr s) c))
-> Step (ManyTillState s sr s) c
-> m (Step (ManyTillState s sr s) c)
forall a b. (a -> b) -> a -> b
$ String -> Step (ManyTillState s sr s) c
forall s b. String -> Step s b
Error String
err
Continue Int
n s
s -> Step (ManyTillState s sr s) c -> m (Step (ManyTillState s sr s) c)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (ManyTillState s sr s) c
-> m (Step (ManyTillState s sr s) c))
-> Step (ManyTillState s sr s) c
-> m (Step (ManyTillState s sr s) c)
forall a b. (a -> b) -> a -> b
$ Int -> ManyTillState s sr s -> Step (ManyTillState s sr s) c
forall s b. Int -> s -> Step s b
Continue Int
n (s -> s -> ManyTillState s sr s
forall fs sr sl. fs -> sl -> ManyTillState fs sr sl
ManyTillL s
fs s
s)
Partial Int
_ s
_ -> String -> m (Step (ManyTillState s sr s) c)
forall a. HasCallStack => String -> a
error String
"Partial in extract"
extract (ManyTillR Int
_ s
fs sr
_) = (c -> Step (ManyTillState s sr s) c)
-> m c -> m (Step (ManyTillState s sr 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 (ManyTillState s sr s) c
forall s b. Int -> b -> Step s b
Done Int
0) (m c -> m (Step (ManyTillState s sr s) c))
-> m c -> m (Step (ManyTillState s sr s) c)
forall a b. (a -> b) -> a -> b
$ s -> m c
ffinal s
fs
{-# INLINE manyThen #-}
manyThen ::
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
manyThen :: forall a (m :: * -> *) b x c.
Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
manyThen Parser a m b
_parser Parser a m x
_recover Fold m b c
_f = Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE retryMaxTotal #-}
retryMaxTotal ::
Int -> Parser a m b -> Fold m b c -> Parser a m c
retryMaxTotal :: forall a (m :: * -> *) b c.
Int -> Parser a m b -> Fold m b c -> Parser a m c
retryMaxTotal Int
_n Parser a m b
_p Fold m b c
_f = Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE retryMaxSuccessive #-}
retryMaxSuccessive ::
Int -> Parser a m b -> Fold m b c -> Parser a m c
retryMaxSuccessive :: forall a (m :: * -> *) b c.
Int -> Parser a m b -> Fold m b c -> Parser a m c
retryMaxSuccessive Int
_n Parser a m b
_p Fold m b c
_f = Parser a m c
forall a. HasCallStack => a
undefined
{-# INLINE retry #-}
retry ::
Parser a m b -> Parser a m b
retry :: forall a (m :: * -> *) b. Parser a m b -> Parser a m b
retry Parser a m b
_p = Parser a m b
forall a. HasCallStack => a
undefined