HCodecs-0.5.1: A library to read, write and manipulate MIDI, WAVE, and SoundFont2 files.

Copyright Lennart Kolmodin George Giorgidze BSD3 George Giorgidze experimental Portable None Haskell98

Codec.ByteString.Parser

Description

A monad for efficiently building structures from encoded lazy ByteStrings.

Synopsis

# The Parser type

data Parser a Source #

The Get monad is just a State monad carrying around the input ByteString

Instances

 Source # Methods(>>=) :: Parser a -> (a -> Parser b) -> Parser b #(>>) :: Parser a -> Parser b -> Parser b #return :: a -> Parser a #fail :: String -> Parser a # Source # Methodsfmap :: (a -> b) -> Parser a -> Parser b #(<\$) :: a -> Parser b -> Parser a # Source # Methodspure :: a -> Parser a #(<*>) :: Parser (a -> b) -> Parser a -> Parser b #liftA2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c #(*>) :: Parser a -> Parser b -> Parser b #(<*) :: Parser a -> Parser b -> Parser a # Source # Methodsempty :: Parser a #(<|>) :: Parser a -> Parser a -> Parser a #some :: Parser a -> Parser [a] #many :: Parser a -> Parser [a] # Source # Methodsmzero :: Parser a #mplus :: Parser a -> Parser a -> Parser a #

Run the Get monad applies a get-based parser on the input ByteString

Run the Get monad applies a get-based parser on the input ByteString. Additional to the result of get it returns the number of consumed bytes and the rest of the input.

# Parsing

expect :: (Show a, Eq a) => (a -> Bool) -> Parser a -> Parser a Source #

skip :: Word64 -> Parser () Source #

Skip ahead n bytes. Fails if fewer than n bytes are available.

lookAhead :: Parser a -> Parser a Source #

Run ga, but return without consuming its input. Fails if ga fails.

lookAheadM :: Parser (Maybe a) -> Parser (Maybe a) Source #

Like lookAhead, but consume the input if gma returns 'Just _'. Fails if gma fails.

lookAheadE :: Parser (Either a b) -> Parser (Either a b) Source #

Like lookAhead, but consume the input if gea returns 'Right _'. Fails if gea fails.

# Utility

Get the total number of bytes read to this point.

Pull n bytes from the input, as a strict ByteString.

Get the number of remaining unparsed bytes. Useful for checking whether all input has been consumed. Note that this forces the rest of the input.

Test whether all input has been consumed, i.e. there are no remaining unparsed bytes.

# Parsing particular types

## ByteStrings

An efficient get method for strict ByteStrings. Fails if fewer than n bytes are left in the input.

An efficient get method for lazy ByteStrings. Does not fail if fewer than n bytes are left in the input.

Get a lazy ByteString that is terminated with a NUL byte. Fails if it reaches the end of input without hitting a NUL.

Get the remaining bytes as a lazy ByteString

Read a Word16 in big endian format

Read a 24 bit word into Word32 in big endian format

Read a Word32 in big endian format

Read a Word64 in big endian format

Read a Word16 in little endian format

Read a Word32 in little endian format

Read a Word64 in little endian format