module Hidden.SrcRegActList (
selfTest
, plusesList
, oneCharList
, backSlashesList
, parensesList
, charClassList
) where
import Hidden.RegexPRTypes ( RegexAction(..), reverseRegexAction )
import Data.Char ( isAlphaNum, isAlpha, isUpper, isLower,
isDigit, isHexDigit, isSpace, isPrint, isControl )
import Hidden.Tools ( (&&&), (|||), isSymbol, isBit7On )
selfTest :: Char -> Bool
selfTest :: Char -> Bool
selfTest
= (Char -> [Char] -> Bool) -> [Char] -> Char -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem "\b\n\f\r\t !\"#%&',-/:;<=>@]_'~}" (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| Char -> Bool
isAlphaNum (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| Char -> Bool
isBit7On
plusesList :: [ (String, RegexAction -> RegexAction) ]
plusesList :: [([Char], RegexAction -> RegexAction)]
plusesList = [
( "" , RegexAction -> RegexAction
forall a. a -> a
id )
, ( "*" , Int -> Maybe Int -> RegexAction -> RegexAction
Repeat 0 Maybe Int
forall a. Maybe a
Nothing )
, ( "*?", Int -> Maybe Int -> RegexAction -> RegexAction
RepeatNotGreedy 0 Maybe Int
forall a. Maybe a
Nothing )
, ( "+" , Int -> Maybe Int -> RegexAction -> RegexAction
Repeat 1 Maybe Int
forall a. Maybe a
Nothing )
, ( "+?", Int -> Maybe Int -> RegexAction -> RegexAction
RepeatNotGreedy 1 Maybe Int
forall a. Maybe a
Nothing )
, ( "?" , Int -> Maybe Int -> RegexAction -> RegexAction
Repeat 0 (Maybe Int -> RegexAction -> RegexAction)
-> Maybe Int -> RegexAction -> RegexAction
forall a b. (a -> b) -> a -> b
$ Int -> Maybe Int
forall a. a -> Maybe a
Just 1 )
, ( "??", Int -> Maybe Int -> RegexAction -> RegexAction
RepeatNotGreedy 0 (Maybe Int -> RegexAction -> RegexAction)
-> Maybe Int -> RegexAction -> RegexAction
forall a b. (a -> b) -> a -> b
$ Int -> Maybe Int
forall a. a -> Maybe a
Just 1 )
]
oneCharList :: [ (Char, RegexAction) ]
oneCharList :: [(Char, RegexAction)]
oneCharList = [
('.', (Char -> Bool) -> RegexAction
Select (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/='\n'))
, ('$', [RegexAction] -> [RegexAction] -> RegexAction
RegexOr [RegexAction
EndOfInput] [[RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
Select (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='\n')]])
, ('^', [RegexAction] -> [RegexAction] -> RegexAction
RegexOr [RegexAction
BeginningOfInput] [[RegexAction] -> RegexAction
Still [[RegexAction] -> RegexAction
Backword [(Char -> Bool) -> RegexAction
Select (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='\n')]]])
]
backSlashesList :: [ (Char, RegexAction) ]
backSlashesList :: [(Char, RegexAction)]
backSlashesList = [
( 'w', (Char -> Bool) -> RegexAction
Select Char -> Bool
isWord )
, ( 'W', (Char -> Bool) -> RegexAction
Select ((Char -> Bool) -> RegexAction) -> (Char -> Bool) -> RegexAction
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isWord )
, ( 's', (Char -> Bool) -> RegexAction
Select (Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` " \t\n\r\f") )
, ( 'S', (Char -> Bool) -> RegexAction
Select (Char -> [Char] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` " \t\n\r\f") )
, ( 'd', (Char -> Bool) -> RegexAction
Select Char -> Bool
isDigit )
, ( 'D', (Char -> Bool) -> RegexAction
Select (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isDigit) )
, ( 'A', RegexAction
BeginningOfInput )
, ( 'Z', [RegexAction] -> [RegexAction] -> RegexAction
RegexOr [RegexAction
EndOfInput] [[RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
Select (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='\n'), RegexAction
EndOfInput]] )
, ( 'z', RegexAction
EndOfInput )
, ( 'b', [[RegexAction]] -> RegexAction
regexOr [
[ [RegexAction] -> RegexAction
lookBehind [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord], [RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
selectNot Char -> Bool
isWord] ]
, [ [RegexAction] -> RegexAction
lookBehind [(Char -> Bool) -> RegexAction
selectNot Char -> Bool
isWord], [RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord] ]
, [ RegexAction
BeginningOfInput, [RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord] ]
, [ [RegexAction] -> RegexAction
lookBehind [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord], RegexAction
EndOfInput ]
] )
, ( 'B', [RegexAction] -> RegexAction
RegActNot [ [[RegexAction]] -> RegexAction
regexOr [
[ [RegexAction] -> RegexAction
lookBehind [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord], [RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
selectNot Char -> Bool
isWord] ]
, [ [RegexAction] -> RegexAction
lookBehind [(Char -> Bool) -> RegexAction
selectNot Char -> Bool
isWord], [RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord] ]
, [ RegexAction
BeginningOfInput, [RegexAction] -> RegexAction
Still [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord] ]
, [ [RegexAction] -> RegexAction
lookBehind [(Char -> Bool) -> RegexAction
Select Char -> Bool
isWord], RegexAction
EndOfInput ]
] ] )
, ( 'G', RegexAction
PreMatchPoint )
]
parensesList :: [ (String, [RegexAction] -> RegexAction) ]
parensesList :: [([Char], [RegexAction] -> RegexAction)]
parensesList = [
( "?<=", [RegexAction] -> RegexAction
Still ([RegexAction] -> RegexAction)
-> ([RegexAction] -> [RegexAction]) -> [RegexAction] -> RegexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RegexAction -> [RegexAction] -> [RegexAction]
forall a. a -> [a] -> [a]
:[]) (RegexAction -> [RegexAction])
-> ([RegexAction] -> RegexAction) -> [RegexAction] -> [RegexAction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [RegexAction] -> RegexAction
Backword ([RegexAction] -> RegexAction)
-> ([RegexAction] -> [RegexAction]) -> [RegexAction] -> RegexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [RegexAction] -> [RegexAction]
forall a. [a] -> [a]
reverse ([RegexAction] -> [RegexAction])
-> ([RegexAction] -> [RegexAction])
-> [RegexAction]
-> [RegexAction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RegexAction -> RegexAction) -> [RegexAction] -> [RegexAction]
forall a b. (a -> b) -> [a] -> [b]
map RegexAction -> RegexAction
reverseRegexAction )
, ( "?<!", [RegexAction] -> RegexAction
Still ([RegexAction] -> RegexAction)
-> ([RegexAction] -> [RegexAction]) -> [RegexAction] -> RegexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RegexAction -> [RegexAction] -> [RegexAction]
forall a. a -> [a] -> [a]
:[]) (RegexAction -> [RegexAction])
-> ([RegexAction] -> RegexAction) -> [RegexAction] -> [RegexAction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [RegexAction] -> RegexAction
RegActNot ([RegexAction] -> RegexAction)
-> ([RegexAction] -> [RegexAction]) -> [RegexAction] -> RegexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RegexAction -> [RegexAction] -> [RegexAction]
forall a. a -> [a] -> [a]
:[]) (RegexAction -> [RegexAction])
-> ([RegexAction] -> RegexAction) -> [RegexAction] -> [RegexAction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [RegexAction] -> RegexAction
Backword ([RegexAction] -> RegexAction)
-> ([RegexAction] -> [RegexAction]) -> [RegexAction] -> RegexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [RegexAction] -> [RegexAction]
forall a. [a] -> [a]
reverse
([RegexAction] -> [RegexAction])
-> ([RegexAction] -> [RegexAction])
-> [RegexAction]
-> [RegexAction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RegexAction -> RegexAction) -> [RegexAction] -> [RegexAction]
forall a b. (a -> b) -> [a] -> [b]
map RegexAction -> RegexAction
reverseRegexAction )
, ( "?=", [RegexAction] -> RegexAction
Still )
, ( "?!", [RegexAction] -> RegexAction
Still ([RegexAction] -> RegexAction)
-> ([RegexAction] -> [RegexAction]) -> [RegexAction] -> RegexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RegexAction -> [RegexAction] -> [RegexAction]
forall a. a -> [a] -> [a]
:[]) (RegexAction -> [RegexAction])
-> ([RegexAction] -> RegexAction) -> [RegexAction] -> [RegexAction]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [RegexAction] -> RegexAction
RegActNot )
, ( "?:", [RegexAction] -> RegexAction
Parens )
, ( "?>", [RegexAction] -> RegexAction
NoBacktrack )
, ( "$>", [RegexAction] -> RegexAction
NoBacktrack )
]
charClassList :: [ (String, Char -> Bool) ]
charClassList :: [([Char], Char -> Bool)]
charClassList = [
( "alnum" , Char -> Bool
isAlphaNum )
, ( "alpha" , Char -> Bool
isAlpha )
, ( "blank" , Char -> Bool
isSpace )
, ( "cntrl" , Char -> Bool
isControl )
, ( "digit" , Char -> Bool
isDigit )
, ( "graph" , Char -> Bool
isPrint (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
&&& (Bool -> Bool
not(Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) Char -> Bool
isSpace )
, ( "lower" , Char -> Bool
isLower )
, ( "print" , Char -> Bool
isPrint )
, ( "punct" , Char -> Bool
isSymbol )
, ( "space" , Char -> Bool
isSpace )
, ( "upper" , Char -> Bool
isUpper )
, ( "xdigit", Char -> Bool
isHexDigit )
]
isWord :: Char -> Bool
isWord :: Char -> Bool
isWord = Char -> Bool
isAlphaNum (Char -> Bool) -> (Char -> Bool) -> Char -> Bool
forall a. (a -> Bool) -> (a -> Bool) -> a -> Bool
||| (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='_')
regexOr :: [[RegexAction]] -> RegexAction
regexOr :: [[RegexAction]] -> RegexAction
regexOr = [RegexAction] -> RegexAction
forall a. [a] -> a
head ([RegexAction] -> RegexAction)
-> ([[RegexAction]] -> [RegexAction])
-> [[RegexAction]]
-> RegexAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([RegexAction] -> [RegexAction] -> [RegexAction])
-> [[RegexAction]] -> [RegexAction]
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 (\ra1 :: [RegexAction]
ra1 ra2 :: [RegexAction]
ra2 -> [[RegexAction] -> [RegexAction] -> RegexAction
RegexOr [RegexAction]
ra1 [RegexAction]
ra2])
lookBehind :: [RegexAction] -> RegexAction
lookBehind :: [RegexAction] -> RegexAction
lookBehind ras :: [RegexAction]
ras = [RegexAction] -> RegexAction
Still [[RegexAction] -> RegexAction
Backword [RegexAction]
ras]
selectNot :: (Char -> Bool) -> RegexAction
selectNot :: (Char -> Bool) -> RegexAction
selectNot s :: Char -> Bool
s = (Char -> Bool) -> RegexAction
Select (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
s)