pcre-less 0.0.0 → 0.2.0
raw patch · 5 files changed
+84/−139 lines, 5 filesdep +arraydep +regex-pcredep −bytestringdep −pcre-lightPVP ok
version bump matches the API change (PVP)
Dependencies added: array, regex-pcre
Dependencies removed: bytestring, pcre-light
API changes (from Hackage documentation)
- Text.Regex.Less: backref :: Result -> Int -> String
- Text.Regex.Less: base :: Result -> String
- Text.Regex.Less: subst :: Result -> String -> String
- Text.Regex.Less: unjust :: Maybe a -> a
- Text.Regex.Less: yank :: Result -> [String]
- Text.Regex.Less.REOpts: CtDupNames :: RECtOpt
- Text.Regex.Less.REOpts: CtNlAnyCrLf :: RECtOpt
- Text.Regex.Less.REOpts: CtNlAnyUnicode :: RECtOpt
- Text.Regex.Less.REOpts: CtNlCr :: RECtOpt
- Text.Regex.Less.REOpts: CtNlCrLf :: RECtOpt
- Text.Regex.Less.REOpts: CtNlLf :: RECtOpt
- Text.Regex.Less.REOpts: CtRAnyCrLf :: RECtOpt
- Text.Regex.Less.REOpts: CtRAnyUnicode :: RECtOpt
- Text.Regex.Less.REOpts: CtReverseGreedy :: RECtOpt
- Text.Regex.Less.REOpts: RtNlAny :: RERtOpt
- Text.Regex.Less.REOpts: RtNlAnyCrLf :: RERtOpt
- Text.Regex.Less.REOpts: RtNlCr :: RERtOpt
- Text.Regex.Less.REOpts: RtNlCrLf :: RERtOpt
- Text.Regex.Less.REOpts: RtNlLf :: RERtOpt
- Text.Regex.Less.REOpts: RtNotRtOl :: RERtOpt
- Text.Regex.Less.REOpts: data RECtOpt
- Text.Regex.Less.REOpts: data RERtOpt
+ Text.Regex.Less: (<<) :: a -> b -> (a, b)
+ Text.Regex.Less: bref :: Result -> Int -> String
+ Text.Regex.Less: derefs :: Result -> String -> String
+ Text.Regex.Less: subs :: Result -> String -> String
+ Text.Regex.Less.REOpts: CtBlank :: RECtOpts
+ Text.Regex.Less.REOpts: CtUngreedy :: RECtOpts
+ Text.Regex.Less.REOpts: RtBlank :: RERtOpts
+ Text.Regex.Less.REOpts: RtNotEol :: RERtOpts
+ Text.Regex.Less.REOpts: data RECtOpts
+ Text.Regex.Less.REOpts: data RERtOpts
- Text.Regex.Less.REOpts: CtAnchored :: RECtOpt
+ Text.Regex.Less.REOpts: CtAnchored :: RECtOpts
- Text.Regex.Less.REOpts: CtAutoCallout :: RECtOpt
+ Text.Regex.Less.REOpts: CtAutoCallout :: RECtOpts
- Text.Regex.Less.REOpts: CtCaseless :: RECtOpt
+ Text.Regex.Less.REOpts: CtCaseless :: RECtOpts
- Text.Regex.Less.REOpts: CtDollarEndOnly :: RECtOpt
+ Text.Regex.Less.REOpts: CtDollarEndOnly :: RECtOpts
- Text.Regex.Less.REOpts: CtDotAll :: RECtOpt
+ Text.Regex.Less.REOpts: CtDotAll :: RECtOpts
- Text.Regex.Less.REOpts: CtExtended :: RECtOpt
+ Text.Regex.Less.REOpts: CtExtended :: RECtOpts
- Text.Regex.Less.REOpts: CtExtra :: RECtOpt
+ Text.Regex.Less.REOpts: CtExtra :: RECtOpts
- Text.Regex.Less.REOpts: CtFirstLine :: RECtOpt
+ Text.Regex.Less.REOpts: CtFirstLine :: RECtOpts
- Text.Regex.Less.REOpts: CtMultiLine :: RECtOpt
+ Text.Regex.Less.REOpts: CtMultiLine :: RECtOpts
- Text.Regex.Less.REOpts: CtNoAutoCapture :: RECtOpt
+ Text.Regex.Less.REOpts: CtNoAutoCapture :: RECtOpts
- Text.Regex.Less.REOpts: CtNoUtf8Check :: RECtOpt
+ Text.Regex.Less.REOpts: CtNoUtf8Check :: RECtOpts
- Text.Regex.Less.REOpts: CtUtf8 :: RECtOpt
+ Text.Regex.Less.REOpts: CtUtf8 :: RECtOpts
- Text.Regex.Less.REOpts: RtAnchored :: RERtOpt
+ Text.Regex.Less.REOpts: RtAnchored :: RERtOpts
- Text.Regex.Less.REOpts: RtNoUtf8Check :: RERtOpt
+ Text.Regex.Less.REOpts: RtNoUtf8Check :: RERtOpts
- Text.Regex.Less.REOpts: RtNotBol :: RERtOpt
+ Text.Regex.Less.REOpts: RtNotBol :: RERtOpts
- Text.Regex.Less.REOpts: RtNotEmpty :: RERtOpt
+ Text.Regex.Less.REOpts: RtNotEmpty :: RERtOpts
- Text.Regex.Less.REOpts: RtPartial :: RERtOpt
+ Text.Regex.Less.REOpts: RtPartial :: RERtOpts
- Text.Regex.Less.REOpts: reCtOpts :: [RECtOpt] -> [PCREOption]
+ Text.Regex.Less.REOpts: reCtOpts :: [RECtOpts] -> CompOption
- Text.Regex.Less.REOpts: reRtOpts :: [RERtOpt] -> [PCREExecOption]
+ Text.Regex.Less.REOpts: reRtOpts :: [RERtOpts] -> ExecOption
Files
- Text/Regex/Less.hs +28/−52
- Text/Regex/Less/Quackers.hs +14/−31
- Text/Regex/Less/RECtOpts.hs +23/−31
- Text/Regex/Less/RERtOpts.hs +14/−20
- pcre-less.cabal +5/−5
Text/Regex/Less.hs view
@@ -1,70 +1,46 @@ {- copyright (c) sreservoir. license bsd three-clause. -} -module Text.Regex.Less ((=~),truth,yank,base,subst,backref,unjust) where+module Text.Regex.Less ((=~),(<<),truth,subs,derefs,bref) where -import qualified Data.ByteString.Char8 as B-import qualified Text.Regex.PCRE.Light as R-import Data.List+import qualified Text.Regex.PCRE as R+import qualified Data.Array as A import Text.Regex.Less.Quackers -type Result = (String,Maybe [String])+type Result = (String,[R.MatchArray]) -- standard usage: -- "" =~ ""- -- "" =~ "" << RECOpts- -- "" =~ "" << REEOpts- -- "" =~ "" << RECOpts << REEOpts+ -- "" =~ "" << RECtOpts+ -- "" =~ "" << RERtOpts+ -- "" =~ "" << RECtOpts << RERtOpts -- value suitable for use below.-infixl 6 =~+infixl 4 =~ (=~) :: QLR a => String -> a -> Result-a =~ b =- case R.match (compile b) (B.pack a) (runopts b) of- Just c -> (a,Just (map B.unpack c))- Nothing -> (a,Nothing)---- success/failure of a regex.-truth :: Result -> Bool-truth (_,a) =- case a of- Just _ -> True- Nothing -> False+a =~ b = a << R.matchAll (compile b) a --- yanks out the matches.-yank :: Result -> [String]-yank (_,a) = unjust a+infixl 5 <<+(<<) :: a -> b -> (a,b)+a << b = (a,b) --- returns the original string.-base :: Result -> String-base (a,_) = a+truth :: Result -> Bool+truth (_,a) = not (null a) --- substitutes the matched part.--- does backrefs with derefs.-subst :: Result -> String -> String-subst a b = subst' (base a) b (yank a)- where subst' [] _ _ = []- subst' _ _ [] = []- subst' ca@(c:cs) d es@(e:_)- | e `isPrefixOf` ca = derefs es d ++ unjust (stripPrefix e ca)- | otherwise = c : subst' cs d es+subs :: Result -> String -> String+subs a b = s ++ derefs a b ++ f+ where o = fst a+ (i,c) = head (snd a) A.! 0+ (s,r) = splitAt i o+ f = drop c r --- dereferences backrefs with ^ .-derefs :: [String] -> String -> String+derefs :: Result -> String -> String derefs a ('^':'^':bs) = '^' : derefs a bs-derefs a ('^':bs) =+derefs a ('^':bs) = case reads bs of- [(c,d)] -> a !! c ++ derefs a d- _ -> error "there's nothing here."-derefs a (b:bs) = b : derefs a bs-derefs _ [] = []---- takes the backrefs of a match.- -- backref 0 is the whole match.-backref :: Result -> Int -> String-backref a b = yank a !! b+ [(c,d)] -> bref a c ++ derefs a d+ _ -> undefined+derefs a (b:bs) = b : derefs a bs+derefs _ [] = [] --- takes a Maybe(Just)'s value.--- fails with [] on Nothing.-unjust :: Maybe a -> a-unjust (Just a) = a-unjust Nothing = error "not unjustifiable."+bref :: Result -> Int -> String+bref a i = R.extract (head (snd a) A.! i) (fst a)
Text/Regex/Less/Quackers.hs view
@@ -5,13 +5,11 @@ module Text.Regex.Less.Quackers (QLR(..)) where -import qualified Text.Regex.PCRE.Light as R-import qualified Data.ByteString.Char8 as B+import qualified Text.Regex.PCRE as R import Text.Regex.Less.REOpts -- the QLR (QuacksLikeRegex) class: -- compile- -- runopts -- instances of QLR: -- String -- (String,[RECtOpts])@@ -24,39 +22,24 @@ -- QuacksLikeRegex: can =~ . class QLR a where compile :: a -> R.Regex- runopts :: a -> [R.PCREExecOption] --- standard string. instance QLR String where- compile a = R.compile (B.pack a) []- runopts _ = []+ compile a = R.makeRegexOpts (reCtOpts []) (reRtOpts []) a --- re << compile-instance QLR (String,[RECtOpt]) where- compile (a,b) = R.compile (B.pack a) (reCtOpts b)- runopts (_,_) = []+instance QLR (String,[RECtOpts]) where+ compile (a,b) = R.makeRegexOpts (reCtOpts b) (reRtOpts []) a --- re << runtime-instance QLR (String,[RERtOpt]) where- compile (a,_) = R.compile (B.pack a) []- runopts (_,b) = reRtOpts b+instance QLR (String,[RERtOpts]) where+ compile (a,b) = R.makeRegexOpts (reCtOpts []) (reRtOpts b) a --- re << compile << runtime-instance QLR (String,([RECtOpt],[RERtOpt])) where- compile (a,(b,_)) = R.compile (B.pack a) (reCtOpts b)- runopts (_,(_,c)) = reRtOpts c+instance QLR ((String,[RECtOpts]),[RERtOpts]) where+ compile ((a,b),c) = R.makeRegexOpts (reCtOpts b) (reRtOpts c) a --- re << runtime << compile-instance QLR (String,([RERtOpt],[RECtOpt])) where- compile (a,(_,b)) = R.compile (B.pack a) (reCtOpts b)- runopts (_,(c,_)) = reRtOpts c+instance QLR ((String,[RERtOpts]),[RECtOpts]) where+ compile ((a,b),c) = R.makeRegexOpts (reCtOpts c) (reRtOpts b) a --- (re << compile) << runtime-instance QLR ((String,[RECtOpt]),[RERtOpt]) where- compile ((a,b),_) = R.compile (B.pack a) (reCtOpts b)- runopts ((_,_),c) = reRtOpts c+instance QLR (String,([RECtOpts],[RERtOpts])) where+ compile (a,(b,c)) = R.makeRegexOpts (reCtOpts b) (reRtOpts c) a --- (re << runtime) << compile-instance QLR ((String,[RERtOpt]),[RECtOpt]) where- compile ((a,_),b) = R.compile (B.pack a) (reCtOpts b)- runopts ((_,c),_) = reRtOpts c+instance QLR (String,([RERtOpts],[RECtOpts])) where+ compile (a,(b,c)) = R.makeRegexOpts (reCtOpts c) (reRtOpts b) a
Text/Regex/Less/RECtOpts.hs view
@@ -1,42 +1,34 @@ {- copyright (c) sreservoir. license bsd three-clause. -} -module Text.Regex.Less.RECtOpts (reCtOpts,RECtOpt(..)) where+module Text.Regex.Less.RECtOpts (reCtOpts,RECtOpts(..)) where -import qualified Text.Regex.PCRE.Light as R+import qualified Text.Regex.PCRE as R -- compile options.-data RECtOpt = CtAnchored | CtAutoCallout | CtCaseless | CtDollarEndOnly- | CtDotAll | CtDupNames | CtExtended | CtFirstLine | CtMultiLine- | CtNoAutoCapture | CtReverseGreedy | CtUtf8 | CtNoUtf8Check- | CtNlAnyCrLf | CtNlAnyUnicode | CtNlCr | CtNlLf | CtNlCrLf- | CtRAnyCrLf | CtRAnyUnicode | CtExtra+data RECtOpts = CtAnchored | CtAutoCallout | CtBlank | CtCaseless+ | CtDollarEndOnly | CtDotAll | CtExtended | CtExtra+ | CtFirstLine | CtMultiLine | CtNoAutoCapture | CtNoUtf8Check+ | CtUtf8 | CtUngreedy deriving (Eq,Show) -- translates lists of compile option constructors.-reCtOpts :: [RECtOpt] -> [R.PCREOption]-reCtOpts = map reCtOpt1+reCtOpts :: [RECtOpts] -> R.CompOption+reCtOpts = sum . map reCtOpt1 -- translates a compile option constructor.-reCtOpt1 :: RECtOpt -> R.PCREOption-reCtOpt1 CtAnchored = R.anchored-reCtOpt1 CtAutoCallout = R.auto_callout-reCtOpt1 CtCaseless = R.caseless-reCtOpt1 CtDollarEndOnly = R.dollar_endonly-reCtOpt1 CtDotAll = R.dotall-reCtOpt1 CtDupNames = R.dupnames-reCtOpt1 CtExtended = R.extended-reCtOpt1 CtFirstLine = R.firstline-reCtOpt1 CtMultiLine = R.multiline-reCtOpt1 CtNoAutoCapture = R.no_auto_capture-reCtOpt1 CtReverseGreedy = R.ungreedy-reCtOpt1 CtUtf8 = R.utf8-reCtOpt1 CtNoUtf8Check = R.no_utf8_check-reCtOpt1 CtNlCr = R.newline_cr-reCtOpt1 CtNlLf = R.newline_lf-reCtOpt1 CtNlCrLf = R.newline_crlf---reCtOpt1 CtNAnyCrLf = R.newline_anycrlf---reCtOpt1 CtNAnyUnicode = R.newline_any---reCtOpt1 CtNAnyCrLf = R.bsr_anycrlf---reCtOpt1 CtNAnyUnicode = R.bsr_unicode-reCtOpt1 _ = undefined+reCtOpt1 :: RECtOpts -> R.CompOption+reCtOpt1 CtAnchored = R.compAnchored+reCtOpt1 CtAutoCallout = R.compAutoCallout+reCtOpt1 CtBlank = R.compBlank+reCtOpt1 CtCaseless = R.compCaseless+reCtOpt1 CtDollarEndOnly = R.compDollarEndOnly+reCtOpt1 CtDotAll = R.compDotAll+reCtOpt1 CtExtended = R.compExtended+reCtOpt1 CtExtra = R.compExtra+reCtOpt1 CtFirstLine = R.compFirstLine+reCtOpt1 CtMultiLine = R.compMultiline+reCtOpt1 CtNoAutoCapture = R.compNoAutoCapture+reCtOpt1 CtNoUtf8Check = R.compNoUTF8Check+reCtOpt1 CtUtf8 = R.compUTF8+reCtOpt1 CtUngreedy = R.compUngreedy
Text/Regex/Less/RERtOpts.hs view
@@ -1,31 +1,25 @@ {- copyright (c) sreservoir. license bsd three-clause. -} -module Text.Regex.Less.RERtOpts (reRtOpts,RERtOpt(..)) where+module Text.Regex.Less.RERtOpts (reRtOpts,RERtOpts(..)) where -import qualified Text.Regex.PCRE.Light as R+import qualified Text.Regex.PCRE as R -- runtime options.-data RERtOpt = RtAnchored | RtNlAny | RtNlAnyCrLf | RtNlCr | RtNlLf- | RtNlCrLf | RtNotBol | RtNotRtOl | RtNotEmpty | RtNoUtf8Check- | RtPartial+data RERtOpts = RtAnchored | RtBlank | RtNoUtf8Check | RtNotBol | RtNotEol+ | RtNotEmpty | RtPartial deriving (Eq,Show) -- translates lists of runtime option constructors.-reRtOpts :: [RERtOpt] -> [R.PCREExecOption]-reRtOpts = map reRtOpt1+reRtOpts :: [RERtOpts] -> R.ExecOption+reRtOpts = sum . map reRtOpt1 -- translates a runtime option constructor.-reRtOpt1 :: RERtOpt -> R.PCREExecOption-reRtOpt1 RtAnchored = R.exec_anchored-reRtOpt1 RtNlCr = R.exec_newline_cr-reRtOpt1 RtNlLf = R.exec_newline_lf-reRtOpt1 RtNlCrLf = R.exec_newline_crlf-reRtOpt1 RtNotBol = R.exec_notbol-reRtOpt1 RtNotRtOl = R.exec_noteol-reRtOpt1 RtNotEmpty = R.exec_notempty-reRtOpt1 RtNoUtf8Check = R.exec_no_utf8_check-reRtOpt1 RtPartial = R.exec_partial ;---reRtOpt1 RtNlAny = R.exec_newline_any---reRtOpt1 RtNlAnyCrLf = R.exec_newline_anycrlf-reRtOpt1 _ = undefined+reRtOpt1 :: RERtOpts -> R.ExecOption+reRtOpt1 RtAnchored = R.execAnchored+reRtOpt1 RtBlank = R.execBlank+reRtOpt1 RtNoUtf8Check = R.execNoUTF8Check+reRtOpt1 RtNotBol = R.execNotBOL+reRtOpt1 RtNotEol = R.execNotEOL+reRtOpt1 RtNotEmpty = R.execNotEmpty+reRtOpt1 RtPartial = R.execPartial
pcre-less.cabal view
@@ -1,8 +1,8 @@ name: pcre-less-version: 0.0.0-synopsis: Nicer interface to pcre-light.+version: 0.2.0+synopsis: Nicer interface to regex-pcre description:- You'll have to read the comments until I get around to writing docs.+ Unfortunately, docs don't exist yet. homepage: ~ license: BSD3 -- The file containing the license text.@@ -21,7 +21,7 @@ Text.Regex.Less.RECtOpts Text.Regex.Less.RERtOpts Text.Regex.Less.Quackers- build-depends: base >= 4 && < 5,pcre-light >= 0.4,bytestring >= 0.9+ build-depends: base >= 4 && < 5,regex-pcre >= 0.94,array >= 0.3 extensions: FlexibleInstances,TypeSynonymInstances- ghc-options: -O2+ ghc-options: -Wall ghc-prof-options: -auto-all