{-# LANGUAGE TupleSections #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_HADDOCK hide #-}
module Text.HTML.Scalpel.Internal.Serial (
SerialScraper
, SerialScraperT
, inSerial
, stepBack
, stepNext
, seekBack
, seekNext
, untilBack
, untilNext
) where
import Text.HTML.Scalpel.Internal.Scrape
import Text.HTML.Scalpel.Internal.Select
import Control.Applicative
import Control.Monad
import Control.Monad.Trans
import Control.Monad.Except (MonadError)
import Control.Monad.Cont (MonadCont)
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Trans.Maybe
import Control.Monad.Writer (MonadWriter)
import Control.Monad.Fix
import Data.Bifunctor
import Data.Functor.Identity
import Data.List.PointedList (PointedList)
import Data.Maybe
import Prelude hiding (until)
import qualified Control.Monad.Fail as Fail
import qualified Data.List.PointedList as PointedList
import qualified Data.Tree as Tree
import qualified Text.StringLike as TagSoup
type SpecZipper str = PointedList (Maybe (TagSpec str))
type SerialScraper str a = SerialScraperT str Identity a
newtype SerialScraperT str m a =
MkSerialScraper (StateT (SpecZipper str) (MaybeT m) a)
deriving (forall a b. a -> SerialScraperT str m b -> SerialScraperT str m a
forall a b.
(a -> b) -> SerialScraperT str m a -> SerialScraperT str m b
forall str (m :: * -> *) a b.
Functor m =>
a -> SerialScraperT str m b -> SerialScraperT str m a
forall str (m :: * -> *) a b.
Functor m =>
(a -> b) -> SerialScraperT str m a -> SerialScraperT str m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> SerialScraperT str m b -> SerialScraperT str m a
$c<$ :: forall str (m :: * -> *) a b.
Functor m =>
a -> SerialScraperT str m b -> SerialScraperT str m a
fmap :: forall a b.
(a -> b) -> SerialScraperT str m a -> SerialScraperT str m b
$cfmap :: forall str (m :: * -> *) a b.
Functor m =>
(a -> b) -> SerialScraperT str m a -> SerialScraperT str m b
Functor, forall a. a -> SerialScraperT str m a
forall a b.
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m a
forall a b.
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
forall a b.
SerialScraperT str m (a -> b)
-> SerialScraperT str m a -> SerialScraperT str m b
forall a b c.
(a -> b -> c)
-> SerialScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m c
forall {str} {m :: * -> *}.
Monad m =>
Functor (SerialScraperT str m)
forall str (m :: * -> *) a. Monad m => a -> SerialScraperT str m a
forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m a
forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m (a -> b)
-> SerialScraperT str m a -> SerialScraperT str m b
forall str (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> SerialScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b.
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m a
$c<* :: forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m a
*> :: forall a b.
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
$c*> :: forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
liftA2 :: forall a b c.
(a -> b -> c)
-> SerialScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m c
$cliftA2 :: forall str (m :: * -> *) a b c.
Monad m =>
(a -> b -> c)
-> SerialScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m c
<*> :: forall a b.
SerialScraperT str m (a -> b)
-> SerialScraperT str m a -> SerialScraperT str m b
$c<*> :: forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m (a -> b)
-> SerialScraperT str m a -> SerialScraperT str m b
pure :: forall a. a -> SerialScraperT str m a
$cpure :: forall str (m :: * -> *) a. Monad m => a -> SerialScraperT str m a
Applicative, forall a. SerialScraperT str m a
forall a. SerialScraperT str m a -> SerialScraperT str m [a]
forall a.
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
forall str (m :: * -> *).
Monad m =>
Applicative (SerialScraperT str m)
forall str (m :: * -> *) a. Monad m => SerialScraperT str m a
forall str (m :: * -> *) a.
Monad m =>
SerialScraperT str m a -> SerialScraperT str m [a]
forall str (m :: * -> *) a.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
many :: forall a. SerialScraperT str m a -> SerialScraperT str m [a]
$cmany :: forall str (m :: * -> *) a.
Monad m =>
SerialScraperT str m a -> SerialScraperT str m [a]
some :: forall a. SerialScraperT str m a -> SerialScraperT str m [a]
$csome :: forall str (m :: * -> *) a.
Monad m =>
SerialScraperT str m a -> SerialScraperT str m [a]
<|> :: forall a.
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
$c<|> :: forall str (m :: * -> *) a.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
empty :: forall a. SerialScraperT str m a
$cempty :: forall str (m :: * -> *) a. Monad m => SerialScraperT str m a
Alternative, forall a. a -> SerialScraperT str m a
forall a b.
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
forall a b.
SerialScraperT str m a
-> (a -> SerialScraperT str m b) -> SerialScraperT str m b
forall str (m :: * -> *).
Monad m =>
Applicative (SerialScraperT str m)
forall str (m :: * -> *) a. Monad m => a -> SerialScraperT str m a
forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> (a -> SerialScraperT str m b) -> SerialScraperT str m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> SerialScraperT str m a
$creturn :: forall str (m :: * -> *) a. Monad m => a -> SerialScraperT str m a
>> :: forall a b.
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
$c>> :: forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
>>= :: forall a b.
SerialScraperT str m a
-> (a -> SerialScraperT str m b) -> SerialScraperT str m b
$c>>= :: forall str (m :: * -> *) a b.
Monad m =>
SerialScraperT str m a
-> (a -> SerialScraperT str m b) -> SerialScraperT str m b
Monad, forall a. SerialScraperT str m a
forall a.
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
forall str (m :: * -> *). Monad m => Monad (SerialScraperT str m)
forall str (m :: * -> *).
Monad m =>
Alternative (SerialScraperT str m)
forall str (m :: * -> *) a. Monad m => SerialScraperT str m a
forall str (m :: * -> *) a.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
mplus :: forall a.
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
$cmplus :: forall str (m :: * -> *) a.
Monad m =>
SerialScraperT str m a
-> SerialScraperT str m a -> SerialScraperT str m a
mzero :: forall a. SerialScraperT str m a
$cmzero :: forall str (m :: * -> *) a. Monad m => SerialScraperT str m a
MonadPlus, forall a. (a -> SerialScraperT str m a) -> SerialScraperT str m a
forall {str} {m :: * -> *}.
MonadFix m =>
Monad (SerialScraperT str m)
forall str (m :: * -> *) a.
MonadFix m =>
(a -> SerialScraperT str m a) -> SerialScraperT str m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
mfix :: forall a. (a -> SerialScraperT str m a) -> SerialScraperT str m a
$cmfix :: forall str (m :: * -> *) a.
MonadFix m =>
(a -> SerialScraperT str m a) -> SerialScraperT str m a
MonadFix,
forall a. IO a -> SerialScraperT str m a
forall {str} {m :: * -> *}.
MonadIO m =>
Monad (SerialScraperT str m)
forall str (m :: * -> *) a.
MonadIO m =>
IO a -> SerialScraperT str m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: forall a. IO a -> SerialScraperT str m a
$cliftIO :: forall str (m :: * -> *) a.
MonadIO m =>
IO a -> SerialScraperT str m a
MonadIO, forall a b.
((a -> SerialScraperT str m b) -> SerialScraperT str m a)
-> SerialScraperT str m a
forall {str} {m :: * -> *}.
MonadCont m =>
Monad (SerialScraperT str m)
forall str (m :: * -> *) a b.
MonadCont m =>
((a -> SerialScraperT str m b) -> SerialScraperT str m a)
-> SerialScraperT str m a
forall (m :: * -> *).
Monad m -> (forall a b. ((a -> m b) -> m a) -> m a) -> MonadCont m
callCC :: forall a b.
((a -> SerialScraperT str m b) -> SerialScraperT str m a)
-> SerialScraperT str m a
$ccallCC :: forall str (m :: * -> *) a b.
MonadCont m =>
((a -> SerialScraperT str m b) -> SerialScraperT str m a)
-> SerialScraperT str m a
MonadCont, MonadError e, MonadReader r, MonadWriter w)
#if MIN_VERSION_base(4,9,0)
deriving instance Monad m => Fail.MonadFail (SerialScraperT str m)
#else
instance Fail.MonadFail m => Fail.MonadFail (SerialScraperT str m) where
fail = lift . Fail.fail
#endif
instance MonadTrans (SerialScraperT str) where
lift :: forall (m :: * -> *) a. Monad m => m a -> SerialScraperT str m a
lift m a
op = forall str (m :: * -> *) a.
StateT (SpecZipper str) (MaybeT m) a -> SerialScraperT str m a
MkSerialScraper forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ m a
op
instance MonadState s m => MonadState s (SerialScraperT str m) where
get :: SerialScraperT str m s
get = forall str (m :: * -> *) a.
StateT (SpecZipper str) (MaybeT m) a -> SerialScraperT str m a
MkSerialScraper (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => m s
get)
put :: s -> SerialScraperT str m ()
put = forall str (m :: * -> *) a.
StateT (SpecZipper str) (MaybeT m) a -> SerialScraperT str m a
MkSerialScraper forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *). MonadState s m => s -> m ()
put
inSerial :: (TagSoup.StringLike str, Monad m)
=> SerialScraperT str m a -> ScraperT str m a
inSerial :: forall str (m :: * -> *) a.
(StringLike str, Monad m) =>
SerialScraperT str m a -> ScraperT str m a
inSerial (MkSerialScraper StateT (SpecZipper str) (MaybeT m) a
serialScraper) = forall str (m :: * -> *) a.
ReaderT (TagSpec str) (MaybeT m) a -> ScraperT str m a
MkScraper forall a b. (a -> b) -> a -> b
$ forall r (m :: * -> *) a. (r -> m a) -> ReaderT r m a
ReaderT forall a b. (a -> b) -> a -> b
$ (TagVector str, [Tree Span], SelectContext) -> MaybeT m a
scraper
where
scraper :: (TagVector str, [Tree Span], SelectContext) -> MaybeT m a
scraper spec :: (TagVector str, [Tree Span], SelectContext)
spec@(TagVector str
vec, Tree Span
root : [Tree Span]
_, SelectContext
ctx)
| SelectContext -> Bool
ctxInChroot SelectContext
ctx = forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT StateT (SpecZipper str) (MaybeT m) a
serialScraper
(forall {str}.
StringLike str =>
(TagVector str, [Tree Span], SelectContext) -> SpecZipper str
toZipper (TagVector str
vec, forall a. Tree a -> [Tree a]
Tree.subForest Tree Span
root, SelectContext
ctx))
| Bool
otherwise = forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT StateT (SpecZipper str) (MaybeT m) a
serialScraper (forall {str}.
StringLike str =>
(TagVector str, [Tree Span], SelectContext) -> SpecZipper str
toZipper (TagVector str, [Tree Span], SelectContext)
spec)
scraper (TagVector str, [Tree Span], SelectContext)
_ = forall (f :: * -> *) a. Alternative f => f a
empty
toZipper :: (TagVector str, [Tree Span], SelectContext) -> SpecZipper str
toZipper (TagVector str
vector, [Tree Span]
forest, SelectContext
context) =
forall str. StringLike str => [TagSpec str] -> SpecZipper str
zipperFromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map ((TagVector str
vector, , SelectContext
context) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return) [Tree Span]
forest
zipperFromList :: TagSoup.StringLike str => [TagSpec str] -> SpecZipper str
zipperFromList :: forall str. StringLike str => [TagSpec str] -> SpecZipper str
zipperFromList = forall a. a -> PointedList a -> PointedList a
PointedList.insertLeft forall a. Maybe a
Nothing
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (forall a. a -> PointedList a -> PointedList a
PointedList.insertLeft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just)
(forall a. a -> PointedList a
PointedList.singleton forall a. Maybe a
Nothing)
stepWith :: (TagSoup.StringLike str, Monad m)
=> (SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b
-> SerialScraperT str m b
stepWith :: forall str (m :: * -> *) b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b -> SerialScraperT str m b
stepWith SpecZipper str -> Maybe (SpecZipper str)
moveList (MkScraper (ReaderT TagSpec str -> MaybeT m b
scraper)) = forall str (m :: * -> *) a.
StateT (SpecZipper str) (MaybeT m) a -> SerialScraperT str m a
MkSerialScraper forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT forall a b. (a -> b) -> a -> b
$
\SpecZipper str
zipper -> do
SpecZipper str
zipper' <- forall (m :: * -> *) a. Monad m => Maybe a -> MaybeT m a
maybeT forall a b. (a -> b) -> a -> b
$ SpecZipper str -> Maybe (SpecZipper str)
moveList SpecZipper str
zipper
TagSpec str
focus <- forall (m :: * -> *) a. Monad m => Maybe a -> MaybeT m a
maybeT forall a b. (a -> b) -> a -> b
$ forall a. PointedList a -> a
PointedList._focus SpecZipper str
zipper'
b
value <- TagSpec str -> MaybeT m b
scraper TagSpec str
focus
forall (m :: * -> *) a. Monad m => a -> m a
return (b
value, SpecZipper str
zipper')
stepBack :: (TagSoup.StringLike str, Monad m) => ScraperT str m a -> SerialScraperT str m a
stepBack :: forall str (m :: * -> *) a.
(StringLike str, Monad m) =>
ScraperT str m a -> SerialScraperT str m a
stepBack = forall str (m :: * -> *) b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b -> SerialScraperT str m b
stepWith forall a. PointedList a -> Maybe (PointedList a)
PointedList.previous
stepNext :: (TagSoup.StringLike str, Monad m)
=> ScraperT str m a -> SerialScraperT str m a
stepNext :: forall str (m :: * -> *) a.
(StringLike str, Monad m) =>
ScraperT str m a -> SerialScraperT str m a
stepNext = forall str (m :: * -> *) b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b -> SerialScraperT str m b
stepWith forall a. PointedList a -> Maybe (PointedList a)
PointedList.next
seekWith :: (TagSoup.StringLike str, Monad m)
=> (SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b
-> SerialScraperT str m b
seekWith :: forall str (m :: * -> *) b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b -> SerialScraperT str m b
seekWith SpecZipper str -> Maybe (SpecZipper str)
moveList (MkScraper (ReaderT TagSpec str -> MaybeT m b
scraper)) = forall str (m :: * -> *) a.
StateT (SpecZipper str) (MaybeT m) a -> SerialScraperT str m a
MkSerialScraper (forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT SpecZipper str -> MaybeT m (b, SpecZipper str)
go)
where
go :: SpecZipper str -> MaybeT m (b, SpecZipper str)
go SpecZipper str
zipper = do SpecZipper str
zipper' <- forall (m :: * -> *) a. Monad m => Maybe a -> MaybeT m a
maybeT forall a b. (a -> b) -> a -> b
$ SpecZipper str -> Maybe (SpecZipper str)
moveList SpecZipper str
zipper
SpecZipper str -> MaybeT m (b, SpecZipper str)
runScraper SpecZipper str
zipper' forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> SpecZipper str -> MaybeT m (b, SpecZipper str)
go SpecZipper str
zipper'
runScraper :: SpecZipper str -> MaybeT m (b, SpecZipper str)
runScraper SpecZipper str
zipper = do
TagSpec str
focus <- forall (m :: * -> *) a. Monad m => Maybe a -> MaybeT m a
maybeT forall a b. (a -> b) -> a -> b
$ forall a. PointedList a -> a
PointedList._focus SpecZipper str
zipper
b
value <- TagSpec str -> MaybeT m b
scraper TagSpec str
focus
forall (m :: * -> *) a. Monad m => a -> m a
return (b
value, SpecZipper str
zipper)
seekBack :: (TagSoup.StringLike str, Monad m)
=> ScraperT str m a -> SerialScraperT str m a
seekBack :: forall str (m :: * -> *) a.
(StringLike str, Monad m) =>
ScraperT str m a -> SerialScraperT str m a
seekBack = forall str (m :: * -> *) b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b -> SerialScraperT str m b
seekWith forall a. PointedList a -> Maybe (PointedList a)
PointedList.previous
seekNext :: (TagSoup.StringLike str, Monad m)
=> ScraperT str m a -> SerialScraperT str m a
seekNext :: forall str (m :: * -> *) a.
(StringLike str, Monad m) =>
ScraperT str m a -> SerialScraperT str m a
seekNext = forall str (m :: * -> *) b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> ScraperT str m b -> SerialScraperT str m b
seekWith forall a. PointedList a -> Maybe (PointedList a)
PointedList.next
untilWith :: (TagSoup.StringLike str, Monad m)
=> (SpecZipper str -> Maybe (SpecZipper str))
-> (Maybe (TagSpec str) -> SpecZipper str -> SpecZipper str)
-> ScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m b
untilWith :: forall str (m :: * -> *) a b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> (Maybe (TagSpec str) -> SpecZipper str -> SpecZipper str)
-> ScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m b
untilWith SpecZipper str -> Maybe (SpecZipper str)
moveList Maybe (TagSpec str) -> SpecZipper str -> SpecZipper str
appendNode (MkScraper (ReaderT TagSpec str -> MaybeT m a
until)) (MkSerialScraper StateT (SpecZipper str) (MaybeT m) b
scraper) =
forall str (m :: * -> *) a.
StateT (SpecZipper str) (MaybeT m) a -> SerialScraperT str m a
MkSerialScraper forall a b. (a -> b) -> a -> b
$ do
SpecZipper str
inner <- forall s (m :: * -> *) a. (s -> m (a, s)) -> StateT s m a
StateT SpecZipper str -> MaybeT m (SpecZipper str, SpecZipper str)
split
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT StateT (SpecZipper str) (MaybeT m) b
scraper (Maybe (TagSpec str) -> SpecZipper str -> SpecZipper str
appendNode forall a. Maybe a
Nothing SpecZipper str
inner))
where
split :: SpecZipper str -> MaybeT m (SpecZipper str, SpecZipper str)
split SpecZipper str
zipper =
do SpecZipper str
zipper' <- forall (m :: * -> *) a. Monad m => Maybe a -> MaybeT m a
maybeT forall a b. (a -> b) -> a -> b
$ SpecZipper str -> Maybe (SpecZipper str)
moveList SpecZipper str
zipper
TagSpec str
spec <- forall (m :: * -> *) a. Monad m => Maybe a -> MaybeT m a
maybeT forall a b. (a -> b) -> a -> b
$ forall a. PointedList a -> a
PointedList._focus SpecZipper str
zipper'
do TagSpec str -> MaybeT m a
until TagSpec str
spec
forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> PointedList a
PointedList.singleton forall a. Maybe a
Nothing, SpecZipper str
zipper)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (Maybe (TagSpec str) -> SpecZipper str -> SpecZipper str
appendNode (forall a. a -> Maybe a
Just TagSpec str
spec)) forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` SpecZipper str -> MaybeT m (SpecZipper str, SpecZipper str)
split SpecZipper str
zipper')
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> PointedList a
PointedList.singleton forall a. Maybe a
Nothing, SpecZipper str
zipper)
untilBack :: (TagSoup.StringLike str, Monad m)
=> ScraperT str m a -> SerialScraperT str m b -> SerialScraperT str m b
untilBack :: forall str (m :: * -> *) a b.
(StringLike str, Monad m) =>
ScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
untilBack = forall str (m :: * -> *) a b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> (Maybe (TagSpec str) -> SpecZipper str -> SpecZipper str)
-> ScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m b
untilWith forall a. PointedList a -> Maybe (PointedList a)
PointedList.previous forall a. a -> PointedList a -> PointedList a
PointedList.insertRight
untilNext :: (TagSoup.StringLike str, Monad m)
=> ScraperT str m a -> SerialScraperT str m b -> SerialScraperT str m b
untilNext :: forall str (m :: * -> *) a b.
(StringLike str, Monad m) =>
ScraperT str m a
-> SerialScraperT str m b -> SerialScraperT str m b
untilNext = forall str (m :: * -> *) a b.
(StringLike str, Monad m) =>
(SpecZipper str -> Maybe (SpecZipper str))
-> (Maybe (TagSpec str) -> SpecZipper str -> SpecZipper str)
-> ScraperT str m a
-> SerialScraperT str m b
-> SerialScraperT str m b
untilWith forall a. PointedList a -> Maybe (PointedList a)
PointedList.next forall a. a -> PointedList a -> PointedList a
PointedList.insertLeft
maybeT :: Monad m => Maybe a -> MaybeT m a
maybeT :: forall (m :: * -> *) a. Monad m => Maybe a -> MaybeT m a
maybeT = forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => a -> m a
return