regex 0.0.0.1 → 0.0.0.2
raw patch · 25 files changed
+514/−149 lines, 25 filesdep −hsyslogdep ~basedep ~regex-tdfadep ~shellynew-component:exe:re-nginx-log-processornew-component:exe:re-tutorialPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: hsyslog
Dependency ranges changed: base, regex-tdfa, shelly, tasty-smallcheck, transformers
API changes (from Hackage documentation)
- Text.RE.Capture: instance RegexContext regex source (AllTextSubmatches (Array Int) (source, (Int, Int))) => RegexContext regex source (Match source)
- Text.RE.Capture: instance RegexContext regex source [MatchText source] => RegexContext regex source (Matches source)
- Text.RE.Parsers: parseSyslogSeverity :: Replace a => a -> Maybe Priority
- Text.RE.Parsers: syslogSeverityKeywords :: Priority -> (String, [String])
- Text.RE.TestBench: regexSource :: RegexType -> WithCaptures -> RegexSource -> String
+ Text.RE.Capture: instance (RegexContext regex source (AllTextSubmatches (Array Int) (source, (Int, Int))), RegexLike regex source) => RegexContext regex source (Match source)
+ Text.RE.Capture: instance (RegexContext regex source [MatchText source], RegexLike regex source) => RegexContext regex source (Matches source)
+ Text.RE.Internal.PreludeMacros: ExclCaptures :: WithCaptures
+ Text.RE.Internal.PreludeMacros: InclCaptures :: WithCaptures
+ Text.RE.Internal.PreludeMacros: MacroDescriptor :: !RegexSource -> ![String] -> ![String] -> ![TestResult] -> !(Maybe FunctionID) -> !String -> MacroDescriptor
+ Text.RE.Internal.PreludeMacros: PCRE :: RegexType
+ Text.RE.Internal.PreludeMacros: PM_address_ipv4 :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_date :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_date_slashes :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_datetime :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_datetime_8601 :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_datetime_clf :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_decimal :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_email_simple :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_id :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_id' :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_integer :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_natural :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_natural_hex :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_shortmonth :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_string :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_string_simple :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_syslog_severity :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_time :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_timezone :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: PM_url :: PreludeMacro
+ Text.RE.Internal.PreludeMacros: RegexSource :: String -> RegexSource
+ Text.RE.Internal.PreludeMacros: TDFA :: RegexType
+ Text.RE.Internal.PreludeMacros: _RegexSource :: RegexSource -> String
+ Text.RE.Internal.PreludeMacros: _md_counter_samples :: MacroDescriptor -> ![String]
+ Text.RE.Internal.PreludeMacros: _md_description :: MacroDescriptor -> !String
+ Text.RE.Internal.PreludeMacros: _md_parser :: MacroDescriptor -> !(Maybe FunctionID)
+ Text.RE.Internal.PreludeMacros: _md_samples :: MacroDescriptor -> ![String]
+ Text.RE.Internal.PreludeMacros: _md_source :: MacroDescriptor -> !RegexSource
+ Text.RE.Internal.PreludeMacros: _md_test_results :: MacroDescriptor -> ![TestResult]
+ Text.RE.Internal.PreludeMacros: data MacroDescriptor
+ Text.RE.Internal.PreludeMacros: data PreludeMacro
+ Text.RE.Internal.PreludeMacros: data RegexType
+ Text.RE.Internal.PreludeMacros: data WithCaptures
+ Text.RE.Internal.PreludeMacros: instance Bounded PreludeMacro
+ Text.RE.Internal.PreludeMacros: instance Enum PreludeMacro
+ Text.RE.Internal.PreludeMacros: instance Eq PreludeMacro
+ Text.RE.Internal.PreludeMacros: instance Ord PreludeMacro
+ Text.RE.Internal.PreludeMacros: instance Show PreludeMacro
+ Text.RE.Internal.PreludeMacros: newtype RegexSource
+ Text.RE.Internal.PreludeMacros: preludeMacroDescriptor :: RegexType -> MacroEnv -> PreludeMacro -> Maybe MacroDescriptor
+ Text.RE.Internal.PreludeMacros: preludeMacroEnv :: RegexType -> MacroEnv
+ Text.RE.Internal.PreludeMacros: preludeMacroSource :: RegexType -> PreludeMacro -> String
+ Text.RE.Internal.PreludeMacros: preludeMacroSources :: RegexType -> String
+ Text.RE.Internal.PreludeMacros: preludeMacroSummary :: RegexType -> PreludeMacro -> String
+ Text.RE.Internal.PreludeMacros: preludeMacroTable :: RegexType -> String
+ Text.RE.Internal.PreludeMacros: preludeMacros :: (Monad m, Functor m) => (String -> m r) -> RegexType -> WithCaptures -> m (Macros r)
+ Text.RE.Internal.PreludeMacros: presentPreludeMacro :: PreludeMacro -> String
+ Text.RE.Internal.QQ: QQFailure :: String -> String -> QQFailure
+ Text.RE.Internal.QQ: _qqf_component :: QQFailure -> String
+ Text.RE.Internal.QQ: _qqf_context :: QQFailure -> String
+ Text.RE.Internal.QQ: data QQFailure
+ Text.RE.Internal.QQ: instance Exception QQFailure
+ Text.RE.Internal.QQ: instance Show QQFailure
+ Text.RE.Internal.QQ: instance Typeable QQFailure
+ Text.RE.Internal.QQ: qq0 :: String -> QuasiQuoter
+ Text.RE.Parsers: Alert :: Severity
+ Text.RE.Parsers: Crit :: Severity
+ Text.RE.Parsers: Debug :: Severity
+ Text.RE.Parsers: Emerg :: Severity
+ Text.RE.Parsers: Err :: Severity
+ Text.RE.Parsers: Info :: Severity
+ Text.RE.Parsers: Notice :: Severity
+ Text.RE.Parsers: Warning :: Severity
+ Text.RE.Parsers: data Severity
+ Text.RE.Parsers: instance Bounded Severity
+ Text.RE.Parsers: instance Enum Severity
+ Text.RE.Parsers: instance Eq Severity
+ Text.RE.Parsers: instance Ord Severity
+ Text.RE.Parsers: instance Show Severity
+ Text.RE.Parsers: parseSeverity :: Replace a => a -> Maybe Severity
+ Text.RE.Parsers: severityKeywords :: Severity -> (String, [String])
+ Text.RE.TestBench: instance Bounded RegexType
+ Text.RE.TestBench: instance Enum RegexType
- Text.RE.Options: Options :: Mode -> Macros r -> c -> e -> Options_ r c e
+ Text.RE.Options: Options :: !Mode -> !(Macros r) -> !c -> !e -> Options_ r c e
- Text.RE.Options: _options_comp :: Options_ r c e -> c
+ Text.RE.Options: _options_comp :: Options_ r c e -> !c
- Text.RE.Options: _options_exec :: Options_ r c e -> e
+ Text.RE.Options: _options_exec :: Options_ r c e -> !e
- Text.RE.Options: _options_macs :: Options_ r c e -> Macros r
+ Text.RE.Options: _options_macs :: Options_ r c e -> !(Macros r)
- Text.RE.Options: _options_mode :: Options_ r c e -> Mode
+ Text.RE.Options: _options_mode :: Options_ r c e -> !Mode
- Text.RE.TestBench: MacroDescriptor :: RegexSource -> [String] -> [String] -> [TestResult] -> Maybe FunctionID -> String -> MacroDescriptor
+ Text.RE.TestBench: MacroDescriptor :: !RegexSource -> ![String] -> ![String] -> ![TestResult] -> !(Maybe FunctionID) -> !String -> MacroDescriptor
- Text.RE.TestBench: _md_counter_samples :: MacroDescriptor -> [String]
+ Text.RE.TestBench: _md_counter_samples :: MacroDescriptor -> ![String]
- Text.RE.TestBench: _md_description :: MacroDescriptor -> String
+ Text.RE.TestBench: _md_description :: MacroDescriptor -> !String
- Text.RE.TestBench: _md_parser :: MacroDescriptor -> Maybe FunctionID
+ Text.RE.TestBench: _md_parser :: MacroDescriptor -> !(Maybe FunctionID)
- Text.RE.TestBench: _md_samples :: MacroDescriptor -> [String]
+ Text.RE.TestBench: _md_samples :: MacroDescriptor -> ![String]
- Text.RE.TestBench: _md_source :: MacroDescriptor -> RegexSource
+ Text.RE.TestBench: _md_source :: MacroDescriptor -> !RegexSource
- Text.RE.TestBench: _md_test_results :: MacroDescriptor -> [TestResult]
+ Text.RE.TestBench: _md_test_results :: MacroDescriptor -> ![TestResult]
Files
- README.md +47/−0
- Text/RE/Capture.lhs +8/−2
- Text/RE/Internal/PreludeMacros.hs +37/−41
- Text/RE/Internal/QQ.hs +18/−13
- Text/RE/IsRegex.lhs +1/−0
- Text/RE/Options.lhs +4/−4
- Text/RE/PCRE/ByteString.hs +4/−0
- Text/RE/PCRE/ByteString/Lazy.hs +4/−0
- Text/RE/PCRE/RE.hs +4/−6
- Text/RE/PCRE/Sequence.hs +4/−0
- Text/RE/PCRE/String.hs +4/−0
- Text/RE/Parsers.hs +24/−13
- Text/RE/TDFA/ByteString.hs +4/−0
- Text/RE/TDFA/ByteString/Lazy.hs +4/−0
- Text/RE/TDFA/RE.hs +4/−6
- Text/RE/TDFA/Sequence.hs +4/−0
- Text/RE/TDFA/String.hs +4/−0
- Text/RE/TDFA/Text.hs +4/−0
- Text/RE/TDFA/Text/Lazy.hs +4/−0
- Text/RE/TestBench.lhs +8/−8
- changelog +8/−1
- examples/TestKit.lhs +2/−0
- examples/re-nginx-log-processor.lhs +16/−20
- examples/re-tests.lhs +189/−5
- regex.cabal +104/−30
+ README.md view
@@ -0,0 +1,47 @@+[](https://hackage.haskell.org/package/regex)+[](https://tldrlegal.com/license/bsd-3-clause-license-%28revised%29)+[](https://travis-ci.org/iconnect/regex)+[](https://ci.appveyor.com/project/engineerirngirisconnectcouk/regex/branch/master)+[](https://coveralls.io/github/iconnect/regex?branch=master)++# regex: A Regular Expression Toolkit for regex-base++regex extends regex-base with:++ * a text-replacement toolkit+ * special datatypes for many matches, first match and individual captures+ * compile-time checking of RE syntax+ * a unified means of controlling case-sensitivity and multi-line options+ * high-level AWK-like tools for building text processing apps+ * the option of using match operators with reduced polymorphism on the+ text and/or result types+ * regular expression macros including+ + a number of useful RE macros+ + a test bench for testing and documenting new macro environments+ * built-in support for the TDFA and PCRE backends+ * comprehensive documentation and copious examples+++Schedule+--------++- [X] **2017-01-26** 0.0.0.1 Pre-release (I)+- [X] **2017-01-30** 0.0.0.2 Pre-release (II)+- [ ] **2017-02-06** 0.0.1.0 RFC+- [ ] **2017-02-20** 0.1.0.0 a candidate stable release+- [ ] **2017-03-20** 1.0.0.0 first stable release+++The Web Page+------------++We have a [web page](https://iconnect.github.io/regex/) with a tutorial,+a major example and and more examples than you can shake a stick at (most+of them used in the package itself).+++The Macro Tables+----------------++The macro environments are an important part of the package and they+are documented [in these tables](tables).
Text/RE/Capture.lhs view
@@ -213,7 +213,10 @@ \begin{code} -- | for matching just the first RE against the source text-instance RegexContext regex source (AllTextSubmatches (Array Int) (source,(Int,Int))) =>+instance+ ( RegexContext regex source (AllTextSubmatches (Array Int) (source,(Int,Int)))+ , RegexLike regex source+ ) => RegexContext regex source (Match source) where match r s = cvt s $ getAllTextSubmatches $ match r s matchM r s = do@@ -221,7 +224,10 @@ return $ cvt s $ getAllTextSubmatches y -- | for matching all REs against the source text-instance RegexContext regex source [MatchText source] =>+instance+ ( RegexContext regex source [MatchText source]+ , RegexLike regex source+ ) => RegexContext regex source (Matches source) where match r s = Matches s $ map (cvt s) $ match r s matchM r s = do
Text/RE/Internal/PreludeMacros.hs view
@@ -8,6 +8,7 @@ , MacroDescriptor(..) , RegexSource(..) , PreludeMacro(..)+ , presentPreludeMacro , preludeMacros , preludeMacroTable , preludeMacroSummary@@ -23,7 +24,6 @@ import Data.List import Data.Maybe import Data.Time-import System.Posix.Syslog import Text.RE.Options import Text.RE.Parsers import Text.RE.TestBench@@ -143,7 +143,7 @@ { _md_source = "[0-9]+" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseInteger" , _md_description = "a string of one or more decimal digits" }@@ -171,7 +171,7 @@ { _md_source = "[0-9a-fA-F]+" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseHex" , _md_description = "a string of one or more hexadecimal digits" }@@ -199,7 +199,7 @@ { _md_source = "-?[0-9]+" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseInteger" , _md_description = "a decimal integer" }@@ -227,7 +227,7 @@ { _md_source = "-?[0-9]+(?:\\.[0-9]+)?" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseInteger" , _md_description = "a decimal integer" }@@ -268,7 +268,7 @@ { _md_source = "\"(?:[^\"\\]+|\\\\[\\\"])*\"" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseString" , _md_description = "a double-quote string, with simple \\ escapes for \\s and \"s" }@@ -299,7 +299,7 @@ { _md_source = "\"[^\"[:cntrl:]]*\"" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseSimpleString" , _md_description = "a decimal integer" }@@ -332,7 +332,7 @@ { _md_source = "_*[a-zA-Z][a-zA-Z0-9_]*" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Nothing , _md_description = "a standard C-style alphanumeric identifier (with _s)" }@@ -370,7 +370,7 @@ { _md_source = "_*[a-zA-Z][a-zA-Z0-9_']*" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Nothing , _md_description = "a standard Haskell-style alphanumeric identifier (with '_'s and '''s)" }@@ -411,7 +411,7 @@ { _md_source = "[0-9]{4}-[0-9]{2}-[0-9]{2}" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseDate" , _md_description = "a YYYY-MM-DD format date" }@@ -443,7 +443,7 @@ { _md_source = "[0-9]{4}/[0-9]{2}/[0-9]{2}" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseSlashesDate" , _md_description = "a YYYY/MM/DD format date" }@@ -475,19 +475,19 @@ { _md_source = "[0-9]{2}:[0-9]{2}:[0-9]{2}(?:[.][0-9]+)?" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseTimeOfDay" , _md_description = "a HH:MM:SS[.Q+]" } where samples :: [(String,TimeOfDay)] samples =- [ f "00:00:00" 00 00 0- , f "23:59:59" 23 59 59000000000000- , f "00:00:00.1234567890" 00 00 00123456789000+ [ f "00:00:00" 00 00 0+ , f "23:59:59" 23 59 59+ , f "00:00:00.1234567890" 00 00 $ 123456789 / 1000000000 ] where- f s h m ps = (s,TimeOfDay h m $ toEnum ps)+ f s h m ps = (s,TimeOfDay h m ps) counter_samples = [ ""@@ -508,7 +508,7 @@ { _md_source = "(?:Z|[+-][0-9]{2}:?[0-9]{2})" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseTimeZone" , _md_description = "an IOS-8601 TZ specification" }@@ -539,7 +539,7 @@ { _md_source = "@{%date}[ T]@{%time}(?:@{%timezone}| UTC)?" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseDateTime" , _md_description = "ISO-8601 format date and time + simple variants" }@@ -573,7 +573,7 @@ { _md_source = "@{%date}T@{%time}@{%timezone}" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseDateTime8601" , _md_description = "YYYY-MM-DDTHH:MM:SS[.Q*](Z|[+-]HHMM) format date and time" }@@ -600,7 +600,7 @@ { _md_source = re , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseDateTimeCLF" , _md_description = "Common Log Format date+time: %d/%b/%Y:%H:%M:%S %z" }@@ -639,7 +639,7 @@ intercalate "|" $ elems shortMonthArray , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Just "parseShortMonth" , _md_description = "three letter month name: Jan-Dec" }@@ -672,8 +672,8 @@ { _md_source = "[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm- , _md_parser = Just "parseSyslogSeverity"+ , _md_test_results = []+ , _md_parser = Just "parseSeverity" , _md_description = "an a.b.c.d IPv4 address" } where@@ -703,24 +703,24 @@ -> PreludeMacro -> Maybe MacroDescriptor syslog_severity_macro rty env pm =- Just $ run_tests rty parseSyslogSeverity samples env pm+ Just $ run_tests rty parseSeverity samples env pm MacroDescriptor { _md_source = re , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm- , _md_parser = Just "parseSyslogSeverity"+ , _md_test_results = []+ , _md_parser = Just "parseSeverity" , _md_description = "syslog severity keyword (debug-emerg)" } where- samples :: [(String,Priority)]+ samples :: [(String,Severity)] samples =- [ f "emerg" Emergency- , f "panic" Emergency+ [ f "emerg" Emerg+ , f "panic" Emerg , f "alert" Alert- , f "crit" Critical- , f "err" Error- , f "error" Error+ , f "crit" Crit+ , f "err" Err+ , f "error" Err , f "warn" Warning , f "warning" Warning , f "notice" Notice@@ -743,15 +743,15 @@ re_tdfa = bracketedRegexSource $ intercalate "|" $ [ kw- | (kw0,kws) <- map syslogSeverityKeywords [minBound..maxBound]+ | (kw0,kws) <- map severityKeywords [minBound..maxBound] , kw <- kw0:kws ] re_pcre = bracketedRegexSource $ intercalate "|" $ [ kw- | (kw0,kws) <- map syslogSeverityKeywords $- filter (/=Error) [minBound..maxBound]+ | (kw0,kws) <- map severityKeywords $+ filter (/=Err) [minBound..maxBound] , kw <- kw0:kws ] ++ ["err(?:or)?"] @@ -765,7 +765,7 @@ { _md_source = "[a-zA-Z0-9%_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9.-]+" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Nothing , _md_description = "an email address" }@@ -794,7 +794,7 @@ { _md_source = "([hH][tT][tT][pP][sS]?|[fF][tT][pP])://[^[:space:]/$.?#].[^[:space:]]*" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = test_stub pm+ , _md_test_results = [] , _md_parser = Nothing , _md_description = "a URL" }@@ -829,10 +829,6 @@ , "http://##" , "http://##/" ]--test_stub :: PreludeMacro -> [TestResult]-test_stub pm =- error $ "test_stub: tests missing: " ++ presentPreludeMacro pm run_tests :: (Eq a,Show a) => RegexType
Text/RE/Internal/QQ.hs view
@@ -1,21 +1,26 @@+{-# LANGUAGE DeriveDataTypeable #-}+ module Text.RE.Internal.QQ where +import Control.Exception+import Data.Typeable import Language.Haskell.TH.Quote +data QQFailure =+ QQFailure+ { _qqf_context :: String+ , _qqf_component :: String+ }+ deriving (Show,Typeable)++instance Exception QQFailure where+ qq0 :: String -> QuasiQuoter-qq0 nm =+qq0 ctx = QuasiQuoter- { quoteExp = const $ error $ oops "an expression"- , quotePat = const $ error $ oops "a pattern"- , quoteType = const $ error $ oops "a type"- , quoteDec = const $ error $ oops "a declaration"+ { quoteExp = const $ throw $ QQFailure ctx "expression"+ , quotePat = const $ throw $ QQFailure ctx "pattern"+ , quoteType = const $ throw $ QQFailure ctx "type"+ , quoteDec = const $ throw $ QQFailure ctx "declaration" }- where- oops sc = unwords- [ "`"- , nm- , "` QuasiQuoter has been used in"- , sc- , "context but it should be used in an expresion context."- ]
Text/RE/IsRegex.lhs view
@@ -1,5 +1,6 @@ \begin{code} {-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE AllowAmbiguousTypes #-} module Text.RE.IsRegex where
Text/RE/Options.lhs view
@@ -17,10 +17,10 @@ \begin{code} data Options_ r c e = Options- { _options_mode :: Mode- , _options_macs :: Macros r- , _options_comp :: c- , _options_exec :: e+ { _options_mode :: !Mode+ , _options_macs :: !(Macros r)+ , _options_comp :: !c+ , _options_exec :: !e } deriving (Show) \end{code}
Text/RE/PCRE/ByteString.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.PCRE as PCRE +-- | find all matches in text (*=~) :: B.ByteString -> RE -> Matches B.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: B.ByteString -> RE -> Match B.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex B.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex B.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String
Text/RE/PCRE/ByteString/Lazy.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.PCRE as PCRE +-- | find all matches in text (*=~) :: LBS.ByteString -> RE -> Matches LBS.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: LBS.ByteString -> RE -> Match LBS.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex LBS.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex LBS.ByteString a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String
Text/RE/PCRE/RE.hs view
@@ -79,10 +79,10 @@ data RE = RE- { _re_options :: Options- , _re_source :: String- , _re_cnames :: CaptureNames- , _re_regex :: Regex+ { _re_options :: !Options+ , _re_source :: !String+ , _re_cnames :: !CaptureNames+ , _re_regex :: !Regex } reOptions :: RE -> Options@@ -177,8 +177,6 @@ , _re_cnames = cnms , _re_regex = rex }-- Options{..} = os re' :: Maybe SimpleRegexOptions -> QuasiQuoter re' mb = case mb of
Text/RE/PCRE/Sequence.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.PCRE as PCRE +-- | find all matches in text (*=~) :: (S.Seq Char) -> RE -> Matches (S.Seq Char) (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: (S.Seq Char) -> RE -> Match (S.Seq Char) (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex (S.Seq Char) a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex (S.Seq Char) a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String
Text/RE/PCRE/String.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.PCRE as PCRE +-- | find all matches in text (*=~) :: String -> RE -> Matches String (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: String -> RE -> Match String (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext PCRE.Regex String a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext PCRE.Regex String a , RegexMaker PCRE.Regex PCRE.CompOption PCRE.ExecOption String
Text/RE/Parsers.hs view
@@ -15,8 +15,9 @@ , shortMonthArray , IPV4Address , parseIPv4Address- , parseSyslogSeverity- , syslogSeverityKeywords+ , Severity(..)+ , parseSeverity+ , severityKeywords ) where import Data.Array@@ -24,7 +25,6 @@ import Data.Maybe import Data.Time import Data.Word-import System.Posix.Syslog import Text.Printf import Text.Read import Text.RE.Replace@@ -126,23 +126,34 @@ is_o x = 0 <= x && x <= 255 -parseSyslogSeverity :: Replace a => a -> Maybe Priority-parseSyslogSeverity = flip HM.lookup syslog_severity_hm . unpack_+data Severity+ = Emerg+ | Alert+ | Crit+ | Err+ | Warning+ | Notice+ | Info+ | Debug+ deriving (Bounded,Enum,Ord,Eq,Show) -syslog_severity_hm :: HM.HashMap String Priority-syslog_severity_hm = HM.fromList+parseSeverity :: Replace a => a -> Maybe Severity+parseSeverity = flip HM.lookup severity_hm . unpack_++severity_hm :: HM.HashMap String Severity+severity_hm = HM.fromList [ (kw,pri) | pri<-[minBound..maxBound]- , let (kw0,kws) = syslogSeverityKeywords pri+ , let (kw0,kws) = severityKeywords pri , kw <- kw0:kws ] -syslogSeverityKeywords :: Priority -> (String,[String])-syslogSeverityKeywords pri = case pri of- Emergency -> (,) "emerg" ["panic"]+severityKeywords :: Severity -> (String,[String])+severityKeywords pri = case pri of+ Emerg -> (,) "emerg" ["panic"] Alert -> (,) "alert" []- Critical -> (,) "crit" []- Error -> (,) "err" ["error"]+ Crit -> (,) "crit" []+ Err -> (,) "err" ["error"] Warning -> (,) "warning" ["warn"] Notice -> (,) "notice" [] Info -> (,) "info" []
Text/RE/TDFA/ByteString.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.TDFA as TDFA +-- | find all matches in text (*=~) :: B.ByteString -> RE -> Matches B.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: B.ByteString -> RE -> Match B.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex B.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex B.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String
Text/RE/TDFA/ByteString/Lazy.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.TDFA as TDFA +-- | find all matches in text (*=~) :: LBS.ByteString -> RE -> Matches LBS.ByteString (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: LBS.ByteString -> RE -> Match LBS.ByteString (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex LBS.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex LBS.ByteString a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String
Text/RE/TDFA/RE.hs view
@@ -78,10 +78,10 @@ data RE = RE- { _re_options :: Options- , _re_source :: String- , _re_cnames :: CaptureNames- , _re_regex :: Regex+ { _re_options :: !Options+ , _re_source :: !String+ , _re_cnames :: !CaptureNames+ , _re_regex :: !Regex } reOptions :: RE -> Options@@ -173,8 +173,6 @@ , _re_cnames = cnms , _re_regex = rx }-- Options{..} = os re' :: Maybe SimpleRegexOptions -> QuasiQuoter re' mb = case mb of
Text/RE/TDFA/Sequence.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.TDFA as TDFA +-- | find all matches in text (*=~) :: (S.Seq Char) -> RE -> Matches (S.Seq Char) (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: (S.Seq Char) -> RE -> Match (S.Seq Char) (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex (S.Seq Char) a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex (S.Seq Char) a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String
Text/RE/TDFA/String.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.TDFA as TDFA +-- | find all matches in text (*=~) :: String -> RE -> Matches String (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: String -> RE -> Match String (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex String a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex String a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String
Text/RE/TDFA/Text.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.TDFA as TDFA +-- | find all matches in text (*=~) :: T.Text -> RE -> Matches T.Text (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: T.Text -> RE -> Match T.Text (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex T.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex T.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String
Text/RE/TDFA/Text/Lazy.hs view
@@ -20,16 +20,19 @@ import qualified Text.Regex.TDFA as TDFA +-- | find all matches in text (*=~) :: TL.Text -> RE -> Matches TL.Text (*=~) bs rex = addCaptureNamesToMatches (reCaptureNames rex) $ match (reRegex rex) bs +-- | find first matches in text (?=~) :: TL.Text -> RE -> Match TL.Text (?=~) bs rex = addCaptureNamesToMatch (reCaptureNames rex) $ match (reRegex rex) bs +-- | regex-base polymorphic match operator (=~) :: ( RegexContext TDFA.Regex TL.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String )@@ -38,6 +41,7 @@ -> a (=~) bs rex = match (reRegex rex) bs +-- | regex-base monadic, polymorphic match operator (=~~) :: ( Monad m , RegexContext TDFA.Regex TL.Text a , RegexMaker TDFA.Regex TDFA.CompOption TDFA.ExecOption String
Text/RE/TestBench.lhs view
@@ -23,7 +23,7 @@ , formatMacroSources , formatMacroSource , testMacroDescriptors- , regexSource+-- , regexSource ) where import Data.Array@@ -49,7 +49,7 @@ data RegexType = TDFA -- the TDFA back end | PCRE -- the PCRE back end- deriving (Eq,Ord,Show)+ deriving (Bounded,Enum,Eq,Ord,Show) -- | do we need the captures in the RE or whould they be stripped out -- where possible@@ -66,12 +66,12 @@ -- description data MacroDescriptor = MacroDescriptor- { _md_source :: RegexSource -- ^ the RE- , _md_samples :: [String] -- ^ some sample matches- , _md_counter_samples :: [String] -- ^ some sample non-matches- , _md_test_results :: [TestResult] -- ^ validation test results- , _md_parser :: Maybe FunctionID -- ^ WA, the parser function- , _md_description :: String -- ^ summary comment+ { _md_source :: !RegexSource -- ^ the RE+ , _md_samples :: ![String] -- ^ some sample matches+ , _md_counter_samples :: ![String] -- ^ some sample non-matches+ , _md_test_results :: ![TestResult] -- ^ validation test results+ , _md_parser :: !(Maybe FunctionID) -- ^ WA, the parser function+ , _md_description :: !String -- ^ summary comment } deriving (Show)
changelog view
@@ -1,4 +1,11 @@ -*-change-log-*- -0.0.0.1 Chris Dornan <chrisd@irisconnect.co.uk> Feb 2014+0.0.0.2 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-01-30+ * Fix for Windows+ * Remove hsyslog dependency+ * Establish Travis CI, AppVeyor and coveralls.io integrations+ * Fix time parser to use Fixed arithmetic+ * Miscelaneous minor adjustments++0.0.0.1 Chris Dornan <chris.dornan@irisconnect.co.uk> 2017-01-26 * First public release
examples/TestKit.lhs view
@@ -12,6 +12,7 @@ import Control.Exception import qualified Data.Text as T import qualified Shelly as SH+import System.Directory import System.Environment import System.Exit import System.IO@@ -68,6 +69,7 @@ -> FilePath -> IO () test_pp lab loop test_file gold_file = do+ createDirectoryIfMissing False "tmp" loop test_file tmp_pth ok <- cmp (T.pack tmp_pth) (T.pack gold_file) case ok of
examples/re-nginx-log-processor.lhs view
@@ -25,7 +25,6 @@ import qualified Shelly as SH import System.Directory import System.Environment-import System.Posix.Syslog import System.Exit import System.IO import Text.RE.Options@@ -114,9 +113,9 @@ \begin{code} script :: Ctx -> SedScript RE script ctx = Select- [ on [re_|@{access}|] Acc parse_access- , on [re_|@{access_deg}|] AcQ parse_deg_access- , on [re_|@{error}|] Err parse_error+ [ on [re_|@{access}|] ACC parse_access+ , on [re_|@{access_deg}|] AQQ parse_deg_access+ , on [re_|@{error}|] ERR parse_error , on [re_|.*|] QQQ parse_def ] where@@ -165,7 +164,7 @@ event_is_notifiable :: Event -> Bool event_is_notifiable Event{..} =- fromEnum (fromMaybe Debug _event_severity) <= fromEnum Error+ fromEnum (fromMaybe Debug _event_severity) <= fromEnum Err flag_event :: Ctx -> Event -> IO () flag_event False = const $ return ()@@ -181,13 +180,13 @@ { _event_line :: LineNo , _event_source :: Source , _event_utc :: UTCTime- , _event_severity :: Maybe Priority+ , _event_severity :: Maybe Severity , _event_address :: IPV4Address , _event_details :: LBS.ByteString } deriving (Show) -data Source = Acc | AcQ | Err | QQQ+data Source = ACC | AQQ | ERR | QQQ deriving (Show,Read) presentEvent :: Event -> LBS.ByteString@@ -202,7 +201,7 @@ where (a,b,c,d) = _event_address - svrty_kw = fst . syslogSeverityKeywords+ svrty_kw = fst . severityKeywords class IsEvent a where mkEvent :: LineNo -> Source -> a -> Event@@ -299,7 +298,7 @@ { _md_source = "(?:-|[^[:space:]]+)" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = def_test_results+ , _md_test_results = [] , _md_parser = Just "parse_user" , _md_description = "a user ident (per RFC1413)" }@@ -322,7 +321,7 @@ { _md_source = "(?:@{%natural})#(?:@{%natural}):" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = def_test_results+ , _md_test_results = [] , _md_parser = Just "parse_pid_tid" , _md_description = "<PID>#<TID>:" }@@ -347,7 +346,7 @@ { _md_source = access_re , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = def_test_results+ , _md_test_results = [] , _md_parser = Just "parse_a" , _md_description = "an Nginx access log file line" }@@ -380,7 +379,7 @@ { _md_source = " - \\[\\] \"\" \"\" \"\" \"\"" , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = def_test_results+ , _md_test_results = [] , _md_parser = Nothing , _md_description = "a degenerate Nginx access log file line" }@@ -402,7 +401,7 @@ { _md_source = error_re , _md_samples = map fst samples , _md_counter_samples = counter_samples- , _md_test_results = def_test_results+ , _md_test_results = [] , _md_parser = Just "parse_e" , _md_description = "an Nginx error log file line" }@@ -413,7 +412,7 @@ ERROR { _e_date = read "2016-12-21" , _e_time = read "11:53:35"- , _e_severity = Emergency+ , _e_severity = Emerg , _e_pid_tid = (1378,0) , _e_other = " foo" }@@ -421,7 +420,7 @@ ERROR { _e_date = read "2017-01-04" , _e_time = read "05:40:19"- , _e_severity = Error+ , _e_severity = Err , _e_pid_tid = (31623,0) , _e_other = " *1861296 no \"ssl_certificate\" is defined in server listening on SSL port while SSL handshaking, client: 192.168.31.38, server: 0.0.0.0:80" }@@ -431,9 +430,6 @@ [ "" , "foo" ]--def_test_results :: [TestResult]-def_test_results = error "def_test_results" \end{code} \begin{code}@@ -521,7 +517,7 @@ ERROR { _e_date :: Day , _e_time :: TimeOfDay- , _e_severity :: Priority+ , _e_severity :: Severity , _e_pid_tid :: (Int,Int) , _e_other :: LBS.ByteString }@@ -543,7 +539,7 @@ ERROR <$> f parseSlashesDate [cp|1|] <*> f parseTimeOfDay [cp|2|]- <*> f parseSyslogSeverity [cp|3|]+ <*> f parseSeverity [cp|3|] <*> f parse_pid_tid [cp|4|] <*> f Just [cp|5|] where
examples/re-tests.lhs view
@@ -2,30 +2,48 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-} module Main (main) where import Control.Applicative+import Control.Exception import Data.Array import qualified Data.ByteString.Char8 as B import qualified Data.ByteString.Lazy.Char8 as LBS-import Data.Foldable+import qualified Data.Foldable as F+import Data.Maybe import Data.Monoid import qualified Data.Sequence as S import Data.String import qualified Data.Text as T import qualified Data.Text.Lazy as LT+import Language.Haskell.TH.Quote import Test.Tasty import Test.Tasty.HUnit+import qualified Text.Regex.PCRE as PCRE_+import qualified Text.Regex.TDFA as TDFA_ import Text.RE import Text.RE.Internal.NamedCaptures-import qualified Text.RE.PCRE as PCRE-import Text.RE.TDFA as TDFA+import Text.RE.Internal.PreludeMacros+import Text.RE.Internal.QQ+import qualified Text.RE.PCRE as PCRE+import Text.RE.TDFA as TDFA import Text.RE.TestBench -import Text.RE.TDFA.String()+import qualified Text.RE.PCRE.String as P_ST+import qualified Text.RE.PCRE.ByteString as P_BS+import qualified Text.RE.PCRE.ByteString.Lazy as PLBS+import qualified Text.RE.PCRE.Sequence as P_SQ +import qualified Text.RE.TDFA.String as T_ST+import qualified Text.RE.TDFA.ByteString as T_BS+import qualified Text.RE.TDFA.ByteString.Lazy as TLBS+import qualified Text.RE.TDFA.Sequence as T_SQ+import qualified Text.RE.TDFA.Text as T_TX+import qualified Text.RE.TDFA.Text.Lazy as TLTX + main :: IO () main = defaultMain $ testGroup "Tests"@@ -35,6 +53,8 @@ , replace_tests , options_tests , namedCapturesTestTree+ , many_tests+ , misc_tests ] prelude_tests :: TestTree@@ -199,7 +219,7 @@ let ms = S.fromList str =~ regex_ :: Matches (S.Seq Char) f = \_ (Location i j) Capture{..} -> Just $ S.fromList $ "(" <> show i <> ":" <> show_co j <> ":" <>- toList capturedText <> ")"+ F.toList capturedText <> ")" r = replaceAllCaptures' ALL f ms assertEqual "replaceAllCaptures'" r $ S.fromList "(0:0:(0:1:a) (0:2:bbbb)) (1:0:(1:1:aa) (1:2:b))"@@ -254,4 +274,168 @@ ] where s = "0a\nbb\nFe\nA5" :: String++many_tests :: TestTree+many_tests = testGroup "Many Tests"+ [ testCase "PCRE a" $ test (PCRE.*=~) (PCRE.?=~) (PCRE.=~) (PCRE.=~~) matchOnce matchMany id re_pcre+ , testCase "PCRE ByteString" $ test (P_BS.*=~) (P_BS.?=~) (P_BS.=~) (P_BS.=~~) matchOnce matchMany B.pack re_pcre+ , testCase "PCRE ByteString.Lazy" $ test (PLBS.*=~) (PLBS.?=~) (PLBS.=~) (PLBS.=~~) matchOnce matchMany LBS.pack re_pcre+ , testCase "PCRE Sequence" $ test (P_SQ.*=~) (P_SQ.?=~) (P_SQ.=~) (P_SQ.=~~) matchOnce matchMany S.fromList re_pcre+ , testCase "PCRE String" $ test (P_ST.*=~) (P_ST.?=~) (P_ST.=~) (P_ST.=~~) matchOnce matchMany id re_pcre+ , testCase "TDFA a" $ test (TDFA.*=~) (TDFA.?=~) (TDFA.=~) (TDFA.=~~) matchOnce matchMany id re_tdfa+ , testCase "TDFA ByteString" $ test (T_BS.*=~) (T_BS.?=~) (T_BS.=~) (T_BS.=~~) matchOnce matchMany B.pack re_tdfa+ , testCase "TDFA ByteString.Lazy" $ test (TLBS.*=~) (TLBS.?=~) (TLBS.=~) (TLBS.=~~) matchOnce matchMany LBS.pack re_tdfa+ , testCase "TDFA Sequence" $ test (T_SQ.*=~) (T_SQ.?=~) (T_SQ.=~) (T_SQ.=~~) matchOnce matchMany S.fromList re_tdfa+ , testCase "TDFA String" $ test (T_ST.*=~) (T_ST.?=~) (T_ST.=~) (T_ST.=~~) matchOnce matchMany id re_tdfa+ , testCase "TDFA Text" $ test (T_TX.*=~) (T_TX.?=~) (T_TX.=~) (T_TX.=~~) matchOnce matchMany T.pack re_tdfa+ , testCase "TDFA Text.Lazy" $ test (TLTX.*=~) (TLTX.?=~) (TLTX.=~) (TLTX.=~~) matchOnce matchMany LT.pack re_tdfa+ ]+ where+ test :: (Show s,Eq s)+ => (s->r->Matches s)+ -> (s->r->Match s)+ -> (s->r->Matches s)+ -> (s->r->Maybe(Match s))+ -> (r->s->Match s)+ -> (r->s->Matches s)+ -> (String->s)+ -> r+ -> Assertion+ test (%*=~) (%?=~) (%=~) (%=~~) mo mm inj r = do+ 2 @=? countMatches mtchs+ Just txt' @=? matchedText mtch+ mtchs @=? mtchs'+ mb_mtch @=? Just mtch+ mtch @=? mtch''+ mtchs @=? mtchs''+ where+ mtchs = txt %*=~ r+ mtch = txt %?=~ r+ mtchs' = txt %=~ r+ mb_mtch = txt %=~~ r+ mtch'' = mo r txt+ mtchs'' = mm r txt++ txt = inj "2016-01-09 2015-12-5 2015-10-05"+ txt' = inj "2016-01-09"++ re_pcre = fromMaybe oops $ PCRE.compileRegex () "[0-9]{4}-[0-9]{2}-[0-9]{2}"+ re_tdfa = fromMaybe oops $ TDFA.compileRegex () "[0-9]{4}-[0-9]{2}-[0-9]{2}"++ oops = error "many_tests"++misc_tests :: TestTree+misc_tests = testGroup "Miscelaneous Tests"+ [ testGroup "QQ"+ [ qq_tc "expression" quoteExp+ , qq_tc "pattern" quotePat+ , qq_tc "type" quoteType+ , qq_tc "declaration" quoteDec+ ]+ , testGroup "PreludeMacros"+ [ valid_string "preludeMacroTable" preludeMacroTable+ , valid_macro "preludeMacroSummary" preludeMacroSummary+ , valid_string "preludeMacroSources" preludeMacroSources+ , valid_macro "preludeMacroSource" preludeMacroSource+ ]+ , testGroup "RE"+ [ valid_res TDFA+ [ TDFA.re+ , TDFA.reMS+ , TDFA.reMI+ , TDFA.reBS+ , TDFA.reBI+ , TDFA.reMultilineSensitive+ , TDFA.reMultilineInsensitive+ , TDFA.reBlockSensitive+ , TDFA.reBlockInsensitive+ , TDFA.re_+ ]+ , testCase "TDFA.regexType" $ TDFA @=? TDFA.regexType+ , testCase "TDFA.reOptions" $ Simple @=? _options_mode (TDFA.reOptions tdfa_re)+ , testCase "TDFA.makeOptions md" $ Block @=? _options_mode (makeOptions Block :: Options_ TDFA.RE TDFA_.CompOption TDFA_.ExecOption)+ , testCase "TDFA.preludeTestsFailing" $ [] @=? TDFA.preludeTestsFailing+ , ne_string "TDFA.preludeTable" TDFA.preludeTable+ , ne_string "TDFA.preludeSources" TDFA.preludeSources+ , testGroup "TDFA.preludeSummary"+ [ ne_string (presentPreludeMacro pm) $ TDFA.preludeSummary pm+ | pm <- tdfa_prelude_macros+ ]+ , testGroup "TDFA.preludeSource"+ [ ne_string (presentPreludeMacro pm) $ TDFA.preludeSource pm+ | pm <- tdfa_prelude_macros+ ]+ , valid_res PCRE+ [ PCRE.re+ , PCRE.reMS+ , PCRE.reMI+ , PCRE.reBS+ , PCRE.reBI+ , PCRE.reMultilineSensitive+ , PCRE.reMultilineInsensitive+ , PCRE.reBlockSensitive+ , PCRE.reBlockInsensitive+ , PCRE.re_+ ]+ , testCase "PCRE.regexType" $ PCRE @=? PCRE.regexType+ , testCase "PCRE.reOptions" $ Simple @=? _options_mode (PCRE.reOptions pcre_re)+ , testCase "PCRE.makeOptions md" $ Block @=? _options_mode (makeOptions Block :: Options_ PCRE.RE PCRE_.CompOption PCRE_.ExecOption)+ , testCase "PCRE.preludeTestsFailing" $ [] @=? PCRE.preludeTestsFailing+ , ne_string "PCRE.preludeTable" PCRE.preludeTable+ , ne_string "PCRE.preludeTable" PCRE.preludeSources+ , testGroup "PCRE.preludeSummary"+ [ ne_string (presentPreludeMacro pm) $ PCRE.preludeSummary pm+ | pm <- pcre_prelude_macros+ ]+ , testGroup "PCRE.preludeSource"+ [ ne_string (presentPreludeMacro pm) $ PCRE.preludeSource pm+ | pm <- pcre_prelude_macros+ ]+ ]+ ]+ where+ tdfa_re = fromMaybe oops $ TDFA.compileRegex () ".*"+ pcre_re = fromMaybe oops $ PCRE.compileRegex () ".*"++ oops = error "misc_tests"++qq_tc :: String -> (QuasiQuoter->String->a) -> TestTree+qq_tc sc prj = testCase sc $+ try tst >>= either hdl (const $ assertFailure "qq0")+ where+ tst :: IO ()+ tst = prj (qq0 "qq_tc") "" `seq` return ()++ hdl :: QQFailure -> IO ()+ hdl qqf = do+ "qq_tc" @=? _qqf_context qqf+ sc @=? _qqf_component qqf++valid_macro :: String -> (RegexType->PreludeMacro->String) -> TestTree+valid_macro label f = testGroup label+ [ valid_string (presentPreludeMacro pm) (flip f pm)+ | pm<-[minBound..maxBound]+ ]++valid_string :: String -> (RegexType->String) -> TestTree+valid_string label f = testGroup label+ [ ne_string (show rty) $ f rty+ | rty<-[TDFA] -- until PCRE has a binding for all macros+ ]++ne_string :: String -> String -> TestTree+ne_string label s =+ testCase label $ assertBool "non-empty string" $ length s > 0++-- just evaluating quasi quoters to HNF for now -- they+-- being tested everywhere [re|...|] (etc.) calculations+-- are bings used but HPC isn't measuring this+valid_res :: RegexType -> [QuasiQuoter] -> TestTree+valid_res rty = testCase (show rty) . foldr seq (return ())++pcre_prelude_macros :: [PreludeMacro]+pcre_prelude_macros = filter (/= PM_string) [minBound..maxBound]++tdfa_prelude_macros :: [PreludeMacro]+tdfa_prelude_macros = [minBound..maxBound] \end{code}
regex.cabal view
@@ -1,10 +1,10 @@ Name: regex-Version: 0.0.0.1+Version: 0.0.0.2 Synopsis: A Regular Expression Toolkit for regex-base Description: A Regular Expression Toolkit for regex-base with Compile-time checking of RE syntax, data types for matches and captures, a text replacement toolkit,- portable options, high-level Awk-like tools+ portable options, high-level AWK-like tools for building text processing apps, regular expression macros and test bench, a tutorial and copious examples. Homepage: https://iconnect.github.io/regex@@ -12,23 +12,26 @@ License: BSD3 license-file: LICENSE Maintainer: chris.dornan@irisconnect.co.uk-Copyright: Chris Dornan+Copyright: Chris Dornan 2016-2017 Category: Text Build-type: Simple Stability: rfc-Extra-source-files: changelog bug-reports: https://github.com/iconnect/regex/issues -Cabal-version: >= 1.14+extra-source-files:+ README.md+ changelog +Cabal-version: >= 1.16+ Source-repository head type: git- location: git://github.com/iconnect/regex.git+ location: https://github.com/iconnect/regex.git Source-Repository this- Type: git- Location: git://github.com/iconnect/regex.git- Tag: 0.0.0.1+ Type: git+ Location: https://github.com/iconnect/regex.git+ Tag: 0.0.0.2 Library Exposed-modules:@@ -37,6 +40,8 @@ Text.RE.CaptureID Text.RE.Edit Text.RE.Internal.NamedCaptures+ Text.RE.Internal.PreludeMacros+ Text.RE.Internal.QQ Text.RE.IsRegex Text.RE.LineNo Text.RE.Options@@ -63,8 +68,6 @@ Other-modules: Text.RE.Internal.AddCaptureNames- Text.RE.Internal.PreludeMacros- Text.RE.Internal.QQ Build-depends: array >= 0.4 ,@@ -73,7 +76,6 @@ containers >= 0.4 , hashable >= 1.2.3.3 , heredoc >= 0.2.0.0 ,- hsyslog >= 2 , regex-base >= 0.93.2 , regex-tdfa >= 1.2.1 , regex-tdfa-text >= 1.0.0.3 ,@@ -81,7 +83,7 @@ smallcheck >= 1.1.1 , tasty >= 0.10.1.2 , tasty-hunit >= 0.9.2 ,- tasty-smallcheck >= 0.8.1 ,+ tasty-smallcheck >= 0.8.0.1 , template-haskell >= 2.7 , transformers >= 0.2.2 , text >= 1.2.1.3 ,@@ -112,10 +114,33 @@ directory >= 1.2.1.0 , regex-base >= 0.93.2 , regex-tdfa >= 1.2.0 ,- shelly >= 1.6.3.4 ,+ shelly >= 1.6.1.2 , text >= 1.2.1.3 +Test-Suite re-gen-modules-test+ type: exitcode-stdio-1.0+ Hs-Source-Dirs: examples++ Main-is: re-gen-modules.lhs++ Default-Language: Haskell2010+ GHC-Options:+ -Wall+ -fwarn-tabs++ Build-depends:+ regex ,+ array >= 0.4 ,+ bytestring >= 0.10.2.0 ,+ base >= 4 && < 5 ,+ directory >= 1.2.1.0 ,+ regex-base >= 0.93.2 ,+ regex-tdfa >= 1.2.0 ,+ shelly >= 1.6.1.2 ,+ text >= 1.2.1.3++ Executable re-include Hs-Source-Dirs: examples @@ -126,11 +151,15 @@ -Wall -fwarn-tabs + Other-modules:+ TestKit+ Build-depends: regex , bytestring >= 0.10.2.0 , base >= 4 && < 5 ,- shelly >= 1.6.3.4 ,+ directory >= 1.2.1.0 ,+ shelly >= 1.6.1.2 , text >= 1.2.1.3 @@ -145,19 +174,23 @@ -Wall -fwarn-tabs + Other-modules:+ TestKit+ Build-depends: regex , bytestring >= 0.10.2.0 , base >= 4 ,- shelly >= 1.6.3.4 ,+ directory >= 1.2.1.0 ,+ shelly >= 1.6.1.2 , text >= 1.2.1.3 -Test-Suite re-gen-modules-test+Test-Suite re-nginx-log-processor-test type: exitcode-stdio-1.0 Hs-Source-Dirs: examples - Main-is: re-gen-modules.lhs+ Main-is: re-nginx-log-processor.lhs Default-Language: Haskell2010 GHC-Options:@@ -172,12 +205,14 @@ directory >= 1.2.1.0 , regex-base >= 0.93.2 , regex-tdfa >= 1.2.0 ,- shelly >= 1.6.3.4 ,- text >= 1.2.1.3+ shelly >= 1.6.1.2 ,+ text >= 1.2.1.3 ,+ time >= 1.5.0.1 ,+ transformers >= 0.3.0.0 ,+ unordered-containers >= 0.2.5.1 -Test-Suite re-nginx-log-processor- type: exitcode-stdio-1.0+Executable re-nginx-log-processor Hs-Source-Dirs: examples Main-is: re-nginx-log-processor.lhs@@ -193,10 +228,9 @@ bytestring >= 0.10.2.0 , base >= 4 && < 5 , directory >= 1.2.1.0 ,- hsyslog >= 2.0 , regex-base >= 0.93.2 , regex-tdfa >= 1.2.0 ,- shelly >= 1.6.3.4 ,+ shelly >= 1.6.1.2 , text >= 1.2.1.3 , time >= 1.5.0.1 , transformers >= 0.3.0.0 ,@@ -221,7 +255,7 @@ bytestring >= 0.10.2.0 , base >= 4 && < 5 , directory >= 1.2.1.0 ,- shelly >= 1.6.3.4 ,+ shelly >= 1.6.1.2 , text >= 1.2.1.3 @@ -244,7 +278,7 @@ bytestring >= 0.10.2.0 , base >= 4 && < 5 , directory >= 1.2.1.0 ,- shelly >= 1.6.3.4 ,+ shelly >= 1.6.1.2 , text >= 1.2.1.3 @@ -268,16 +302,56 @@ bytestring >= 0.10.2.0 , base >= 4 && < 5 , containers >= 0.4 ,+ directory >= 1.2.1.0 , regex-base >= 0.93.2 , regex-tdfa >= 1.2.0 , regex-tdfa-text >= 1.0.0.3 , regex-pcre-builtin >= 0.94.4.8.8.35 , tasty >= 0.10.1.2 , tasty-hunit >= 0.9.2 ,+ template-haskell >= 2.7 , text >= 1.2.1.3 -Test-Suite re-tutorial+Executable re-tutorial+ Hs-Source-Dirs: examples .++ Main-is: re-tutorial.lhs++ Other-modules:+ TestKit++ Default-Language: Haskell2010+ Default-Extensions: QuasiQuotes+ GHC-Options:+ -Wall+ -fwarn-tabs++ Build-depends:+ regex ,+ array >= 0.4 ,+ bytestring >= 0.10.2.0 ,+ base >= 4 && < 5 ,+ containers >= 0.4 ,+ directory >= 1.2.1.0 ,+ hashable >= 1.2.3.3 ,+ heredoc >= 0.2.0.0 ,+ regex-base >= 0.93.2 ,+ regex-tdfa >= 1.2.1 ,+ regex-tdfa-text >= 1.0.0.3 ,+ regex-pcre-builtin >= 0.94.4.8.8.35 ,+ shelly >= 1.6.1.2 ,+ smallcheck >= 1.1.1 ,+ tasty >= 0.10.1.2 ,+ tasty-hunit >= 0.9.2 ,+ tasty-smallcheck >= 0.8.0.1 ,+ template-haskell >= 2.7 ,+ transformers >= 0.2.2 ,+ text >= 1.2.1.3 ,+ time >= 1.5.0.1 ,+ unordered-containers >= 0.2.5.1++Test-Suite re-tutorial-test type: exitcode-stdio-1.0 Hs-Source-Dirs: examples . @@ -298,18 +372,18 @@ bytestring >= 0.10.2.0 , base >= 4 && < 5 , containers >= 0.4 ,+ directory >= 1.2.1.0 , hashable >= 1.2.3.3 , heredoc >= 0.2.0.0 ,- hsyslog >= 2 , regex-base >= 0.93.2 , regex-tdfa >= 1.2.1 , regex-tdfa-text >= 1.0.0.3 , regex-pcre-builtin >= 0.94.4.8.8.35 ,- shelly >= 1.6.3.4 ,+ shelly >= 1.6.1.2 , smallcheck >= 1.1.1 , tasty >= 0.10.1.2 , tasty-hunit >= 0.9.2 ,- tasty-smallcheck >= 0.8.1 ,+ tasty-smallcheck >= 0.8.0.1 , template-haskell >= 2.7 , transformers >= 0.2.2 , text >= 1.2.1.3 ,