read a file, apply an Edits script to each line it and write the file out again; "-" is used to indicate standard input standard output as appropriate
Moduleregex-1.1.0.2Haskell2010
Text.RE.Tools
- 9 types
- 1 class
- 20 values
- Packageregex-1.1.0.2
- Exports30
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceSed.lhs
The Tools Tutorial
0 declarationsThis API module provides some familiar RE tools on top of the core package functions and types.
See the Regex Tools tutorial at http://re-tutorial-tools.regex.uk
Sed
2 declarationsapply an Edits script to each line of the argument text
Grep
9 declarationsoperates a bit like classic grep printing out the lines matched
specifies whether to return the lines matched or missed
Constructors
LinegetLineNumber :: LineNothe LineNo for this line
getLineMatches :: Matches sall the Matches of the RE on this line
returns a Line for each line in the file, enumerating all of the matches for that line
returns a Line for each line in the argument text, enumerating all of the matches for that line
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
given a list of lines, apply the GrepScript to each line of the file
generate a grep report from a list of Line
given a velocity flag filter out either the lines matched or not
matched
Lex
2 declarationsa simple regex-based scanner interpreter for prototyping scanners
a higher order version of alex parameterised over the matchOnce
function
Find
3 declarationsas we don't want the directory and FilePath dependencies
we will abstract the three calls we need into this record type
Constructors
FindMethodsdoesDirectoryExistDM :: s -> IO BooldoesDirectoryExist from System.Directory
listDirectoryDM :: s -> IO [s]either getDirectoryContents or listDirectory from System.Directory
combineDM :: s -> s -> s/ from System.FilePath
recursively list all files whose filename matches given RE, sorting the list into ascending order; if the argument path has a trailing / then it will be removed
findMatches_' :: IsRegex re s=> FindMethods sthe directory and filepath methods
-> ([s] -> [s])result post-processing function
-> (Match s -> Bool)filtering function
-> rere to be matched against the leaf filename
-> sroot directory of the search
-> IO [s]
recursively list all files whose filename matches given RE, using the given function to determine which matches to accept
IsRegex
4 declarationsthe IsRegex class allows polymorhic tools to be written that will work with a variety of regex back ends and text types
Methods
matchOnce :: re -> s -> Match sfinding the first match
matchMany :: re -> s -> Matches sfinding all matches
makeRegex :: (Functor m, Monad m, MonadFail m) => s -> m recompiling an RE, failing if the RE is not well formed
makeRegexWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> s -> m recomiling an RE, specifying the SimpleREOptions
makeSearchReplace :: (Functor m, Monad m, MonadFail m, IsRegex re s) => s -> s -> m (SearchReplace re s)compiling a SearchReplace template from the RE text and the template Text, failing if they are not well formed
makeSearchReplaceWith :: (Functor m, Monad m, MonadFail m, IsRegex re s) => SimpleREOptions -> s -> s -> m (SearchReplace re s)compiling a SearchReplace template specifying the SimpleREOptions for the RE
makeEscaped :: (Functor m, Monad m, MonadFail m) => (s -> s) -> s -> m reincorporate an escaped string into a compiled RE with the default options
makeEscapedWith :: (Functor m, Monad m, MonadFail m) => SimpleREOptions -> (s -> s) -> s -> m reincorporate an escaped string into a compiled RE with the specified SimpleREOptions
regexSource :: re -> sextract the text of the RE from the RE
Instances6IsRegex
IsRegex RE ByteStringDefined in regex-1.1.0.2 · Text.RE.TDFA.ByteString · orphanIsRegex RE ByteStringDefined in regex-1.1.0.2 · Text.RE.TDFA.ByteString.Lazy · orphanIsRegex RE StringDefined in regex-1.1.0.2 · Text.RE.TDFA.String · orphanIsRegex RE TextDefined in regex-1.1.0.2 · Text.RE.TDFA.Text · orphanIsRegex RE TextDefined in regex-1.1.0.2 · Text.RE.TDFA.Text.Lazy · orphanIsRegex RE (Seq Char)Defined in regex-1.1.0.2 · Text.RE.TDFA.Sequence · orphan
contains a compiled RE and replacement template
Constructors
SearchReplacegetSearch :: !rethe RE to match a string to replace
getTemplate :: !sthe replacement template with ${cap} used to identify a capture (by number or name if one was given) and
$$being used to escape a single $
Instances2Functor, Show
Functor (SearchReplace re)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.SearchReplace(Show re, Show s) => Show (SearchReplace re s)Defined in regex-1.1.0.2 · Text.RE.ZeInternals.Types.SearchReplace
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}|]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|]Edit
6 declarationsan Edits script will, for each line in the file, either perform the action selected by the first RE in the list, or perform all of the actions on line, arranged as a pipeline
each Edit action specifies how the match should be processed
Constructors
Template !(SearchReplace re s)replace the match with this template text, substituting ${capture} as appropriate
Function !re REContext !(LineNo -> Match s -> RELocation -> Capture s -> m (Maybe s))use this function to replace the REContext specified captures in each line matched
LineEdit !re !(LineNo -> Matches s -> m (LineEdit s))use this function to edit each line matched
a LineEdit is the most general action that can be performed on a line and is the only means of deleting a line
Constructors
NoEditdo not edit this line but leave as is
ReplaceWith !sreplace the line with this text (terminating newline should not be included)
Deletedelete the this line altogether
apply an Edit script to a single line
apply a single edit action to a line, the function in the first argument
being used to add a new line onto the end of the line where appropriate;
the function returns Nothing if no edit is to be performed on the line,
Just mempty to delete the line
apply a LineEdit to a line, using the function in the first
argument to append a new line to the result; Nothing should be
returned if no edit is to be performed, Just mempty to
delete the line
LineNo
4 declarationsour line numbers are of the proper zero-based kind
Constructors
the first line in a file
extract a conventional 1-based line number
inject a conventional 1-based line number
Replace
0 declarationsmodule Text.RE.Replace