Portability | unknown |
---|---|
Stability | experimental |
Maintainer | bos@serpentine.com |
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.
- type ParseError = String
- data Parser a
- parse :: Parser a -> ByteString -> (ByteString, Either ParseError a)
- parseAt :: Parser a -> ByteString -> Int64 -> (ByteString, Either ParseError (a, Int64))
- parseTest :: Show a => Parser a -> ByteString -> IO ()
- (<?>) :: Parser a -> String -> Parser a
- try :: Parser a -> Parser a
- anyChar :: Parser Char
- char :: Char -> Parser Char
- digit :: Parser Char
- letter :: Parser Char
- notChar :: Char -> Parser Char
- space :: Parser Char
- satisfy :: (Char -> Bool) -> Parser Char
- inClass :: String -> Char -> Bool
- notInClass :: String -> Char -> Bool
- string :: ByteString -> Parser ByteString
- stringCI :: ByteString -> Parser ByteString
- skipSpace :: Parser ()
- skipWhile :: (Char -> Bool) -> Parser ()
- takeAll :: Parser ByteString
- takeCount :: Int -> Parser ByteString
- takeTill :: (Char -> Bool) -> Parser ByteString
- takeWhile :: (Char -> Bool) -> Parser ByteString
- takeWhile1 :: (Char -> Bool) -> Parser ByteString
- match :: Parser a -> Parser ByteString
- notEmpty :: Parser ByteString -> Parser ByteString
- endOfLine :: Parser ()
- int :: Parser Int
- integer :: Parser Integer
- double :: Parser Double
- endOfInput :: Parser ()
- getConsumed :: Parser Int64
- getInput :: Parser ByteString
- lookAhead :: Parser a -> Parser a
- module Data.Attoparsec.Combinator
Parser types
type ParseError = StringSource
A description of a parsing error.
Running parsers
:: Parser a | parser to run |
-> ByteString | input to parse |
-> (ByteString, Either ParseError a) |
Run a parser.
:: 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.
Combinators
Name the parser, in case failure occurs.
Parsing individual characters
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.
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.
takeWhile :: (Char -> Bool) -> Parser ByteStringSource
Consume characters while the predicate succeeds.
takeWhile1 :: (Char -> Bool) -> Parser ByteStringSource
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
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
State observation functions
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.
Combinators
module Data.Attoparsec.Combinator