attoparsec-0.13.0.1: Fast combinator parsing for bytestrings and text

CopyrightBryan O'Sullivan 2007-2015
LicenseBSD3
Maintainerbos@serpentine.com
Stabilityexperimental
Portabilityunknown
Safe HaskellNone
LanguageHaskell98

Data.Attoparsec.Internal.Types

Description

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

Synopsis

Documentation

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

Constructors

Parser 

Fields

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 Source

Instances

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

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

newtype Pos Source

Constructors

Pos 

Fields

fromPos :: Int
 

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

Functor (IResult i) Source 
(Show i, Show r) => Show (IResult i r) Source 
(NFData i, NFData r) => NFData (IResult i r) Source 

data More Source

Have we read all available input?

Constructors

Complete 
Incomplete 

(<>) :: Monoid m => m -> m -> m Source

class Monoid c => Chunk c where Source

A common interface for input chunks.

Associated Types

type ChunkElem c Source

Methods

nullChunk :: c -> Bool Source

Test if the chunk is empty.

pappendChunk :: State c -> c -> State c Source

Append chunk to a buffer.

atBufferEnd :: c -> State c -> Pos Source

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

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

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

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

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