Safe Haskell | None |
---|---|
Language | Haskell2010 |
Text.RE.Tools.Sed
- sed :: IsRegex re ByteString => Edits IO re ByteString -> FilePath -> FilePath -> IO ()
- sed' :: (IsRegex re a, Monad m, Functor m) => Edits m re a -> a -> m a
- class Replace s => IsRegex re s where
- data Edits m re s
- data Edit m re s
- data LineEdit s
- = NoEdit
- | ReplaceWith !s
- | Delete
- applyEdits :: (IsRegex re s, Monad m, Functor m) => LineNo -> Edits m re s -> s -> m s
- applyEdit :: (IsRegex re s, Monad m, Functor m) => (s -> s) -> LineNo -> Edit m re s -> s -> m (Maybe s)
- applyLineEdit :: Monoid s => (s -> s) -> LineEdit s -> Maybe s
- newtype LineNo = ZeroBasedLineNo {}
- firstLine :: LineNo
- getLineNo :: LineNo -> Int
- lineNo :: Int -> LineNo
- module Text.RE
Documentation
sed :: IsRegex re ByteString => Edits IO re ByteString -> FilePath -> FilePath -> IO () Source #
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
sed' :: (IsRegex re a, Monad m, Functor m) => Edits m re a -> a -> m a Source #
apply an Edits
script to each line of the argument text
IsRegex
class Replace s => IsRegex re s where Source #
the IsRegex
class allows tools to be written that will work with
regex back end text type supported by the back end
Minimal complete definition
matchOnce, matchMany, makeRegexWith, makeSearchReplaceWith, regexSource
Methods
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
regexSource :: re -> s Source #
extract the text of the RE from the RE
Edit
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
each Edit action specifies how the match should be processed
a LineEdit is the most general action thar can be performed on a line and is the only means of deleting a line
Constructors
NoEdit | |
ReplaceWith !s | |
Delete |
applyEdits :: (IsRegex re s, Monad m, Functor m) => LineNo -> Edits m re s -> s -> m s Source #
apply an Edit
script to a single line
applyEdit :: (IsRegex re s, Monad m, Functor m) => (s -> s) -> LineNo -> Edit m re s -> s -> m (Maybe s) Source #
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
applyLineEdit :: Monoid s => (s -> s) -> LineEdit s -> Maybe s Source #
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
our line numbers are of the proper zero-based kind
Constructors
ZeroBasedLineNo | |
Fields |
Text.RE
module Text.RE