attoparsec-0.7.1: Fast combinator parsing with Data.ByteString.Lazy

Portabilityunknown
Stabilityexperimental
Maintainerbos@serpentine.com

Data.Attoparsec

Contents

Description

Simple, efficient parser combinators for lazy ByteString strings, loosely based on Text.ParserCombinators.Parsec.

Synopsis

Parser types

type ParseError = StringSource

A description of a parsing error.

Running parsers

parseSource

Arguments

:: Parser a

parser to run

-> ByteString

input to parse

-> (ByteString, Either ParseError a) 

Run a parser.

parseAtSource

Arguments

:: Parser a

parser to run

-> ByteString

input to parse

-> Int64

offset to count input from

-> (ByteString, Either ParseError (a, Int64)) 

Run a parser. The Int64 value is used as a base to count the number of bytes consumed.

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

Try out a parser, and print its result.

Combinators

(<?>)Source

Arguments

:: Parser a 
-> String

the name to use if parsing fails

-> Parser a 

Name the parser, in case failure occurs.

try :: Parser a -> Parser aSource

Attempt a parse, but do not consume any input if the parse fails.

Parsing individual bytes

anyWord8 :: Parser Word8Source

Match any byte.

notWord8 :: Word8 -> Parser Word8Source

Match any byte except the given one.

word8 :: Word8 -> Parser Word8Source

Match a specific byte.

satisfy :: (Word8 -> Bool) -> Parser Word8Source

Match a single byte based on the given predicate.

Efficient string handling

string :: ByteString -> Parser ByteStringSource

Match a literal string exactly.

skipWhile :: (Word8 -> Bool) -> Parser ()Source

Skip over bytes while the predicate is true.

stringTransform :: (ByteString -> ByteString) -> ByteString -> Parser ByteStringSource

Match a literal string, after applying a transformation to both it and the matching text. Useful for e.g. case insensitive string comparison.

takeAll :: Parser ByteStringSource

Return all of the remaining input as a single string.

takeTill :: (Word8 -> Bool) -> Parser ByteStringSource

Consume bytes while the predicate fails. If the predicate never succeeds, the entire input string is returned.

takeWhile :: (Word8 -> Bool) -> Parser ByteStringSource

Consume bytes while the predicate succeeds.

takeWhile1 :: (Word8 -> Bool) -> Parser ByteStringSource

Consume bytes while the predicate is true. Fails if the predicate fails on the first byte.

Combinators

match :: Parser a -> Parser ByteStringSource

Parse some input with the given parser, and return the input it consumed as a string.

notEmpty :: Parser ByteString -> Parser ByteStringSource

Test that a parser returned a non-null ByteString.

State observation functions

endOfInput :: Parser ()Source

Succeed if we have reached the end of the input string.

getConsumed :: Parser Int64Source

Get number of bytes consumed so far.

getInput :: Parser ByteStringSource

Get remaining input.

lookAhead :: Parser a -> Parser aSource

Apply a parser without consuming any input.