parsec-utils-0.1.0.0: Utility functions and combinators for Text.Parsec

Safe HaskellSafe-Inferred

Text.Parsec.Utils

Contents

Synopsis

Main parse functions

parseString :: Parser a -> String -> aSource

Parse a string. Parse errors are reported through the error function.

>>> parseString int "123" == 123
True

parseFile :: Parser a -> FilePath -> IO aSource

Parse the contents of a file. Parse errors are reported through the error function.

Number parsers

nat :: Integral a => Parser aSource

Parse a natural (i.e. non-negative) number

>>> parseString nat "123" == 123
True

int :: Integral a => Parser aSource

Parse an integer (or any instance of Integral)

>>> parseString int "-123" == -123
True

float :: (Read a, RealFloat a) => Parser aSource

Parse a floating point number

>>> parseString float "-12.34" == -12.34
True

Parser operators

Mostly synonyms for the operators from Control.Applicative, but left-associative and with different priorities for easier composition with fewer parentheses.

(=:) :: Functor f => b -> f a -> f bSource

Synonym for <$

>>> parseString (2 =: char 'a') "a" == 2
True

(+:) :: Applicative f => f (a -> b) -> f a -> f bSource

Synonym for <*>

>>> parseString ((,) .: char 'a' +: int) "a1" == ('a', 1)
True

(-:) :: Applicative f => f a -> f b -> f aSource

Synonym for <* Allows chaining parsers without the need for parentheses

>>> parseString ((+) .: int -: space +: int) "1 2" == 3
True

(.:) :: Functor f => (a -> b) -> f a -> f bSource

Synonym for <$>

>>> parseString ((,) .: char 'a' +: int) "a1" == ('a', 1)
True

($:) :: Functor f => (a -> b) -> f a -> f bSource

Synonym for <* Identical to .: but with lower precedence.

>>> parseString (show $: (+) .: int -: space +: int) "1 2" == "3"
True

(<:) :: Parser t -> Parser String -> Parser tSource

Apply a parser that returns a String and parse the result with another parser.

>>> parseString (int <: manyTill anyChar (char '9')) "129" == 12
True