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

  • 9 types
  • 1 class
  • 20 values
  • Packageregex-1.1.0.2
  • Exports30
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceSed.lhs

The Tools Tutorial

0 declarations

This 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 declarations

Grep

9 declarations
valuegrepFilter :: IsRegex re s => re -> s -> [Line s]
#

returns a Line for each line in the argument text, enumerating all of the matches for that line

typetype GrepScript re s t = [(re, LineNo -> Matches s -> Maybe t)]
#

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

Lex

2 declarations
valuealex :: IsRegex re s => [(re, Match s -> Maybe t)] -> t -> s -> [t]
#

a simple regex-based scanner interpreter for prototyping scanners

valuealex'
  1. :: Replace s
  2. => re -> s -> Match s
  3. -> [(re, Match s -> Maybe t)]
  4. -> t
  5. -> s
  6. -> [t]
#

a higher order version of alex parameterised over the matchOnce function

Find

3 declarations
datadata FindMethods s
#

as we don't want the directory and FilePath dependencies we will abstract the three calls we need into this record type

Constructors

valuefindMatches_ :: IsRegex re s => FindMethods s -> re -> s -> IO [s]
#

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

valuefindMatches_'
  1. :: IsRegex re s
  2. => FindMethods s

    the directory and filepath methods

  3. -> ([s] -> [s])

    result post-processing function

  4. -> (Match s -> Bool)

    filtering function

  5. -> re

    re to be matched against the leaf filename

  6. -> s

    root directory of the search

  7. -> IO [s]
#

recursively list all files whose filename matches given RE, using the given function to determine which matches to accept

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|]

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

LineNo

4 declarations

Replace

0 declarations