Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Parser :: forall (r :: RuntimeRep). Type -> Type -> TYPE r -> Type where
- data Result e a
- parseByteArray :: (forall s. Parser e s a) -> ByteArray -> Result e a
- parseBytes :: forall e a. (forall s. Parser e s a) -> Bytes -> Result e a
- parseBytesST :: Parser e s a -> Bytes -> ST s (Result e a)
- fail :: e -> Parser e s a
- peekAnyAscii :: e -> Parser e s Char
- ascii :: e -> Char -> Parser e s ()
- ascii3 :: e -> Char -> Char -> Char -> Parser e s ()
- ascii4 :: e -> Char -> Char -> Char -> Char -> Parser e s ()
- any :: e -> Parser e s Word8
- anyAscii :: e -> Parser e s Char
- anyAscii# :: e -> Parser e s Char#
- anyUtf8# :: e -> Parser e s Char#
- anyAsciiOpt :: e -> Parser e s (Maybe Char)
- decWord :: e -> Parser e s Word
- decWord8 :: e -> Parser e s Word8
- decWord16 :: e -> Parser e s Word16
- decWord32 :: e -> Parser e s Word32
- hexWord16 :: e -> Parser e s Word16
- decPositiveInteger :: e -> Parser e s Integer
- endOfInput :: e -> Parser e s ()
- isEndOfInput :: Parser e s Bool
- skipUntilAsciiConsume :: e -> Char -> Parser e s ()
- skipWhile :: (Word8 -> Bool) -> Parser e s ()
- skipAscii :: Char -> Parser e s ()
- skipAscii1 :: e -> Char -> Parser e s ()
- skipAlphaAscii :: Parser e s ()
- skipAlphaAscii1 :: e -> Parser e s ()
- skipDigitsAscii :: Parser e s ()
- skipDigitsAscii1 :: e -> Parser e s ()
- effect :: ST s a -> Parser e s a
- cursor :: Parser e s Int
- expose :: Parser e s ByteArray
- unconsume :: Int -> Parser e s ()
- unboxWord32 :: Parser s e Word32 -> Parser s e Word#
- boxWord32 :: Parser s e Word# -> Parser s e Word32
- bindChar :: Parser s e Char# -> (Char# -> Parser s e a) -> Parser s e a
- orElse :: Parser s e a -> Parser s e a -> Parser s e a
Types
newtype Parser :: forall (r :: RuntimeRep). Type -> Type -> TYPE r -> Type where Source #
A non-resumable parser.
Parser | |
|
The result of running a parser.
Run Parsers
parseByteArray :: (forall s. Parser e s a) -> ByteArray -> Result e a Source #
Variant of parseBytes
that accepts an unsliced ByteArray
.
parseBytes :: forall e a. (forall s. Parser e s a) -> Bytes -> Result e a Source #
Parse a slice of a byte array. This can succeed even if the entire slice was not consumed by the parser.
parseBytesST :: Parser e s a -> Bytes -> ST s (Result e a) Source #
Variant of parseBytes
that allows the parser to be run
as part of an existing effectful context.
Build Parsers
peekAnyAscii :: e -> Parser e s Char Source #
Interpret the next byte as an ASCII-encoded character. Fails if the byte corresponds to a number above 127.
ascii :: e -> Char -> Parser e s () Source #
Only valid for characters with a Unicode code point lower than 128. This consumes a single byte, decoding it as an ASCII character.
ascii4 :: e -> Char -> Char -> Char -> Char -> Parser e s () Source #
Parse four bytes in succession.
any :: e -> Parser e s Word8 Source #
Consumes and returns the next byte in the input. Fails if no characters are left.
anyAscii :: e -> Parser e s Char Source #
Interpret the next byte as an ASCII-encoded character. Fails if the byte corresponds to a number above 127.
anyAscii# :: e -> Parser e s Char# Source #
Interpret the next byte as an ASCII-encoded character. Fails if the byte corresponds to a number above 127.
anyUtf8# :: e -> Parser e s Char# Source #
Interpret the next one to four bytes as a UTF-8-encoded character. Fails if the decoded codepoint is in the range U+D800 through U+DFFF.
anyAsciiOpt :: e -> Parser e s (Maybe Char) Source #
Interpret the next byte as an ASCII-encoded character. Fails if the byte corresponds to a number above 127. Returns nothing if the end of the input has been reached.
decWord :: e -> Parser e s Word Source #
Parse a decimal-encoded number. If the number is too large to be represented by a machine word, this overflows rather than failing. This may be changed in a future release.
decWord8 :: e -> Parser e s Word8 Source #
Parse a decimal-encoded 8-bit word. If the number is larger than 255, this parser fails.
decWord16 :: e -> Parser e s Word16 Source #
Parse a decimal-encoded 16-bit word. If the number is larger than 65535, this parser fails.
decWord32 :: e -> Parser e s Word32 Source #
Parse a decimal-encoded 32-bit word. If the number is larger than 4294967295, this parser fails.
hexWord16 :: e -> Parser e s Word16 Source #
Parse exactly four ASCII-encoded characters, interpretting
them as the hexadecimal encoding of a 32-bit number. Note that
this rejects a sequence such as 5A9
, requiring 05A9
instead.
This is insensitive to case.
decPositiveInteger :: e -> Parser e s Integer Source #
Parse a decimal-encoded positive integer of arbitrary size. Note: this is not implemented efficiently. This pulls in one digit at a time, multiplying the accumulator by ten each time and adding the new digit. Since arithmetic involving arbitrary-precision integers is somewhat expensive, it would be better to pull in several digits at a time, convert those to a machine-sized integer, then upcast and perform the multiplication and addition.
endOfInput :: e -> Parser e s () Source #
Fails if there is still more input remaining.
isEndOfInput :: Parser e s Bool Source #
Returns true if there are no more bytes in the input. Returns false otherwise. Always succeeds.
skipUntilAsciiConsume :: e -> Char -> Parser e s () Source #
Skip bytes until the character from the ASCII plane is encountered. This does not ensure that the skipped bytes were ASCII-encoded characters.
skipWhile :: (Word8 -> Bool) -> Parser e s () Source #
Skip while the predicate is matched. This is always inlined.
skipAscii :: Char -> Parser e s () Source #
Skip the character any number of times. This succeeds even if the character was not present.
skipAscii1 :: e -> Char -> Parser e s () Source #
Skip the character any number of times. It must occur at least once or else this will fail.
skipAlphaAscii :: Parser e s () Source #
Skip uppercase and lowercase letters until a non-alpha character is encountered.
skipAlphaAscii1 :: e -> Parser e s () Source #
Skip uppercase and lowercase letters until a non-alpha character is encountered.
skipDigitsAscii :: Parser e s () Source #
Skip ASCII-encoded digits until a non-digit is encountered.
skipDigitsAscii1 :: e -> Parser e s () Source #
Skip uppercase and lowercase letters until a non-alpha character is encountered.
Lift Effects
Expose Internals
cursor :: Parser e s Int Source #
Get the current offset into the chunk. Using this makes
it possible to observe the internal difference between Bytes
that refer to equivalent slices. Be careful.
expose :: Parser e s ByteArray Source #
Return the byte array being parsed. This includes bytes that preceed the current offset and may include bytes that go beyond the length. This is somewhat dangerous, so only use this is you know what you're doing.
unconsume :: Int -> Parser e s () Source #
Move the cursor back by n
bytes. Precondition: you
must have previously consumed at least n
bytes.
Cut down on boxing
Specialized Bind
Sometimes, GHC ends up building join points in a way that
boxes arguments unnecessarily. In this situation, special variants
of monadic >>=
can be helpful. If C#
, I#
, etc. never
get used in you original source code, GHC cannot introduce them.
bindChar :: Parser s e Char# -> (Char# -> Parser s e a) -> Parser s e a Source #
Specialization of monadic bind for parsers that return Char#
.
Alternative
orElse :: Parser s e a -> Parser s e a -> Parser s e a Source #
There is a law-abiding instance of Alternative
for Parser
.
However, it is not terribly useful since error messages seldom
have a Monoid
instance. This function is a right-biased
variant of <|>
. Consequently, it lacks an identity.
See attoparsec #122
for more discussion of this topic.