{-# LANGUAGE BangPatterns #-}
module Text.Regex.XMLSchema.Generic.Matching
( grep
, grepExt
, grepRE
, grepREwithLineNum
, match
, matchExt
, matchSubex
, sed
, sedExt
, split
, splitExt
, splitSubex
, tokenize
, tokenizeExt
, tokenize'
, tokenizeExt'
, tokenizeSubex
, matchRE
, matchSubexRE
, sedRE
, splitRE
, splitSubexRE
, tokenizeRE
, tokenizeRE'
, tokenizeSubexRE
)
where
import Control.Arrow
import Data.Maybe
import Text.Regex.XMLSchema.Generic.Regex
import Text.Regex.XMLSchema.Generic.RegexParser
import Text.Regex.XMLSchema.Generic.StringLike
splitRE :: StringLike s => GenRegex s -> s -> Maybe (s, s)
splitRE :: GenRegex s -> s -> Maybe (s, s)
splitRE GenRegex s
re s
input
= do
(SubexResults s
sms, s
rest) <- GenRegex s -> s -> Maybe (SubexResults s, s)
forall s.
StringLike s =>
GenRegex s -> s -> Maybe (SubexResults s, s)
splitWithRegex GenRegex s
re s
input
(s, s) -> Maybe (s, s)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Label s, s) -> s
forall a b. (a, b) -> b
snd ((Label s, s) -> s)
-> (SubexResults s -> (Label s, s)) -> SubexResults s -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SubexResults s -> (Label s, s)
forall a. [a] -> a
head (SubexResults s -> s) -> SubexResults s -> s
forall a b. (a -> b) -> a -> b
$ SubexResults s
sms, s
rest)
split :: StringLike s => s -> s -> (s, s)
split :: s -> s -> (s, s)
split = (s -> GenRegex s) -> s -> s -> (s, s)
forall s. StringLike s => (s -> GenRegex s) -> s -> s -> (s, s)
split' s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegex
splitExt :: StringLike s => s -> s -> (s, s)
splitExt :: s -> s -> (s, s)
splitExt = (s -> GenRegex s) -> s -> s -> (s, s)
forall s. StringLike s => (s -> GenRegex s) -> s -> s -> (s, s)
split' s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt
split' :: StringLike s => (s -> GenRegex s) -> s -> s -> (s, s)
split' :: (s -> GenRegex s) -> s -> s -> (s, s)
split' s -> GenRegex s
parseRe s
re s
input
= (s, s) -> Maybe (s, s) -> (s, s)
forall a. a -> Maybe a -> a
fromMaybe (s
forall a. StringLike a => a
emptyS, s
input)
(Maybe (s, s) -> (s, s)) -> (s -> Maybe (s, s)) -> s -> (s, s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenRegex s -> s -> Maybe (s, s)
forall s. StringLike s => GenRegex s -> s -> Maybe (s, s)
splitRE (GenRegex s -> s -> Maybe (s, s))
-> (s -> GenRegex s) -> s -> s -> Maybe (s, s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
parseRe (s -> s -> Maybe (s, s)) -> s -> s -> Maybe (s, s)
forall a b. (a -> b) -> a -> b
$ s
re) (s -> (s, s)) -> s -> (s, s)
forall a b. (a -> b) -> a -> b
$ s
input
splitSubexRE :: StringLike s => GenRegex s -> s -> Maybe ([(s, s)], s)
splitSubexRE :: GenRegex s -> s -> Maybe ([(s, s)], s)
splitSubexRE GenRegex s
re s
input
= do
(SubexResults s
sms, s
rest) <- GenRegex s -> s -> Maybe (SubexResults s, s)
forall s.
StringLike s =>
GenRegex s -> s -> Maybe (SubexResults s, s)
splitWithRegex GenRegex s
re s
input
([(s, s)], s) -> Maybe ([(s, s)], s)
forall (m :: * -> *) a. Monad m => a -> m a
return (((Label s, s) -> (s, s)) -> SubexResults s -> [(s, s)]
forall a b. (a -> b) -> [a] -> [b]
map ((Label s -> s) -> (Label s, s) -> (s, s)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Label s -> s
forall a. HasCallStack => Maybe a -> a
fromJust) (SubexResults s -> [(s, s)])
-> (SubexResults s -> SubexResults s) -> SubexResults s -> [(s, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> SubexResults s -> SubexResults s
forall a. Int -> [a] -> [a]
drop Int
1 (SubexResults s -> [(s, s)]) -> SubexResults s -> [(s, s)]
forall a b. (a -> b) -> a -> b
$ SubexResults s
sms, s
rest)
splitSubex :: StringLike s => s -> s -> ([(s, s)], s)
splitSubex :: s -> s -> ([(s, s)], s)
splitSubex s
re s
inp
= ([(s, s)], s) -> Maybe ([(s, s)], s) -> ([(s, s)], s)
forall a. a -> Maybe a -> a
fromMaybe ([], s
inp) (Maybe ([(s, s)], s) -> ([(s, s)], s))
-> (s -> Maybe ([(s, s)], s)) -> s -> ([(s, s)], s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenRegex s -> s -> Maybe ([(s, s)], s)
forall s. StringLike s => GenRegex s -> s -> Maybe ([(s, s)], s)
splitSubexRE (GenRegex s -> s -> Maybe ([(s, s)], s))
-> (s -> GenRegex s) -> s -> s -> Maybe ([(s, s)], s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt (s -> s -> Maybe ([(s, s)], s)) -> s -> s -> Maybe ([(s, s)], s)
forall a b. (a -> b) -> a -> b
$ s
re) (s -> ([(s, s)], s)) -> s -> ([(s, s)], s)
forall a b. (a -> b) -> a -> b
$ s
inp
tokenizeRE :: StringLike s => GenRegex s -> s -> [s]
tokenizeRE :: GenRegex s -> s -> [s]
tokenizeRE GenRegex s
re
= s -> [s]
token''
where
fcs :: CharSet
fcs = GenRegex s -> CharSet
forall s. StringLike s => GenRegex s -> CharSet
firstChars GenRegex s
re
re1 :: GenRegex s
re1 = GenRegex s -> GenRegex s -> GenRegex s
forall s. StringLike s => GenRegex s -> GenRegex s -> GenRegex s
mkDiff GenRegex s
re GenRegex s
forall s. GenRegex s
mkUnit
token'' :: s -> [s]
token'' = GenRegex s -> CharSet -> s -> [s]
token' GenRegex s
re CharSet
fcs
token1'' :: s -> [s]
token1'' = GenRegex s -> CharSet -> s -> [s]
token' GenRegex s
re1 CharSet
fcs
token' :: GenRegex s -> CharSet -> s -> [s]
token' GenRegex s
re' CharSet
fcs' s
inp
| s -> Bool
forall a. StringLike a => a -> Bool
nullS s
inp = []
| Bool
otherwise = Maybe ([(Label s, s)], s) -> [s]
forall a. Maybe ([(a, s)], s) -> [s]
evalRes (Maybe ([(Label s, s)], s) -> [s])
-> (s -> Maybe ([(Label s, s)], s)) -> s -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenRegex s -> CharSet -> s -> Maybe ([(Label s, s)], s)
forall s.
StringLike s =>
GenRegex s -> CharSet -> s -> Maybe (SubexResults s, s)
splitWithRegexCS GenRegex s
re' CharSet
fcs' (s -> [s]) -> s -> [s]
forall a b. (a -> b) -> a -> b
$ s
inp
where
evalRes :: Maybe ([(a, s)], s) -> [s]
evalRes Maybe ([(a, s)], s)
Nothing
= s -> [s]
token'' (Int -> s -> s
forall a. StringLike a => Int -> a -> a
dropS Int
1 s
inp)
evalRes (Just ([(a, s)]
toks, s
rest))
| s -> Bool
forall a. StringLike a => a -> Bool
nullS s
tok = s
tok s -> [s] -> [s]
forall a. a -> [a] -> [a]
: s -> [s]
token'' (Int -> s -> s
forall a. StringLike a => Int -> a -> a
dropS Int
1 s
rest)
| Bool
otherwise = s
tok s -> [s] -> [s]
forall a. a -> [a] -> [a]
: s -> [s]
token1'' s
rest
where
tok :: s
tok = (a, s) -> s
forall a b. (a, b) -> b
snd ((a, s) -> s) -> ([(a, s)] -> (a, s)) -> [(a, s)] -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(a, s)] -> (a, s)
forall a. [a] -> a
head ([(a, s)] -> s) -> [(a, s)] -> s
forall a b. (a -> b) -> a -> b
$ [(a, s)]
toks
tokenize :: StringLike s => s -> s -> [s]
tokenize :: s -> s -> [s]
tokenize = GenRegex s -> s -> [s]
forall s. StringLike s => GenRegex s -> s -> [s]
tokenizeRE (GenRegex s -> s -> [s]) -> (s -> GenRegex s) -> s -> s -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegex
tokenizeExt :: StringLike s => s -> s -> [s]
tokenizeExt :: s -> s -> [s]
tokenizeExt = GenRegex s -> s -> [s]
forall s. StringLike s => GenRegex s -> s -> [s]
tokenizeRE (GenRegex s -> s -> [s]) -> (s -> GenRegex s) -> s -> s -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt
tokenizeRE' :: StringLike s => GenRegex s -> s -> [Either s s]
tokenizeRE' :: GenRegex s -> s -> [Either s s]
tokenizeRE' GenRegex s
re s
inp0
= (s, Int) -> s -> [Either s s]
token'' (s
inp0, Int
0) s
inp0
where
fcs :: CharSet
fcs = GenRegex s -> CharSet
forall s. StringLike s => GenRegex s -> CharSet
firstChars GenRegex s
re
re1 :: GenRegex s
re1 = GenRegex s -> GenRegex s -> GenRegex s
forall s. StringLike s => GenRegex s -> GenRegex s -> GenRegex s
mkDiff GenRegex s
re GenRegex s
forall s. GenRegex s
mkUnit
token'' :: (s, Int) -> s -> [Either s s]
token'' = GenRegex s -> CharSet -> (s, Int) -> s -> [Either s s]
token' GenRegex s
re CharSet
fcs
token1'' :: (s, Int) -> s -> [Either s s]
token1'' = GenRegex s -> CharSet -> (s, Int) -> s -> [Either s s]
token' GenRegex s
re1 CharSet
fcs
token' :: GenRegex s -> CharSet -> (s, Int) -> s -> [Either s s]
token' GenRegex s
re' CharSet
fcs' (s
uns, !Int
n) s
inp
| s -> Bool
forall a. StringLike a => a -> Bool
nullS s
inp = [Either s s] -> [Either s s]
forall b. [Either s b] -> [Either s b]
addUnmatched []
| Bool
otherwise = Maybe ([(Label s, s)], s) -> [Either s s]
forall a. Maybe ([(a, s)], s) -> [Either s s]
evalRes (Maybe ([(Label s, s)], s) -> [Either s s])
-> (s -> Maybe ([(Label s, s)], s)) -> s -> [Either s s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenRegex s -> CharSet -> s -> Maybe ([(Label s, s)], s)
forall s.
StringLike s =>
GenRegex s -> CharSet -> s -> Maybe (SubexResults s, s)
splitWithRegexCS GenRegex s
re' CharSet
fcs' (s -> [Either s s]) -> s -> [Either s s]
forall a b. (a -> b) -> a -> b
$ s
inp
where
addUnmatched :: [Either s b] -> [Either s b]
addUnmatched
| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = [Either s b] -> [Either s b]
forall a. a -> a
id
| Bool
otherwise = ((s -> Either s b
forall a b. a -> Either a b
Left (s -> Either s b) -> s -> Either s b
forall a b. (a -> b) -> a -> b
$ Int -> s -> s
forall a. StringLike a => Int -> a -> a
takeS Int
n s
uns) Either s b -> [Either s b] -> [Either s b]
forall a. a -> [a] -> [a]
:)
addMatched :: b -> [Either s b] -> [Either s b]
addMatched b
t
= [Either s b] -> [Either s b]
forall b. [Either s b] -> [Either s b]
addUnmatched ([Either s b] -> [Either s b])
-> ([Either s b] -> [Either s b]) -> [Either s b] -> [Either s b]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((b -> Either s b
forall a b. b -> Either a b
Right b
t) Either s b -> [Either s b] -> [Either s b]
forall a. a -> [a] -> [a]
:)
evalRes :: Maybe ([(a, s)], s) -> [Either s s]
evalRes Maybe ([(a, s)], s)
Nothing
= (s, Int) -> s -> [Either s s]
token'' (s
uns, Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int -> s -> s
forall a. StringLike a => Int -> a -> a
dropS Int
1 s
inp)
evalRes (Just ([(a, s)]
toks, s
rest))
| s -> Bool
forall a. StringLike a => a -> Bool
nullS s
tok = s -> [Either s s] -> [Either s s]
forall b. b -> [Either s b] -> [Either s b]
addMatched s
tok
([Either s s] -> [Either s s]) -> [Either s s] -> [Either s s]
forall a b. (a -> b) -> a -> b
$ (s, Int) -> s -> [Either s s]
token'' (s
rest, Int
1)
(Int -> s -> s
forall a. StringLike a => Int -> a -> a
dropS Int
1 s
rest)
| Bool
otherwise = s -> [Either s s] -> [Either s s]
forall b. b -> [Either s b] -> [Either s b]
addMatched s
tok
([Either s s] -> [Either s s]) -> [Either s s] -> [Either s s]
forall a b. (a -> b) -> a -> b
$ (s, Int) -> s -> [Either s s]
token1'' (s
rest, Int
0) s
rest
where
tok :: s
tok = (a, s) -> s
forall a b. (a, b) -> b
snd ((a, s) -> s) -> ([(a, s)] -> (a, s)) -> [(a, s)] -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(a, s)] -> (a, s)
forall a. [a] -> a
head ([(a, s)] -> s) -> [(a, s)] -> s
forall a b. (a -> b) -> a -> b
$ [(a, s)]
toks
tokenize' :: StringLike s => s -> s -> [Either s s]
tokenize' :: s -> s -> [Either s s]
tokenize' = GenRegex s -> s -> [Either s s]
forall s. StringLike s => GenRegex s -> s -> [Either s s]
tokenizeRE' (GenRegex s -> s -> [Either s s])
-> (s -> GenRegex s) -> s -> s -> [Either s s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegex
tokenizeExt' :: StringLike s => s -> s -> [Either s s]
tokenizeExt' :: s -> s -> [Either s s]
tokenizeExt' = GenRegex s -> s -> [Either s s]
forall s. StringLike s => GenRegex s -> s -> [Either s s]
tokenizeRE' (GenRegex s -> s -> [Either s s])
-> (s -> GenRegex s) -> s -> s -> [Either s s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt
tokenizeSubexRE :: StringLike s => GenRegex s -> s -> [(s, s)]
tokenizeSubexRE :: GenRegex s -> s -> [(s, s)]
tokenizeSubexRE GenRegex s
re
= s -> [(s, s)]
token''
where
fcs :: CharSet
fcs = GenRegex s -> CharSet
forall s. StringLike s => GenRegex s -> CharSet
firstChars GenRegex s
re
re1 :: GenRegex s
re1 = GenRegex s -> GenRegex s -> GenRegex s
forall s. StringLike s => GenRegex s -> GenRegex s -> GenRegex s
mkDiff GenRegex s
re GenRegex s
forall s. GenRegex s
mkUnit
token'' :: s -> [(s, s)]
token'' = GenRegex s -> CharSet -> s -> [(s, s)]
token' GenRegex s
re CharSet
fcs
token1'' :: s -> [(s, s)]
token1'' = GenRegex s -> CharSet -> s -> [(s, s)]
token' GenRegex s
re1 CharSet
fcs
token' :: GenRegex s -> CharSet -> s -> [(s, s)]
token' GenRegex s
re' CharSet
fcs' s
inp
| s -> Bool
forall a. StringLike a => a -> Bool
nullS s
inp = []
| Bool
otherwise = Maybe ([(Maybe s, s)], s) -> [(s, s)]
evalRes (Maybe ([(Maybe s, s)], s) -> [(s, s)])
-> (s -> Maybe ([(Maybe s, s)], s)) -> s -> [(s, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenRegex s -> CharSet -> s -> Maybe ([(Maybe s, s)], s)
forall s.
StringLike s =>
GenRegex s -> CharSet -> s -> Maybe (SubexResults s, s)
splitWithRegexCS GenRegex s
re' CharSet
fcs' (s -> [(s, s)]) -> s -> [(s, s)]
forall a b. (a -> b) -> a -> b
$ s
inp
where
evalRes :: Maybe ([(Maybe s, s)], s) -> [(s, s)]
evalRes Maybe ([(Maybe s, s)], s)
Nothing
= s -> [(s, s)]
token'' (Int -> s -> s
forall a. StringLike a => Int -> a -> a
dropS Int
1 s
inp)
evalRes (Just ([(Maybe s, s)]
toks, s
rest))
| s -> Bool
forall a. StringLike a => a -> Bool
nullS s
tok = [(s, s)]
res [(s, s)] -> [(s, s)] -> [(s, s)]
forall a. [a] -> [a] -> [a]
++ s -> [(s, s)]
token'' (Int -> s -> s
forall a. StringLike a => Int -> a -> a
dropS Int
1 s
rest)
| Bool
otherwise = [(s, s)]
res [(s, s)] -> [(s, s)] -> [(s, s)]
forall a. [a] -> [a] -> [a]
++ s -> [(s, s)]
token1'' s
rest
where
res :: [(s, s)]
res = ((Maybe s, s) -> (s, s)) -> [(Maybe s, s)] -> [(s, s)]
forall a b. (a -> b) -> [a] -> [b]
map ((Maybe s -> s) -> (Maybe s, s) -> (s, s)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Maybe s -> s
forall a. HasCallStack => Maybe a -> a
fromJust) ([(Maybe s, s)] -> [(s, s)])
-> ([(Maybe s, s)] -> [(Maybe s, s)]) -> [(Maybe s, s)] -> [(s, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Maybe s, s)] -> [(Maybe s, s)]
forall a. [a] -> [a]
tail ([(Maybe s, s)] -> [(s, s)]) -> [(Maybe s, s)] -> [(s, s)]
forall a b. (a -> b) -> a -> b
$ [(Maybe s, s)]
toks
tok :: s
tok = (Maybe s, s) -> s
forall a b. (a, b) -> b
snd ((Maybe s, s) -> s)
-> ([(Maybe s, s)] -> (Maybe s, s)) -> [(Maybe s, s)] -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Maybe s, s)] -> (Maybe s, s)
forall a. [a] -> a
head ([(Maybe s, s)] -> s) -> [(Maybe s, s)] -> s
forall a b. (a -> b) -> a -> b
$ [(Maybe s, s)]
toks
tokenizeSubex :: StringLike s => s -> s -> [(s, s)]
tokenizeSubex :: s -> s -> [(s, s)]
tokenizeSubex = GenRegex s -> s -> [(s, s)]
forall s. StringLike s => GenRegex s -> s -> [(s, s)]
tokenizeSubexRE (GenRegex s -> s -> [(s, s)])
-> (s -> GenRegex s) -> s -> s -> [(s, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt
sedRE :: StringLike s => (s -> s) -> GenRegex s -> s -> s
sedRE :: (s -> s) -> GenRegex s -> s -> s
sedRE s -> s
edit GenRegex s
re = [s] -> s
forall a. StringLike a => [a] -> a
concatS ([s] -> s) -> (s -> [s]) -> s -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either s s -> s) -> [Either s s] -> [s]
forall a b. (a -> b) -> [a] -> [b]
map ((s -> s) -> (s -> s) -> Either s s -> s
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either s -> s
forall a. a -> a
id s -> s
edit) ([Either s s] -> [s]) -> (s -> [Either s s]) -> s -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenRegex s -> s -> [Either s s]
forall s. StringLike s => GenRegex s -> s -> [Either s s]
tokenizeRE' GenRegex s
re
sed :: StringLike s => (s -> s) -> s -> s -> s
sed :: (s -> s) -> s -> s -> s
sed s -> s
edit = (s -> s) -> GenRegex s -> s -> s
forall s. StringLike s => (s -> s) -> GenRegex s -> s -> s
sedRE s -> s
edit (GenRegex s -> s -> s) -> (s -> GenRegex s) -> s -> s -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegex
sedExt :: StringLike s => (s -> s) -> s -> s -> s
sedExt :: (s -> s) -> s -> s -> s
sedExt s -> s
edit = (s -> s) -> GenRegex s -> s -> s
forall s. StringLike s => (s -> s) -> GenRegex s -> s -> s
sedRE s -> s
edit (GenRegex s -> s -> s) -> (s -> GenRegex s) -> s -> s -> s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt
matchRE :: StringLike s => GenRegex s -> s -> Bool
matchRE :: GenRegex s -> s -> Bool
matchRE = GenRegex s -> s -> Bool
forall s. StringLike s => GenRegex s -> s -> Bool
matchWithRegex
match :: StringLike s => s -> s -> Bool
match :: s -> s -> Bool
match = GenRegex s -> s -> Bool
forall s. StringLike s => GenRegex s -> s -> Bool
matchWithRegex (GenRegex s -> s -> Bool) -> (s -> GenRegex s) -> s -> s -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegex
matchExt :: StringLike s => s -> s -> Bool
matchExt :: s -> s -> Bool
matchExt = GenRegex s -> s -> Bool
forall s. StringLike s => GenRegex s -> s -> Bool
matchWithRegex (GenRegex s -> s -> Bool) -> (s -> GenRegex s) -> s -> s -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt
matchSubexRE :: StringLike s => GenRegex s -> s -> [(s, s)]
matchSubexRE :: GenRegex s -> s -> [(s, s)]
matchSubexRE GenRegex s
re = ((Label s, s) -> (s, s)) -> [(Label s, s)] -> [(s, s)]
forall a b. (a -> b) -> [a] -> [b]
map ((Label s -> s) -> (Label s, s) -> (s, s)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Label s -> s
forall a. HasCallStack => Maybe a -> a
fromJust) ([(Label s, s)] -> [(s, s)])
-> (s -> [(Label s, s)]) -> s -> [(s, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Label s, s)] -> Maybe [(Label s, s)] -> [(Label s, s)]
forall a. a -> Maybe a -> a
fromMaybe [] (Maybe [(Label s, s)] -> [(Label s, s)])
-> (s -> Maybe [(Label s, s)]) -> s -> [(Label s, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenRegex s -> s -> Maybe [(Label s, s)]
forall s. StringLike s => GenRegex s -> s -> Maybe (SubexResults s)
matchWithRegex' GenRegex s
re
matchSubex :: StringLike s => s -> s -> [(s, s)]
matchSubex :: s -> s -> [(s, s)]
matchSubex = GenRegex s -> s -> [(s, s)]
forall s. StringLike s => GenRegex s -> s -> [(s, s)]
matchSubexRE (GenRegex s -> s -> [(s, s)])
-> (s -> GenRegex s) -> s -> s -> [(s, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> GenRegex s
forall s. StringLike s => s -> GenRegex s
parseRegexExt
grep :: StringLike s => s -> [s] -> [s]
grep :: s -> [s] -> [s]
grep = (String -> GenRegex s) -> s -> [s] -> [s]
forall s. StringLike s => (String -> GenRegex s) -> s -> [s] -> [s]
grep' String -> GenRegex s
forall s. StringLike s => String -> GenRegex s
parseRegex'
grepExt :: StringLike s => s -> [s] -> [s]
grepExt :: s -> [s] -> [s]
grepExt = (String -> GenRegex s) -> s -> [s] -> [s]
forall s. StringLike s => (String -> GenRegex s) -> s -> [s] -> [s]
grep' String -> GenRegex s
forall s. StringLike s => String -> GenRegex s
parseRegexExt'
grep' :: StringLike s => (String -> GenRegex s) -> s -> [s] -> [s]
grep' :: (String -> GenRegex s) -> s -> [s] -> [s]
grep' String -> GenRegex s
parseRe = GenRegex s -> [s] -> [s]
forall s. StringLike s => GenRegex s -> [s] -> [s]
grepRE (GenRegex s -> [s] -> [s]) -> (s -> GenRegex s) -> s -> [s] -> [s]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> GenRegex s) -> s -> GenRegex s
forall s. StringLike s => (String -> GenRegex s) -> s -> GenRegex s
parseContextRegex String -> GenRegex s
parseRe
grepRE :: StringLike s => GenRegex s-> [s] -> [s]
grepRE :: GenRegex s -> [s] -> [s]
grepRE GenRegex s
re = (s -> Bool) -> [s] -> [s]
forall a. (a -> Bool) -> [a] -> [a]
filter (GenRegex s -> s -> Bool
forall s. StringLike s => GenRegex s -> s -> Bool
matchRE GenRegex s
re)
grepREwithLineNum :: StringLike s => GenRegex s -> [s] -> [(Int, s)]
grepREwithLineNum :: GenRegex s -> [s] -> [(Int, s)]
grepREwithLineNum GenRegex s
re = ((Int, s) -> Bool) -> [(Int, s)] -> [(Int, s)]
forall a. (a -> Bool) -> [a] -> [a]
filter (GenRegex s -> s -> Bool
forall s. StringLike s => GenRegex s -> s -> Bool
matchRE GenRegex s
re (s -> Bool) -> ((Int, s) -> s) -> (Int, s) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, s) -> s
forall a b. (a, b) -> b
snd) ([(Int, s)] -> [(Int, s)])
-> ([s] -> [(Int, s)]) -> [s] -> [(Int, s)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [s] -> [(Int, s)]
forall a b. [a] -> [b] -> [(a, b)]
zip [(Int
1::Int)..]