Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Parser.Lathe
Description
Pure incremental byte parser.
Laziness
Parser functions that return concrete types in this library fully evaluate their results before returning unless their documentation specifies otherwise.
Synopsis
- data Parser e a
- type ByteOffset = Int64
- data More
- data Scrap = Scrap !ByteOffset !ByteString !More
- parse :: Parser e a -> ByteString -> (Scrap, Either e a)
- data Blank
- data Result a = Result ByteString !ByteOffset a
- data Resupply
- data Partial a
- prepare :: ByteOffset -> ByteString -> ByteString -> More -> Blank
- draw :: Parser e a -> Blank -> Partial (Blank, Either e a)
- scrap :: Blank -> Scrap
- bytesRead :: Parser never ByteOffset
- atEnd :: Parser never Bool
- err :: e -> Parser e a
- mapError :: (e -> Either x a) -> Parser e a -> Parser x a
- catch :: Parser e a -> (e -> Parser x a) -> Parser x a
- match :: Parser e a -> Parser e (ByteString, a)
- skip1 :: end -> Parser end ()
- skip :: Int64 -> end -> Parser end ()
- skipNul :: end -> Parser end ()
- skipUntil :: (Word8 -> Bool) -> end -> Parser end ()
- skipEndOr1 :: Parser never ()
- skipEndOr :: Int64 -> Parser never ()
- skipUntilEndOr :: (Word8 -> Bool) -> Parser never ()
- byteString :: Int -> end -> Parser end ByteString
- byteStringNul :: end -> Parser end ByteString
- byteStringUntil :: (Word8 -> Bool) -> end -> Parser end ByteString
- shortByteString :: Int -> end -> Parser end ShortByteString
- shortByteStringNul :: end -> Parser end ShortByteString
- shortByteStringUntil :: (Word8 -> Bool) -> end -> Parser end ShortByteString
- lazyByteString :: Int -> end -> Parser end ByteString
- lazyByteStringNul :: end -> Parser end ByteString
- lazyByteStringUntil :: (Word8 -> Bool) -> end -> Parser end ByteString
- lazyByteStringRest :: Parser never ByteString
Itself
The parser type, parametrized by an error type e
and a return type a
.
Note that there is no Alternative
instance for this parser,
see instead catch
.
Run
Immediate
type ByteOffset = Int64 Source #
An offset, counted in bytes.
Whether more input can be supplied.
Remaining bits of state.
Constructors
Scrap | |
Fields
|
parse :: Parser e a -> ByteString -> (Scrap, Either e a) Source #
Run a parser by providing all of the input immediately.
Incremental
Final parsing outcome.
Constructors
Result | |
Fields
|
Providing additional input to the decoder.
Constructors
Supply !ByteString | A chunk of the input. It should not be empty. N.B.: Lazy |
EndOfInput |
Arguments
:: ByteOffset | Initial byte offset. |
-> ByteString | First chunk of the stream. It may be empty. |
-> ByteString | Rest of the known stream. |
-> More | Whether more input can be requested. |
-> Blank |
Define the initial parser state.
Manage
bytesRead :: Parser never ByteOffset Source #
Get the total number of bytes read to this point.
Err
mapError :: (e -> Either x a) -> Parser e a -> Parser x a Source #
Modify the error type, or forget an error.
catch :: Parser e a -> (e -> Parser x a) -> Parser x a Source #
Execute the left parser; should an error occur, backtrack and execute the right parser.
References to all new input chunks consumed by the left parser are kept until it completes.
match :: Parser e a -> Parser e (ByteString, a) Source #
Execute the supplied parser, returning the slice of input consumed in the process alongside the result.
References to all new input chunks consumed by the supplied parser are kept until it completes.
Parse
No output
skipUntil :: (Word8 -> Bool) -> end -> Parser end () Source #
Skip ahead until the predicate holds (exclusive).
Optional
skipEndOr1 :: Parser never () Source #
Skip ahead 1 byte or do nothing.
skipEndOr :: Int64 -> Parser never () Source #
Skip ahead \(n\) or fewer bytes.
Does nothing if \(n \le 0\).
skipUntilEndOr :: (Word8 -> Bool) -> Parser never () Source #
Skip ahead until either the end is reached or the predicate holds (exclusive).
Strict ByteString
byteString :: Int -> end -> Parser end ByteString Source #
Consume \(n\) bytes into a strict ByteString
.
Returns an empty string if \(n \le 0\).
byteStringNul :: end -> Parser end ByteString Source #
Consume input into a strict ByteString
until a NUL byte (inclusive) is reached.
The returned string does not contain the NUL byte.
byteStringUntil :: (Word8 -> Bool) -> end -> Parser end ByteString Source #
Consume input into a strict ByteString
until the predicate holds (exclusive).
Short ByteString
shortByteString :: Int -> end -> Parser end ShortByteString Source #
Consume \(n\) bytes into a ShortByteString
.
Returns an empty string if \(n \le 0\).
shortByteStringNul :: end -> Parser end ShortByteString Source #
Consume input into a ShortByteString
until a NUL byte (inclusive) is reached.
The returned string does not contain the NUL byte.
shortByteStringUntil :: (Word8 -> Bool) -> end -> Parser end ShortByteString Source #
Consume input into a ShortByteString
until the predicate holds (exclusive).
Lazy ByteString
lazyByteString :: Int -> end -> Parser end ByteString Source #
Consume \(n\) bytes into a lazy ByteString
.
Returns an empty string if \(n \le 0\).
lazyByteStringNul :: end -> Parser end ByteString Source #
Consume input into a lazy ByteString
until a NUL byte (inclusive) is reached.
The returned string does not contain the NUL byte.
lazyByteStringUntil :: (Word8 -> Bool) -> end -> Parser end ByteString Source #
Consume input into a lazy ByteString
until the predicate holds (exclusive).
lazyByteStringRest :: Parser never ByteString Source #
Consume all remaining input into a lazy ByteString
.