Text.Megaparsec.Byte

megaparsec-9.7.0: Monadic parser combinators

Copyright | © 2015–present Megaparsec contributors
License | FreeBSD
Maintainer | Mark Karpov <markkarpov92@gmail.com>
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Text.Megaparsec.Byte

Contents

- Simple parsers
- Categories of characters
- Single byte
- Sequence of bytes

Description

Commonly used binary parsers.

Since: 6.0.0

Synopsis

- newline :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- crlf :: (MonadParsec e s m, Token s ~ Word8) => m (Tokens s)
- eol :: (MonadParsec e s m, Token s ~ Word8) => m (Tokens s)
- tab :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- space :: (MonadParsec e s m, Token s ~ Word8) => m ()
- hspace :: (MonadParsec e s m, Token s ~ Word8) => m ()
- space1 :: (MonadParsec e s m, Token s ~ Word8) => m ()
- hspace1 :: (MonadParsec e s m, Token s ~ Word8) => m ()
- controlChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- spaceChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- upperChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- lowerChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- letterChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- alphaNumChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- printChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- digitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- binDigitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- octDigitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- hexDigitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- asciiChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s)
- char :: (MonadParsec e s m, Token s ~ Word8) => Token s -> m (Token s)
- char' :: (MonadParsec e s m, Token s ~ Word8) => Token s -> m (Token s)
- string :: MonadParsec e s m => Tokens s -> m (Tokens s)
- string' :: (MonadParsec e s m, FoldCase (Tokens s)) => Tokens s -> m (Tokens s)

# Simple parsers

newline :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a newline byte.

crlf :: (MonadParsec e s m, Token s ~ Word8) => m (Tokens s) #

Parse a carriage return character followed by a newline character. Return the sequence of characters parsed.

eol :: (MonadParsec e s m, Token s ~ Word8) => m (Tokens s) #

Parse a CRLF (see `crlf`) or LF (see `newline`) end of line. Return the sequence of characters parsed.

tab :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a tab character.

space :: (MonadParsec e s m, Token s ~ Word8) => m () #

Skip zero or more white space characters.

See also: `skipMany` and `spaceChar`.

hspace :: (MonadParsec e s m, Token s ~ Word8) => m () #

Like `space`, but does not accept newlines and carriage returns.

Since: 9.0.0

space1 :: (MonadParsec e s m, Token s ~ Word8) => m () #

Skip one or more white space characters.

See also: `skipSome` and `spaceChar`.

hspace1 :: (MonadParsec e s m, Token s ~ Word8) => m () #

Like `space1`, but does not accept newlines and carriage returns.

Since: 9.0.0

# Categories of characters

controlChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a control character.

spaceChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a space character, and the control characters: tab, newline, carriage return, form feed, and vertical tab.

upperChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse an upper-case character.

lowerChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a lower-case alphabetic character.

letterChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse an alphabetic character: lower-case or upper-case.

alphaNumChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse an alphabetic or digit characters.

printChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a printable character: letter, number, mark, punctuation, symbol or space.

digitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse an ASCII digit, i.e between “0” and “9”.

binDigitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a binary digit, i.e. “0” or “1”.

Since: 7.0.0

octDigitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse an octal digit, i.e. between “0” and “7”.

hexDigitChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a hexadecimal digit, i.e. between “0” and “9”, or “a” and “f”, or “A” and “F”.

asciiChar :: (MonadParsec e s m, Token s ~ Word8) => m (Token s) #

Parse a character from the first 128 characters of the Unicode character set, corresponding to the ASCII character set.

# Single byte

char :: (MonadParsec e s m, Token s ~ Word8) => Token s -> m (Token s) #

A type-constrained version of `single`.

    newline = char 10

char' :: (MonadParsec e s m, Token s ~ Word8) => Token s -> m (Token s) #

The same as `char` but case-insensitive. This parser returns the actually parsed character preserving its case.

    >>> parseTest (char' 101) "E"
    69 -- 'E'
    >>> parseTest (char' 101) "G"
    1:1:
    unexpected 'G'
    expecting 'E' or 'e'

# Sequence of bytes

string :: MonadParsec e s m => Tokens s -> m (Tokens s) #

A synonym for `chunk`.

string' :: (MonadParsec e s m, FoldCase (Tokens s)) => Tokens s -> m (Tokens s) #

The same as `string`, but case-insensitive. On success returns string cased as the parsed input.

    >>> parseTest (string' "foobar") "foObAr"
    "foObAr"