Safe Haskell | Safe-Inferred |
---|
Element-agnostic parsing utilities for pipes
See Pipes.Parse.Tutorial for an extended tutorial
- type Parser a m r = forall x. StateT (Producer a m x) m r
- draw :: Monad m => Parser a m (Maybe a)
- skip :: Monad m => Parser a m Bool
- drawAll :: Monad m => Parser a m [a]
- skipAll :: Monad m => Parser a m ()
- unDraw :: Monad m => a -> Parser a m ()
- peek :: Monad m => Parser a m (Maybe a)
- isEndOfInput :: Monad m => Parser a m Bool
- foldAll :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Parser a m b
- foldAllM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> Parser a m b
- span :: Monad m => (a -> Bool) -> Lens' (Producer a m x) (Producer a m (Producer a m x))
- splitAt :: Monad m => Int -> Lens' (Producer a m x) (Producer a m (Producer a m x))
- groupBy :: Monad m => (a -> a -> Bool) -> Lens' (Producer a m x) (Producer a m (Producer a m x))
- group :: (Monad m, Eq a) => Lens' (Producer a m x) (Producer a m (Producer a m x))
- toParser :: Monad m => Consumer (Maybe a) m r -> Parser a m r
- toParser_ :: Monad m => Consumer a m X -> Parser a m ()
- module Control.Monad.Trans.Class
- module Control.Monad.Trans.State.Strict
- module Pipes
Parsing
pipes-parse
handles end-of-input and pushback by storing a Producer
in
a StateT
layer.
Connect Parser
s to Producer
s using either runStateT
, evalStateT
, or
execStateT
:
runStateT :: Parser a m r -> Producer a m x -> m (r, Producer a m x) evalStateT :: Parser a m r -> Producer a m x -> m r execStateT :: Parser a m r -> Producer a m x -> m (Producer a m x) ^^^^^^^^^^^^^^ Leftovers
drawAll :: Monad m => Parser a m [a]Source
Draw all elements from the underlying Producer
Note that drawAll
is not an idiomatic use of pipes-parse
, but I provide
it for simple testing purposes. Idiomatic pipes-parse
style consumes the
elements immediately as they are generated instead of loading all elements
into memory. For example, you can use foldAll
or foldAllM
for this
purpose.
isEndOfInput :: Monad m => Parser a m BoolSource
Check if the underlying Producer
is empty
isEndOfInput = fmap isNothing peek
:: Monad m | |
=> (x -> a -> x) | Step function |
-> x | Initial accumulator |
-> (x -> b) | Extraction function |
-> Parser a m b |
Fold all input values
Control.Foldl.purely foldAll :: Monad m => Fold a b -> Parser a m b
:: Monad m | |
=> (x -> a -> m x) | Step function |
-> m x | Initial accumulator |
-> (x -> m b) | Extraction function |
-> Parser a m b |
Fold all input values monadically
Control.Foldl.impurely foldAllM :: Monad m => FoldM a m b -> Parser a m b
Parsing Lenses
Connect lenses to Producer
s using (^.
) or
view
:
(^.) :: Producer a m x -> Lens' (Producer a m x) (Producer b m y) -> Producer b m y
Connect lenses to Parser
s using zoom
:
zoom :: Lens' (Producer a m x) (Producer b m y) -> Parser b m r -> Parser a m r
Connect lenses to each other using (.
) (i.e. function composition):
(.) :: Lens' (Producer a m x) (Producer b m y) -> Lens' (Producer b m y) (Producer c m z) -> Lens' (Producer a m y) (Producer c m z)
groupBy :: Monad m => (a -> a -> Bool) -> Lens' (Producer a m x) (Producer a m (Producer a m x))Source
Utilities
Re-exports
Control.Monad.Trans.Class re-exports lift
.
Control.Monad.Trans.State.Strict re-exports StateT
, runStateT
,
evalStateT
, and execStateT
.
module Control.Monad.Trans.Class
module Pipes