HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulebytesmith-0.3.14.0Haskell2010

Data.Bytes.Parser.Latin

Parse input as though it were text encoded by ISO 8859-1 (Latin-1). All byte sequences are valid text under ISO 8859-1.

Contents
  1. Matching
  2. Required
  3. Try
  4. One Character
  5. Many Characters
  6. Lookahead
  7. Skip
  8. End of Input
  9. Numbers
  10. Decimal
  11. Unsigned
  12. Signed
  13. Hexadecimal
  14. Variable Length
  15. Fixed Length
  16. Digit
Synopsis

Matching

Required

valuechar :: e -> Char -> Parser e s ()

Consume the next character, failing if it does not match the expected value or if there is no more input.

valuechar2 :: e -> Char -> Char -> Parser e s ()

Consume the next two characters, failing if they do not match the expected values.

char2 e a b === char e a *> char e b
valuechar3 :: e -> Char -> Char -> Char -> Parser e s ()

Consume three characters, failing if they do not match the expected values.

char3 e a b c === char e a *> char e b *> char e c
valuechar4 :: e -> Char -> Char -> Char -> Char -> Parser e s ()

Consume four characters, failing if they do not match the expected values.

char4 e a b c d === char e a *> char e b *> char e c *> char e d

Try

valuetrySatisfy :: (Char -> Bool) -> Parser e s Bool

Runs the predicate on the next character in the input. If the predicate is matched, this consumes the character. Otherwise, the character is not consumed. This returns False if the end of the input has been reached. This never fails.

valuetrySatisfyThen
  1. :: Parser e s a

    Default parser. Runs on Nothing or end of input.

  2. -> (Char -> Maybe (Parser e s a))

    Parser-selecting predicate

  3. -> Parser e s a

Runs the function on the next character in the input. If the function returns Just, this consumes the character and then runs the parser on the remaining input. If the function returns Nothing, this does not consume the tested character, and it runs the default parser on the input (which includes the tested character). If there is no input remaining, this also runs the default parser. This combinator never fails.

One Character

valueopt :: Parser e s (Maybe Char)

Consume a character from the input or return Nothing if end of the stream has been reached. Since ISO 8859-1 maps every bytes to a character, this parser never fails.

Many Characters

valuetakeTrailedBy :: e -> Char -> Parser e s Bytes

Take characters until the specified character is encountered. Consumes the matched character as well. Fails if the character is not present. Visually, the cursor advancement and resulting Bytes for takeTrailedBy 'D' look like this:

 A B C D E F | input
|->->->-|    | cursor
{\-*-*-\}      | result bytes

Lookahead

valuepeek :: Parser e s (Maybe Char)

Match any character, to perform lookahead. Returns Nothing if end of input has been reached. Does not consume any input.

Note: Because this parser does not fail, do not use it with combinators such as many, because such as many, because such parsers loop until a failure occurs. Careless use will thus result in an infinite loop.

valuepeek' :: e -> Parser e s Char

Match any byte, to perform lookahead. Does not consume any input, but will fail if end of input has been reached.

Skip

valueskipDigits :: Parser e s ()

Skip the characters 0-9 until a non-digit is encountered. This parser does not fail.

valueskipChar :: Char -> Parser e s ()

Skip the character any number of times. This succeeds even if the character was not present.

valueskipChar1 :: e -> Char -> Parser e s ()

Skip the character any number of times. It must occur at least once or else this will fail.

valueskipTrailedBy :: e -> Char -> Parser e s ()

Skip all characters until the terminator is encountered and then consume the matching character as well. Visually, skipTrailedBy 'C' advances the cursor like this:

 A Z B Y C X C W
|->->->->-|

This fails if it reaches the end of input without encountering the character.

valueskipUntil :: Char -> Parser e s ()

Skip all characters until the terminator is encountered. This does not consume the terminator. Visually, skipUntil 'C' advances the cursor like this:

 A Z B Y C X C W
|->->->-|

This succeeds if it reaches the end of the input without encountering the terminator. It never fails.

End of Input

Numbers

Decimal

Unsigned

valuedecWord :: e -> Parser e s Word

Parse a decimal-encoded number. If the number is too large to be represented by a machine word, this fails with the provided error message. This accepts any number of leading zeroes.

valuedecWord8 :: e -> Parser e s Word8

Parse a decimal-encoded 8-bit word. If the number is larger than 255, this parser fails.

valuedecWord16 :: e -> Parser e s Word16

Parse a decimal-encoded 16-bit word. If the number is larger than 65535, this parser fails.

valuedecWord32 :: e -> Parser e s Word32

Parse a decimal-encoded 32-bit word. If the number is larger than 4294967295, this parser fails.

valuedecWord64 :: e -> Parser e s Word64

Parse a decimal-encoded unsigned number. If the number is too large to be represented by a 64-bit word, this fails with the provided error message. This accepts any number of leading zeroes.

Signed

valuedecUnsignedInt :: e -> Parser e s Int

Parse a decimal-encoded number. If the number is too large to be represented by a machine integer, this fails with the provided error message. This rejects input with that is preceeded by plus or minus. Consequently, it does not parse negative numbers. Use decStandardInt or decSignedInt for that purpose. On a 64-bit platform decWord will successfully parse 9223372036854775808 (i.e. 2 ^ 63), but decUnsignedInt will fail. This parser allows leading zeroes.

valuedecSignedInt :: e -> Parser e s Int

Parse a decimal-encoded number. If the number is too large to be represented by a machine integer, this fails with the provided error message. This allows the number to optionally be prefixed by plus or minus. If the sign prefix is not present, the number is interpreted as positive. This allows leading zeroes.

valuedecStandardInt :: e -> Parser e s Int

Parse a decimal-encoded number. If the number is too large to be represented by a machine integer, this fails with the provided error message. This allows the number to optionally be prefixed by minus. If the minus prefix is not present, the number is interpreted as positive. The disallows a leading plus sign. For example, decStandardInt rejects +42, but decSignedInt allows it.

valuedecTrailingInt
  1. :: e

    Error message

  2. -> Int

    Leading digit, should be between 0 and 9.

  3. -> Parser e s Int

Variant of decUnsignedInt that lets the caller supply a leading digit. This is useful when parsing formats like JSON where integers with leading zeroes are considered invalid. The calling context must consume the first digit before calling this parser. Results are always positive numbers.

valuedecSignedInteger :: e -> Parser e s Integer

Parse a decimal-encoded integer of arbitrary size. This accepts input that begins with a plus or minus sign. Input without a sign prefix is interpreted as positive.

valuedecTrailingInteger
  1. :: Int

    Leading digit, should be between 0 and 9.

  2. -> Parser e s Integer

Variant of decUnsignedInteger that lets the caller supply a leading digit. This is useful when parsing formats like JSON where integers with leading zeroes are considered invalid. The calling context must consume the first digit before calling this parser. Results are always positive numbers.

Hexadecimal

Variable Length

valuehexWord8 :: e -> Parser e s Word8

Parse a hexadecimal-encoded 8-bit word. If the number is larger than 255, this parser fails. This allows leading zeroes and is insensitive to case. For example, 00A, 0a and A would all be accepted as the same number.

valuehexWord16 :: e -> Parser e s Word16

Parse a hexadecimal-encoded 16-bit word. If the number is larger than 65535, this parser fails. This allows leading zeroes and is insensitive to case. For example, 0100a and 100A would both be accepted as the same number.

Fixed Length

valuehexFixedWord8 :: e -> Parser e s Word8

Parse exactly two ASCII-encoded characters, interpretting them as the hexadecimal encoding of a 8-bit number. Note that this rejects a sequence such as A, requiring 0A instead. This is insensitive to case.

valuehexFixedWord16 :: e -> Parser e s Word16

Parse exactly four ASCII-encoded characters, interpreting them as the hexadecimal encoding of a 16-bit number. Note that this rejects a sequence such as 5A9, requiring 05A9 instead. This is insensitive to case. This is particularly useful when parsing escape sequences in C or JSON, which allow encoding characters in the Basic Multilingual Plane as \uhhhh.

valuehexFixedWord16# :: e -> Parser e s Word#

Variant of hexFixedWord16 that returns an unboxed result. The result is a machine-sized word instead of a 16-bit word, but this function guarantees that only the low 16 bits may be non-zero. This is helpful because the result needs to be constructed as a machine-sized word. GHC's primitives for working with 16-bit words lower to most ISAs poorly.

valuehexFixedWord32 :: e -> Parser e s Word32

Parse exactly eight ASCII-encoded characters, interpreting them as the hexadecimal encoding of a 32-bit number. Note that this rejects a sequence such as BC5A9, requiring 000BC5A9 instead. This is insensitive to case.

valuehexFixedWord64 :: e -> Parser e s Word64

Parse exactly 16 ASCII-encoded characters, interpreting them as the hexadecimal encoding of a 64-bit number. Note that this rejects a sequence such as BC5A9, requiring 00000000000BC5A9 instead. This is insensitive to case.

Digit

valuehexNibbleLower :: e -> Parser e s Word

Consume a single character that is the lowercase hexadecimal encoding of a 4-bit word. Fails if the character is not in the class [a-f0-9].

Consume a single character that is the lowercase hexadecimal encoding of a 4-bit word. Returns Nothing without consuming the character if it is not in the class [a-f0-9]. The parser never fails.

valuehexNibble :: e -> Parser e s Word

Consume a single character that is the case-insensitive hexadecimal encoding of a 4-bit word. Fails if the character is not in the class [a-fA-F0-9].

Consume a single character that is the case-insensitive hexadecimal encoding of a 4-bit word. Returns Nothing without consuming the character if it is not in the class [a-fA-F0-9]. This parser never fails.