Data.Attoparsec.Zepto

attoparsec-0.13.1.0: Fast combinator parsing for bytestrings and text

Copyright | Bryan O'Sullivan 2007-2015
License | BSD3
Maintainer | bos@serpentine.com
Stability | experimental
Portability | unknown
Safe Haskell | Trustworthy
Language | Haskell98

Data.Attoparsec.Zepto

Description

A tiny, highly specialized combinator parser for `ByteString` strings.

While the main attoparsec module generally performs well, this module is particularly fast for simple non-recursive loops that should not normally result in failed parses.

Warning: on more complex inputs involving recursion or failure, parsers based on this module may be as much as ten times slower than regular attoparsec! You should only use this module when you have benchmarks that prove that its use speeds your code up.

Synopsis

- type Parser a = ZeptoT Identity a
- data ZeptoT m a
- parse :: Parser a -> ByteString -> Either String a
- parseT :: Monad m => ZeptoT m a -> ByteString -> m (Either String a)
- atEnd :: Monad m => ZeptoT m Bool
- string :: Monad m => ByteString -> ZeptoT m ()
- take :: Monad m => Int -> ZeptoT m ByteString
- takeWhile :: Monad m => (Word8 -> Bool) -> ZeptoT m ByteString

# Documentation

type Parser a = ZeptoT Identity a #

data ZeptoT m a #

A simple parser.

This monad is strict in its state, and the monadic bind operator (`>>=`) evaluates each result to weak head normal form before passing it along.

Instances

Monad m => Monad (ZeptoT m) # |
Methods (>>=) :: ZeptoT m a -> (a -> ZeptoT m b) -> ZeptoT m b # (>>) :: ZeptoT m a -> ZeptoT m b -> ZeptoT m b # return :: a -> ZeptoT m a # fail :: String -> ZeptoT m a #
Monad m => Functor (ZeptoT m) # |
Methods fmap :: (a -> b) -> ZeptoT m a -> ZeptoT m b # (<$) :: a -> ZeptoT m b -> ZeptoT m a #
Monad m => MonadFail (ZeptoT m) # |
Methods fail :: String -> ZeptoT m a #
Monad m => Applicative (ZeptoT m) # |
Methods pure :: a -> ZeptoT m a # (<*>) :: ZeptoT m (a -> b) -> ZeptoT m a -> ZeptoT m b # (*>) :: ZeptoT m a -> ZeptoT m b -> ZeptoT m b # (<*) :: ZeptoT m a -> ZeptoT m b -> ZeptoT m a #
MonadIO m => MonadIO (ZeptoT m) # |
Methods liftIO :: IO a -> ZeptoT m a #
Monad m => Alternative (ZeptoT m) # |
Methods empty :: ZeptoT m a # (<|>) :: ZeptoT m a -> ZeptoT m a -> ZeptoT m a # some :: ZeptoT m a -> ZeptoT m [a] # many :: ZeptoT m a -> ZeptoT m [a] #
Monad m => MonadPlus (ZeptoT m) # |
Methods mzero :: ZeptoT m a # mplus :: ZeptoT m a -> ZeptoT m a -> ZeptoT m a #
Monad m => Semigroup (ZeptoT m a) # |
Methods (<>) :: ZeptoT m a -> ZeptoT m a -> ZeptoT m a # sconcat :: NonEmpty (ZeptoT m a) -> ZeptoT m a # stimes :: Integral b => b -> ZeptoT m a -> ZeptoT m a #
Monad m => Monoid (ZeptoT m a) # |
Methods mempty :: ZeptoT m a # mappend :: ZeptoT m a -> ZeptoT m a -> ZeptoT m a # mconcat :: [ZeptoT m a] -> ZeptoT m a #

parse :: Parser a -> ByteString -> Either String a #

Run a parser.

parseT :: Monad m => ZeptoT m a -> ByteString -> m (Either String a) #

Run a parser on top of the given base monad.

atEnd :: Monad m => ZeptoT m Bool #

Indicate whether the end of the input has been reached.

string :: Monad m => ByteString -> ZeptoT m () #

Match a string exactly.

take :: Monad m => Int -> ZeptoT m ByteString #

Consume `n` bytes of input.

takeWhile :: Monad m => (Word8 -> Bool) -> ZeptoT m ByteString #

Consume input while the predicate returns `True`.