Safe Haskell | Safe-Inferred |
---|
- parseString :: Parser a -> String -> a
- parseFile :: Parser a -> FilePath -> IO a
- nat :: Integral a => Parser a
- int :: Integral a => Parser a
- float :: (Read a, RealFloat a) => Parser a
- (=:) :: Functor f => b -> f a -> f b
- (+:) :: Applicative f => f (a -> b) -> f a -> f b
- (-:) :: Applicative f => f a -> f b -> f a
- (.:) :: Functor f => (a -> b) -> f a -> f b
- ($:) :: Functor f => (a -> b) -> f a -> f b
- (<:) :: Parser t -> Parser String -> Parser t
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