Data.Attoparsec.ByteString.Lazy

attoparsec-0.13.0.2: 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 | Trustworthy
Language | Haskell98

Data.Attoparsec.ByteString.Lazy

Contents

- Running parsers
  - Result conversion

Description

Simple, efficient combinator parsing that can consume lazy `ByteString` strings, loosely based on the Parsec library.

This is essentially the same code as in the `Attoparsec` module, only with a `parse` function that can consume a lazy `ByteString` incrementally, and a `Result` type that does not allow more input to be fed in. Think of this as suitable for use with a lazily read file, e.g. via `readFile` or `hGetContents`.

Note: The various parser functions and combinators such as `string` still expect strict `ByteString` parameters, and return strict `ByteString` results. Behind the scenes, strict `ByteString` values are still used internally to store parser input and manipulate it efficiently.

Synopsis

- data Result r
  - = Fail ByteString [String] String
  - | Done ByteString r
- module Data.Attoparsec.ByteString
- parse :: Parser a -> ByteString -> Result a
- parseTest :: Show a => Parser a -> ByteString -> IO ()
- maybeResult :: Result r -> Maybe r
- eitherResult :: Result r -> Either String r

# Documentation

data Result r #

The result of a parse.

Constructors

Fail ByteString [String] String | The parse failed. The `ByteString` 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.
Done ByteString r | The parse succeeded. The `ByteString` is the input that had not yet been consumed (if any) when the parse succeeded.

Instances

Functor Result # |
Methods fmap :: (a -> b) -> Result a -> Result b # (<$) :: a -> Result b -> Result a #
Show r => Show (Result r) # |
Methods showsPrec :: Int -> Result r -> ShowS # show :: Result r -> String # showList :: [Result r] -> ShowS #
NFData r => NFData (Result r) # |
Methods rnf :: Result r -> () #

module Data.Attoparsec.ByteString

# Running parsers

parse :: Parser a -> ByteString -> Result a #

Run a parser and return its result.

parseTest :: Show a => Parser a -> ByteString -> IO () #

Run a parser and print its result to standard output.

## Result conversion

maybeResult :: Result r -> Maybe r #

Convert a `Result` value to a `Maybe` value.

eitherResult :: Result r -> Either String r #

Convert a `Result` value to an `Either` value.