bytesmith-0.3.6.0: Nonresumable byte parser

Safe HaskellNone
LanguageHaskell2010

Data.Bytes.Parser.Ascii

Contents

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

Matching

char :: e -> Char -> Parser e s () Source #

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 () Source #

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 () Source #

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 () Source #

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

Get Character

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

Consumes and returns the next character in the input.

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

Variant of any with unboxed result.

peek :: e -> Parser e s Char Source #

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) Source #

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 Source #

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 Source #

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 () Source #

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

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

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

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

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

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

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

skipAlpha :: Parser e s () Source #

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

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

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

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

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 () Source #

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 Source #

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