HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleregex-1.1.0.2Haskell2010

Text.RE.Tools.Sed

  • 5 types
  • 1 class
  • 10 values
  • Packageregex-1.1.0.2
  • Exports16
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSed.lhs

Sed

2 declarations

The Sed toolkit applies Edits scripts to each line of a text, running the actions and adjusting each line accordingly.

See the Regex Tools tutorial at http://re-tutorial-tools.regex.uk

Edit

6 declarations
datadata Edits (m :: Type -> Type) re s
#

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

Constructors

  • Select ![Edit m re s]

    for each line select the first Edit to match each line and edit the line with it

  • Pipe ![Edit m re s]

    for each line apply every edit that matches in turn to the line

datadata LineEdit s
#

a LineEdit is the most general action that can be performed on a line and is the only means of deleting a line

Constructors

  • NoEdit

    do not edit this line but leave as is

  • ReplaceWith !s

    replace the line with this text (terminating newline should not be included)

  • Delete

    delete the this line altogether

Instances2Functor, Show
valueapplyEdit
  1. :: (IsRegex re s, Monad m, Functor m)
  2. => s -> s
  3. -> LineNo
  4. -> Edit m re s
  5. -> s
  6. -> m (Maybe s)
#

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

valueapplyLineEdit :: Monoid s => (s -> s) -> LineEdit s -> Maybe s
#

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 declarations
classclass Replace s => IsRegex re s where
#

the IsRegex class allows polymorhic tools to be written that will work with a variety of regex back ends and text types

Methods

Instances6IsRegex
datadata SearchReplace re s
#

contains a compiled RE and replacement template

Constructors

  • SearchReplace
    • getSearch :: !re

      the RE to match a string to replace

    • getTemplate :: !s

      the 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
valuesearchReplaceAll :: IsRegex re s => SearchReplace re s -> s -> s
#

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}|]
valuesearchReplaceFirst :: IsRegex re s => SearchReplace re s -> s -> s
#

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 declarations

Replace

0 declarations