Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype CommonHighlightM r s e a = CommonHighlightM {
- unCommonHighlightM :: ReaderT r (StateT s (ExceptT e IO)) a
- runCommonHighlightM :: r -> s -> CommonHighlightM r s e a -> IO (Either e a)
- getIgnoreCaseM :: (HasIgnoreCase r, MonadReader r m) => m IgnoreCase
- getRecursiveM :: (HasRecursive r, MonadReader r m) => m Recursive
- getRawRegexM :: (HasRawRegex r, MonadReader r m) => m RawRegex
- getInputFilenamesM :: (HasInputFilenames r, MonadReader r m) => m [InputFilename]
- throwHighlightErr :: HighlightErr -> CommonHighlightM r s HighlightErr a
- throwRegexCompileErr :: RawRegex -> CommonHighlightM r s HighlightErr a
- compileHighlightRegexWithErr :: (HasIgnoreCase r, HasRawRegex r) => CommonHighlightM r s HighlightErr RE
- compileHighlightRegex :: IgnoreCase -> RawRegex -> Maybe RE
- data FilenameHandlingFromFiles
- data InputData m a
- createInputData :: forall m. MonadIO m => Recursive -> [InputFilename] -> Producer ByteString m () -> m (InputData m ())
- data Output
- handleInputData :: forall m. MonadIO m => (ByteString -> m [ByteString]) -> (FilenameHandlingFromFiles -> ByteString -> Int -> ByteString -> m [ByteString]) -> (ByteString -> IOException -> Maybe IOException -> m [ByteString]) -> InputData m () -> Producer Output m ()
- runOutputProducer :: forall m. MonadIO m => Producer Output m () -> m ()
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.
CommonHighlightM | |
|
Instances
runCommonHighlightM :: r -> s -> CommonHighlightM r s e a -> IO (Either e a) Source #
Given an r
and s
, run CommonHighlightM
.
getIgnoreCaseM :: (HasIgnoreCase r, MonadReader r m) => m IgnoreCase Source #
Get the IgnoreCase
option.
getRecursiveM :: (HasRecursive r, MonadReader r m) => m Recursive Source #
Get the Recursive
option.
getRawRegexM :: (HasRawRegex r, MonadReader r m) => m RawRegex Source #
Get the RawRegex
option.
getInputFilenamesM :: (HasInputFilenames r, MonadReader r m) => m [InputFilename] Source #
Get a list of the InputFilename
.
throwHighlightErr :: HighlightErr -> CommonHighlightM r s HighlightErr a Source #
Throw a HighlightErr
.
throwRegexCompileErr :: RawRegex -> CommonHighlightM r s HighlightErr a Source #
Throw a HighlightRegexCompileErr
.
compileHighlightRegexWithErr :: (HasIgnoreCase r, HasRawRegex r) => CommonHighlightM r s HighlightErr RE Source #
Call compileHighlightRegex
. Throw a HighlightErr
if the regex cannot
be compiled.
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
data FilenameHandlingFromFiles Source #
This data type specifies how printing filenames will be handled, along
with the computeFilenameHandlingFromFiles
function.
NoFilename | Do not print the filename on stdout. |
PrintFilename | Print the filename on stdout. |
Instances
This wraps up two pieces of information.
One is the value of FilenameHandlingFromFiles
. This signals as to whether
or not we need to print the filename when printing each line of output.
This other is a Producer
of FileReader
ByteString
s. This is a
Producer
for each line of each input file.
The main job of this module is to define createInputData
, which produces
InputData
. InputData
is what is processed to figure out what to output.
:: forall m. MonadIO m | |
=> Recursive | Whether or not to recursively read in files. |
-> [InputFilename] | List of files passed in on the command line. |
-> Producer ByteString m () | A producer for standard input |
-> m (InputData m ()) |
Create InputData
based InputFilename
list.
Setup for examples:
>>>
:set -XOverloadedStrings
>>>
import Highlight.Common.Options (InputFilename(InputFilename))
>>>
import Highlight.Common.Options (Recursive(NotRecursive))
If the InputFilename
list is empty, just create an InputData
with
NoFilename
and the standard input Producer
passed in.
>>>
let stdinProd = yield ("hello" :: ByteString)
>>>
let create = createInputData NotRecursive [] stdinProd
>>>
InputData NoFilename prod <- create
>>>
toListM prod
[FileReaderSuccess Stdin "hello"]
If the InputFilename
list is not empty, create an InputData
with lines
from each file found on the command line.
>>>
let inFiles = [InputFilename "test/golden/test-files/file1"]
>>>
let create = createInputData NotRecursive inFiles stdinProd
>>>
InputData NoFilename prod <- create
>>>
Pipes.head prod
Just (FileReaderSuccess (FileSpecifiedByUser "test/golden/test-files/file1") "The...")
Sum-type to represent where a given ByteString
should be output, whether
it is stdout or stderr.
:: forall m. MonadIO m | |
=> (ByteString -> m [ByteString]) | Function to use for conversion for a line from stdin. |
-> (FilenameHandlingFromFiles -> ByteString -> Int -> ByteString -> m [ByteString]) | Function to use for conversion for a line from a normal file. |
-> (ByteString -> IOException -> Maybe IOException -> m [ByteString]) | Function to use for conversion for an io error. |
-> InputData m () | All of the input lines. |
-> Producer Output m () |