binary-parsers-0.2.3.0: Extends binary with parsec/attoparsec style parsing combinators.

CopyrightBryan O'Sullivan 2007-2015 Winterland 2016
LicenseBSD3
Maintainerdrkoster@qq.com
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell2010

Data.Binary.Parser.Word8

Description

Simple, efficient combinator parsing for ByteString strings.

Synopsis

Documentation

peekMaybe :: Get (Maybe Word8) #

Match any byte, to perform lookahead. Returns Nothing if end of input has been reached. Does not consume any input.

peek :: Get Word8 #

Match any byte, to perform lookahead. Does not consume any input, but will fail if end of input has been reached.

satisfy :: (Word8 -> Bool) -> Get Word8 #

The parser satisfy p succeeds for any byte for which the predicate p returns True. Returns the byte that is actually parsed.

digit = satisfy isDigit
    where isDigit w = w >= 48 && w <= 57

satisfyWith :: (Word8 -> a) -> (a -> Bool) -> Get a #

The parser satisfyWith f p transforms a byte, and succeeds if the predicate p returns True on the transformed value. The parser returns the transformed byte that was parsed.

word8 :: Word8 -> Get () #

Match a specific byte.

anyWord8 :: Get Word8 #

Match any byte.

skipWord8 :: (Word8 -> Bool) -> Get () #

The parser skipWord8 p succeeds for any byte for which the predicate p returns True.

skipN :: Int -> Get () #

This is a faster version of skip for small N (smaller than chunk size).

takeTill :: (Word8 -> Bool) -> Get ByteString #

Consume input as long as the predicate returns False or reach the end of input, and return the consumed input.

takeWhile :: (Word8 -> Bool) -> Get ByteString #

Consume input as long as the predicate returns True or reach the end of input, and return the consumed input.

takeWhile1 :: (Word8 -> Bool) -> Get ByteString #

Similar to takeWhile, but requires the predicate to succeed on at least one byte of input: it will fail if the predicate never returns True or reach the end of input

skipWhile :: (Word8 -> Bool) -> Get () #

Skip past input for as long as the predicate returns True.

skipSpaces :: Get () #

Skip over white space using isSpace.

string :: ByteString -> Get () #

string s parses a sequence of bytes that identically match s.

scan :: s -> (s -> Word8 -> Maybe s) -> Get ByteString #

A stateful scanner. The predicate consumes and transforms a state argument, and each transformed state is passed to successive invocations of the predicate on each byte of the input until one returns Nothing or the input ends.

This parser does not fail. It will return an empty string if the predicate returns Nothing on the first byte of input.

scanChunks :: s -> Consume s -> Get ByteString #

Similar to scan, but working on ByteString chunks, The predicate consumes a ByteString chunk and transforms a state argument, and each transformed state is passed to successive invocations of the predicate on each chunk of the input until one chunk got splited to Right (ByteString, ByteString) or the input ends.

isSpace :: Word8 -> Bool #

Fast Word8 predicate for matching ASCII space characters

isSpace w = w == 32 || w - 9 <= 4

isDigit :: Word8 -> Bool #

Decimal digit predicate.

isHexDigit :: Word8 -> Bool #

Hex digit predicate.

isHorizontalSpace :: Word8 -> Bool #

A predicate that matches either a space ' ' or horizontal tab '\t' character.

isEndOfLine :: Word8 -> Bool #

A predicate that matches either a carriage return '\r' or newline '\n' character.

endOfLine :: Get () #

Match either a single newline byte '\n', or a carriage return followed by a newline byte "\r\n".