darcs-2.11.0: a distributed, interactive, smart revision control system

Safe HaskellNone

Darcs.Patch.ReadMonads

Description

This module defines our parsing monad. In the past there have been lazy and strict parsers in this module. Currently we have only the strict variant and it is used for parsing patch files.

Synopsis

Documentation

class (Functor m, Applicative m, Alternative m, Monad m, MonadPlus m) => ParserM m where

Methods

parse :: m a -> ByteString -> Maybe (a, ByteString)

Run the parser

take :: ParserM m => Int -> m ByteString

Takes exactly n bytes, or fails.

parseStrictly :: SM a -> ByteString -> Maybe (a, ByteString)

parseStrictly applies the parser functions to a string and checks that each parser produced a result as it goes. The strictness is in the ParserM instance for SM.

char :: ParserM m => Char -> m ()

Accepts only the specified character. Consumes a character, if available.

int :: ParserM m => m Int

Parse an integer and return it. Skips leading whitespaces and | uses the efficient ByteString readInt.

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

If p fails it returns x, otherwise it returns the result of p.

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

Attempts each option until one succeeds.

skipSpace :: ParserM m => m ()

Discards spaces until a non-space character is encountered. Always succeeds.

skipWhile :: ParserM m => (Char -> Bool) -> m ()

Discards any characters as long as p returns True. Always | succeeds.

string :: ParserM m => ByteString -> m ()

Only succeeds if the characters in the input exactly match str.

lexChar :: ParserM m => Char -> m ()

lexChar checks if the next space delimited token from the input stream matches a specific Char. Uses Maybe inside ParserM to handle failed matches, so that it always returns () on success.

lexString :: ParserM m => ByteString -> m ()

lexString fetches the next whitespace delimited token from from the input and checks if it matches the ByteString input. Uses Maybe inside ParserM to handle failed matches, so that it always returns () on success.

lexEof :: ParserM m => m ()

lexEof looks for optional spaces followed by the end of input. Uses Maybe inside ParserM to handle failed matches, so that it always returns () on success.

takeTillChar :: ParserM m => Char -> m ByteString

Equivalent to takeTill (==c), except that it is optimized for | the equality case.

myLex' :: ParserM m => m ByteString

Like myLex except that it is in ParserM

anyChar :: ParserM m => m Char

Accepts the next character and returns it. Only fails at end of input.

endOfInput :: ParserM m => m ()

Only succeeds at end of input, consumes no characters.

takeTill :: ParserM m => (Char -> Bool) -> m ByteString

Takes characters while p returns True. Always succeeds.

checkConsumes :: ParserM m => m a -> m a

Ensure that a parser consumes input when producing a result Causes the initial state of the input stream to be held on to while the parser runs, so use with caution.

linesStartingWith :: ParserM m => Char -> m [ByteString]

This is a highly optimized way to read lines that start with a particular character. To implement this efficiently we need access to the parser's internal state. If this is implemented in terms of the other primitives for the parser it requires us to consume one character at a time. That leads to (>>=) wasting significant time.

linesStartingWithEndingWith :: ParserM m => Char -> Char -> m [ByteString]

This is a highly optimized way to read lines that start with a particular character, and stops when it reaches a particular | character. See linesStartingWith for details on why this | defined here as a primitive.