parsers-0.12.4: Parsing combinators

Copyright | (c) Edward Kmett 2011
License | BSD3
Maintainer | ekmett@gmail.com
Stability | experimental
Portability | non-portable
Safe Haskell | None
Language | Haskell2010

Text.Parser.Char

Contents

- Combinators
- Class

Description

Parsers for character streams

Synopsis

- oneOf :: CharParsing m => [Char] -> m Char
- noneOf :: CharParsing m => [Char] -> m Char
- oneOfSet :: CharParsing m => CharSet -> m Char
- noneOfSet :: CharParsing m => CharSet -> m Char
- spaces :: CharParsing m => m ()
- space :: CharParsing m => m Char
- newline :: CharParsing m => m Char
- tab :: CharParsing m => m Char
- upper :: CharParsing m => m Char
- lower :: CharParsing m => m Char
- alphaNum :: CharParsing m => m Char
- letter :: CharParsing m => m Char
- digit :: CharParsing m => m Char
- hexDigit :: CharParsing m => m Char
- octDigit :: CharParsing m => m Char
- satisfyRange :: CharParsing m => Char -> Char -> m Char
- class Parsing m => CharParsing m where

# Combinators

oneOf :: CharParsing m => [Char] -> m Char #

`oneOf cs` succeeds if the current character is in the supplied list of characters `cs`. Returns the parsed character. See also `satisfy`.

      vowel  = oneOf "aeiou"

noneOf :: CharParsing m => [Char] -> m Char #

As the dual of `oneOf`, `noneOf cs` succeeds if the current character is not in the supplied list of characters `cs`. Returns the parsed character.

     consonant = noneOf "aeiou"

oneOfSet :: CharParsing m => CharSet -> m Char #

`oneOfSet cs` succeeds if the current character is in the supplied set of characters `cs`. Returns the parsed character. See also `satisfy`.

      vowel  = oneOf "aeiou"

noneOfSet :: CharParsing m => CharSet -> m Char #

As the dual of `oneOf`, `noneOf cs` succeeds if the current character is not in the supplied list of characters `cs`. Returns the parsed character.

     consonant = noneOf "aeiou"

spaces :: CharParsing m => m () #

Skips zero or more white space characters. See also `skipMany`.

space :: CharParsing m => m Char #

Parses a white space character (any character which satisfies `isSpace`) Returns the parsed character.

newline :: CharParsing m => m Char #

Parses a newline character ('\n'). Returns a newline character.

tab :: CharParsing m => m Char #

Parses a tab character ('\t'). Returns a tab character.

upper :: CharParsing m => m Char #

Parses an upper case letter. Returns the parsed character.

lower :: CharParsing m => m Char #

Parses a lower case character. Returns the parsed character.

alphaNum :: CharParsing m => m Char #

Parses a letter or digit. Returns the parsed character.

letter :: CharParsing m => m Char #

Parses a letter (an upper case or lower case character). Returns the parsed character.

digit :: CharParsing m => m Char #

Parses a digit. Returns the parsed character.

hexDigit :: CharParsing m => m Char #

Parses a hexadecimal digit (a digit or a letter between 'a' and 'f' or 'A' and 'F'). Returns the parsed character.

octDigit :: CharParsing m => m Char #

Parses an octal digit (a character between '0' and '7'). Returns the parsed character.

satisfyRange :: CharParsing m => Char -> Char -> m Char #

# Class

class Parsing m => CharParsing m where #

Additional functionality needed to parse character streams.

Methods

satisfy :: (Char -> Bool) -> m Char #

Parse a single character of the input, with UTF-8 decoding

satisfy :: (MonadTrans t, CharParsing n, Monad n, m ~ t n) => (Char -> Bool) -> t n Char #

Parse a single character of the input, with UTF-8 decoding

char :: Char -> m Char #

`char c` parses a single character `c`. Returns the parsed character (i.e. `c`).

e.g.

    semiColon = char ';'

notChar :: Char -> m Char #

`notChar c` parses any single character other than `c`. Returns the parsed character.

anyChar :: m Char #

This parser succeeds for any character. Returns the parsed character.

string :: String -> m String #

`string s` parses a sequence of characters given by `s`. Returns the parsed string (i.e. `s`).

     divOrMod    =   string "div"
                 <|> string "mod"

text :: Text -> m Text #

`text t` parses a sequence of characters determined by the text `t` Returns the parsed text fragment (i.e. `t`).

Using `OverloadedStrings`:

     divOrMod    =   text "div"
                 <|> text "mod"

Instances

CharParsing ReadP # |
Methods satisfy :: (Char -> Bool) -> ReadP Char # char :: Char -> ReadP Char # notChar :: Char -> ReadP Char # anyChar :: ReadP Char # string :: String -> ReadP String # text :: Text -> ReadP Text #
Chunk t => CharParsing (Parser t) # |
Methods satisfy :: (Char -> Bool) -> Parser t Char # char :: Char -> Parser t Char # notChar :: Char -> Parser t Char # anyChar :: Parser t Char # string :: String -> Parser t String # text :: Text -> Parser t Text #
CharParsing m => CharParsing (Unlined m) # |
Methods satisfy :: (Char -> Bool) -> Unlined m Char # char :: Char -> Unlined m Char # notChar :: Char -> Unlined m Char # anyChar :: Unlined m Char # string :: String -> Unlined m String # text :: Text -> Unlined m Text #
CharParsing m => CharParsing (Unspaced m) # |
Methods satisfy :: (Char -> Bool) -> Unspaced m Char # char :: Char -> Unspaced m Char # notChar :: Char -> Unspaced m Char # anyChar :: Unspaced m Char # string :: String -> Unspaced m String # text :: Text -> Unspaced m Text #
CharParsing m => CharParsing (Unhighlighted m) # |
Methods satisfy :: (Char -> Bool) -> Unhighlighted m Char # char :: Char -> Unhighlighted m Char # notChar :: Char -> Unhighlighted m Char # anyChar :: Unhighlighted m Char # string :: String -> Unhighlighted m String # text :: Text -> Unhighlighted m Text #
(CharParsing m, MonadPlus m) => CharParsing (StateT s m) # |
Methods satisfy :: (Char -> Bool) -> StateT s m Char # char :: Char -> StateT s m Char # notChar :: Char -> StateT s m Char # anyChar :: StateT s m Char # string :: String -> StateT s m String # text :: Text -> StateT s m Text #
(CharParsing m, MonadPlus m) => CharParsing (StateT s m) # |
Methods satisfy :: (Char -> Bool) -> StateT s m Char # char :: Char -> StateT s m Char # notChar :: Char -> StateT s m Char # anyChar :: StateT s m Char # string :: String -> StateT s m String # text :: Text -> StateT s m Text #
(CharParsing m, MonadPlus m, Monoid w) => CharParsing (WriterT w m) # |
Methods satisfy :: (Char -> Bool) -> WriterT w m Char # char :: Char -> WriterT w m Char # notChar :: Char -> WriterT w m Char # anyChar :: WriterT w m Char # string :: String -> WriterT w m String # text :: Text -> WriterT w m Text #
(CharParsing m, MonadPlus m, Monoid w) => CharParsing (WriterT w m) # |
Methods satisfy :: (Char -> Bool) -> WriterT w m Char # char :: Char -> WriterT w m Char # notChar :: Char -> WriterT w m Char # anyChar :: WriterT w m Char # string :: String -> WriterT w m String # text :: Text -> WriterT w m Text #
(CharParsing m, MonadPlus m) => CharParsing (IdentityT * m) # |
Methods satisfy :: (Char -> Bool) -> IdentityT * m Char # char :: Char -> IdentityT * m Char # notChar :: Char -> IdentityT * m Char # anyChar :: IdentityT * m Char # string :: String -> IdentityT * m String # text :: Text -> IdentityT * m Text #
(CharParsing m, MonadPlus m) => CharParsing (ReaderT * e m) # |
Methods satisfy :: (Char -> Bool) -> ReaderT * e m Char # char :: Char -> ReaderT * e m Char # notChar :: Char -> ReaderT * e m Char # anyChar :: ReaderT * e m Char # string :: String -> ReaderT * e m String # text :: Text -> ReaderT * e m Text #
Stream s m Char => CharParsing (ParsecT s u m) # |
Methods satisfy :: (Char -> Bool) -> ParsecT s u m Char # char :: Char -> ParsecT s u m Char # notChar :: Char -> ParsecT s u m Char # anyChar :: ParsecT s u m Char # string :: String -> ParsecT s u m String # text :: Text -> ParsecT s u m Text #
(CharParsing m, MonadPlus m, Monoid w) => CharParsing (RWST r w s m) # |
Methods satisfy :: (Char -> Bool) -> RWST r w s m Char # char :: Char -> RWST r w s m Char # notChar :: Char -> RWST r w s m Char # anyChar :: RWST r w s m Char # string :: String -> RWST r w s m String # text :: Text -> RWST r w s m Text #
(CharParsing m, MonadPlus m, Monoid w) => CharParsing (RWST r w s m) # |
Methods satisfy :: (Char -> Bool) -> RWST r w s m Char # char :: Char -> RWST r w s m Char # notChar :: Char -> RWST r w s m Char # anyChar :: RWST r w s m Char # string :: String -> RWST r w s m String # text :: Text -> RWST r w s m Text #