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

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

- class Monad m => ParserM m where
  - work :: (ByteString -> Maybe (a, ByteString)) -> m a
  - maybeWork :: (ByteString -> Maybe (a, ByteString)) -> m (Maybe a)
  - peekInput :: m ByteString
- alterInput :: ParserM m => (ByteString -> ByteString) -> m ()
- parseStrictly :: SM a -> ByteString -> Maybe (a, ByteString)
- lexChar :: ParserM m => Char -> m ()
- lexString :: ParserM m => String -> m ()
- lexStrings :: ParserM m => [String] -> m String
- lexEof :: ParserM m => m ()
- myLex :: ByteString -> Maybe (ByteString, ByteString)

# Documentation

class Monad m => ParserM m where

Methods

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

Applies a parsing function inside the `ParserM` monad.

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

Applies a parsing function, that can return `Nothing`, inside the `ParserM` monad.

peekInput :: m ByteString

Allows for the inspection of the input that is yet to be parsed.

Instances

ParserM SM |

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

Applies a function to the input stream and discards the result of the function.

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`.

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 => String -> m ()

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

lexStrings :: ParserM m => [String] -> m String

Checks if any of the input `String`s match the next space delimited token in the input stream. Uses `Maybe` inside `ParserM` to handle failed matches, on success it returns the matching `String`.

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.

myLex :: ByteString -> Maybe (ByteString, ByteString)

`myLex` drops leading spaces and then breaks the string at the next space. Returns `Nothing` when the string is empty after dropping leading spaces, otherwise it returns the first sequence of non-spaces and the remainder of the input.