an 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
Moduleregex-1.1.0.2Haskell2010
Text.RE.Tools.Edit
- 5 types
- 1 class
- 8 values
- Packageregex-1.1.0.2
- Exports14
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceEdit.lhs
Editing
6 declarationsThe Edit toolkit looks for REs that match a text and runs the associated actions.
See the Regex Tools tutorial at http://re-tutorial-tools.regex.uk
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
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|]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