binary-parser-0.5.5: A highly-efficient but limited parser API specialised for bytestrings

Safe Haskell | None
Language | Haskell2010

BinaryParser

Contents

- Extras

Synopsis

- data BinaryParser a
- run :: BinaryParser a -> ByteString -> Either Text a
- failure :: Text -> BinaryParser a
- byte :: BinaryParser Word8
- matchingByte :: (Word8 -> Either Text a) -> BinaryParser a
- bytesOfSize :: Int -> BinaryParser ByteString
- bytesWhile :: (Word8 -> Bool) -> BinaryParser ByteString
- unitOfSize :: Int -> BinaryParser ()
- unitOfBytes :: ByteString -> BinaryParser ()
- unitWhile :: (Word8 -> Bool) -> BinaryParser ()
- remainders :: BinaryParser ByteString
- fold :: (a -> Word8 -> Maybe a) -> a -> BinaryParser a
- endOfInput :: BinaryParser ()
- sized :: Int -> BinaryParser a -> BinaryParser a
- storableOfSize :: Storable a => Int -> BinaryParser a
- beWord16 :: BinaryParser Word16
- leWord16 :: BinaryParser Word16
- beWord32 :: BinaryParser Word32
- leWord32 :: BinaryParser Word32
- beWord64 :: BinaryParser Word64
- leWord64 :: BinaryParser Word64
- asciiIntegral :: Integral a => BinaryParser a

# Documentation

data BinaryParser a #

A highly-efficient parser specialised for strict `ByteString`s.

Supports the roll-back and alternative branching on the basis of the `Alternative` interface.

Does not generate fancy error-messages, which contributes to its efficiency.

Instances

Monad BinaryParser # |
Methods (>>=) :: BinaryParser a -> (a -> BinaryParser b) -> BinaryParser b # (>>) :: BinaryParser a -> BinaryParser b -> BinaryParser b # return :: a -> BinaryParser a # fail :: String -> BinaryParser a #
Functor BinaryParser # |
Methods fmap :: (a -> b) -> BinaryParser a -> BinaryParser b # (<$) :: a -> BinaryParser b -> BinaryParser a #
Applicative BinaryParser # |
Methods pure :: a -> BinaryParser a # (<*>) :: BinaryParser (a -> b) -> BinaryParser a -> BinaryParser b # (*>) :: BinaryParser a -> BinaryParser b -> BinaryParser b # (<*) :: BinaryParser a -> BinaryParser b -> BinaryParser a #
Alternative BinaryParser # |
Methods empty :: BinaryParser a # (<|>) :: BinaryParser a -> BinaryParser a -> BinaryParser a # some :: BinaryParser a -> BinaryParser [a] # many :: BinaryParser a -> BinaryParser [a] #
MonadPlus BinaryParser # |
Methods mzero :: BinaryParser a # mplus :: BinaryParser a -> BinaryParser a -> BinaryParser a #
MonadError Text BinaryParser # |
Methods throwError :: Text -> BinaryParser a # catchError :: BinaryParser a -> (Text -> BinaryParser a) -> BinaryParser a #

run :: BinaryParser a -> ByteString -> Either Text a #

Apply a parser to bytes.

failure :: Text -> BinaryParser a #

Fail with a message.

byte :: BinaryParser Word8 #

Consume a single byte.

matchingByte :: (Word8 -> Either Text a) -> BinaryParser a #

Consume a single byte, which satisfies the predicate.

bytesOfSize :: Int -> BinaryParser ByteString #

Consume an amount of bytes.

bytesWhile :: (Word8 -> Bool) -> BinaryParser ByteString #

Consume multiple bytes, which satisfy the predicate.

unitOfSize :: Int -> BinaryParser () #

Skip an amount of bytes.

unitOfBytes :: ByteString -> BinaryParser () #

Skip specific bytes, while failing if they don't match.

unitWhile :: (Word8 -> Bool) -> BinaryParser () #

Skip bytes, which satisfy the predicate.

remainders :: BinaryParser ByteString #

Consume all the remaining bytes.

fold :: (a -> Word8 -> Maybe a) -> a -> BinaryParser a #

Left-fold the bytes, terminating before the byte, on which the step function returns Nothing.

endOfInput :: BinaryParser () #

Fail if the input hasn't ended.

sized :: Int -> BinaryParser a -> BinaryParser a #

Run a subparser passing it a chunk of the current input of the specified size.

# Extras

storableOfSize :: Storable a => Int -> BinaryParser a #

Storable value of the given amount of bytes.

beWord16 :: BinaryParser Word16 #

Big-endian word of 2 bytes.

leWord16 :: BinaryParser Word16 #

Little-endian word of 2 bytes.

beWord32 :: BinaryParser Word32 #

Big-endian word of 4 bytes.

leWord32 :: BinaryParser Word32 #

Little-endian word of 4 bytes.

beWord64 :: BinaryParser Word64 #

Big-endian word of 8 bytes.

leWord64 :: BinaryParser Word64 #

Little-endian word of 8 bytes.

asciiIntegral :: Integral a => BinaryParser a #

Integral number encoded in ASCII.