highlight-1.0.0.0: Command line tool for highlighting parts of files matching a regex.

Safe HaskellNone
LanguageHaskell2010

Highlight.Common.Monad

Synopsis

Documentation

newtype CommonHighlightM r s e a Source #

This is the common monad for both highlight and hrep. It has been kept polymorphic here so it can be easily specialized by highlight and hrep.

r is the options or config type. s is the state. e is the error.

Constructors

CommonHighlightM 

Fields

Instances

MonadState s (CommonHighlightM r s e) Source # 

Methods

get :: CommonHighlightM r s e s #

put :: s -> CommonHighlightM r s e () #

state :: (s -> (a, s)) -> CommonHighlightM r s e a #

MonadReader r (CommonHighlightM r s e) Source # 

Methods

ask :: CommonHighlightM r s e r #

local :: (r -> r) -> CommonHighlightM r s e a -> CommonHighlightM r s e a #

reader :: (r -> a) -> CommonHighlightM r s e a #

MonadError e (CommonHighlightM r s e) Source # 

Methods

throwError :: e -> CommonHighlightM r s e a #

catchError :: CommonHighlightM r s e a -> (e -> CommonHighlightM r s e a) -> CommonHighlightM r s e a #

Monad (CommonHighlightM r s e) Source # 

Methods

(>>=) :: CommonHighlightM r s e a -> (a -> CommonHighlightM r s e b) -> CommonHighlightM r s e b #

(>>) :: CommonHighlightM r s e a -> CommonHighlightM r s e b -> CommonHighlightM r s e b #

return :: a -> CommonHighlightM r s e a #

fail :: String -> CommonHighlightM r s e a #

Functor (CommonHighlightM r s e) Source # 

Methods

fmap :: (a -> b) -> CommonHighlightM r s e a -> CommonHighlightM r s e b #

(<$) :: a -> CommonHighlightM r s e b -> CommonHighlightM r s e a #

Applicative (CommonHighlightM r s e) Source # 

Methods

pure :: a -> CommonHighlightM r s e a #

(<*>) :: CommonHighlightM r s e (a -> b) -> CommonHighlightM r s e a -> CommonHighlightM r s e b #

(*>) :: CommonHighlightM r s e a -> CommonHighlightM r s e b -> CommonHighlightM r s e b #

(<*) :: CommonHighlightM r s e a -> CommonHighlightM r s e b -> CommonHighlightM r s e a #

MonadIO (CommonHighlightM r s e) Source # 

Methods

liftIO :: IO a -> CommonHighlightM r s e a #

runCommonHighlightM :: r -> s -> CommonHighlightM r s e a -> IO (Either e a) Source #

Given an r and s, run CommonHighlightM.

getRawRegexM :: (HasRawRegex r, MonadReader r m) => m RawRegex Source #

Get the RawRegex option.

compileHighlightRegex :: IgnoreCase -> RawRegex -> Maybe RE Source #

Try compiling a RawRegex into a RE.

Setup for examples:

>>> import Data.Maybe (isJust)

Return Just for a proper regex:

>>> isJust $ compileHighlightRegex IgnoreCase (RawRegex "good regex")
True

Return Nothing for an improper regex:

>>> isJust $ compileHighlightRegex IgnoreCase (RawRegex "bad regex (")
False