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

Description

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

Synopsis

- newtype Parser i a = Parser {
  - runParser :: forall r. State i -> Pos -> More -> Failure i (State i) r -> Success i (State i) a r -> IResult i r
  }
- type family State i
- type Failure i t r = t -> Pos -> More -> [String] -> String -> IResult i r
- type Success i t a r = t -> Pos -> More -> a -> IResult i r
- newtype Pos = Pos {
  - fromPos :: Int
  }
- data IResult i r
  - = Fail i [String] String
  - | Partial (i -> IResult i r)
  - | Done i r
- data More
  - = Complete
  - | Incomplete
- (<>) :: Semigroup a => a -> a -> a
- class Monoid c => Chunk c where
  - type ChunkElem c
  - nullChunk :: c -> Bool
  - pappendChunk :: State c -> c -> State c
  - atBufferEnd :: c -> State c -> Pos
  - bufferElemAt :: c -> Pos -> State c -> Maybe (ChunkElem c, Int)
  - chunkElemToChar :: c -> ChunkElem c -> Char

# Documentation

newtype Parser i a #

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

Constructors

Parser |

Fields

- runParser :: forall r. State i -> Pos -> More -> Failure i (State i) r -> Success i (State i) a r -> IResult i r

#### Instances

Instances details

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

type family State i #

#### Instances

Instances details

type State ByteString # |
Instance details Defined in Data.Attoparsec.Internal.Types type State ByteString = Buffer
type State Text # |
Instance details Defined in Data.Attoparsec.Internal.Types type State Text = Buffer

type Failure i t r = t -> Pos -> More -> [String] -> String -> IResult i r #

type Success i t a r = t -> Pos -> More -> a -> IResult i r #

newtype Pos #

Constructors

Pos |

Fields

- fromPos :: Int

#### Instances

Instances details

Num Pos # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods (+) :: Pos -> Pos -> Pos # (-) :: Pos -> Pos -> Pos # (*) :: Pos -> Pos -> Pos # negate :: Pos -> Pos # abs :: Pos -> Pos # signum :: Pos -> Pos # fromInteger :: Integer -> Pos #
Show Pos # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods showsPrec :: Int -> Pos -> ShowS # show :: Pos -> String # showList :: [Pos] -> ShowS #
Eq Pos # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods (==) :: Pos -> Pos -> Bool # (/=) :: Pos -> Pos -> Bool #
Ord Pos # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods compare :: Pos -> Pos -> Ordering # (<) :: Pos -> Pos -> Bool # (<=) :: Pos -> Pos -> Bool # (>) :: Pos -> Pos -> Bool # (>=) :: Pos -> Pos -> Bool # max :: Pos -> Pos -> Pos # min :: Pos -> Pos -> Pos #

data IResult i r #

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

data More #

Have we read all available input?

Constructors

Complete |
Incomplete |

#### Instances

Instances details

Monoid More # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods mempty :: More # mappend :: More -> More -> More # mconcat :: [More] -> More #
Semigroup More # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods (<>) :: More -> More -> More # sconcat :: NonEmpty More -> More # stimes :: Integral b => b -> More -> More #
Show More # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods showsPrec :: Int -> More -> ShowS # show :: More -> String # showList :: [More] -> ShowS #
Eq More # |
Instance details Defined in Data.Attoparsec.Internal.Types Methods (==) :: More -> More -> Bool # (/=) :: More -> More -> Bool #

(<>) :: Semigroup a => a -> a -> a infixr 6 #

An associative operation.

#### Examples

Expand

    >>> [1,2,3] <> [4,5,6]
    [1,2,3,4,5,6]

    >>> Just [1, 2, 3] <> Just [4, 5, 6]
    Just [1,2,3,4,5,6]

    >>> putStr "Hello, " <> putStrLn "World!"
    Hello, World!

class Monoid c => Chunk c where #

A common interface for input chunks.

Associated Types

type ChunkElem c #

Methods

nullChunk :: c -> Bool #

Test if the chunk is empty.

pappendChunk :: State c -> c -> State c #

Append chunk to a buffer.

atBufferEnd :: c -> State c -> Pos #

Position at the end of a buffer. The first argument is ignored.

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

Return the buffer element at the given position along with its length.

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

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

#### Instances

Instances details

Chunk ByteString # |

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 #

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

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

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

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

Chunk Text # |

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 #

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

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

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

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