attoparsec- Fast combinator parsing for bytestrings and text

Safe HaskellNone



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



data Parser t a Source

The core parser type. This is parameterised over the type t 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.


data IResult t r Source

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

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


Fail t [String] String

The parse failed. The t 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 (t -> IResult t r)

Supply this continuation with more input so that the parser can resume. To indicate that no more input is available, use an empty string.

Done t r

The parse succeeded. The t parameter is the input that had not yet been consumed (if any) when the parse succeeded.


Functor (IResult t) 
(Show t, Show r) => Show (IResult t r) 
(NFData t, NFData r) => NFData (IResult t r) 

class Monoid c => Chunk c whereSource

A common interface for input chunks.

Associated Types

type ChunkElem c Source


nullChunk :: c -> BoolSource

Test if the chunk is empty.

unsafeChunkHead :: c -> ChunkElem cSource

Get the head element of a non-empty chunk.

unsafeChunkTail :: c -> cSource

Get the tail of a non-empty chunk.

chunkLengthAtLeast :: c -> Int -> BoolSource

Check if the chunk has the length of at least n elements.

chunkElemToChar :: c -> ChunkElem c -> CharSource

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