packages feed

polysoup 0.4.0 → 0.5.0

raw patch · 2 files changed

+41/−1 lines, 2 files

Files

polysoup.cabal view
@@ -1,5 +1,5 @@ name:               polysoup-version:            0.4.0+version:            0.5.0 synopsis:           Online XML parsing with polyparse and tagsoup description:     The library provides combinators for lazy, incremental XML parsing.
src/Text/XML/PolySoup/Parser.hs view
@@ -20,6 +20,11 @@ , every -- ** Sequential , pop+-- ** Peek+, peek+, spy+-- ** Utilities+, many_ ) where  @@ -98,3 +103,38 @@ pop (Q p) = P $ \tts -> case tts of     (t:ts)  -> (,ts) <$> p t     []      -> Nothing+++---------------------------------------------------------------------+-- Peek+---------------------------------------------------------------------+++-- | Like `pop`, but doesn't consume the tree.+peek :: Q a b -> P a b+peek (Q p) = P $ \tts -> case tts of+    (t:_)   -> (,tts) <$> p t+    []      -> Nothing+++-- | Like `first`, but doesn't consume the tree.+spy :: Q a b -> P a b+spy (Q p) = P $ \tts ->+    let go (t:ts) = case p t of+            Just v  -> Just (v, tts)+            Nothing -> go ts+        go [] = Nothing+    in  go tts+++---------------------------------------------------------------------+-- Utilities+---------------------------------------------------------------------+++-- | Many combinator which ignores parsing results.+many_ :: Alternative f => f a -> f ()+many_ v = many_v+  where+    many_v = some_v <|> pure ()+    some_v = v *> many_v