list-t-html-parser 0.2.0.0 → 0.2.1.0
raw patch · 2 files changed
+35/−3 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ ListT.HTMLParser: eoi :: Monad m => Parser m ()
+ ListT.HTMLParser: total :: Monad m => Parser m a -> Parser m a
Files
- library/ListT/HTMLParser.hs +34/−2
- list-t-html-parser.cabal +1/−1
library/ListT/HTMLParser.hs view
@@ -5,6 +5,7 @@ ErrorDetails(..), run, -- * Parsers+ eoi, token, openingTag, closingTag,@@ -13,6 +14,7 @@ -- * Combinators manyTill, skipTill,+ total, ) where @@ -26,12 +28,14 @@ -- |--- A backtracking HTML parser.+-- A backtracking HTML-tokens stream parser. newtype Parser m a = Parser { unwrap :: EitherT Error (StateT (ListT m HT.Token, [HT.Token]) m) a } deriving (Functor, Applicative, MonadError Error) --- | +-- |+-- A possibly detailed parser error.+-- When 'mzero' or 'empty' is used, an error value of 'Nothing' is produced. type Error = Maybe ErrorDetails @@ -75,6 +79,14 @@ run p l = flip evalStateT (l, []) $ runEitherT $ unwrap $ p +-- |+-- End of input.+eoi :: Monad m => Parser m ()+eoi =+ token $> () <|> pure ()++-- |+-- Any HTML token. token :: Monad m => Parser m HT.Token token = Parser $ EitherT $ StateT $ \(incoming, backtrack) -> @@ -82,30 +94,41 @@ (\(a, incoming') -> (Right a, (incoming', a : backtrack)))) $ L.uncons incoming +-- |+-- An opening tag. openingTag :: Monad m => Parser m HT.OpeningTag openingTag = token >>= \case HT.Token_OpeningTag x -> return x _ -> throwError (Just ErrorDetails_UnexpectedToken) +-- |+-- A closing tag. closingTag :: Monad m => Parser m HT.ClosingTag closingTag = token >>= \case HT.Token_ClosingTag x -> return x _ -> throwError (Just ErrorDetails_UnexpectedToken) +-- |+-- A text between tags with HTML-entities decoded. text :: Monad m => Parser m Text text = token >>= \case HT.Token_Text x -> return x _ -> throwError (Just ErrorDetails_UnexpectedToken) +-- |+-- Contents of a comment. comment :: Monad m => Parser m Text comment = token >>= \case HT.Token_Comment x -> return x _ -> throwError (Just ErrorDetails_UnexpectedToken) +-- |+-- Apply a parser multiple times until another parser is satisfied.+-- Returns results of both parsers. manyTill :: Monad m => Parser m a -> Parser m b -> Parser m ([a], b) manyTill a b = fix $ \loop -> @@ -119,3 +142,12 @@ fix $ \loop -> a <|> (token *> loop) +-- |+-- Greedily consume all the input until the end,+-- while running the provided parser.+-- Same as:+-- +-- > theParser <* eoi+total :: Monad m => Parser m a -> Parser m a+total a =+ a <* eoi
list-t-html-parser.cabal view
@@ -1,7 +1,7 @@ name: list-t-html-parser version:- 0.2.0.0+ 0.2.1.0 synopsis: Streaming HTML parser category: