Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data FileOrigin
- data FileReader a
- getFileOriginFromFileReader :: FileReader a -> FileOrigin
- getFilePathFromFileReader :: FileReader a -> Maybe FilePath
- data InputData m a = InputData !FilenameHandlingFromFiles !(Producer (FileReader ByteString) m a)
- createInputData :: forall m. MonadIO m => Recursive -> [InputFilename] -> Producer ByteString m () -> m (InputData m ())
- data FilenameHandlingFromFiles
Documentation
data FileOrigin Source #
Place where a file originally came from.
FileSpecifiedByUser FilePath | File was specified on the command line by the user. |
FileFoundRecursively FilePath | File was found recursively (not directly specified by the user). |
Stdin | Standard input. It was either specified on the command line as |
data FileReader a Source #
This is used in two different places.
One is in fileListProducer
, where a
becomes Handle
. This represents a
single file that has been opened. FileReaderSuccess
contains the
FileOrigin
and the Handle
. FileReaderErr
contains the FileOrigin
and any errors that occurred when trying to open the Handle
.
The other is in fileReaderHandleToLine
and InputData
, where a
becomes
ByteString
. This represents a single ByteString
line from a file, or an
error that occurred when trying to read the file.
FileReader
is usually wrapped in a Producer
. This is a stream of either
Handle
s or ByteString
lines (with any errors that have occurred).
Eq a => Eq (FileReader a) Source # | |
Show a => Show (FileReader a) Source # | |
getFileOriginFromFileReader :: FileReader a -> FileOrigin Source #
Get a FileOrigin
from a FileReader
.
>>>
let fileOrigin1 = FileSpecifiedByUser "hello.txt"
>>>
let fileReader1 = FileReaderSuccess fileOrigin1 "some line"
>>>
getFileOriginFromFileReader fileReader1
FileSpecifiedByUser "hello.txt"
>>>
let fileOrigin2 = FileFoundRecursively "bye.txt"
>>>
let fileReader2 = FileReaderErr fileOrigin2 (userError "err") Nothing
>>>
getFileOriginFromFileReader fileReader2
FileFoundRecursively "bye.txt"
getFilePathFromFileReader :: FileReader a -> Maybe FilePath Source #
This is just
.getFilePathFromFileOrigin
.
getFileOriginFromFileReader
>>>
let fileOrigin1 = Stdin
>>>
let fileReader1 = FileReaderSuccess fileOrigin1 "some line"
>>>
getFilePathFromFileReader fileReader1
Nothing
>>>
let fileOrigin2 = FileFoundRecursively "bye.txt"
>>>
let fileReader2 = FileReaderErr fileOrigin2 (userError "err") Nothing
>>>
getFilePathFromFileReader fileReader2
Just "bye.txt"
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.
:: 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...")
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. |