Safe Haskell | None |
---|---|
Language | Haskell2010 |
- grep :: IsRegex re ByteString => Verbosity -> re -> FilePath -> IO ()
- data Verbosity
- data Line s = Line {
- getLineNumber :: LineNo
- getLineMatches :: Matches s
- grepLines :: IsRegex re ByteString => re -> FilePath -> IO [Line ByteString]
- grepFilter :: IsRegex re s => re -> s -> [Line s]
- type GrepScript re s t = [(re, LineNo -> Matches s -> Maybe t)]
- grepWithScript :: IsRegex re s => GrepScript re s t -> [s] -> [t]
- report :: Verbosity -> [Line ByteString] -> String
- linesMatched :: Verbosity -> [Line s] -> [Line s]
- class Replace s => IsRegex re s where
- data SearchReplace re s = SearchReplace {
- getSearch :: !re
- getTemplate :: !s
- searchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s
- searchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s
- newtype LineNo = ZeroBasedLineNo {}
- firstLine :: LineNo
- getLineNo :: LineNo -> Int
- lineNo :: Int -> LineNo
- module Text.RE.Replace
Documentation
The Grep toolkit matches REs againt each line of a text.
See the Regex Tools tutorial at http://re-tutorial-tools.regex.uk
grep :: IsRegex re ByteString => Verbosity -> re -> FilePath -> IO () Source #
operates a bit like classic grep
printing out the lines matched
specifies whether to return the linss matched or missed
Line | |
|
grepLines :: IsRegex re ByteString => re -> FilePath -> IO [Line ByteString] Source #
returns a Line
for each line in the file, enumerating all of the
matches for that line
grepFilter :: IsRegex re s => re -> s -> [Line s] Source #
returns a Line
for each line in the argument text, enumerating
all of the matches for that line
type GrepScript re s t = [(re, LineNo -> Matches s -> Maybe t)] Source #
a GrepScript lists RE-action associations, with the first RE to match a line selecting the action to be executed on each line in the file
grepWithScript :: IsRegex re s => GrepScript re s t -> [s] -> [t] Source #
given a list of lines, apply the GrepScript
to each line of the file
report :: Verbosity -> [Line ByteString] -> String Source #
generate a grep report from a list of Line
linesMatched :: Verbosity -> [Line s] -> [Line s] Source #
given a velocity
flag filter out either the lines matched or not
matched
IsRegex
class Replace s => IsRegex re s where Source #
the IsRegex
class allows polymorhic tools to be written that
will work with a variety of regex back ends and text types
matchOnce :: re -> s -> Match s Source #
finding the first match
matchMany :: re -> s -> Matches s Source #
finding all matches
makeRegex :: (Functor m, Monad m) => s -> m re Source #
compiling an RE, failing if the RE is not well formed
makeRegexWith :: (Functor m, Monad m) => SimpleREOptions -> s -> m re Source #
comiling an RE, specifying the SimpleREOptions
makeSearchReplace :: (Functor m, Monad m, IsRegex re s) => s -> s -> m (SearchReplace re s) Source #
compiling a SearchReplace
template from the RE text and the template Text, failing if they are not well formed
makeSearchReplaceWith :: (Functor m, Monad m, IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s) Source #
compiling a SearchReplace
template specifing the SimpleREOptions
for the RE
makeEscaped :: (Functor m, Monad m) => (s -> s) -> s -> m re Source #
incorporate an escaped string into a compiled RE with the default options
makeEscapedWith :: (Functor m, Monad m) => SimpleREOptions -> (s -> s) -> s -> m re Source #
incorporate an escaped string into a compiled RE with the specified SimpleREOptions
regexSource :: re -> s Source #
extract the text of the RE from the RE
data SearchReplace re s Source #
contains a compiled RE and replacement template
SearchReplace | |
|
Functor (SearchReplace re) Source # | |
(Show s, Show re) => Show (SearchReplace re s) Source # | |
searchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s Source #
search and replace all matches in the argument text; e.g., this function will convert every YYYY-MM-DD format date in its argument text into a DD/MM/YYYY date:
searchReplaceAll [ed|${y}([0-9]{4})-0*${m}([0-9]{2})-0*${d}([0-9]{2})///${d}/${m}/${y}|]
searchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s Source #
search and replace the first occurrence only (if any) in the input text
e.g., to prefix the first string of four hex digits in the imput text,
if any, with 0x
:
searchReplaceFirst [ed|[0-9A-Fa-f]{4}///0x$0|]
LineNo
our line numbers are of the proper zero-based kind
Replace
module Text.RE.Replace