module System.FilePath.Glob.Primitive
( literal
, singleWildcard, wildcard, recursiveWildcard
, charRange, numberRange
) where
import System.FilePath (isPathSeparator, isExtSeparator)
import System.FilePath.Glob.Base (Pattern(..), Token(..), optimize)
literal :: String -> Pattern
literal :: String -> Pattern
literal = Pattern -> Pattern
optimize (Pattern -> Pattern) -> (String -> Pattern) -> String -> Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Token] -> Pattern
Pattern ([Token] -> Pattern) -> (String -> [Token]) -> String -> Pattern
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Token) -> String -> [Token]
forall a b. (a -> b) -> [a] -> [b]
map Char -> Token
f
where
f :: Char -> Token
f Char
c | Char -> Bool
isPathSeparator Char
c = Token
PathSeparator
| Char -> Bool
isExtSeparator Char
c = Token
ExtSeparator
| Bool
otherwise = Char -> Token
Literal Char
c
singleWildcard :: Pattern
singleWildcard :: Pattern
singleWildcard = [Token] -> Pattern
Pattern [Token
NonPathSeparator]
wildcard :: Pattern
wildcard :: Pattern
wildcard = [Token] -> Pattern
Pattern [Token
AnyNonPathSeparator]
recursiveWildcard :: Pattern
recursiveWildcard :: Pattern
recursiveWildcard = [Token] -> Pattern
Pattern [Token
AnyDirectory]
charRange :: Bool -> [Either Char (Char,Char)] -> Pattern
charRange :: Bool -> [Either Char (Char, Char)] -> Pattern
charRange Bool
b [Either Char (Char, Char)]
rs = Pattern -> Pattern
optimize (Pattern -> Pattern) -> Pattern -> Pattern
forall a b. (a -> b) -> a -> b
$ [Token] -> Pattern
Pattern [Bool -> [Either Char (Char, Char)] -> Token
CharRange Bool
b [Either Char (Char, Char)]
rs]
numberRange :: Maybe Integer -> Maybe Integer -> Pattern
numberRange :: Maybe Integer -> Maybe Integer -> Pattern
numberRange Maybe Integer
a Maybe Integer
b = [Token] -> Pattern
Pattern [Maybe String -> Maybe String -> Token
OpenRange ((Integer -> String) -> Maybe Integer -> Maybe String
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> String
forall a. Show a => a -> String
show Maybe Integer
a) ((Integer -> String) -> Maybe Integer -> Maybe String
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> String
forall a. Show a => a -> String
show Maybe Integer
b)]