Cabal-syntax
Safe HaskellSafe-Inferred
LanguageHaskell2010

Distribution.Types.CondTree

Synopsis

Documentation

data CondTree v a Source #

A CondTree is used to represent the conditional structure of a Cabal file, reflecting a syntax element subject to constraints, and then any number of sub-elements which may be enabled subject to some condition. Both a and c are usually Monoids.

To be more concrete, consider the following fragment of a Cabal file:

build-depends: base >= 4.0
if flag(extra)
    build-depends: base >= 4.2

One way to represent this is to have CondTree ConfVar [Dependency] BuildInfo. Here, condTreeData represents the actual fields which are not behind any conditional, while condTreeComponents recursively records any further fields which are behind a conditional. condTreeConstraints records the constraints (in this case, base >= 4.0) which would be applied if you use this syntax; in general, this is derived off of targetBuildInfo (perhaps a good refactoring would be to convert this into an opaque type, with a smart constructor that pre-computes the dependencies.)

Constructors

CondNode 

Instances

Instances details
Functor (CondTree v) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

fmap :: (a -> b) -> CondTree v a -> CondTree v b #

(<$) :: a -> CondTree v b -> CondTree v a #

Foldable (CondTree v) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

fold :: Monoid m => CondTree v m -> m #

foldMap :: Monoid m => (a -> m) -> CondTree v a -> m #

foldMap' :: Monoid m => (a -> m) -> CondTree v a -> m #

foldr :: (a -> b -> b) -> b -> CondTree v a -> b #

foldr' :: (a -> b -> b) -> b -> CondTree v a -> b #

foldl :: (b -> a -> b) -> b -> CondTree v a -> b #

foldl' :: (b -> a -> b) -> b -> CondTree v a -> b #

foldr1 :: (a -> a -> a) -> CondTree v a -> a #

foldl1 :: (a -> a -> a) -> CondTree v a -> a #

toList :: CondTree v a -> [a] #

null :: CondTree v a -> Bool #

length :: CondTree v a -> Int #

elem :: Eq a => a -> CondTree v a -> Bool #

maximum :: Ord a => CondTree v a -> a #

minimum :: Ord a => CondTree v a -> a #

sum :: Num a => CondTree v a -> a #

product :: Num a => CondTree v a -> a #

Traversable (CondTree v) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

traverse :: Applicative f => (a -> f b) -> CondTree v a -> f (CondTree v b) #

sequenceA :: Applicative f => CondTree v (f a) -> f (CondTree v a) #

mapM :: Monad m => (a -> m b) -> CondTree v a -> m (CondTree v b) #

sequence :: Monad m => CondTree v (m a) -> m (CondTree v a) #

(Structured v, Structured a) => Structured (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

structure :: Proxy (CondTree v a) -> Structure Source #

structureHash' :: Tagged (CondTree v a) MD5

(Binary v, Binary a) => Binary (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

put :: CondTree v a -> Put #

get :: Get (CondTree v a) #

putList :: [CondTree v a] -> Put #

(NFData v, NFData a) => NFData (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

rnf :: CondTree v a -> () #

Monoid a => Monoid (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

mempty :: CondTree v a #

mappend :: CondTree v a -> CondTree v a -> CondTree v a #

mconcat :: [CondTree v a] -> CondTree v a #

Semigroup a => Semigroup (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

(<>) :: CondTree v a -> CondTree v a -> CondTree v a #

sconcat :: NonEmpty (CondTree v a) -> CondTree v a #

stimes :: Integral b => b -> CondTree v a -> CondTree v a #

(Data v, Data a) => Data (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CondTree v a -> c (CondTree v a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (CondTree v a) #

toConstr :: CondTree v a -> Constr #

dataTypeOf :: CondTree v a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (CondTree v a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CondTree v a)) #

gmapT :: (forall b. Data b => b -> b) -> CondTree v a -> CondTree v a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CondTree v a -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CondTree v a -> r #

gmapQ :: (forall d. Data d => d -> u) -> CondTree v a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> CondTree v a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> CondTree v a -> m (CondTree v a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CondTree v a -> m (CondTree v a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CondTree v a -> m (CondTree v a) #

Generic (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Associated Types

type Rep (CondTree v a) 
Instance details

Defined in Distribution.Types.CondTree

type Rep (CondTree v a) = D1 ('MetaData "CondTree" "Distribution.Types.CondTree" "Cabal-syntax-3.18.1.0-inplace" 'False) (C1 ('MetaCons "CondNode" 'PrefixI 'True) (S1 ('MetaSel ('Just "condTreeData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "condTreeComponents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [CondBranch v a])))

Methods

from :: CondTree v a -> Rep (CondTree v a) x #

to :: Rep (CondTree v a) x -> CondTree v a #

(Show a, Show v) => Show (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

showsPrec :: Int -> CondTree v a -> ShowS #

show :: CondTree v a -> String #

showList :: [CondTree v a] -> ShowS #

(Eq a, Eq v) => Eq (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

(==) :: CondTree v a -> CondTree v a -> Bool #

(/=) :: CondTree v a -> CondTree v a -> Bool #

type Rep (CondTree v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

type Rep (CondTree v a) = D1 ('MetaData "CondTree" "Distribution.Types.CondTree" "Cabal-syntax-3.18.1.0-inplace" 'False) (C1 ('MetaCons "CondNode" 'PrefixI 'True) (S1 ('MetaSel ('Just "condTreeData") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "condTreeComponents") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [CondBranch v a])))

data CondBranch v a Source #

A CondBranch represents a conditional branch, e.g., if flag(foo) on some syntax a. It also has an optional false branch.

Instances

Instances details
Functor (CondBranch v) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

fmap :: (a -> b) -> CondBranch v a -> CondBranch v b #

(<$) :: a -> CondBranch v b -> CondBranch v a #

Foldable (CondBranch v) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

fold :: Monoid m => CondBranch v m -> m #

foldMap :: Monoid m => (a -> m) -> CondBranch v a -> m #

foldMap' :: Monoid m => (a -> m) -> CondBranch v a -> m #

foldr :: (a -> b -> b) -> b -> CondBranch v a -> b #

foldr' :: (a -> b -> b) -> b -> CondBranch v a -> b #

foldl :: (b -> a -> b) -> b -> CondBranch v a -> b #

foldl' :: (b -> a -> b) -> b -> CondBranch v a -> b #

foldr1 :: (a -> a -> a) -> CondBranch v a -> a #

foldl1 :: (a -> a -> a) -> CondBranch v a -> a #

toList :: CondBranch v a -> [a] #

null :: CondBranch v a -> Bool #

length :: CondBranch v a -> Int #

elem :: Eq a => a -> CondBranch v a -> Bool #

maximum :: Ord a => CondBranch v a -> a #

minimum :: Ord a => CondBranch v a -> a #

sum :: Num a => CondBranch v a -> a #

product :: Num a => CondBranch v a -> a #

Traversable (CondBranch v) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

traverse :: Applicative f => (a -> f b) -> CondBranch v a -> f (CondBranch v b) #

sequenceA :: Applicative f => CondBranch v (f a) -> f (CondBranch v a) #

mapM :: Monad m => (a -> m b) -> CondBranch v a -> m (CondBranch v b) #

sequence :: Monad m => CondBranch v (m a) -> m (CondBranch v a) #

(Structured v, Structured a) => Structured (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

(Binary v, Binary a) => Binary (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

put :: CondBranch v a -> Put #

get :: Get (CondBranch v a) #

putList :: [CondBranch v a] -> Put #

(NFData v, NFData a) => NFData (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

rnf :: CondBranch v a -> () #

(Data v, Data a) => Data (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CondBranch v a -> c (CondBranch v a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (CondBranch v a) #

toConstr :: CondBranch v a -> Constr #

dataTypeOf :: CondBranch v a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (CondBranch v a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CondBranch v a)) #

gmapT :: (forall b. Data b => b -> b) -> CondBranch v a -> CondBranch v a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CondBranch v a -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CondBranch v a -> r #

gmapQ :: (forall d. Data d => d -> u) -> CondBranch v a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> CondBranch v a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> CondBranch v a -> m (CondBranch v a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CondBranch v a -> m (CondBranch v a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CondBranch v a -> m (CondBranch v a) #

Generic (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Associated Types

type Rep (CondBranch v a) 
Instance details

Defined in Distribution.Types.CondTree

type Rep (CondBranch v a) = D1 ('MetaData "CondBranch" "Distribution.Types.CondTree" "Cabal-syntax-3.18.1.0-inplace" 'False) (C1 ('MetaCons "CondBranch" 'PrefixI 'True) (S1 ('MetaSel ('Just "condBranchCondition") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Condition v)) :*: (S1 ('MetaSel ('Just "condBranchIfTrue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (CondTree v a)) :*: S1 ('MetaSel ('Just "condBranchIfFalse") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (CondTree v a))))))

Methods

from :: CondBranch v a -> Rep (CondBranch v a) x #

to :: Rep (CondBranch v a) x -> CondBranch v a #

(Show v, Show a) => Show (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

showsPrec :: Int -> CondBranch v a -> ShowS #

show :: CondBranch v a -> String #

showList :: [CondBranch v a] -> ShowS #

(Eq v, Eq a) => Eq (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

Methods

(==) :: CondBranch v a -> CondBranch v a -> Bool #

(/=) :: CondBranch v a -> CondBranch v a -> Bool #

type Rep (CondBranch v a) Source # 
Instance details

Defined in Distribution.Types.CondTree

type Rep (CondBranch v a) = D1 ('MetaData "CondBranch" "Distribution.Types.CondTree" "Cabal-syntax-3.18.1.0-inplace" 'False) (C1 ('MetaCons "CondBranch" 'PrefixI 'True) (S1 ('MetaSel ('Just "condBranchCondition") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Condition v)) :*: (S1 ('MetaSel ('Just "condBranchIfTrue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (CondTree v a)) :*: S1 ('MetaSel ('Just "condBranchIfFalse") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (CondTree v a))))))

foldCondTree :: b -> (a -> b) -> (b -> b -> b) -> (b -> b -> b) -> CondTree v a -> b Source #

Flatten a CondTree. This will traverse the CondTree by taking all possible paths into account, but merging inclusive when two paths may co-exist, and exclusively when the paths are an if/else

mapCondTree :: (a -> b) -> (Condition v -> Condition w) -> CondTree v a -> CondTree w b Source #

mapTreeData :: (a -> b) -> CondTree v a -> CondTree v b Source #

traverseCondTreeA :: forall v a b f. Applicative f => LensLike f (CondTree v a) (CondTree v b) a b Source #

@Traversal@ for the data

traverseCondTreeV :: forall v a w f. Applicative f => LensLike f (CondTree v a) (CondTree w a) v w Source #

@Traversal@ for the variables

traverseCondBranchA :: forall v a b f. Applicative f => LensLike f (CondBranch v a) (CondBranch v b) a b Source #

@Traversal@ for the data

traverseCondBranchV :: forall v a w f. Applicative f => LensLike f (CondBranch v a) (CondBranch w a) v w Source #

@Traversal@ for the variables

extractCondition :: Eq v => (a -> Bool) -> CondTree v a -> Condition v Source #

Extract the condition matched by the given predicate from a cond tree.

We use this mainly for extracting buildable conditions (see the Note in Distribution.PackageDescription.Configuration), but the function is in fact more general.

simplifyCondTree :: Semigroup a => (v -> Either v Bool) -> CondTree v a -> a Source #

Flattens a CondTree using a partial flag assignment. When a condition cannot be evaluated, both branches are ignored.

simplifyCondBranch :: Semigroup a => (v -> Either v Bool) -> CondBranch v a -> Maybe a Source #

Realizes a CondBranch using partial flag assignment. When a condition cannot be evaluated, returns Nothing.

ignoreConditions :: Semigroup a => CondTree v a -> a Source #

Flatten a CondTree. This will resolve the CondTree by taking all possible paths into account. Note that since branches represent exclusive choices this may not result in a "sane" result.