2 {-# LANGUAGE ConstraintKinds #-}
3 {-# LANGUAGE FunctionalDependencies #-}
4 {-# LANGUAGE RankNTypes #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
6 {-# LANGUAGE UndecidableSuperClasses #-}
8 module Distribution
.FieldGrammar
.Class
14 , defaultFreeTextFieldDefST
17 import Distribution
.Compat
.Lens
18 import Distribution
.Compat
.Prelude
21 import Distribution
.CabalSpecVersion
(CabalSpecVersion
)
22 import Distribution
.Compat
.Newtype
(Newtype
)
23 import Distribution
.FieldGrammar
.Newtypes
24 import Distribution
.Fields
.Field
25 import Distribution
.Utils
.ShortText
27 -- | 'FieldGrammar' is parametrised by
29 -- * @s@ which is a structure we are parsing. We need this to provide prettyprinter
32 -- * @a@ type of the field.
34 -- /Note:/ We'd like to have @forall s. Applicative (f s)@ context.
46 -- | Unfocus, zoom out, /blur/ 'FieldGrammar'.
47 blurFieldGrammar
:: ALens
' a b
-> g b d
-> g a d
49 -- | Field which should be defined, exactly once.
57 -- ^ lens into the field
60 -- | Boolean field with a default value.
65 -- ^ lens into the field
78 -- ^ lens into the field
81 -- | Optional field with default value.
83 :: (c b
, Newtype a b
, Eq a
)
89 -- ^ @'Lens'' s a@: lens into the field
94 -- | Free text field is essentially 'optionalFieldDefAla` with @""@
95 -- as the default and "accept everything" parser.
100 -> ALens
' s
(Maybe String)
101 -- ^ lens into the field
102 -> g s
(Maybe String)
104 -- | Free text field is essentially 'optionalFieldDefAla` with @""@
105 -- as the default and "accept everything" parser.
111 -- ^ lens into the field
117 -> ALens
' s ShortText
118 -- ^ lens into the field
123 -- Values are combined with 'mappend'.
125 -- /Note:/ 'optionalFieldAla' is a @monoidalField@ with 'Last' monoid.
127 :: (c b
, Monoid a
, Newtype a b
)
133 -- ^ lens into the field
136 -- | Parser matching all fields with a name starting with a prefix.
139 -- ^ field name prefix
140 -> ALens
' s
[(String, String)]
141 -- ^ lens into the field
142 -> g s
[(String, String)]
144 -- | Known field, which we don't parse, nor pretty print.
145 knownField
:: FieldName
-> g s
()
147 -- | Field which is parsed but not pretty printed.
148 hiddenField
:: g s a
-> g s a
150 -- | Deprecated since
155 -- ^ deprecation message
159 -- | Removed in. If we encounter removed field, parsing fails.
168 -- | Annotate field with since spec-version.
177 -- | Annotate field with since spec-version.
178 -- This is used to recognise, but warn about the field.
179 -- It is used to process @other-extensions@ field.
181 -- Default implementation is to not warn.
189 availableSinceWarn _
= id
191 -- | Field which can be defined at most once.
193 :: (FieldGrammar c g
, c
(Identity a
))
197 -- ^ lens into the field
199 uniqueField fn l
= uniqueFieldAla fn Identity l
201 -- | Field which can be defined at most once.
203 :: (FieldGrammar c g
, c
(Identity a
))
206 -> ALens
' s
(Maybe a
)
207 -- ^ lens into the field
209 optionalField fn l
= optionalFieldAla fn Identity l
211 -- | Optional field with default value.
213 :: (FieldGrammar c g
, Functor
(g s
), c
(Identity a
), Eq a
)
217 -- ^ @'Lens'' s a@: lens into the field
221 optionalFieldDef fn l x
= optionalFieldDefAla fn Identity l x
223 -- | Field which can be define multiple times, and the results are @mappend@ed.
225 :: (FieldGrammar c g
, c
(Identity a
), Monoid a
)
229 -- ^ lens into the field
231 monoidalField fn l
= monoidalFieldAla fn Identity l
233 -- | Default implementation for 'freeTextFieldDefST'.
234 defaultFreeTextFieldDefST
235 :: (Functor
(g s
), FieldGrammar c g
)
237 -> ALens
' s ShortText
238 -- ^ lens into the field
240 defaultFreeTextFieldDefST fn l
=
241 toShortText
<$> freeTextFieldDef fn
(cloneLens l
. st
)
243 st
:: Lens
' ShortText
String
244 st f s
= toShortText
<$> f
(fromShortText s
)