memory-0.7: memory and related abtraction stuff

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.ByteArray.Parse

Contents

Description

A very simple bytearray parser related to Parsec and Attoparsec

Simple example:

> parse ((,,) <$> take 2 <*> byte 0x20 <*> (bytes "abc" *> anyByte)) "xx abctest"
ParseOK "est" ("xx", 116)

Synopsis

Documentation

data Parser byteArray a

Simple ByteString parser structure

Instances

Alternative (Parser byteArray) 
Monad (Parser byteArray) 
Functor (Parser byteArray) 
MonadPlus (Parser byteArray) 
Applicative (Parser byteArray) 

data Result byteArray a

Simple parsing result, that represent respectively:

  • failure: with the error message
  • continuation: that need for more input data
  • success: the remaining unparsed data and the parser value

Constructors

ParseFail String 
ParseMore (byteArray -> Result byteArray a) 
ParseOK byteArray a 

Instances

(Show ba, Show a) => Show (Result ba a) 

run the Parser

parse :: ByteArrayAccess byteArray => Parser byteArray a -> byteArray -> Result byteArray a

Run a Parser on a ByteString and return a Result

parseFeed :: (ByteArrayAccess byteArray, Monad m) => m byteArray -> Parser byteArray a -> byteArray -> m (Result byteArray a)

Run a parser on an @initial byteArray.

If the Parser need more data than available, the @feeder function is automatically called and fed to the More continuation.

Parser methods

byte :: ByteArray byteArray => Word8 -> Parser byteArray ()

Parse a specific byte at current position

if the byte is different than the expected on, this parser will raise a failure.

anyByte :: ByteArray byteArray => Parser byteArray Word8

Get the next byte from the parser

bytes :: (Show ba, Eq ba, ByteArray ba) => ba -> Parser ba ()

Parse a sequence of bytes from current position

if the following bytes don't match the expected bytestring completely, the parser will raise a failure

take :: ByteArray byteArray => Int -> Parser byteArray byteArray

Take @n bytes from the current position in the stream

takeWhile :: ByteArray byteArray => (Word8 -> Bool) -> Parser byteArray byteArray

Take bytes while the @predicate hold from the current position in the stream

takeAll :: ByteArray byteArray => Parser byteArray byteArray

Take the remaining bytes from the current position in the stream

skip :: ByteArray byteArray => Int -> Parser byteArray ()

Skip @n bytes from the current position in the stream

skipWhile :: ByteArray byteArray => (Word8 -> Bool) -> Parser byteArray ()

Skip bytes while the @predicate hold from the current position in the stream

skipAll :: ByteArray byteArray => Parser byteArray ()

Skip all the remaining bytes from the current position in the stream

takeStorable :: (ByteArray byteArray, Storable d) => Parser byteArray d

Take a storable from the current position in the stream