{-# LANGUAGE DeriveGeneric #-}
module Distribution.Simple.InstallDirs.Internal
( PathComponent(..)
, PathTemplateVariable(..)
) where
import Prelude ()
import Distribution.Compat.Prelude
data PathComponent =
Ordinary FilePath
| Variable PathTemplateVariable
deriving (PathComponent -> PathComponent -> Bool
(PathComponent -> PathComponent -> Bool)
-> (PathComponent -> PathComponent -> Bool) -> Eq PathComponent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PathComponent -> PathComponent -> Bool
$c/= :: PathComponent -> PathComponent -> Bool
== :: PathComponent -> PathComponent -> Bool
$c== :: PathComponent -> PathComponent -> Bool
Eq, Eq PathComponent
Eq PathComponent
-> (PathComponent -> PathComponent -> Ordering)
-> (PathComponent -> PathComponent -> Bool)
-> (PathComponent -> PathComponent -> Bool)
-> (PathComponent -> PathComponent -> Bool)
-> (PathComponent -> PathComponent -> Bool)
-> (PathComponent -> PathComponent -> PathComponent)
-> (PathComponent -> PathComponent -> PathComponent)
-> Ord PathComponent
PathComponent -> PathComponent -> Bool
PathComponent -> PathComponent -> Ordering
PathComponent -> PathComponent -> PathComponent
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PathComponent -> PathComponent -> PathComponent
$cmin :: PathComponent -> PathComponent -> PathComponent
max :: PathComponent -> PathComponent -> PathComponent
$cmax :: PathComponent -> PathComponent -> PathComponent
>= :: PathComponent -> PathComponent -> Bool
$c>= :: PathComponent -> PathComponent -> Bool
> :: PathComponent -> PathComponent -> Bool
$c> :: PathComponent -> PathComponent -> Bool
<= :: PathComponent -> PathComponent -> Bool
$c<= :: PathComponent -> PathComponent -> Bool
< :: PathComponent -> PathComponent -> Bool
$c< :: PathComponent -> PathComponent -> Bool
compare :: PathComponent -> PathComponent -> Ordering
$ccompare :: PathComponent -> PathComponent -> Ordering
$cp1Ord :: Eq PathComponent
Ord, (forall x. PathComponent -> Rep PathComponent x)
-> (forall x. Rep PathComponent x -> PathComponent)
-> Generic PathComponent
forall x. Rep PathComponent x -> PathComponent
forall x. PathComponent -> Rep PathComponent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PathComponent x -> PathComponent
$cfrom :: forall x. PathComponent -> Rep PathComponent x
Generic)
instance Binary PathComponent
data PathTemplateVariable =
PrefixVar
| BindirVar
| LibdirVar
| LibsubdirVar
| DynlibdirVar
| DatadirVar
| DatasubdirVar
| DocdirVar
| HtmldirVar
| PkgNameVar
| PkgVerVar
| PkgIdVar
| LibNameVar
| CompilerVar
| OSVar
| ArchVar
| AbiVar
| AbiTagVar
| ExecutableNameVar
| TestSuiteNameVar
| TestSuiteResultVar
| BenchmarkNameVar
deriving (PathTemplateVariable -> PathTemplateVariable -> Bool
(PathTemplateVariable -> PathTemplateVariable -> Bool)
-> (PathTemplateVariable -> PathTemplateVariable -> Bool)
-> Eq PathTemplateVariable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PathTemplateVariable -> PathTemplateVariable -> Bool
$c/= :: PathTemplateVariable -> PathTemplateVariable -> Bool
== :: PathTemplateVariable -> PathTemplateVariable -> Bool
$c== :: PathTemplateVariable -> PathTemplateVariable -> Bool
Eq, Eq PathTemplateVariable
Eq PathTemplateVariable
-> (PathTemplateVariable -> PathTemplateVariable -> Ordering)
-> (PathTemplateVariable -> PathTemplateVariable -> Bool)
-> (PathTemplateVariable -> PathTemplateVariable -> Bool)
-> (PathTemplateVariable -> PathTemplateVariable -> Bool)
-> (PathTemplateVariable -> PathTemplateVariable -> Bool)
-> (PathTemplateVariable
-> PathTemplateVariable -> PathTemplateVariable)
-> (PathTemplateVariable
-> PathTemplateVariable -> PathTemplateVariable)
-> Ord PathTemplateVariable
PathTemplateVariable -> PathTemplateVariable -> Bool
PathTemplateVariable -> PathTemplateVariable -> Ordering
PathTemplateVariable
-> PathTemplateVariable -> PathTemplateVariable
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PathTemplateVariable
-> PathTemplateVariable -> PathTemplateVariable
$cmin :: PathTemplateVariable
-> PathTemplateVariable -> PathTemplateVariable
max :: PathTemplateVariable
-> PathTemplateVariable -> PathTemplateVariable
$cmax :: PathTemplateVariable
-> PathTemplateVariable -> PathTemplateVariable
>= :: PathTemplateVariable -> PathTemplateVariable -> Bool
$c>= :: PathTemplateVariable -> PathTemplateVariable -> Bool
> :: PathTemplateVariable -> PathTemplateVariable -> Bool
$c> :: PathTemplateVariable -> PathTemplateVariable -> Bool
<= :: PathTemplateVariable -> PathTemplateVariable -> Bool
$c<= :: PathTemplateVariable -> PathTemplateVariable -> Bool
< :: PathTemplateVariable -> PathTemplateVariable -> Bool
$c< :: PathTemplateVariable -> PathTemplateVariable -> Bool
compare :: PathTemplateVariable -> PathTemplateVariable -> Ordering
$ccompare :: PathTemplateVariable -> PathTemplateVariable -> Ordering
$cp1Ord :: Eq PathTemplateVariable
Ord, (forall x. PathTemplateVariable -> Rep PathTemplateVariable x)
-> (forall x. Rep PathTemplateVariable x -> PathTemplateVariable)
-> Generic PathTemplateVariable
forall x. Rep PathTemplateVariable x -> PathTemplateVariable
forall x. PathTemplateVariable -> Rep PathTemplateVariable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PathTemplateVariable x -> PathTemplateVariable
$cfrom :: forall x. PathTemplateVariable -> Rep PathTemplateVariable x
Generic)
instance Binary PathTemplateVariable
instance Show PathTemplateVariable where
show :: PathTemplateVariable -> String
show PathTemplateVariable
PrefixVar = String
"prefix"
show PathTemplateVariable
LibNameVar = String
"libname"
show PathTemplateVariable
BindirVar = String
"bindir"
show PathTemplateVariable
LibdirVar = String
"libdir"
show PathTemplateVariable
LibsubdirVar = String
"libsubdir"
show PathTemplateVariable
DynlibdirVar = String
"dynlibdir"
show PathTemplateVariable
DatadirVar = String
"datadir"
show PathTemplateVariable
DatasubdirVar = String
"datasubdir"
show PathTemplateVariable
DocdirVar = String
"docdir"
show PathTemplateVariable
HtmldirVar = String
"htmldir"
show PathTemplateVariable
PkgNameVar = String
"pkg"
show PathTemplateVariable
PkgVerVar = String
"version"
show PathTemplateVariable
PkgIdVar = String
"pkgid"
show PathTemplateVariable
CompilerVar = String
"compiler"
show PathTemplateVariable
OSVar = String
"os"
show PathTemplateVariable
ArchVar = String
"arch"
show PathTemplateVariable
AbiTagVar = String
"abitag"
show PathTemplateVariable
AbiVar = String
"abi"
show PathTemplateVariable
ExecutableNameVar = String
"executablename"
show PathTemplateVariable
TestSuiteNameVar = String
"test-suite"
show PathTemplateVariable
TestSuiteResultVar = String
"result"
show PathTemplateVariable
BenchmarkNameVar = String
"benchmark"
instance Read PathTemplateVariable where
readsPrec :: Int -> ReadS PathTemplateVariable
readsPrec Int
_ String
s =
Int
-> [(PathTemplateVariable, String)]
-> [(PathTemplateVariable, String)]
forall a. Int -> [a] -> [a]
take Int
1
[ (PathTemplateVariable
var, Int -> ShowS
forall a. Int -> [a] -> [a]
drop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
varStr) String
s)
| (String
varStr, PathTemplateVariable
var) <- [(String, PathTemplateVariable)]
vars
, String
varStr String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
s ]
where vars :: [(String, PathTemplateVariable)]
vars = [(String
"prefix", PathTemplateVariable
PrefixVar)
,(String
"bindir", PathTemplateVariable
BindirVar)
,(String
"libdir", PathTemplateVariable
LibdirVar)
,(String
"libsubdir", PathTemplateVariable
LibsubdirVar)
,(String
"dynlibdir", PathTemplateVariable
DynlibdirVar)
,(String
"datadir", PathTemplateVariable
DatadirVar)
,(String
"datasubdir", PathTemplateVariable
DatasubdirVar)
,(String
"docdir", PathTemplateVariable
DocdirVar)
,(String
"htmldir", PathTemplateVariable
HtmldirVar)
,(String
"pkgid", PathTemplateVariable
PkgIdVar)
,(String
"libname", PathTemplateVariable
LibNameVar)
,(String
"pkgkey", PathTemplateVariable
LibNameVar)
,(String
"pkg", PathTemplateVariable
PkgNameVar)
,(String
"version", PathTemplateVariable
PkgVerVar)
,(String
"compiler", PathTemplateVariable
CompilerVar)
,(String
"os", PathTemplateVariable
OSVar)
,(String
"arch", PathTemplateVariable
ArchVar)
,(String
"abitag", PathTemplateVariable
AbiTagVar)
,(String
"abi", PathTemplateVariable
AbiVar)
,(String
"executablename", PathTemplateVariable
ExecutableNameVar)
,(String
"test-suite", PathTemplateVariable
TestSuiteNameVar)
,(String
"result", PathTemplateVariable
TestSuiteResultVar)
,(String
"benchmark", PathTemplateVariable
BenchmarkNameVar)]
instance Show PathComponent where
show :: PathComponent -> String
show (Ordinary String
path) = String
path
show (Variable PathTemplateVariable
var) = Char
'$'Char -> ShowS
forall a. a -> [a] -> [a]
:PathTemplateVariable -> String
forall a. Show a => a -> String
show PathTemplateVariable
var
showList :: [PathComponent] -> ShowS
showList = (PathComponent -> ShowS -> ShowS)
-> ShowS -> [PathComponent] -> ShowS
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\PathComponent
x -> (PathComponent -> ShowS
forall a. Show a => a -> ShowS
shows PathComponent
x ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.)) ShowS
forall a. a -> a
id
instance Read PathComponent where
readsPrec :: Int -> ReadS PathComponent
readsPrec Int
_ = ReadS PathComponent
lex0
where lex0 :: ReadS PathComponent
lex0 [] = []
lex0 (Char
'$':Char
'$':String
s') = ReadS PathComponent
lex0 (Char
'$'Char -> ShowS
forall a. a -> [a] -> [a]
:String
s')
lex0 (Char
'$':String
s') = case [ (PathTemplateVariable -> PathComponent
Variable PathTemplateVariable
var, String
s'')
| (PathTemplateVariable
var, String
s'') <- ReadS PathTemplateVariable
forall a. Read a => ReadS a
reads String
s' ] of
[] -> String -> ReadS PathComponent
lex1 String
"$" String
s'
[(PathComponent, String)]
ok -> [(PathComponent, String)]
ok
lex0 String
s' = String -> ReadS PathComponent
lex1 [] String
s'
lex1 :: String -> ReadS PathComponent
lex1 String
"" String
"" = []
lex1 String
acc String
"" = [(String -> PathComponent
Ordinary (ShowS
forall a. [a] -> [a]
reverse String
acc), String
"")]
lex1 String
acc (Char
'$':Char
'$':String
s) = String -> ReadS PathComponent
lex1 String
acc (Char
'$'Char -> ShowS
forall a. a -> [a] -> [a]
:String
s)
lex1 String
acc (Char
'$':String
s) = [(String -> PathComponent
Ordinary (ShowS
forall a. [a] -> [a]
reverse String
acc), Char
'$'Char -> ShowS
forall a. a -> [a] -> [a]
:String
s)]
lex1 String
acc (Char
c:String
s) = String -> ReadS PathComponent
lex1 (Char
cChar -> ShowS
forall a. a -> [a] -> [a]
:String
acc) String
s
readList :: ReadS [PathComponent]
readList [] = [([],String
"")]
readList String
s = [ (PathComponent
componentPathComponent -> [PathComponent] -> [PathComponent]
forall a. a -> [a] -> [a]
:[PathComponent]
components, String
s'')
| (PathComponent
component, String
s') <- ReadS PathComponent
forall a. Read a => ReadS a
reads String
s
, ([PathComponent]
components, String
s'') <- ReadS [PathComponent]
forall a. Read a => ReadS [a]
readList String
s' ]