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

Portabilityunknown
Stabilityexperimental
Maintainerbos@serpentine.com

Data.Attoparsec.Char8

Contents

Description

Simple, efficient, character-oriented parser combinators for lazy ByteString strings, loosely based on the Parsec library.

Note: This module is intended for parsing text that is represented using an 8-bit character set, e.g. ASCII or ISO-8859-15. It does not deal with character encodings, multibyte characters, or wide characters. Any attempts to use characters above code point 255 will give wrong answers.

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 characters

char :: Char -> Parser CharSource

Match a specific character.

notChar :: Char -> Parser CharSource

Match any character except the given one.

satisfy :: (Char -> Bool) -> Parser CharSource

Character parser.

Character classes

inClass :: String -> Char -> BoolSource

Match any character in a set.

 vowel = inClass "aeiou"

Range notation is supported.

 halfAlphabet = inClass "a-nA-N"

To add a literal '-' to a set, place it at the beginning or end of the string.

notInClass :: String -> Char -> BoolSource

Match any character not in a set.

Efficient string handling

string :: ByteString -> Parser ByteStringSource

Match a literal string exactly.

stringCI :: ByteString -> Parser ByteStringSource

Satisfy a literal string, ignoring case.

skipSpace :: Parser ()Source

Skip over white space.

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

Skip over characters while the predicate succeeds.

takeAll :: Parser ByteStringSource

Return all of the remaining input as a single string.

takeCount :: Int -> Parser ByteStringSource

Return exactly the given number of bytes. If not enough are available, fail.

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

Consume characters while the predicate fails.

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

Consume characters while the predicate succeeds.

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.

Text parsing

endOfLine :: Parser ()Source

Match the end of a line. This may be any of a newline character, a carriage return character, or a carriage return followed by a newline.

Numeric parsers

int :: Parser IntSource

Parse an integer. The position counter is not updated.

integer :: Parser IntegerSource

Parse an integer. The position counter is not updated.

double :: Parser DoubleSource

Parse a Double. The position counter is not updated.

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.

Combinators