11{-# LANGUAGE CPP #-}
2+ {-# LANGUAGE DeriveGeneric #-}
23{-# LANGUAGE DeriveTraversable #-}
34{-# LANGUAGE StandaloneDeriving #-}
45
@@ -17,6 +18,12 @@ module Distribution.Fields.Field
1718 , SectionArg (.. )
1819 , sectionArgAnn
1920
21+ -- * Comment
22+ , Comment (.. )
23+ , WithComments (.. )
24+ , mapComments
25+ , mapCommentedData
26+
2027 -- * Name
2128 , FieldName
2229 , Name (.. )
@@ -44,11 +51,26 @@ import qualified Data.Foldable1 as F1
4451-- Cabal file
4552-------------------------------------------------------------------------------
4653
54+ data Comment ann = Comment ! ByteString ! ann
55+ deriving (Show , Generic , Eq , Ord , Functor )
56+
57+ data WithComments ann = WithComments
58+ { justComments :: ! [Comment ann ]
59+ , unComments :: ! ann
60+ }
61+ deriving (Show , Generic , Eq , Ord , Functor )
62+
63+ mapComments :: ([Comment ann ] -> [Comment ann ]) -> WithComments ann -> WithComments ann
64+ mapComments f (WithComments cs x) = WithComments (f cs) x
65+
66+ mapCommentedData :: (ann -> ann ) -> WithComments ann -> WithComments ann
67+ mapCommentedData f (WithComments cs x) = WithComments cs (f x)
68+
4769-- | A Cabal-like file consists of a series of fields (@foo: bar@) and sections (@library ...@).
4870data Field ann
4971 = Field ! (Name ann ) [FieldLine ann ]
5072 | Section ! (Name ann ) [SectionArg ann ] [Field ann ]
51- deriving (Eq , Show , Functor , Foldable , Traversable )
73+ deriving (Eq , Show , Functor , Foldable , Traversable , Generic )
5274
5375-- | @since 3.12.0.0
5476deriving instance Ord ann => Ord (Field ann )
@@ -73,7 +95,7 @@ fieldUniverse f@(Field _ _) = [f]
7395--
7496-- /Invariant:/ 'ByteString' has no newlines.
7597data FieldLine ann = FieldLine ! ann ! ByteString
76- deriving (Eq , Show , Functor , Foldable , Traversable )
98+ deriving (Eq , Show , Functor , Foldable , Traversable , Generic )
7799
78100-- | @since 3.12.0.0
79101deriving instance Ord ann => Ord (FieldLine ann )
@@ -94,7 +116,7 @@ data SectionArg ann
94116 SecArgStr ! ann ! ByteString
95117 | -- | everything else, mm. operators (e.g. in if-section conditionals)
96118 SecArgOther ! ann ! ByteString
97- deriving (Eq , Show , Functor , Foldable , Traversable )
119+ deriving (Eq , Show , Functor , Foldable , Traversable , Generic )
98120
99121-- | @since 3.12.0.0
100122deriving instance Ord ann => Ord (SectionArg ann )
@@ -115,7 +137,7 @@ type FieldName = ByteString
115137--
116138-- /Invariant/: 'ByteString' is lower-case ASCII.
117139data Name ann = Name ! ann ! FieldName
118- deriving (Eq , Show , Functor , Foldable , Traversable )
140+ deriving (Eq , Show , Functor , Foldable , Traversable , Generic )
119141
120142-- | @since 3.12.0.0
121143deriving instance Ord ann => Ord (Name ann )
0 commit comments