attoparsec-0.14.4: Fast combinator parsing for bytestrings and text

Copyright | Bryan O'Sullivan 2007-2015
License | BSD3
Maintainer | bos@serpentine.com
Stability | experimental
Portability | unknown
Safe Haskell | None
Language | Haskell2010

Data.Attoparsec.Types

Description

Simple, efficient parser combinators for strings, loosely based on the Parsec library.

Synopsis

- data Parser i a
- data IResult i r
  - = Fail i [String] String
  - | Partial (i -> IResult i r)
  - | Done i r
- class Monoid c => Chunk c where
  - chunkElemToChar :: c -> ChunkElem c -> Char

# Documentation

data Parser i a Source #

The core parser type. This is parameterised over the type `i` of string being processed.

This type is an instance of the following classes:

- `Monad`, where `fail` throws an exception (i.e. fails) with an error message.
- `Functor` and `Applicative`, which follow the usual definitions.
- `MonadPlus`, where `mzero` fails (with no error message) and `mplus` executes the right-hand parser if the left-hand one fails. When the parser on the right executes, the input is reset to the same state as the parser on the left started with. (In other words, attoparsec is a backtracking parser that supports arbitrary lookahead.)
- `Alternative`, which follows `MonadPlus`.

#### Instances

Instances details

Alternative (Parser i) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods empty :: Parser i a Source # (<|>) :: Parser i a -> Parser i a -> Parser i a Source # some :: Parser i a -> Parser i [a] Source # many :: Parser i a -> Parser i [a] Source #
Applicative (Parser i) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods pure :: a -> Parser i a Source # (<*>) :: Parser i (a -> b) -> Parser i a -> Parser i b Source # liftA2 :: (a -> b -> c) -> Parser i a -> Parser i b -> Parser i c Source # (*>) :: Parser i a -> Parser i b -> Parser i b Source # (<*) :: Parser i a -> Parser i b -> Parser i a Source #
Functor (Parser i) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods fmap :: (a -> b) -> Parser i a -> Parser i b Source # (<$) :: a -> Parser i b -> Parser i a Source #
Monad (Parser i) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods (>>=) :: Parser i a -> (a -> Parser i b) -> Parser i b Source # (>>) :: Parser i a -> Parser i b -> Parser i b Source # return :: a -> Parser i a Source #
MonadPlus (Parser i) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods mzero :: Parser i a Source # mplus :: Parser i a -> Parser i a -> Parser i a Source #
MonadFail (Parser i) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods fail :: String -> Parser i a Source #
a ~ ByteString => IsString (Parser a) Source # |
Instance details Defined in Data.Attoparsec.ByteString.Char8 Methods fromString :: String -> Parser a Source #
a ~ Text => IsString (Parser a) Source # |
Instance details Defined in Data.Attoparsec.Text.Internal Methods fromString :: String -> Parser a Source #
Monoid (Parser i a) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods mempty :: Parser i a Source # mappend :: Parser i a -> Parser i a -> Parser i a Source # mconcat :: [Parser i a] -> Parser i a Source #
Semigroup (Parser i a) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods (<>) :: Parser i a -> Parser i a -> Parser i a Source # sconcat :: NonEmpty (Parser i a) -> Parser i a Source # stimes :: Integral b => b -> Parser i a -> Parser i a Source #

data IResult i r Source #

The result of a parse. This is parameterised over the type `i` of string that was processed.

This type is an instance of `Functor`, where `fmap` transforms the value in a `Done` result.

Constructors

Fail i [String] String | The parse failed. The `i` parameter is the input that had not yet been consumed when the failure occurred. The `[``String``]` is a list of contexts in which the error occurred. The `String` is the message describing the error, if any.
Partial (i -> IResult i r) | Supply this continuation with more input so that the parser can resume. To indicate that no more input is available, pass an empty string to the continuation. Note: if you get a `Partial` result, do not call its continuation more than once.
Done i r | The parse succeeded. The `i` parameter is the input that had not yet been consumed (if any) when the parse succeeded.

#### Instances

Instances details

Functor (IResult i) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods fmap :: (a -> b) -> IResult i a -> IResult i b Source # (<$) :: a -> IResult i b -> IResult i a Source #
(NFData i, NFData r) => NFData (IResult i r) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods rnf :: IResult i r -> () Source #
(Show i, Show r) => Show (IResult i r) Source # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods showsPrec :: Int -> IResult i r -> ShowS Source # show :: IResult i r -> String Source # showList :: [IResult i r] -> ShowS Source #

class Monoid c => Chunk c where Source #

A common interface for input chunks.

Minimal complete definition

nullChunk, pappendChunk, atBufferEnd, bufferElemAt, chunkElemToChar

Methods

chunkElemToChar :: c -> ChunkElem c -> Char Source #

Map an element to the corresponding character. The first argument is ignored.

#### Instances

Instances details

Chunk ByteString Source # |

Instance details

Defined in Data.Attoparsec.Internal.Types

Associated Types

type ChunkElem ByteString |
Instance details Defined in Data.Attoparsec.Internal.Types type ChunkElem ByteString = Word8

Methods

nullChunk :: ByteString -> Bool Source #

pappendChunk :: State ByteString -> ByteString -> State ByteString Source #

atBufferEnd :: ByteString -> State ByteString -> Pos Source #

bufferElemAt :: ByteString -> Pos -> State ByteString -> Maybe (ChunkElem ByteString, Int) Source #

chunkElemToChar :: ByteString -> ChunkElem ByteString -> Char Source #

Chunk Text Source # |

Instance details

Defined in Data.Attoparsec.Internal.Types

Associated Types

type ChunkElem Text |
Instance details Defined in Data.Attoparsec.Internal.Types type ChunkElem Text = Char

Methods

nullChunk :: Text -> Bool Source #

pappendChunk :: State Text -> Text -> State Text Source #

atBufferEnd :: Text -> State Text -> Pos Source #

bufferElemAt :: Text -> Pos -> State Text -> Maybe (ChunkElem Text, Int) Source #

chunkElemToChar :: Text -> ChunkElem Text -> Char Source #