{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Distribution.Types.Flag
(
PackageFlag (..)
, emptyFlag
, FlagName
, mkFlagName
, unFlagName
, FlagAssignment
, mkFlagAssignment
, unFlagAssignment
, lookupFlagAssignment
, insertFlagAssignment
, diffFlagAssignment
, findDuplicateFlagAssignments
, nullFlagAssignment
, showFlagValue
, dispFlagAssignment
, showFlagAssignment
, parsecFlagAssignment
, parsecFlagAssignmentNonEmpty
, legacyShowFlagAssignment
, legacyShowFlagAssignment'
, legacyParsecFlagAssignment
) where
import Distribution.Compat.Prelude
import Distribution.Utils.Generic (lowercase)
import Distribution.Utils.ShortText
import Prelude ()
import Distribution.Parsec
import Distribution.Pretty
import qualified Data.Map as Map
import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint as Disp
data PackageFlag = MkPackageFlag
{ PackageFlag -> FlagName
flagName :: FlagName
, PackageFlag -> String
flagDescription :: String
, PackageFlag -> Bool
flagDefault :: Bool
, PackageFlag -> Bool
flagManual :: Bool
}
deriving (Int -> PackageFlag -> ShowS
[PackageFlag] -> ShowS
PackageFlag -> String
(Int -> PackageFlag -> ShowS)
-> (PackageFlag -> String)
-> ([PackageFlag] -> ShowS)
-> Show PackageFlag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PackageFlag -> ShowS
showsPrec :: Int -> PackageFlag -> ShowS
$cshow :: PackageFlag -> String
show :: PackageFlag -> String
$cshowList :: [PackageFlag] -> ShowS
showList :: [PackageFlag] -> ShowS
Show, PackageFlag -> PackageFlag -> Bool
(PackageFlag -> PackageFlag -> Bool)
-> (PackageFlag -> PackageFlag -> Bool) -> Eq PackageFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PackageFlag -> PackageFlag -> Bool
== :: PackageFlag -> PackageFlag -> Bool
$c/= :: PackageFlag -> PackageFlag -> Bool
/= :: PackageFlag -> PackageFlag -> Bool
Eq, Typeable, Typeable PackageFlag
Typeable PackageFlag =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PackageFlag -> c PackageFlag)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageFlag)
-> (PackageFlag -> Constr)
-> (PackageFlag -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageFlag))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageFlag))
-> ((forall b. Data b => b -> b) -> PackageFlag -> PackageFlag)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r)
-> (forall u. (forall d. Data d => d -> u) -> PackageFlag -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> PackageFlag -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag)
-> Data PackageFlag
PackageFlag -> Constr
PackageFlag -> DataType
(forall b. Data b => b -> b) -> PackageFlag -> PackageFlag
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PackageFlag -> u
forall u. (forall d. Data d => d -> u) -> PackageFlag -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageFlag
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PackageFlag -> c PackageFlag
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageFlag)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageFlag)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PackageFlag -> c PackageFlag
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PackageFlag -> c PackageFlag
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageFlag
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageFlag
$ctoConstr :: PackageFlag -> Constr
toConstr :: PackageFlag -> Constr
$cdataTypeOf :: PackageFlag -> DataType
dataTypeOf :: PackageFlag -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageFlag)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageFlag)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageFlag)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageFlag)
$cgmapT :: (forall b. Data b => b -> b) -> PackageFlag -> PackageFlag
gmapT :: (forall b. Data b => b -> b) -> PackageFlag -> PackageFlag
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PackageFlag -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> PackageFlag -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> PackageFlag -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PackageFlag -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> PackageFlag -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PackageFlag -> m PackageFlag
Data, (forall x. PackageFlag -> Rep PackageFlag x)
-> (forall x. Rep PackageFlag x -> PackageFlag)
-> Generic PackageFlag
forall x. Rep PackageFlag x -> PackageFlag
forall x. PackageFlag -> Rep PackageFlag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PackageFlag -> Rep PackageFlag x
from :: forall x. PackageFlag -> Rep PackageFlag x
$cto :: forall x. Rep PackageFlag x -> PackageFlag
to :: forall x. Rep PackageFlag x -> PackageFlag
Generic)
instance Binary PackageFlag
instance Structured PackageFlag
instance NFData PackageFlag where rnf :: PackageFlag -> ()
rnf = PackageFlag -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf
emptyFlag :: FlagName -> PackageFlag
emptyFlag :: FlagName -> PackageFlag
emptyFlag FlagName
name =
MkPackageFlag
{ flagName :: FlagName
flagName = FlagName
name
, flagDescription :: String
flagDescription = String
""
, flagDefault :: Bool
flagDefault = Bool
True
, flagManual :: Bool
flagManual = Bool
False
}
newtype FlagName = FlagName ShortText
deriving (FlagName -> FlagName -> Bool
(FlagName -> FlagName -> Bool)
-> (FlagName -> FlagName -> Bool) -> Eq FlagName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FlagName -> FlagName -> Bool
== :: FlagName -> FlagName -> Bool
$c/= :: FlagName -> FlagName -> Bool
/= :: FlagName -> FlagName -> Bool
Eq, (forall x. FlagName -> Rep FlagName x)
-> (forall x. Rep FlagName x -> FlagName) -> Generic FlagName
forall x. Rep FlagName x -> FlagName
forall x. FlagName -> Rep FlagName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FlagName -> Rep FlagName x
from :: forall x. FlagName -> Rep FlagName x
$cto :: forall x. Rep FlagName x -> FlagName
to :: forall x. Rep FlagName x -> FlagName
Generic, Eq FlagName
Eq FlagName =>
(FlagName -> FlagName -> Ordering)
-> (FlagName -> FlagName -> Bool)
-> (FlagName -> FlagName -> Bool)
-> (FlagName -> FlagName -> Bool)
-> (FlagName -> FlagName -> Bool)
-> (FlagName -> FlagName -> FlagName)
-> (FlagName -> FlagName -> FlagName)
-> Ord FlagName
FlagName -> FlagName -> Bool
FlagName -> FlagName -> Ordering
FlagName -> FlagName -> FlagName
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
$ccompare :: FlagName -> FlagName -> Ordering
compare :: FlagName -> FlagName -> Ordering
$c< :: FlagName -> FlagName -> Bool
< :: FlagName -> FlagName -> Bool
$c<= :: FlagName -> FlagName -> Bool
<= :: FlagName -> FlagName -> Bool
$c> :: FlagName -> FlagName -> Bool
> :: FlagName -> FlagName -> Bool
$c>= :: FlagName -> FlagName -> Bool
>= :: FlagName -> FlagName -> Bool
$cmax :: FlagName -> FlagName -> FlagName
max :: FlagName -> FlagName -> FlagName
$cmin :: FlagName -> FlagName -> FlagName
min :: FlagName -> FlagName -> FlagName
Ord, Int -> FlagName -> ShowS
[FlagName] -> ShowS
FlagName -> String
(Int -> FlagName -> ShowS)
-> (FlagName -> String) -> ([FlagName] -> ShowS) -> Show FlagName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FlagName -> ShowS
showsPrec :: Int -> FlagName -> ShowS
$cshow :: FlagName -> String
show :: FlagName -> String
$cshowList :: [FlagName] -> ShowS
showList :: [FlagName] -> ShowS
Show, ReadPrec [FlagName]
ReadPrec FlagName
Int -> ReadS FlagName
ReadS [FlagName]
(Int -> ReadS FlagName)
-> ReadS [FlagName]
-> ReadPrec FlagName
-> ReadPrec [FlagName]
-> Read FlagName
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS FlagName
readsPrec :: Int -> ReadS FlagName
$creadList :: ReadS [FlagName]
readList :: ReadS [FlagName]
$creadPrec :: ReadPrec FlagName
readPrec :: ReadPrec FlagName
$creadListPrec :: ReadPrec [FlagName]
readListPrec :: ReadPrec [FlagName]
Read, Typeable, Typeable FlagName
Typeable FlagName =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FlagName -> c FlagName)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FlagName)
-> (FlagName -> Constr)
-> (FlagName -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FlagName))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FlagName))
-> ((forall b. Data b => b -> b) -> FlagName -> FlagName)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r)
-> (forall u. (forall d. Data d => d -> u) -> FlagName -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> FlagName -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName)
-> Data FlagName
FlagName -> Constr
FlagName -> DataType
(forall b. Data b => b -> b) -> FlagName -> FlagName
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> FlagName -> u
forall u. (forall d. Data d => d -> u) -> FlagName -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FlagName
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FlagName -> c FlagName
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FlagName)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FlagName)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FlagName -> c FlagName
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FlagName -> c FlagName
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FlagName
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FlagName
$ctoConstr :: FlagName -> Constr
toConstr :: FlagName -> Constr
$cdataTypeOf :: FlagName -> DataType
dataTypeOf :: FlagName -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FlagName)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FlagName)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FlagName)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FlagName)
$cgmapT :: (forall b. Data b => b -> b) -> FlagName -> FlagName
gmapT :: (forall b. Data b => b -> b) -> FlagName -> FlagName
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FlagName -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FlagName -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> FlagName -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FlagName -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FlagName -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FlagName -> m FlagName
Data, FlagName -> ()
(FlagName -> ()) -> NFData FlagName
forall a. (a -> ()) -> NFData a
$crnf :: FlagName -> ()
rnf :: FlagName -> ()
NFData)
mkFlagName :: String -> FlagName
mkFlagName :: String -> FlagName
mkFlagName = ShortText -> FlagName
FlagName (ShortText -> FlagName)
-> (String -> ShortText) -> String -> FlagName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShortText
toShortText
instance IsString FlagName where
fromString :: String -> FlagName
fromString = String -> FlagName
mkFlagName
unFlagName :: FlagName -> String
unFlagName :: FlagName -> String
unFlagName (FlagName ShortText
s) = ShortText -> String
fromShortText ShortText
s
instance Binary FlagName
instance Structured FlagName
instance Pretty FlagName where
pretty :: FlagName -> Doc
pretty = String -> Doc
Disp.text (String -> Doc) -> (FlagName -> String) -> FlagName -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagName -> String
unFlagName
instance Parsec FlagName where
parsec :: forall (m :: * -> *). CabalParsing m => m FlagName
parsec = String -> FlagName
mkFlagName (String -> FlagName) -> ShowS -> String -> FlagName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
lowercase (String -> FlagName) -> m String -> m FlagName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String
parsec'
where
parsec' :: m String
parsec' = (:) (Char -> ShowS) -> m Char -> m ShowS
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Char
lead m ShowS -> m String -> m String
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m String
rest
lead :: m Char
lead = (Char -> Bool) -> m Char
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m Char
P.satisfy (\Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_')
rest :: m String
rest = (Char -> Bool) -> m String
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch (\Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-')
newtype FlagAssignment = FlagAssignment {FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment :: Map.Map FlagName (Int, Bool)}
deriving (Get FlagAssignment
[FlagAssignment] -> Put
FlagAssignment -> Put
(FlagAssignment -> Put)
-> Get FlagAssignment
-> ([FlagAssignment] -> Put)
-> Binary FlagAssignment
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
$cput :: FlagAssignment -> Put
put :: FlagAssignment -> Put
$cget :: Get FlagAssignment
get :: Get FlagAssignment
$cputList :: [FlagAssignment] -> Put
putList :: [FlagAssignment] -> Put
Binary, (forall x. FlagAssignment -> Rep FlagAssignment x)
-> (forall x. Rep FlagAssignment x -> FlagAssignment)
-> Generic FlagAssignment
forall x. Rep FlagAssignment x -> FlagAssignment
forall x. FlagAssignment -> Rep FlagAssignment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. FlagAssignment -> Rep FlagAssignment x
from :: forall x. FlagAssignment -> Rep FlagAssignment x
$cto :: forall x. Rep FlagAssignment x -> FlagAssignment
to :: forall x. Rep FlagAssignment x -> FlagAssignment
Generic, FlagAssignment -> ()
(FlagAssignment -> ()) -> NFData FlagAssignment
forall a. (a -> ()) -> NFData a
$crnf :: FlagAssignment -> ()
rnf :: FlagAssignment -> ()
NFData, Typeable)
instance Structured FlagAssignment
instance Eq FlagAssignment where
== :: FlagAssignment -> FlagAssignment -> Bool
(==) (FlagAssignment Map FlagName (Int, Bool)
m1) (FlagAssignment Map FlagName (Int, Bool)
m2) =
((Int, Bool) -> Bool)
-> Map FlagName (Int, Bool) -> Map FlagName Bool
forall a b. (a -> b) -> Map FlagName a -> Map FlagName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int, Bool) -> Bool
forall a b. (a, b) -> b
snd Map FlagName (Int, Bool)
m1 Map FlagName Bool -> Map FlagName Bool -> Bool
forall a. Eq a => a -> a -> Bool
== ((Int, Bool) -> Bool)
-> Map FlagName (Int, Bool) -> Map FlagName Bool
forall a b. (a -> b) -> Map FlagName a -> Map FlagName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int, Bool) -> Bool
forall a b. (a, b) -> b
snd Map FlagName (Int, Bool)
m2
instance Ord FlagAssignment where
compare :: FlagAssignment -> FlagAssignment -> Ordering
compare (FlagAssignment Map FlagName (Int, Bool)
m1) (FlagAssignment Map FlagName (Int, Bool)
m2) =
((Int, Bool) -> Bool)
-> Map FlagName (Int, Bool) -> Map FlagName Bool
forall a b. (a -> b) -> Map FlagName a -> Map FlagName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int, Bool) -> Bool
forall a b. (a, b) -> b
snd Map FlagName (Int, Bool)
m1 Map FlagName Bool -> Map FlagName Bool -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` ((Int, Bool) -> Bool)
-> Map FlagName (Int, Bool) -> Map FlagName Bool
forall a b. (a -> b) -> Map FlagName a -> Map FlagName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int, Bool) -> Bool
forall a b. (a, b) -> b
snd Map FlagName (Int, Bool)
m2
combineFlagValues :: (Int, Bool) -> (Int, Bool) -> (Int, Bool)
combineFlagValues :: (Int, Bool) -> (Int, Bool) -> (Int, Bool)
combineFlagValues (Int
c1, Bool
_) (Int
c2, Bool
b2) = (Int
c1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
c2, Bool
b2)
instance Semigroup FlagAssignment where
<> :: FlagAssignment -> FlagAssignment -> FlagAssignment
(<>) (FlagAssignment Map FlagName (Int, Bool)
m1) (FlagAssignment Map FlagName (Int, Bool)
m2) =
Map FlagName (Int, Bool) -> FlagAssignment
FlagAssignment (((Int, Bool) -> (Int, Bool) -> (Int, Bool))
-> Map FlagName (Int, Bool)
-> Map FlagName (Int, Bool)
-> Map FlagName (Int, Bool)
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith (Int, Bool) -> (Int, Bool) -> (Int, Bool)
combineFlagValues Map FlagName (Int, Bool)
m1 Map FlagName (Int, Bool)
m2)
instance Monoid FlagAssignment where
mempty :: FlagAssignment
mempty = Map FlagName (Int, Bool) -> FlagAssignment
FlagAssignment Map FlagName (Int, Bool)
forall k a. Map k a
Map.empty
mappend :: FlagAssignment -> FlagAssignment -> FlagAssignment
mappend = FlagAssignment -> FlagAssignment -> FlagAssignment
forall a. Semigroup a => a -> a -> a
(<>)
mkFlagAssignment :: [(FlagName, Bool)] -> FlagAssignment
mkFlagAssignment :: [(FlagName, Bool)] -> FlagAssignment
mkFlagAssignment =
Map FlagName (Int, Bool) -> FlagAssignment
FlagAssignment
(Map FlagName (Int, Bool) -> FlagAssignment)
-> ([(FlagName, Bool)] -> Map FlagName (Int, Bool))
-> [(FlagName, Bool)]
-> FlagAssignment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, Bool) -> (Int, Bool) -> (Int, Bool))
-> [(FlagName, (Int, Bool))] -> Map FlagName (Int, Bool)
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith (((Int, Bool) -> (Int, Bool) -> (Int, Bool))
-> (Int, Bool) -> (Int, Bool) -> (Int, Bool)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int, Bool) -> (Int, Bool) -> (Int, Bool)
combineFlagValues)
([(FlagName, (Int, Bool))] -> Map FlagName (Int, Bool))
-> ([(FlagName, Bool)] -> [(FlagName, (Int, Bool))])
-> [(FlagName, Bool)]
-> Map FlagName (Int, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((FlagName, Bool) -> (FlagName, (Int, Bool)))
-> [(FlagName, Bool)] -> [(FlagName, (Int, Bool))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Bool -> (Int, Bool))
-> (FlagName, Bool) -> (FlagName, (Int, Bool))
forall a b. (a -> b) -> (FlagName, a) -> (FlagName, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Bool
b -> (Int
1, Bool
b)))
unFlagAssignment :: FlagAssignment -> [(FlagName, Bool)]
unFlagAssignment :: FlagAssignment -> [(FlagName, Bool)]
unFlagAssignment = ((FlagName, (Int, Bool)) -> (FlagName, Bool))
-> [(FlagName, (Int, Bool))] -> [(FlagName, Bool)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((Int, Bool) -> Bool)
-> (FlagName, (Int, Bool)) -> (FlagName, Bool)
forall a b. (a -> b) -> (FlagName, a) -> (FlagName, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int, Bool) -> Bool
forall a b. (a, b) -> b
snd) ([(FlagName, (Int, Bool))] -> [(FlagName, Bool)])
-> (FlagAssignment -> [(FlagName, (Int, Bool))])
-> FlagAssignment
-> [(FlagName, Bool)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map FlagName (Int, Bool) -> [(FlagName, (Int, Bool))]
forall k a. Map k a -> [(k, a)]
Map.toList (Map FlagName (Int, Bool) -> [(FlagName, (Int, Bool))])
-> (FlagAssignment -> Map FlagName (Int, Bool))
-> FlagAssignment
-> [(FlagName, (Int, Bool))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment
nullFlagAssignment :: FlagAssignment -> Bool
nullFlagAssignment :: FlagAssignment -> Bool
nullFlagAssignment = Map FlagName (Int, Bool) -> Bool
forall k a. Map k a -> Bool
Map.null (Map FlagName (Int, Bool) -> Bool)
-> (FlagAssignment -> Map FlagName (Int, Bool))
-> FlagAssignment
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment
lookupFlagAssignment :: FlagName -> FlagAssignment -> Maybe Bool
lookupFlagAssignment :: FlagName -> FlagAssignment -> Maybe Bool
lookupFlagAssignment FlagName
fn = ((Int, Bool) -> Bool) -> Maybe (Int, Bool) -> Maybe Bool
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int, Bool) -> Bool
forall a b. (a, b) -> b
snd (Maybe (Int, Bool) -> Maybe Bool)
-> (FlagAssignment -> Maybe (Int, Bool))
-> FlagAssignment
-> Maybe Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagName -> Map FlagName (Int, Bool) -> Maybe (Int, Bool)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup FlagName
fn (Map FlagName (Int, Bool) -> Maybe (Int, Bool))
-> (FlagAssignment -> Map FlagName (Int, Bool))
-> FlagAssignment
-> Maybe (Int, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment
insertFlagAssignment :: FlagName -> Bool -> FlagAssignment -> FlagAssignment
insertFlagAssignment :: FlagName -> Bool -> FlagAssignment -> FlagAssignment
insertFlagAssignment FlagName
flag Bool
val =
Map FlagName (Int, Bool) -> FlagAssignment
FlagAssignment
(Map FlagName (Int, Bool) -> FlagAssignment)
-> (FlagAssignment -> Map FlagName (Int, Bool))
-> FlagAssignment
-> FlagAssignment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, Bool) -> (Int, Bool) -> (Int, Bool))
-> FlagName
-> (Int, Bool)
-> Map FlagName (Int, Bool)
-> Map FlagName (Int, Bool)
forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith (((Int, Bool) -> (Int, Bool) -> (Int, Bool))
-> (Int, Bool) -> (Int, Bool) -> (Int, Bool)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Int, Bool) -> (Int, Bool) -> (Int, Bool)
combineFlagValues) FlagName
flag (Int
1, Bool
val)
(Map FlagName (Int, Bool) -> Map FlagName (Int, Bool))
-> (FlagAssignment -> Map FlagName (Int, Bool))
-> FlagAssignment
-> Map FlagName (Int, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment
diffFlagAssignment :: FlagAssignment -> FlagAssignment -> FlagAssignment
diffFlagAssignment :: FlagAssignment -> FlagAssignment -> FlagAssignment
diffFlagAssignment FlagAssignment
fa1 FlagAssignment
fa2 =
Map FlagName (Int, Bool) -> FlagAssignment
FlagAssignment
(Map FlagName (Int, Bool)
-> Map FlagName (Int, Bool) -> Map FlagName (Int, Bool)
forall k a b. Ord k => Map k a -> Map k b -> Map k a
Map.difference (FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment FlagAssignment
fa1) (FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment FlagAssignment
fa2))
findDuplicateFlagAssignments :: FlagAssignment -> [FlagName]
findDuplicateFlagAssignments :: FlagAssignment -> [FlagName]
findDuplicateFlagAssignments =
Map FlagName (Int, Bool) -> [FlagName]
forall k a. Map k a -> [k]
Map.keys (Map FlagName (Int, Bool) -> [FlagName])
-> (FlagAssignment -> Map FlagName (Int, Bool))
-> FlagAssignment
-> [FlagName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, Bool) -> Bool)
-> Map FlagName (Int, Bool) -> Map FlagName (Int, Bool)
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter ((Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1) (Int -> Bool) -> ((Int, Bool) -> Int) -> (Int, Bool) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, Bool) -> Int
forall a b. (a, b) -> a
fst) (Map FlagName (Int, Bool) -> Map FlagName (Int, Bool))
-> (FlagAssignment -> Map FlagName (Int, Bool))
-> FlagAssignment
-> Map FlagName (Int, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> Map FlagName (Int, Bool)
getFlagAssignment
instance Read FlagAssignment where
readsPrec :: Int -> ReadS FlagAssignment
readsPrec Int
p String
s = [(Map FlagName (Int, Bool) -> FlagAssignment
FlagAssignment Map FlagName (Int, Bool)
x, String
rest) | (Map FlagName (Int, Bool)
x, String
rest) <- Int -> ReadS (Map FlagName (Int, Bool))
forall a. Read a => Int -> ReadS a
readsPrec Int
p String
s]
instance Show FlagAssignment where
showsPrec :: Int -> FlagAssignment -> ShowS
showsPrec Int
p (FlagAssignment Map FlagName (Int, Bool)
xs) = Int -> Map FlagName (Int, Bool) -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
p Map FlagName (Int, Bool)
xs
showFlagValue :: (FlagName, Bool) -> String
showFlagValue :: (FlagName, Bool) -> String
showFlagValue (FlagName
f, Bool
True) = Char
'+' Char -> ShowS
forall a. a -> [a] -> [a]
: FlagName -> String
unFlagName FlagName
f
showFlagValue (FlagName
f, Bool
False) = Char
'-' Char -> ShowS
forall a. a -> [a] -> [a]
: FlagName -> String
unFlagName FlagName
f
instance Pretty FlagAssignment where
pretty :: FlagAssignment -> Doc
pretty = FlagAssignment -> Doc
dispFlagAssignment
instance Parsec FlagAssignment where
parsec :: forall (m :: * -> *). CabalParsing m => m FlagAssignment
parsec = m FlagAssignment
forall (m :: * -> *). CabalParsing m => m FlagAssignment
parsecFlagAssignment
dispFlagAssignment :: FlagAssignment -> Disp.Doc
dispFlagAssignment :: FlagAssignment -> Doc
dispFlagAssignment = [Doc] -> Doc
Disp.hsep ([Doc] -> Doc)
-> (FlagAssignment -> [Doc]) -> FlagAssignment -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((FlagName, Bool) -> Doc) -> [(FlagName, Bool)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Doc
Disp.text (String -> Doc)
-> ((FlagName, Bool) -> String) -> (FlagName, Bool) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FlagName, Bool) -> String
showFlagValue) ([(FlagName, Bool)] -> [Doc])
-> (FlagAssignment -> [(FlagName, Bool)])
-> FlagAssignment
-> [Doc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> [(FlagName, Bool)]
unFlagAssignment
parsecFlagAssignment :: CabalParsing m => m FlagAssignment
parsecFlagAssignment :: forall (m :: * -> *). CabalParsing m => m FlagAssignment
parsecFlagAssignment = [(FlagName, Bool)] -> FlagAssignment
mkFlagAssignment ([(FlagName, Bool)] -> FlagAssignment)
-> m [(FlagName, Bool)] -> m FlagAssignment
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (FlagName, Bool) -> m () -> m [(FlagName, Bool)]
forall (m :: * -> *) a b. CabalParsing m => m a -> m b -> m [a]
sepByEnding (m (FlagName, Bool)
onFlag m (FlagName, Bool) -> m (FlagName, Bool) -> m (FlagName, Bool)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (FlagName, Bool)
offFlag) m ()
forall (m :: * -> *). CharParsing m => m ()
P.skipSpaces1
where
onFlag :: m (FlagName, Bool)
onFlag = do
Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'+'
FlagName
f <- m FlagName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m FlagName
parsec
(FlagName, Bool) -> m (FlagName, Bool)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (FlagName
f, Bool
True)
offFlag :: m (FlagName, Bool)
offFlag = do
Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'-'
FlagName
f <- m FlagName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m FlagName
parsec
(FlagName, Bool) -> m (FlagName, Bool)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (FlagName
f, Bool
False)
sepByEnding :: CabalParsing m => m a -> m b -> m [a]
sepByEnding :: forall (m :: * -> *) a b. CabalParsing m => m a -> m b -> m [a]
sepByEnding m a
p m b
sep = m [a]
afterSeparator
where
element :: m [a]
element = (:) (a -> [a] -> [a]) -> m a -> m ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
p m ([a] -> [a]) -> m [a] -> m [a]
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m [a]
afterElement
afterElement :: m [a]
afterElement = m b
sep m b -> m [a] -> m [a]
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m [a]
afterSeparator m [a] -> m [a] -> m [a]
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [a] -> m [a]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
afterSeparator :: m [a]
afterSeparator = m [a]
element m [a] -> m [a] -> m [a]
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [a] -> m [a]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
parsecFlagAssignmentNonEmpty :: CabalParsing m => m FlagAssignment
parsecFlagAssignmentNonEmpty :: forall (m :: * -> *). CabalParsing m => m FlagAssignment
parsecFlagAssignmentNonEmpty = [(FlagName, Bool)] -> FlagAssignment
mkFlagAssignment ([(FlagName, Bool)] -> FlagAssignment)
-> m [(FlagName, Bool)] -> m FlagAssignment
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (FlagName, Bool) -> m () -> m [(FlagName, Bool)]
forall (m :: * -> *) a b. CabalParsing m => m a -> m b -> m [a]
sepByEnding1 (m (FlagName, Bool)
onFlag m (FlagName, Bool) -> m (FlagName, Bool) -> m (FlagName, Bool)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (FlagName, Bool)
offFlag) m ()
forall (m :: * -> *). CharParsing m => m ()
P.skipSpaces1
where
onFlag :: m (FlagName, Bool)
onFlag = do
Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'+'
FlagName
f <- m FlagName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m FlagName
parsec
(FlagName, Bool) -> m (FlagName, Bool)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (FlagName
f, Bool
True)
offFlag :: m (FlagName, Bool)
offFlag = do
Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'-'
FlagName
f <- m FlagName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m FlagName
parsec
(FlagName, Bool) -> m (FlagName, Bool)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (FlagName
f, Bool
False)
sepByEnding1 :: CabalParsing m => m a -> m b -> m [a]
sepByEnding1 :: forall (m :: * -> *) a b. CabalParsing m => m a -> m b -> m [a]
sepByEnding1 m a
p m b
sep = m [a]
element
where
element :: m [a]
element = (:) (a -> [a] -> [a]) -> m a -> m ([a] -> [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m a
p m ([a] -> [a]) -> m [a] -> m [a]
forall a b. m (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> m [a]
afterElement
afterElement :: m [a]
afterElement = m b
sep m b -> m [a] -> m [a]
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m [a]
afterSeparator m [a] -> m [a] -> m [a]
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [a] -> m [a]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
afterSeparator :: m [a]
afterSeparator = m [a]
element m [a] -> m [a] -> m [a]
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [a] -> m [a]
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
showFlagAssignment :: FlagAssignment -> String
showFlagAssignment :: FlagAssignment -> String
showFlagAssignment = Doc -> String
forall a. Pretty a => a -> String
prettyShow (Doc -> String)
-> (FlagAssignment -> Doc) -> FlagAssignment -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> Doc
dispFlagAssignment
legacyShowFlagAssignment :: FlagAssignment -> String
legacyShowFlagAssignment :: FlagAssignment -> String
legacyShowFlagAssignment =
Doc -> String
forall a. Pretty a => a -> String
prettyShow (Doc -> String)
-> (FlagAssignment -> Doc) -> FlagAssignment -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
Disp.hsep ([Doc] -> Doc)
-> (FlagAssignment -> [Doc]) -> FlagAssignment -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Doc) -> [String] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map String -> Doc
Disp.text ([String] -> [Doc])
-> (FlagAssignment -> [String]) -> FlagAssignment -> [Doc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> [String]
legacyShowFlagAssignment'
legacyShowFlagAssignment' :: FlagAssignment -> [String]
legacyShowFlagAssignment' :: FlagAssignment -> [String]
legacyShowFlagAssignment' = ((FlagName, Bool) -> String) -> [(FlagName, Bool)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (FlagName, Bool) -> String
legacyShowFlagValue ([(FlagName, Bool)] -> [String])
-> (FlagAssignment -> [(FlagName, Bool)])
-> FlagAssignment
-> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlagAssignment -> [(FlagName, Bool)]
unFlagAssignment
legacyShowFlagValue :: (FlagName, Bool) -> String
legacyShowFlagValue :: (FlagName, Bool) -> String
legacyShowFlagValue (FlagName
f, Bool
True) = FlagName -> String
unFlagName FlagName
f
legacyShowFlagValue (FlagName
f, Bool
False) = Char
'-' Char -> ShowS
forall a. a -> [a] -> [a]
: FlagName -> String
unFlagName FlagName
f
legacyParsecFlagAssignment :: CabalParsing m => m FlagAssignment
legacyParsecFlagAssignment :: forall (m :: * -> *). CabalParsing m => m FlagAssignment
legacyParsecFlagAssignment =
[(FlagName, Bool)] -> FlagAssignment
mkFlagAssignment
([(FlagName, Bool)] -> FlagAssignment)
-> m [(FlagName, Bool)] -> m FlagAssignment
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (FlagName, Bool) -> m () -> m [(FlagName, Bool)]
forall (m :: * -> *) a sep. Alternative m => m a -> m sep -> m [a]
P.sepBy (m (FlagName, Bool)
onFlag m (FlagName, Bool) -> m (FlagName, Bool) -> m (FlagName, Bool)
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> m (FlagName, Bool)
offFlag) m ()
forall (m :: * -> *). CharParsing m => m ()
P.skipSpaces1
where
onFlag :: m (FlagName, Bool)
onFlag = do
Maybe Char
_ <- m Char -> m (Maybe Char)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
P.optional (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'+')
FlagName
f <- m FlagName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m FlagName
parsec
(FlagName, Bool) -> m (FlagName, Bool)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (FlagName
f, Bool
True)
offFlag :: m (FlagName, Bool)
offFlag = do
Char
_ <- Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'-'
FlagName
f <- m FlagName
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m FlagName
parsec
(FlagName, Bool) -> m (FlagName, Bool)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (FlagName
f, Bool
False)