regex 0.7.0.0 → 0.8.0.0
raw patch · 16 files changed
+246/−90 lines, 16 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.RE.Tools.Edit: data LineNo
- Text.RE.Tools.Sed: type SedScript re = Edits IO re ByteString
+ Text.RE.TDFA.ByteString: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.TDFA.ByteString: compileRegexWith :: (Functor m, Monad m) => SimpleRegexOptions -> String -> m RE
+ Text.RE.TDFA.ByteString: data RE
+ Text.RE.TDFA.ByteString: escape :: (String -> String) -> String -> RE
+ Text.RE.TDFA.ByteString: reSource :: RE -> String
+ Text.RE.TDFA.ByteString.Lazy: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.TDFA.ByteString.Lazy: compileRegexWith :: (Functor m, Monad m) => SimpleRegexOptions -> String -> m RE
+ Text.RE.TDFA.ByteString.Lazy: data RE
+ Text.RE.TDFA.ByteString.Lazy: escape :: (String -> String) -> String -> RE
+ Text.RE.TDFA.ByteString.Lazy: reSource :: RE -> String
+ Text.RE.TDFA.Sequence: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.TDFA.Sequence: compileRegexWith :: (Functor m, Monad m) => SimpleRegexOptions -> String -> m RE
+ Text.RE.TDFA.Sequence: data RE
+ Text.RE.TDFA.Sequence: escape :: (String -> String) -> String -> RE
+ Text.RE.TDFA.Sequence: reSource :: RE -> String
+ Text.RE.TDFA.String: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.TDFA.String: compileRegexWith :: (Functor m, Monad m) => SimpleRegexOptions -> String -> m RE
+ Text.RE.TDFA.String: data RE
+ Text.RE.TDFA.String: escape :: (String -> String) -> String -> RE
+ Text.RE.TDFA.String: reSource :: RE -> String
+ Text.RE.TDFA.Text: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.TDFA.Text: compileRegexWith :: (Functor m, Monad m) => SimpleRegexOptions -> String -> m RE
+ Text.RE.TDFA.Text: data RE
+ Text.RE.TDFA.Text: escape :: (String -> String) -> String -> RE
+ Text.RE.TDFA.Text: reSource :: RE -> String
+ Text.RE.TDFA.Text.Lazy: compileRegex :: (Functor m, Monad m) => String -> m RE
+ Text.RE.TDFA.Text.Lazy: compileRegexWith :: (Functor m, Monad m) => SimpleRegexOptions -> String -> m RE
+ Text.RE.TDFA.Text.Lazy: data RE
+ Text.RE.TDFA.Text.Lazy: escape :: (String -> String) -> String -> RE
+ Text.RE.TDFA.Text.Lazy: reSource :: RE -> String
+ Text.RE.Tools: Delete :: LineEdit s
+ Text.RE.Tools: Function :: Context -> (LineNo -> Match s -> Location -> Capture s -> m (Maybe s)) -> Edit m s
+ Text.RE.Tools: LineEdit :: (LineNo -> Matches s -> m (LineEdit s)) -> Edit m s
+ Text.RE.Tools: NoEdit :: LineEdit s
+ Text.RE.Tools: Pipe :: [(re, Edit m s)] -> Edits m re s
+ Text.RE.Tools: ReplaceWith :: s -> LineEdit s
+ Text.RE.Tools: Select :: [(re, Edit m s)] -> Edits m re s
+ Text.RE.Tools: Template :: s -> Edit m s
+ Text.RE.Tools: ZeroBasedLineNo :: Int -> LineNo
+ Text.RE.Tools: [getZeroBasedLineNo] :: LineNo -> Int
+ Text.RE.Tools: alex :: IsRegex re s => [(re, Match s -> Maybe t)] -> t -> s -> [t]
+ Text.RE.Tools: alex' :: Replace s => (re -> s -> Match s) -> [(re, Match s -> Maybe t)] -> t -> s -> [t]
+ Text.RE.Tools: applyEdit :: (IsRegex re s, Monad m, Functor m) => (s -> s) -> LineNo -> re -> Edit m s -> s -> m (Maybe s)
+ Text.RE.Tools: applyEdits :: (IsRegex re s, Monad m, Functor m) => LineNo -> Edits m re s -> s -> m s
+ Text.RE.Tools: applyLineEdit :: Monoid s => (s -> s) -> LineEdit s -> Maybe s
+ Text.RE.Tools: class Replace s => IsRegex re s
+ Text.RE.Tools: data Edit m s
+ Text.RE.Tools: data Edits m re s
+ Text.RE.Tools: data LineEdit s
+ Text.RE.Tools: firstLine :: LineNo
+ Text.RE.Tools: getLineNo :: LineNo -> Int
+ Text.RE.Tools: grep :: IsRegex re ByteString => Verbosity -> re -> FilePath -> IO ()
+ Text.RE.Tools: grepLines :: IsRegex re ByteString => re -> FilePath -> IO [Line]
+ Text.RE.Tools: grepScript :: IsRegex re s => GrepScript re s t -> [s] -> [t]
+ Text.RE.Tools: lineNo :: Int -> LineNo
+ Text.RE.Tools: linesMatched :: Verbosity -> [Line] -> [Line]
+ Text.RE.Tools: makeRegex :: (IsRegex re s, Functor m, Monad m) => s -> m re
+ Text.RE.Tools: makeRegexWith :: (IsRegex re s, Functor m, Monad m) => SimpleRegexOptions -> s -> m re
+ Text.RE.Tools: matchMany :: IsRegex re s => re -> s -> Matches s
+ Text.RE.Tools: matchOnce :: IsRegex re s => re -> s -> Match s
+ Text.RE.Tools: newtype LineNo
+ Text.RE.Tools: regexSource :: IsRegex re s => re -> s
+ Text.RE.Tools: sed :: IsRegex re ByteString => Edits IO re ByteString -> FilePath -> FilePath -> IO ()
+ Text.RE.Tools: sed' :: (IsRegex re a, Monad m, Functor m) => Edits m re a -> a -> m a
+ Text.RE.Tools: type GrepScript re s t = [(re, LineNo -> Matches s -> Maybe t)]
+ Text.RE.Tools.Edit: ZeroBasedLineNo :: Int -> LineNo
+ Text.RE.Tools.Edit: [getZeroBasedLineNo] :: LineNo -> Int
+ Text.RE.Tools.Edit: firstLine :: LineNo
+ Text.RE.Tools.Edit: getLineNo :: LineNo -> Int
+ Text.RE.Tools.Edit: lineNo :: Int -> LineNo
+ Text.RE.Tools.Edit: newtype LineNo
+ Text.RE.Tools.Grep: LinesMatched :: Verbosity
+ Text.RE.Tools.Grep: LinesNotMatched :: Verbosity
+ Text.RE.Tools.Grep: ZeroBasedLineNo :: Int -> LineNo
+ Text.RE.Tools.Grep: [getZeroBasedLineNo] :: LineNo -> Int
+ Text.RE.Tools.Grep: class Replace s => IsRegex re s
+ Text.RE.Tools.Grep: data Verbosity
+ Text.RE.Tools.Grep: firstLine :: LineNo
+ Text.RE.Tools.Grep: getLineNo :: LineNo -> Int
+ Text.RE.Tools.Grep: instance GHC.Classes.Eq Text.RE.Tools.Grep.Verbosity
+ Text.RE.Tools.Grep: instance GHC.Classes.Ord Text.RE.Tools.Grep.Verbosity
+ Text.RE.Tools.Grep: instance GHC.Show.Show Text.RE.Tools.Grep.Verbosity
+ Text.RE.Tools.Grep: lineNo :: Int -> LineNo
+ Text.RE.Tools.Grep: makeRegex :: (IsRegex re s, Functor m, Monad m) => s -> m re
+ Text.RE.Tools.Grep: makeRegexWith :: (IsRegex re s, Functor m, Monad m) => SimpleRegexOptions -> s -> m re
+ Text.RE.Tools.Grep: matchMany :: IsRegex re s => re -> s -> Matches s
+ Text.RE.Tools.Grep: matchOnce :: IsRegex re s => re -> s -> Match s
+ Text.RE.Tools.Grep: newtype LineNo
+ Text.RE.Tools.Grep: regexSource :: IsRegex re s => re -> s
+ Text.RE.Tools.Grep: report :: Verbosity -> [Line] -> String
+ Text.RE.Tools.Lex: class Replace s => IsRegex re s
+ Text.RE.Tools.Lex: makeRegex :: (IsRegex re s, Functor m, Monad m) => s -> m re
+ Text.RE.Tools.Lex: makeRegexWith :: (IsRegex re s, Functor m, Monad m) => SimpleRegexOptions -> s -> m re
+ Text.RE.Tools.Lex: matchMany :: IsRegex re s => re -> s -> Matches s
+ Text.RE.Tools.Lex: matchOnce :: IsRegex re s => re -> s -> Match s
+ Text.RE.Tools.Lex: regexSource :: IsRegex re s => re -> s
+ Text.RE.Tools.Sed: Delete :: LineEdit s
+ Text.RE.Tools.Sed: Function :: Context -> (LineNo -> Match s -> Location -> Capture s -> m (Maybe s)) -> Edit m s
+ Text.RE.Tools.Sed: LineEdit :: (LineNo -> Matches s -> m (LineEdit s)) -> Edit m s
+ Text.RE.Tools.Sed: NoEdit :: LineEdit s
+ Text.RE.Tools.Sed: Pipe :: [(re, Edit m s)] -> Edits m re s
+ Text.RE.Tools.Sed: ReplaceWith :: s -> LineEdit s
+ Text.RE.Tools.Sed: Select :: [(re, Edit m s)] -> Edits m re s
+ Text.RE.Tools.Sed: Template :: s -> Edit m s
+ Text.RE.Tools.Sed: ZeroBasedLineNo :: Int -> LineNo
+ Text.RE.Tools.Sed: [getZeroBasedLineNo] :: LineNo -> Int
+ Text.RE.Tools.Sed: applyEdit :: (IsRegex re s, Monad m, Functor m) => (s -> s) -> LineNo -> re -> Edit m s -> s -> m (Maybe s)
+ Text.RE.Tools.Sed: applyEdits :: (IsRegex re s, Monad m, Functor m) => LineNo -> Edits m re s -> s -> m s
+ Text.RE.Tools.Sed: applyLineEdit :: Monoid s => (s -> s) -> LineEdit s -> Maybe s
+ Text.RE.Tools.Sed: class Replace s => IsRegex re s
+ Text.RE.Tools.Sed: data Edit m s
+ Text.RE.Tools.Sed: data Edits m re s
+ Text.RE.Tools.Sed: data LineEdit s
+ Text.RE.Tools.Sed: firstLine :: LineNo
+ Text.RE.Tools.Sed: getLineNo :: LineNo -> Int
+ Text.RE.Tools.Sed: lineNo :: Int -> LineNo
+ Text.RE.Tools.Sed: makeRegex :: (IsRegex re s, Functor m, Monad m) => s -> m re
+ Text.RE.Tools.Sed: makeRegexWith :: (IsRegex re s, Functor m, Monad m) => SimpleRegexOptions -> s -> m re
+ Text.RE.Tools.Sed: matchMany :: IsRegex re s => re -> s -> Matches s
+ Text.RE.Tools.Sed: matchOnce :: IsRegex re s => re -> s -> Match s
+ Text.RE.Tools.Sed: newtype LineNo
+ Text.RE.Tools.Sed: regexSource :: IsRegex re s => re -> s
- Text.RE.Tools.Grep: grep :: IsRegex re ByteString => re -> FilePath -> IO ()
+ Text.RE.Tools.Grep: grep :: IsRegex re ByteString => Verbosity -> re -> FilePath -> IO ()
- Text.RE.Tools.Grep: linesMatched :: [Line] -> [Line]
+ Text.RE.Tools.Grep: linesMatched :: Verbosity -> [Line] -> [Line]
- Text.RE.Tools.Sed: sed :: IsRegex re ByteString => SedScript re -> FilePath -> FilePath -> IO ()
+ Text.RE.Tools.Sed: sed :: IsRegex re ByteString => Edits IO re ByteString -> FilePath -> FilePath -> IO ()
Files
- README.markdown +7/−2
- Text/RE.hs +12/−8
- Text/RE/TDFA/ByteString.hs +13/−7
- Text/RE/TDFA/ByteString/Lazy.hs +13/−7
- Text/RE/TDFA/Sequence.hs +13/−7
- Text/RE/TDFA/String.hs +13/−7
- Text/RE/TDFA/Text.hs +13/−7
- Text/RE/TDFA/Text/Lazy.hs +13/−7
- Text/RE/TestBench.lhs +6/−4
- Text/RE/Tools.hs +40/−0
- Text/RE/Tools/Edit.lhs +25/−7
- Text/RE/Tools/Grep.lhs +42/−13
- Text/RE/Tools/Lex.lhs +7/−1
- Text/RE/Tools/Sed.lhs +21/−9
- changelog +3/−0
- regex.cabal +5/−4
README.markdown view
@@ -24,7 +24,10 @@ The library and tutorial, tests and examples have been split across two packages: - * the `regex` package contains the regex library and+ * the `regex` package contains the regex library with the Posix TDFA+ back end+ * the `regex-with-pcre` library package contains the extra modules+ needed for the PCRE back end * the `regex-examples` package contains the tutorial, tests and example programs. @@ -57,7 +60,9 @@ ☒ 2017-03-15 v0.7.0.0 [Better organization of API](https://github.com/iconnect/regex/milestone/8) - ☐ 2017-03-17 v0.8.0.0 [Add type-safe replacement templates and use TemplateHaskellQuotes](https://github.com/iconnect/regex/milestone/9)+ ☒ 2017-03-16 v0.8.0.0 [Tidy up the API](https://github.com/iconnect/regex/milestone/10)++ ☐ 2017-03-18 v0.9.0.0 [Add type-safe replacement templates and use TemplateHaskellQuotes](https://github.com/iconnect/regex/milestone/9) ☐ 2017-03-31 v1.0.0.0 [First stable release](https://github.com/iconnect/regex/milestone/3)
Text/RE.hs view
@@ -9,7 +9,7 @@ module Text.RE (- -- * Tutorial+ -- * The Tutorial -- $tutorial -- * How to use this library@@ -98,14 +98,8 @@ -- or indeed a good old-fashioned polymorphic operators? -- -- While we aim to provide all combinations of these choices, some of them--- are currently not available. We have:+-- are currently not available. In the regex package we have: ----- * "Text.RE.PCRE"--- * "Text.RE.PCRE.ByteString"--- * "Text.RE.PCRE.ByteString.Lazy"--- * "Text.RE.PCRE.RE"--- * "Text.RE.PCRE.Sequence"--- * "Text.RE.PCRE.String" -- * "Text.RE.TDFA" -- * "Text.RE.TDFA.ByteString" -- * "Text.RE.TDFA.ByteString.Lazy"@@ -114,6 +108,16 @@ -- * "Text.RE.TDFA.String" -- * "Text.RE.TDFA.Text" -- * "Text.RE.TDFA.Text.Lazy"+--+-- The PCRE modules are contained in the separate @regex-with-pcre@+-- package:+--+-- * "Text.RE.PCRE"+-- * "Text.RE.PCRE.ByteString"+-- * "Text.RE.PCRE.ByteString.Lazy"+-- * "Text.RE.PCRE.RE"+-- * "Text.RE.PCRE.Sequence"+-- * "Text.RE.PCRE.String" -- $operators --
Text/RE/TDFA/ByteString.hs view
@@ -1,9 +1,10 @@-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif@@ -21,8 +22,13 @@ -- * The Toolkit -- $toolkit , module Text.RE- -- * The 'RE' Type+ -- * The 'RE' Type and functions -- $re+ , RE+ , reSource+ , compileRegex+ , compileRegexWith+ , escape , module Text.RE.TDFA.RE ) where
Text/RE/TDFA/ByteString/Lazy.hs view
@@ -1,9 +1,10 @@-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif@@ -21,8 +22,13 @@ -- * The Toolkit -- $toolkit , module Text.RE- -- * The 'RE' Type+ -- * The 'RE' Type and functions -- $re+ , RE+ , reSource+ , compileRegex+ , compileRegexWith+ , escape , module Text.RE.TDFA.RE ) where
Text/RE/TDFA/Sequence.hs view
@@ -1,9 +1,10 @@-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif@@ -21,8 +22,13 @@ -- * The Toolkit -- $toolkit , module Text.RE- -- * The 'RE' Type+ -- * The 'RE' Type and functions -- $re+ , RE+ , reSource+ , compileRegex+ , compileRegexWith+ , escape , module Text.RE.TDFA.RE ) where
Text/RE/TDFA/String.hs view
@@ -1,9 +1,10 @@-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif@@ -21,8 +22,13 @@ -- * The Toolkit -- $toolkit , module Text.RE- -- * The 'RE' Type+ -- * The 'RE' Type and functions -- $re+ , RE+ , reSource+ , compileRegex+ , compileRegexWith+ , escape , module Text.RE.TDFA.RE ) where
Text/RE/TDFA/Text.hs view
@@ -1,9 +1,10 @@-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif@@ -21,8 +22,13 @@ -- * The Toolkit -- $toolkit , module Text.RE- -- * The 'RE' Type+ -- * The 'RE' Type and functions -- $re+ , RE+ , reSource+ , compileRegex+ , compileRegexWith+ , escape , module Text.RE.TDFA.RE ) where
Text/RE/TDFA/Text/Lazy.hs view
@@ -1,9 +1,10 @@-{-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE FlexibleInstances #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}+{-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 800 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-} #endif@@ -21,8 +22,13 @@ -- * The Toolkit -- $toolkit , module Text.RE- -- * The 'RE' Type+ -- * The 'RE' Type and functions -- $re+ , RE+ , reSource+ , compileRegex+ , compileRegexWith+ , escape , module Text.RE.TDFA.RE ) where
Text/RE/TestBench.lhs view
@@ -34,6 +34,10 @@ , formatMacroSource , testMacroDescriptors , mdRegexSource+ -- * Parsers+ , module Text.RE.TestBench.Parsers+ -- * Text.RE+ , module Text.RE ) where import Data.Array@@ -45,11 +49,9 @@ import Data.String import Text.Printf import Prelude.Compat-import Text.RE.Types.Capture+import Text.RE+import Text.RE.TestBench.Parsers import Text.RE.Types.Options-import Text.RE.Types.Match-import Text.RE.Types.Matches-import Text.RE.Types.Replace \end{code} Types
+ Text/RE/Tools.hs view
@@ -0,0 +1,40 @@+module Text.RE.Tools+ (+ -- * The Tools+ -- $tools++ -- * Sed+ sed+ , sed'+ -- * Grep+ , grep+ , grepLines+ , GrepScript+ , grepScript+ , linesMatched+ -- * Lex+ , alex+ , alex'+ -- * IsRegex+ , IsRegex(..)+ -- * Edit+ , Edits(..)+ , Edit(..)+ , LineEdit(..)+ , applyEdits+ , applyEdit+ , applyLineEdit+ -- * LineNo+ , LineNo(..)+ , firstLine+ , getLineNo+ , lineNo+ -- * Text.RE+ , module Text.RE+ ) where++import Text.RE+import Text.RE.Tools.Edit+import Text.RE.Tools.Grep+import Text.RE.Tools.Lex+import Text.RE.Tools.Sed
Text/RE/Tools/Edit.lhs view
@@ -7,40 +7,50 @@ #endif module Text.RE.Tools.Edit- ( LineNo- , Edits(..)+ ( Edits(..) , Edit(..) , LineEdit(..) , applyEdits , applyEdit , applyLineEdit+ -- * LineNo+ , LineNo(..)+ , firstLine+ , getLineNo+ , lineNo+ -- * Text.RE+ , module Text.RE ) where import Data.Maybe import Prelude.Compat-import Text.RE.Types.Capture-import Text.RE.Types.Match-import Text.RE.Types.Matches+import Text.RE import Text.RE.Types.IsRegex import Text.RE.Types.LineNo-import Text.RE.Types.Replace +-- | 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 data Edits m re s = Select [(re,Edit m s)] | Pipe [(re,Edit m s)] +-- | each Edit action specifies how the match should be processed data Edit m s = Template s | Function Context (LineNo->Match s->Location->Capture s->m (Maybe s)) | LineEdit (LineNo->Matches s->m (LineEdit s)) +-- | a LineEdit is the most general action thar can be performed on a line+-- and is the only means of deleting a line data LineEdit s = NoEdit | ReplaceWith s | Delete deriving (Show) +-- | apply an 'Edit' script to a single line applyEdits :: (IsRegex re s,Monad m,Functor m) => LineNo -> Edits m re s@@ -50,6 +60,10 @@ Select ez -> select_edit_scripts lno ez s0 Pipe ez -> pipe_edit_scripts lno ez s0 +-- | 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 applyEdit :: (IsRegex re s,Monad m,Functor m) => (s->s) -> LineNo@@ -68,10 +82,14 @@ s' = anl s acs = matchMany re 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 applyLineEdit :: Monoid s => (s->s) -> LineEdit s -> Maybe s applyLineEdit _ NoEdit = Nothing applyLineEdit anl (ReplaceWith s) = Just $ anl s-applyLineEdit _ Delete = Just $ mempty+applyLineEdit _ Delete = Just mempty select_edit_scripts :: (IsRegex re s,Monad m,Functor m) => LineNo
Text/RE/Tools/Grep.lhs view
@@ -5,15 +5,23 @@ {-# LANGUAGE CPP #-} module Text.RE.Tools.Grep- ( Line(..)- , grep+ ( grep+ , Line(..) , grepLines , GrepScript , grepScript+ , report+ , Verbosity(..) , linesMatched+ -- * IsRegex+ , IsRegex(..)+ -- * LineNo+ , LineNo(..)+ , firstLine+ , getLineNo+ , lineNo+ -- * Text.RE , module Text.RE- , module Text.RE.Types.IsRegex- , module Text.RE.Types.LineNo ) where import qualified Data.ByteString.Lazy.Char8 as LBS@@ -24,24 +32,32 @@ import Text.RE.Types.LineNo +-- | operates a bit like classic @grep@ printing out the lines matched+grep :: IsRegex re LBS.ByteString => Verbosity -> re -> FilePath -> IO ()+grep v rex fp = grepLines rex fp >>= putStr . report v++-- | 'grepLines' returns a 'Line' for each line in the file, listing all+-- of the 'Matches' for that line data Line = Line- { getLineNumber :: LineNo- , getLineMatches :: Matches LBS.ByteString+ { getLineNumber :: LineNo -- ^ the 'LineNo' for this line+ , getLineMatches :: Matches LBS.ByteString -- ^ all the 'Matches' of the RE on this line } deriving (Show) -grep :: IsRegex re LBS.ByteString => re -> FilePath -> IO ()-grep rex fp = grepLines rex fp >>= putStr . report-+-- | returns a 'Line' for each line in the file enumerating all of the+-- matches for that line. grepLines :: IsRegex re LBS.ByteString => re -> FilePath -> IO [Line] grepLines rex fp = grepScript [(rex,mk)] . LBS.lines <$> LBS.readFile fp where mk i mtchs = Just $ Line i mtchs +-- | 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 type GrepScript re s t = [(re,LineNo -> Matches s -> Maybe t)] +-- | given a list of lines, apply the 'GrepScript' to each line of the file grepScript :: IsRegex re s => GrepScript re s t -> [s] -> [t] grepScript scr = loop firstLine where@@ -53,13 +69,26 @@ Nothing -> choose i ln lns scr' Just t -> t : loop (succ i) lns -report :: [Line] -> String-report = unlines . map fmt . linesMatched+-- | generate a grep report from a list of 'Line'+report :: Verbosity -> [Line] -> String+report v = unlines . map fmt . linesMatched v where fmt Line{..} = printf "%05d %s" (getLineNo getLineNumber) $ LBS.unpack $ matchesSource getLineMatches -linesMatched :: [Line] -> [Line]-linesMatched = filter $ anyMatches . getLineMatches+-- | specifies whether to return the linss matched or missed+data Verbosity+ = LinesMatched+ | LinesNotMatched+ deriving (Show,Eq,Ord)++-- | given a 'velocity' flag filter out either the lines matched or not+-- matched+linesMatched :: Verbosity -> [Line] -> [Line]+linesMatched v = filter $ f . anyMatches . getLineMatches+ where+ f = case v of+ LinesMatched -> id+ LinesNotMatched -> not \end{code}
Text/RE/Tools/Lex.lhs view
@@ -4,8 +4,10 @@ module Text.RE.Tools.Lex ( alex , alex'+ -- * IsRegex+ , IsRegex(..)+ -- * Text.RE , module Text.RE- , module Text.RE.Types.IsRegex ) where import Prelude.Compat@@ -13,9 +15,13 @@ import Text.RE.Types.IsRegex +-- | a simple regex-based scanner interpretter for prototyping+-- scanners alex :: IsRegex re s => [(re,Match s->Maybe t)] -> t -> s -> [t] alex = alex' matchOnce +-- | a higher order version of 'alex' parameterised over the @matchOnce@+-- function alex' :: Replace s => (re->s->Match s) -> [(re,Match s->Maybe t)]
Text/RE/Tools/Sed.lhs view
@@ -8,27 +8,38 @@ #endif module Text.RE.Tools.Sed- ( SedScript- , sed+ ( sed , sed'+ -- * IsRegex+ , IsRegex(..)+ -- * Edit+ , Edits(..)+ , Edit(..)+ , LineEdit(..)+ , applyEdits+ , applyEdit+ , applyLineEdit+ -- * LineNo+ , LineNo(..)+ , firstLine+ , getLineNo+ , lineNo+ -- * Text.RE , module Text.RE- , module Text.RE.Types.IsRegex- , module Text.RE.Tools.Edit- , module Text.RE.Types.LineNo ) where import qualified Data.ByteString.Lazy.Char8 as LBS import Prelude.Compat import Text.RE import Text.RE.Tools.Edit-import Text.RE.Types.LineNo import Text.RE.Types.IsRegex -type SedScript re = Edits IO re LBS.ByteString-+-- | 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 LBS.ByteString- => SedScript re+ => Edits IO re LBS.ByteString -> FilePath -> FilePath -> IO ()@@ -40,6 +51,7 @@ ] write_file o_fp $ LBS.concat lns' +-- | apply an 'Edits' script to each line of the argument text sed' :: (IsRegex re a,Monad m,Functor m) => Edits m re a -> a
changelog view
@@ -1,5 +1,8 @@ -*-change-log-*- +0.8.0.0 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-03-16+ * Tidy up the API after recent reorganization (#76)+ 0.7.0.0 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-03-15 * Fix and extend Replace class (#74) * Better package organisation (#73)
regex.cabal view
@@ -1,5 +1,5 @@ Name: regex-Version: 0.7.0.0+Version: 0.8.0.0 Synopsis: Toolkit for regex-base Description: A Regular Expression Toolkit for regex-base with Compile-time checking of RE syntax, data types for@@ -31,7 +31,7 @@ Source-Repository this Type: git Location: https://github.com/iconnect/regex.git- Tag: 0.7.0.0+ Tag: 0.8.0.0 @@ -45,8 +45,6 @@ Text.RE.Internal.NamedCaptures Text.RE.Internal.PreludeMacros Text.RE.Internal.QQ- Text.RE.Types.IsRegex- Text.RE.Types.Replace Text.RE.TDFA Text.RE.TDFA.ByteString Text.RE.TDFA.ByteString.Lazy@@ -57,16 +55,19 @@ Text.RE.TDFA.Text.Lazy Text.RE.TestBench Text.RE.TestBench.Parsers+ Text.RE.Tools Text.RE.Tools.Edit Text.RE.Tools.Grep Text.RE.Tools.Lex Text.RE.Tools.Sed Text.RE.Types.Capture Text.RE.Types.CaptureID+ Text.RE.Types.IsRegex Text.RE.Types.LineNo Text.RE.Types.Match Text.RE.Types.Matches Text.RE.Types.Options+ Text.RE.Types.Replace Default-Language: Haskell2010 GHC-Options: