Data.Bytes.Parser.Ascii

bytesmith-0.3.11.1: Nonresumable byte parser

Safe Haskell | None
Language | Haskell2010

Data.Bytes.Parser.Ascii

Contents

- Matching
- Case-Insensitive Matching
- Get Character
- Match Many
- Skip
- Numbers

Description

Parse input as ASCII-encoded text. Some parsers in this module, like `any` and `peek`, fail if they encounter a byte above `0x7F`. Others, like numeric parsers and skipping parsers, leave the cursor at the position of the offending byte without failing.

Synopsis

- char :: e -> Char -> Parser e s ()
- char2 :: e -> Char -> Char -> Parser e s ()
- char3 :: e -> Char -> Char -> Char -> Parser e s ()
- char4 :: e -> Char -> Char -> Char -> Char -> Parser e s ()
- charInsensitive :: e -> Char -> Parser e s ()
- any :: e -> Parser e s Char
- any# :: e -> Parser e s Char#
- peek :: e -> Parser e s Char
- opt :: e -> Parser e s (Maybe Char)
- shortTrailedBy :: e -> Char -> Parser e s ShortText
- takeShortWhile :: (Char -> Bool) -> Parser e s ShortText
- skipDigits :: Parser e s ()
- skipDigits1 :: e -> Parser e s ()
- skipChar :: Char -> Parser e s ()
- skipChar1 :: e -> Char -> Parser e s ()
- skipAlpha :: Parser e s ()
- skipAlpha1 :: e -> Parser e s ()
- skipTrailedBy :: e -> Char -> Parser e s ()
- skipWhile :: (Char -> Bool) -> Parser e s ()
- decWord :: e -> Parser e s Word
- decWord8 :: e -> Parser e s Word8
- decWord16 :: e -> Parser e s Word16
- decWord32 :: e -> Parser e s Word32

# Matching

char :: 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.

char2 :: 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

char3 :: 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

char4 :: 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

# Case-Insensitive Matching

charInsensitive :: 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. This check for equality is case insensitive.

Precondition: The argument must be a letter (`[a-zA-Z]`). Behavior is undefined if it is not.

# Get Character

any :: e -> Parser e s Char #

Consumes and returns the next character in the input.

any# :: e -> Parser e s Char# #

Variant of `any` with unboxed result.

peek :: e -> Parser e s Char #

Examine the next byte without consuming it, interpret it as an ASCII-encoded character. This fails if the byte is above `0x7F` or if the end of input has been reached.

opt :: e -> Parser e s (Maybe Char) #

Consume the next byte, interpreting it as an ASCII-encoded character. Fails if the byte is above `0x7F`. Returns `Nothing` if the end of the input has been reached.

# Match Many

shortTrailedBy :: e -> Char -> Parser e s ShortText #

Consume input through the next occurrence of the target character and return the consumed input, excluding the target character, as a `ShortText`. This fails if it encounters any bytes above `0x7F`.

takeShortWhile :: (Char -> Bool) -> Parser e s ShortText #

Consume characters matching the predicate. The stops when it encounters a non-matching character or when it encounters a byte above `0x7F`. This never fails.

# Skip

skipDigits :: Parser e s () #

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

skipDigits1 :: e -> Parser e s () #

Variant of `skipDigits` that requires at least one digit to be present.

skipChar :: Char -> Parser e s () #

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

skipChar1 :: e -> Char -> Parser e s () #

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

skipAlpha :: Parser e s () #

Skip uppercase and lowercase letters until a non-alpha character is encountered.

skipAlpha1 :: e -> Parser e s () #

Skip uppercase and lowercase letters until a non-alpha character is encountered.

skipTrailedBy :: e -> Char -> Parser e s () #

Consume input until the trailer is found. Then, consume the trailer as well. This fails if the trailer is not found or if any non-ASCII characters are encountered.

skipWhile :: (Char -> Bool) -> Parser e s () #

Consume characters matching the predicate. The stops when it encounters a non-matching character or when it encounters a byte above `0x7F`. This never fails.

# Numbers

decWord :: 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.

decWord8 :: e -> Parser e s Word8 #

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

decWord16 :: e -> Parser e s Word16 #

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

decWord32 :: e -> Parser e s Word32 #

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