darcs-2.18.2: a distributed, interactive, smart revision control system
Safe HaskellSafe-Inferred
LanguageHaskell2010

Darcs.Util.Parser

Synopsis

Documentation

anyChar :: Parser Char #

Match any character.

choice :: Alternative f => [f a] -> f a #

choice ps tries to apply the actions in the list ps in order, until one of them succeeds. Returns the value of the succeeding action.

endOfInput :: Chunk t => Parser t () #

Match only if all input has been consumed.

lookAhead :: Parser i a -> Parser i a #

Apply a parser without consuming any input.

many :: Alternative f => f a -> f [a] #

Zero or more.

option :: Alternative f => a -> f a -> f a #

option x p tries to apply action p. If p fails without consuming input, it returns the value x, otherwise the value returned by p.

priority  = option 0 (digitToInt <$> digit)

optional :: Alternative f => f a -> f (Maybe a) #

One or none.

It is useful for modelling any computation that is allowed to fail.

Examples

Expand

Using the Alternative instance of Control.Monad.Except, the following functions:

>>> import Control.Monad.Except
>>> canFail = throwError "it failed" :: Except String Int
>>> final = return 42                :: Except String Int

Can be combined by allowing the first function to fail:

>>> runExcept $ canFail *> final
Left "it failed"
>>> runExcept $ optional canFail *> final
Right 42

skipSpace :: Parser () #

Skip over white space.

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

Skip past input for as long as the predicate returns True.

take :: Int -> Parser ByteString #

Consume exactly n bytes of input.

takeTill :: (Char -> Bool) -> Parser ByteString #

Consume input as long as the predicate returns False (i.e. until it returns True), and return the consumed input.

This parser does not fail. It will return an empty string if the predicate returns True on the first byte of input.

Note: Because this parser does not fail, do not use it with combinators such as many, because such parsers loop until a failure occurs. Careless use will thus result in an infinite loop.

(<|>) :: Alternative f => f a -> f a -> f a infixl 3 #

An associative binary operation