| ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
Description | ||||||||||||||||||||||||||||||||||||||||||
This is a version of the Get monad for incremental parsing. The parser is written as if a single, huge, strict ByteString was to be parsed. It produces results as it parses by calling yield. However, if the parser runs out of data, rather than failing the caller sees a Partial result, which includes the list of yielded values so far and a continuation. By calling the continuation with more data, the parser continues, none the wiser. Take the following example testParse = do a <- getWord16be b <- getWord16be return $ a + b test = runGet testParse $ B.pack [1,0,0] Here testParse needs to read 4 bytes in order to complete, so test is a Partial, which includes the continuation function, so which you can pass more data until it completes The lookahead functions have been removed from this parser because of their incompatibility with the incremental monad at the moment. | ||||||||||||||||||||||||||||||||||||||||||
Synopsis | ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
The Get type | ||||||||||||||||||||||||||||||||||||||||||
data Get r a | ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
data Result a | ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
runGet :: Get r r -> ByteString -> Result r | ||||||||||||||||||||||||||||||||||||||||||
Start a parser and return the first Result. | ||||||||||||||||||||||||||||||||||||||||||
Utility | ||||||||||||||||||||||||||||||||||||||||||
skip :: Int -> Get r () | ||||||||||||||||||||||||||||||||||||||||||
Skip ahead n bytes. Fails if fewer than n bytes are available. | ||||||||||||||||||||||||||||||||||||||||||
bytesRead :: Get r Int | ||||||||||||||||||||||||||||||||||||||||||
Get the total number of bytes read to this point. | ||||||||||||||||||||||||||||||||||||||||||
remaining :: Get r Int | ||||||||||||||||||||||||||||||||||||||||||
Get the number of remaining unparsed bytes. Useful for checking whether all input has been consumed. | ||||||||||||||||||||||||||||||||||||||||||
isEmpty :: Get r Bool | ||||||||||||||||||||||||||||||||||||||||||
Test whether all input has been consumed, i.e. there are no remaining unparsed bytes. | ||||||||||||||||||||||||||||||||||||||||||
Parsing particular types | ||||||||||||||||||||||||||||||||||||||||||
getWord8 :: Get r Word8 | ||||||||||||||||||||||||||||||||||||||||||
ByteStrings | ||||||||||||||||||||||||||||||||||||||||||
getByteString :: Int -> Get r ByteString | ||||||||||||||||||||||||||||||||||||||||||
An efficient get method for strict ByteStrings. Fails if fewer than n bytes are left in the input. | ||||||||||||||||||||||||||||||||||||||||||
Big-endian reads | ||||||||||||||||||||||||||||||||||||||||||
getWord16be :: Get r Word16 | ||||||||||||||||||||||||||||||||||||||||||
getWord32be :: Get r Word32 | ||||||||||||||||||||||||||||||||||||||||||
getWord64be :: Get r Word64 | ||||||||||||||||||||||||||||||||||||||||||
Little-endian reads | ||||||||||||||||||||||||||||||||||||||||||
getWord16le :: Get r Word16 | ||||||||||||||||||||||||||||||||||||||||||
getWord32le :: Get r Word32 | ||||||||||||||||||||||||||||||||||||||||||
getWord64le :: Get r Word64 | ||||||||||||||||||||||||||||||||||||||||||
Host-endian, unaligned reads | ||||||||||||||||||||||||||||||||||||||||||
getWordhost :: Get r Word | ||||||||||||||||||||||||||||||||||||||||||
getWord16host :: Get r Word16 | ||||||||||||||||||||||||||||||||||||||||||
getWord32host :: Get r Word32 | ||||||||||||||||||||||||||||||||||||||||||
getWord64host :: Get r Word64 | ||||||||||||||||||||||||||||||||||||||||||
Produced by Haddock version 0.8 |