regex-compat 0.92 → 0.95.2.2
raw patch · 5 files changed
Files
- ChangeLog.md +28/−0
- README.md +9/−0
- Setup.hs +0/−6
- Text/Regex.hs +42/−34
- regex-compat.cabal +65/−43
+ ChangeLog.md view
@@ -0,0 +1,28 @@+## 0.95.2.2++_2025-03-02 Andreas Abel_++- Drop support for GHC 7+- Make `Prelude` imports explicit, add `LANGUAGE NoImplicitPrelude`+- Make upper bounds of dependencies major-major (all are shipped with GHC)+- Tested with GHC 8.0 - 9.12.1++## 0.95.2.1 revision 2++- Allow `base >= 4.17` (GHC 9.4)++## 0.95.2.1 revision 1++- Allow `base-4.16` (GHC 9.2)++## 0.95.2.1++- Allow `base-4.15` (GHC 9.0)++- Workaround for `{-# LANGUAGE Haskell2010 #-}` parser regression introduced in GHC 9.0++- Optimization flag `-O2` has been removed++## 0.95.2.0++- Declare `Text.Regex` module `Trustworthy` under SafeHaskell
+ README.md view
@@ -0,0 +1,9 @@+[](http://hackage.haskell.org/package/regex-compat)+[](http://stackage.org/nightly/package/regex-compat)+[](http://stackage.org/lts/package/regex-compat)+[](https://github.com/haskell-hvr/regex-compat/actions/workflows/haskell-ci.yml)+[](https://opensource.org/licenses/BSD-3-Clause)+regex-compat+============++[Documentation](https://hackage.haskell.org/package/regex-compat/docs/Text-Regex.html) on hackage.
− Setup.hs
@@ -1,6 +0,0 @@-#!/usr/bin/env runhaskell---- I usually compile this with "ghc --make -o setup Setup.hs"--import Distribution.Simple(defaultMain)-main = defaultMain
Text/Regex.hs view
@@ -1,11 +1,11 @@-{-# OPTIONS_GHC -fno-warn-name-shadowing #-}+{-# OPTIONS_GHC -Wno-name-shadowing #-} ----------------------------------------------------------------------------- -- | -- Module : Text.Regex -- Copyright : (c) Chris Kuklewicz 2006, derived from (c) The University of Glasgow 2001 -- License : BSD-style (see the file LICENSE)--- --- Maintainer : libraries@haskell.org+--+-- Maintainer : hvr@gnu.org -- Stability : experimental -- Portability : non-portable (regex-base needs MPTC+FD) --@@ -29,6 +29,14 @@ splitRegex ) where +import Prelude+ ( Bool+ , Maybe+ , String+ , ($), (.), id, fst, snd, seq, read+ , (+), (-)+ , (++), drop, fmap, map, null, take+ ) import Data.Array((!)) import Data.Bits((.|.)) import Text.Regex.Base(RegexMaker(makeRegexOpts),defaultExecOpt,RegexLike(matchAll,matchAllText),RegexContext(matchM),MatchText)@@ -45,12 +53,12 @@ -- | Makes a regular expression, where the multi-line and -- case-sensitive options can be changed from the default settings. mkRegexWithOpts- :: String -- ^ The regular expression to compile- -> Bool -- ^ 'True' @\<=>@ @\'^\'@ and @\'$\'@ match the beginning and - -- end of individual lines respectively, and @\'.\'@ does /not/- -- match the newline character.- -> Bool -- ^ 'True' @\<=>@ matching is case-sensitive- -> Regex -- ^ Returns: the compiled regular expression+ :: String -- ^ The regular expression to compile.+ -> Bool -- ^ 'True' iff @\'^\'@ and @\'$\'@ match the beginning and+ -- end of individual lines respectively, and @\'.\'@ does /not/+ -- match the newline character.+ -> Bool -- ^ 'True' iff matching is case-sensitive.+ -> Regex -- ^ Returns: the compiled regular expression. mkRegexWithOpts s single_line case_sensitive = let opt = (if single_line then (compNewline .|.) else id) .@@ -58,39 +66,39 @@ compExtended in makeRegexOpts opt defaultExecOpt s --- | Match a regular expression against a string+-- | Match a regular expression against a string. matchRegex- :: Regex -- ^ The regular expression- -> String -- ^ The string to match against- -> Maybe [String] -- ^ Returns: @'Just' strs@ if the match succeeded- -- (and @strs@ is the list of subexpression matches),- -- or 'Nothing' otherwise.+ :: Regex -- ^ The regular expression.+ -> String -- ^ The string to match against.+ -> Maybe [String] -- ^ Returns: @'Just' strs@ if the match succeeded+ -- (and @strs@ is the list of subexpression matches),+ -- or 'Nothing' otherwise. matchRegex p str = fmap (\(_,_,_,str) -> str) (matchRegexAll p str) -- | Match a regular expression against a string, returning more information -- about the match. matchRegexAll- :: Regex -- ^ The regular expression- -> String -- ^ The string to match against+ :: Regex -- ^ The regular expression.+ -> String -- ^ The string to match against. -> Maybe ( String, String, String, [String] )- -- ^ Returns: 'Nothing' if the match failed, or:- -- - -- > Just ( everything before match,- -- > portion matched,- -- > everything after the match,- -- > subexpression matches )+ -- ^ Returns: 'Nothing' if the match failed, or:+ --+ -- > Just ( everything before match,+ -- > portion matched,+ -- > everything after the match,+ -- > subexpression matches ) matchRegexAll p str = matchM p str -{- | Replaces every occurance of the given regexp with the replacement string.+{- | Replaces every occurrence of the given regexp with the replacement string. In the replacement string, @\"\\1\"@ refers to the first substring; @\"\\2\"@ to the second, etc; and @\"\\0\"@ to the entire match. @\"\\\\\\\\\"@ will insert a literal backslash. This does not advance if the regex matches an empty string. This-misfeature is here to match the behavior of the the original-Text.Regex API.+misfeature is here to match the behavior of the original+@Text.Regex@ API. -} subRegex :: Regex -- ^ Search pattern@@ -111,16 +119,16 @@ pre = take (off-i) str str' = drop (i'-i) str x = read xstr- in if null str' then \ m -> (pre++) . ((fst (m!x))++)- else \ m -> (pre++) . ((fst (m!x))++) . compile i' str' rest m+ in if null str' then \ m -> (pre ++) . (fst (m ! x) ++)+ else \ m -> (pre ++) . (fst (m ! x) ++) . compile i' str' rest m compiled :: MatchText String -> String -> String compiled = compile 0 repl findrefs where -- bre matches a backslash then capture either a backslash or some digits bre = mkRegex "\\\\(\\\\|[0-9]+)"- findrefs = map (\m -> (fst (m!1),snd (m!0))) (matchAllText bre repl)+ findrefs = map (\m -> (fst (m ! 1), snd (m ! 0))) (matchAllText bre repl) go _i str [] = str go i str (m:ms) =- let (_,(off,len)) = m!0+ let (_, (off, len)) = m ! 0 i' = off+len pre = take (off-i) str str' = drop (i'-i) str@@ -131,15 +139,15 @@ {- | Splits a string based on a regular expression. The regular expression should identify one delimiter. -This does not advance and produces an infinite list of [] if the regex+This does not advance and produces an infinite list of @[]@ if the regex matches an empty string. This misfeature is here to match the-behavior of the the original Text.Regex API.+behavior of the original @Text.Regex@ API. -} splitRegex :: Regex -> String -> [String] splitRegex _ [] = []-splitRegex delim strIn = - let matches = map (!0) (matchAll delim strIn)+splitRegex delim strIn =+ let matches = map (! 0) (matchAll delim strIn) go _i str [] = str : [] go i str ((off,len):rest) = let i' = off+len
regex-compat.cabal view
@@ -1,45 +1,67 @@-Name: regex-compat-Version: 0.92-Cabal-Version: >=1.2+cabal-version: 1.24+name: regex-compat+version: 0.95.2.2+ build-type: Simple-License: BSD3-License-File: LICENSE-Copyright: Copyright (c) 2006, Christopher Kuklewicz-Author: Christopher Kuklewicz-Maintainer: TextRegexLazy@personal.mightyreason.com-Stability: Seems to work, passes a few tests-Homepage: http://sourceforge.net/projects/lazy-regex-Package-URL: http://darcs.haskell.org/packages/regex-unstable/regex-compat/-Synopsis: Replaces/Enhances Text.Regex-Description: One module layer over regex-posix to replace Text.Regex-Category: Text-Tested-With: GHC-flag splitBase- description: Choose the new smaller, split-up base package.+license: BSD3+license-file: LICENSE+copyright: Copyright (c) 2006, Christopher Kuklewicz+author: Christopher Kuklewicz+maintainer: Andreas Abel+homepage: https://wiki.haskell.org/Regular_expressions+bug-reports: https://github.com/haskell-hvr/regex-compat/issues+synopsis: Replaces/enhances "Text.Regex"+category: Text+description:+ One module compat layer over <//hackage.haskell.org/package/regex-posix regex-posix> to replace "Text.Regex".+ .+ See also <https://wiki.haskell.org/Regular_expressions> for more information.++extra-doc-files:+ ChangeLog.md+ README.md++tested-with:+ GHC == 9.12.1+ GHC == 9.10.1+ GHC == 9.8.4+ GHC == 9.6.6+ GHC == 9.4.8+ GHC == 9.2.8+ GHC == 9.0.2+ GHC == 8.10.7+ GHC == 8.8.4+ GHC == 8.6.5+ GHC == 8.4.4+ GHC == 8.2.2+ GHC == 8.0.2++source-repository head+ type: git+ location: https://github.com/haskell-hvr/regex-compat.git++source-repository this+ type: git+ location: https://github.com/haskell-hvr/regex-compat.git+ tag: v0.95.2.2+ library- if flag(splitBase)- Build-Depends: base >= 3.0, regex-base >= 0.93, regex-posix >= 0.93, array- else- Build-Depends: base < 3.0, regex-base >= 0.93, regex-posix >= 0.93- -- Data-Files:- -- Extra-Source-Files:- -- Extra-Tmp-Files:- Exposed-Modules: Text.Regex- Buildable: True- -- Other-Modules:- -- HS-Source-Dirs: "."- Extensions: MultiParamTypeClasses, FunctionalDependencies- GHC-Options: -Wall -O2- -- GHC-Options: -Wall -Werror -O2- -- GHC-Options: -Wall -ddump-minimal-imports- -- GHC-Prog-Options: - -- Hugs-Options:- -- NHC-Options:- -- Includes:- -- Include-Dirs:- -- C-Sources:- -- Extra-Libraries:- -- Extra-Lib-Dirs:- -- CC-Options:- -- LD-Options:- -- Frameworks:+ exposed-modules: Text.Regex++ build-depends:+ base >= 4.9 && < 5+ , regex-base == 0.94.*+ , regex-posix == 0.96.*+ , array >= 0.5 && < 1++ default-language:+ Haskell2010+ default-extensions:+ NoImplicitPrelude+ Trustworthy+ MultiParamTypeClasses+ FunctionalDependencies++ ghc-options:+ -Wall+ -Wcompat