Skip to content

Commit

Permalink
Merge pull request #114 from iconnect/prepare-0.13.0.0
Browse files Browse the repository at this point in the history
0.13.0.0: Protect findCaptureID and add Find, re-sort-imports
  • Loading branch information
cdornan committed Apr 3, 2017
2 parents 7f9482c + 6c33a20 commit 135c24b
Show file tree
Hide file tree
Showing 77 changed files with 2,344 additions and 446 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -54,6 +54,7 @@ two packages:
- [X] 2017-03-29 v0.11.0.0 [Simplify the API](https://github.com/iconnect/regex/milestone/14)
- [X] 2017-03-30 v0.11.1.0 [Fix the Haddocks](https://github.com/iconnect/regex/milestone/15)
- [X] 2017-03-31 v0.12.0.0 [Move IsRegex into Text.RE](https://github.com/iconnect/regex/milestone/16)
- [X] 2017-04-02 v0.13.0.0 [Protect findCaptureID and add Find, re-sort-imports, tutorials](https://github.com/iconnect/regex/milestone/17)
- [ ] 2017-04-03 v1.0.0.0 [First stable release](https://github.com/iconnect/regex/milestone/3)
- [ ] 2017-08-31 v2.0.0.0 [Fast text replacement with benchmarks](https://github.com/iconnect/regex/milestone/4)

Expand Down
6 changes: 3 additions & 3 deletions Text/RE/PCRE.hs
Expand Up @@ -67,19 +67,19 @@ module Text.RE.PCRE
) where


import qualified Text.Regex.Base as B
import qualified Text.Regex.PCRE as PCRE
import Text.RE.PCRE.ByteString()
import Text.RE.PCRE.ByteString.Lazy()
import Text.RE.PCRE.Sequence()
import Text.RE.PCRE.String()
import Text.RE.REOptions
import Text.RE.ZeInternals.AddCaptureNames
import Text.RE.ZeInternals.SearchReplace.PCRE
import Text.RE.ZeInternals.PCRE
import Text.RE.ZeInternals.SearchReplace.PCRE
import Text.RE.ZeInternals.Types.IsRegex
import Text.RE.ZeInternals.Types.Match
import Text.RE.ZeInternals.Types.Matches
import qualified Text.Regex.Base as B
import qualified Text.Regex.PCRE as PCRE


-- | find all the matches in the argument text; e.g., to count the number
Expand Down
4 changes: 2 additions & 2 deletions Text/RE/PCRE/ByteString.hs
Expand Up @@ -59,14 +59,14 @@ module Text.RE.PCRE.ByteString
, module Text.RE.ZeInternals.SearchReplace.PCRE.ByteString
) where

import Prelude.Compat
import qualified Data.ByteString as B
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
import Text.RE.ZeInternals.SearchReplace.PCRE.ByteString
import Text.RE.ZeInternals.PCRE
import Text.RE.ZeInternals.SearchReplace.PCRE.ByteString
import Text.RE.ZeInternals.Types.IsRegex
import Text.Regex.Base
import qualified Text.Regex.PCRE as PCRE
Expand Down
4 changes: 2 additions & 2 deletions Text/RE/PCRE/ByteString/Lazy.hs
Expand Up @@ -59,14 +59,14 @@ module Text.RE.PCRE.ByteString.Lazy
, module Text.RE.ZeInternals.SearchReplace.PCRE.ByteString.Lazy
) where

import Prelude.Compat
import qualified Data.ByteString.Lazy as LBS
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
import Text.RE.ZeInternals.SearchReplace.PCRE.ByteString.Lazy
import Text.RE.ZeInternals.PCRE
import Text.RE.ZeInternals.SearchReplace.PCRE.ByteString.Lazy
import Text.RE.ZeInternals.Types.IsRegex
import Text.Regex.Base
import qualified Text.Regex.PCRE as PCRE
Expand Down
4 changes: 2 additions & 2 deletions Text/RE/PCRE/Sequence.hs
Expand Up @@ -59,14 +59,14 @@ module Text.RE.PCRE.Sequence
, module Text.RE.ZeInternals.SearchReplace.PCRE.Sequence
) where

import Prelude.Compat
import qualified Data.Sequence as S
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
import Text.RE.ZeInternals.SearchReplace.PCRE.Sequence
import Text.RE.ZeInternals.PCRE
import Text.RE.ZeInternals.SearchReplace.PCRE.Sequence
import Text.RE.ZeInternals.Types.IsRegex
import Text.Regex.Base
import qualified Text.Regex.PCRE as PCRE
Expand Down
4 changes: 2 additions & 2 deletions Text/RE/PCRE/String.hs
Expand Up @@ -59,14 +59,14 @@ module Text.RE.PCRE.String
, module Text.RE.ZeInternals.SearchReplace.PCRE.String
) where

import Prelude.Compat

import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
import Text.RE.ZeInternals.SearchReplace.PCRE.String
import Text.RE.ZeInternals.PCRE
import Text.RE.ZeInternals.SearchReplace.PCRE.String
import Text.RE.ZeInternals.Types.IsRegex
import Text.Regex.Base
import qualified Text.Regex.PCRE as PCRE
Expand Down
2 changes: 1 addition & 1 deletion Text/RE/REOptions.lhs
Expand Up @@ -23,8 +23,8 @@ module Text.RE.REOptions
, emptyMacros
) where
import Data.Hashable
import qualified Data.HashMap.Strict as HM
import Data.Hashable
import Data.String
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
Expand Down
2 changes: 1 addition & 1 deletion Text/RE/TDFA/ByteString.hs
Expand Up @@ -59,9 +59,9 @@ module Text.RE.TDFA.ByteString
, module Text.RE.ZeInternals.SearchReplace.TDFA.ByteString
) where

import Prelude.Compat
import qualified Data.ByteString as B
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
Expand Down
2 changes: 1 addition & 1 deletion Text/RE/TDFA/ByteString/Lazy.hs
Expand Up @@ -59,9 +59,9 @@ module Text.RE.TDFA.ByteString.Lazy
, module Text.RE.ZeInternals.SearchReplace.TDFA.ByteString.Lazy
) where

import Prelude.Compat
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
Expand Down
2 changes: 1 addition & 1 deletion Text/RE/TDFA/Sequence.hs
Expand Up @@ -59,9 +59,9 @@ module Text.RE.TDFA.Sequence
, module Text.RE.ZeInternals.SearchReplace.TDFA.Sequence
) where

import Prelude.Compat
import qualified Data.Sequence as S
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
Expand Down
2 changes: 1 addition & 1 deletion Text/RE/TDFA/String.hs
Expand Up @@ -59,9 +59,9 @@ module Text.RE.TDFA.String
, module Text.RE.ZeInternals.SearchReplace.TDFA.String
) where

import Prelude.Compat

import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
Expand Down
2 changes: 1 addition & 1 deletion Text/RE/TDFA/Text.hs
Expand Up @@ -59,9 +59,9 @@ module Text.RE.TDFA.Text
, module Text.RE.ZeInternals.SearchReplace.TDFA.Text
) where

import Prelude.Compat
import qualified Data.Text as T
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
Expand Down
2 changes: 1 addition & 1 deletion Text/RE/TDFA/Text/Lazy.hs
Expand Up @@ -59,9 +59,9 @@ module Text.RE.TDFA.Text.Lazy
, module Text.RE.ZeInternals.SearchReplace.TDFA.Text.Lazy
) where

import Prelude.Compat
import qualified Data.Text.Lazy as TL
import Data.Typeable
import Prelude.Compat
import Text.RE.REOptions
import Text.RE.Replace
import Text.RE.ZeInternals.AddCaptureNames
Expand Down
145 changes: 4 additions & 141 deletions Text/RE/TestBench.hs
Expand Up @@ -43,147 +43,10 @@ module Text.RE.TestBench
, Severity(..)
, parseSeverity
, severityKeywords
-- * Text.RE
, module Text.RE
) where

import Data.Array
import qualified Data.HashMap.Strict as HM
import Data.Maybe
import qualified Data.Text as T
import Data.Time
import qualified Data.Time.Locale.Compat as LC
import Data.Word
import Text.Printf
import Text.Read
import Text.RE.Replace
import Text.RE
import Text.RE.ZeInternals.TestBench


parseInteger :: Replace a => a -> Maybe Int
parseInteger = readMaybe . unpackR

parseHex :: Replace a => a -> Maybe Int
parseHex = readMaybe . ("0x"++) . unpackR

parseDouble :: Replace a => a -> Maybe Double
parseDouble = readMaybe . unpackR

parseString :: Replace a => a -> Maybe T.Text
parseString = readMaybe . unpackR

parseSimpleString :: Replace a => a -> Maybe T.Text
parseSimpleString = Just . T.dropEnd 1 . T.drop 1 . textifyR

date_templates, time_templates, timezone_templates,
date_time_8601_templates, date_time_templates :: [String]
date_templates = ["%F"]
time_templates = ["%H:%M:%S","%H:%M:%S%Q","%H:%M"]
timezone_templates = ["Z","%z"]
date_time_8601_templates =
[ printf "%sT%s%s" dt tm tz
| dt <- date_templates
, tm <- time_templates
, tz <- timezone_templates
]
date_time_templates =
[ printf "%s%c%s%s" dt sc tm tz
| dt <- date_templates
, sc <- ['T',' ']
, tm <- time_templates
, tz <- timezone_templates ++ [" UTC",""]
]

parseDate :: Replace a => a -> Maybe Day
parseDate = parse_time date_templates

parseSlashesDate :: Replace a => a -> Maybe Day
parseSlashesDate = parse_time ["%Y/%m/%d"]

parseTimeOfDay :: Replace a => a -> Maybe TimeOfDay
parseTimeOfDay = parse_time time_templates

parseTimeZone :: Replace a => a -> Maybe TimeZone
parseTimeZone = parse_time timezone_templates

parseDateTime :: Replace a => a -> Maybe UTCTime
parseDateTime = parse_time date_time_templates

parseDateTime8601 :: Replace a => a -> Maybe UTCTime
parseDateTime8601 = parse_time date_time_8601_templates

parseDateTimeCLF :: Replace a => a -> Maybe UTCTime
parseDateTimeCLF = parse_time ["%d/%b/%Y:%H:%M:%S %z"]

parseShortMonth :: Replace a => a -> Maybe Int
parseShortMonth = flip HM.lookup short_month_hm . unpackR

parse_time :: (ParseTime t,Replace s) => [String] -> s -> Maybe t
parse_time tpls = prs . unpackR
where
prs s = listToMaybe $ catMaybes
[ parseTime LC.defaultTimeLocale fmt s
| fmt<-tpls
]

short_month_hm :: HM.HashMap String Int
short_month_hm = HM.fromList [ (T.unpack $ shortMonthArray!i,i) | i<-[1..12] ]

shortMonthArray :: Array Int T.Text
shortMonthArray = listArray (1,12) $
T.words "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"

type IPV4Address = (Word8,Word8,Word8,Word8)

parseIPv4Address :: Replace a => a -> Maybe IPV4Address
parseIPv4Address = prs . words_by (=='.') . unpackR
where
prs [a_s,b_s,c_s,d_s] = do
a <- readMaybe a_s
b <- readMaybe b_s
c <- readMaybe c_s
d <- readMaybe d_s
case all is_o [a,b,c,d] of
True -> Just (toEnum a,toEnum b,toEnum c,toEnum d)
False -> Nothing
prs _ = Nothing

is_o x = 0 <= x && x <= 255

data Severity
= Emerg
| Alert
| Crit
| Err
| Warning
| Notice
| Info
| Debug
deriving (Bounded,Enum,Ord,Eq,Show)

parseSeverity :: Replace a => a -> Maybe Severity
parseSeverity = flip HM.lookup severity_hm . textifyR

severity_hm :: HM.HashMap T.Text Severity
severity_hm = HM.fromList
[ (kw,pri)
| pri<-[minBound..maxBound]
, let (kw0,kws) = severityKeywords pri
, kw <- kw0:kws
]

severityKeywords :: Severity -> (T.Text,[T.Text])
severityKeywords pri = case pri of
Emerg -> (,) "emerg" ["panic"]
Alert -> (,) "alert" []
Crit -> (,) "crit" []
Err -> (,) "err" ["error"]
Warning -> (,) "warning" ["warn"]
Notice -> (,) "notice" []
Info -> (,) "info" []
Debug -> (,) "debug" []

words_by :: (Char->Bool) -> String -> [String]
words_by f s = case dropWhile f s of
"" -> []
s' -> w : words_by f s''
where
(w, s'') = break f s'
import Text.RE.ZeInternals.TestBench.Parsers
11 changes: 10 additions & 1 deletion Text/RE/Tools.hs
Expand Up @@ -8,13 +8,21 @@ module Text.RE.Tools
, sed'
-- * Grep
, grep
, Verbosity(..)
, Line(..)
, grepLines
, grepFilter
, GrepScript
, grepScript
, grepWithScript
, report
, linesMatched
-- * Lex
, alex
, alex'
-- * Find
, FindMethods(..)
, findMatches
, findMatches'
-- * IsRegex
, IsRegex(..)
-- * Edit
Expand All @@ -35,6 +43,7 @@ module Text.RE.Tools

import Text.RE
import Text.RE.Tools.Edit
import Text.RE.Tools.Find
import Text.RE.Tools.Grep
import Text.RE.Tools.Lex
import Text.RE.Tools.Sed

0 comments on commit 135c24b

Please sign in to comment.