@@ -42,7 +42,7 @@ import Distribution.FieldGrammar
42
42
import Distribution.PackageDescription
43
43
import Distribution.PackageDescription.FieldGrammar
44
44
import Distribution.PackageDescription.Quirks (patchQuirks )
45
- import Distribution.Parsec.Class (parsec )
45
+ import Distribution.Parsec.Class (parsec , Versioned , SpecVersionOld , SpecVersion22 )
46
46
import Distribution.Parsec.Common
47
47
import Distribution.Parsec.ConfVar (parseConditionConfVar )
48
48
import Distribution.Parsec.Field (FieldName , getName )
@@ -141,15 +141,20 @@ parseGenericPackageDescription' lexWarnings fs = do
141
141
142
142
-- PackageDescription
143
143
let (fields, sectionFields) = takeFields fs'
144
- pd <- parseFieldGrammar fields packageDescriptionFieldGrammar
144
+ pd <- parseFieldGrammar fields ( packageDescriptionFieldGrammar :: ParsecFieldGrammar' SpecVersionOld PackageDescription )
145
145
maybeWarnCabalVersion syntax pd
146
146
147
147
-- Sections
148
148
let gpd = emptyGpd & L. packageDescription .~ pd
149
149
150
150
-- elif conditional is accepted if spec version is >= 2.1
151
151
let hasElif = if specVersion pd >= mkVersion [2 ,1 ] then HasElif else NoElif
152
- execStateT (goSections hasElif sectionFields) gpd
152
+ let goSections' =
153
+ if specVersion pd >= mkVersion [2 ,1 ]
154
+ then goSections ([] :: [SpecVersion22 ])
155
+ else goSections ([] :: [SpecVersionOld ])
156
+
157
+ execStateT (goSections' hasElif sectionFields) gpd
153
158
where
154
159
emptyGpd :: GenericPackageDescription
155
160
emptyGpd = GenericPackageDescription emptyPackageDescription [] Nothing [] [] [] [] []
@@ -180,8 +185,8 @@ parseGenericPackageDescription' lexWarnings fs = do
180
185
maybeWarnCabalVersion _ _ = return ()
181
186
182
187
-- Sections
183
- goSections :: HasElif -> [Field Position ] -> SectionParser ()
184
- goSections hasElif = traverse_ process
188
+ goSections :: forall proxy v . Versioned v => proxy v -> HasElif -> [Field Position ] -> SectionParser ()
189
+ goSections proxyV hasElif = traverse_ process
185
190
where
186
191
process (Field (Name pos name) _) =
187
192
lift $ parseWarning pos PWTTrailingFields $
@@ -191,56 +196,58 @@ goSections hasElif = traverse_ process
191
196
192
197
snoc x xs = xs ++ [x]
193
198
199
+ parseCondTree' = parseCondTree proxyV
200
+
194
201
parseSection :: Name Position -> [SectionArg Position ] -> [Field Position ] -> SectionParser ()
195
202
parseSection (Name pos name) args fields
196
203
| name == " library" && null args = do
197
- lib <- lift $ parseCondTree hasElif (libraryFieldGrammar Nothing ) (targetBuildDepends . libBuildInfo) fields
204
+ lib <- lift $ parseCondTree' hasElif (libraryFieldGrammar Nothing ) (targetBuildDepends . libBuildInfo) fields
198
205
-- TODO: check that library is defined once
199
206
L. condLibrary ?= lib
200
207
201
208
-- Sublibraries
202
209
| name == " library" = do
203
210
-- TODO: check cabal-version
204
211
name' <- parseUnqualComponentName pos args
205
- lib <- lift $ parseCondTree hasElif (libraryFieldGrammar $ Just name') (targetBuildDepends . libBuildInfo) fields
212
+ lib <- lift $ parseCondTree' hasElif (libraryFieldGrammar $ Just name') (targetBuildDepends . libBuildInfo) fields
206
213
-- TODO check duplicate name here?
207
214
L. condSubLibraries %= snoc (name', lib)
208
215
209
216
| name == " foreign-library" = do
210
217
name' <- parseUnqualComponentName pos args
211
- flib <- lift $ parseCondTree hasElif (foreignLibFieldGrammar name') (targetBuildDepends . foreignLibBuildInfo) fields
218
+ flib <- lift $ parseCondTree' hasElif (foreignLibFieldGrammar name') (targetBuildDepends . foreignLibBuildInfo) fields
212
219
-- TODO check duplicate name here?
213
220
L. condForeignLibs %= snoc (name', flib)
214
221
215
222
| name == " executable" = do
216
223
name' <- parseUnqualComponentName pos args
217
- exe <- lift $ parseCondTree hasElif (executableFieldGrammar name') (targetBuildDepends . buildInfo) fields
224
+ exe <- lift $ parseCondTree' hasElif (executableFieldGrammar name') (targetBuildDepends . buildInfo) fields
218
225
-- TODO check duplicate name here?
219
226
L. condExecutables %= snoc (name', exe)
220
227
221
228
| name == " test-suite" = do
222
229
name' <- parseUnqualComponentName pos args
223
- testStanza <- lift $ parseCondTree hasElif testSuiteFieldGrammar (targetBuildDepends . _testStanzaBuildInfo) fields
230
+ testStanza <- lift $ parseCondTree' hasElif testSuiteFieldGrammar (targetBuildDepends . _testStanzaBuildInfo) fields
224
231
testSuite <- lift $ traverse (validateTestSuite pos) testStanza
225
232
-- TODO check duplicate name here?
226
233
L. condTestSuites %= snoc (name', testSuite)
227
234
228
235
| name == " benchmark" = do
229
236
name' <- parseUnqualComponentName pos args
230
- benchStanza <- lift $ parseCondTree hasElif benchmarkFieldGrammar (targetBuildDepends . _benchmarkStanzaBuildInfo) fields
237
+ benchStanza <- lift $ parseCondTree' hasElif benchmarkFieldGrammar (targetBuildDepends . _benchmarkStanzaBuildInfo) fields
231
238
bench <- lift $ traverse (validateBenchmark pos) benchStanza
232
239
-- TODO check duplicate name here?
233
240
L. condBenchmarks %= snoc (name', bench)
234
241
235
242
| name == " flag" = do
236
243
name' <- parseName pos args
237
244
name'' <- lift $ runFieldParser' pos parsec name' `recoverWith` mkFlagName " "
238
- flag <- lift $ parseFields fields (flagFieldGrammar name'')
245
+ flag <- lift $ parseFields proxyV fields (flagFieldGrammar name'')
239
246
-- Check default flag
240
247
L. genPackageFlags %= snoc flag
241
248
242
249
| name == " custom-setup" && null args = do
243
- sbi <- lift $ parseFields fields (setupBInfoFieldGrammar False )
250
+ sbi <- lift $ parseFields proxyV fields (setupBInfoFieldGrammar False )
244
251
L. packageDescription . L. setupBuildInfo ?= sbi
245
252
246
253
| name == " source-repository" = do
@@ -254,7 +261,7 @@ goSections hasElif = traverse_ process
254
261
parseFailure pos $ " Invalid source-repository kind " ++ show args
255
262
pure RepoHead
256
263
257
- sr <- lift $ parseFields fields (sourceRepoFieldGrammar kind)
264
+ sr <- lift $ parseFields proxyV fields (sourceRepoFieldGrammar kind)
258
265
L. packageDescription . L. sourceRepos %= snoc sr
259
266
260
267
| otherwise = lift $
@@ -279,10 +286,11 @@ parseUnqualComponentName pos args = mkUnqualComponentName <$> parseName pos args
279
286
280
287
-- | Parse a non-recursive list of fields.
281
288
parseFields
282
- :: [Field Position ] -- ^ fields to be parsed
283
- -> ParsecFieldGrammar' a
289
+ :: proxy v
290
+ -> [Field Position ] -- ^ fields to be parsed
291
+ -> ParsecFieldGrammar' v a
284
292
-> ParseResult a
285
- parseFields fields grammar = do
293
+ parseFields _ fields grammar = do
286
294
let (fs0, ss) = partitionFields fields
287
295
traverse_ (traverse_ warnInvalidSubsection) ss
288
296
parseFieldGrammar fs0 grammar
@@ -296,13 +304,14 @@ data HasElif = HasElif | NoElif
296
304
deriving (Eq , Show )
297
305
298
306
parseCondTree
299
- :: forall a c .
300
- HasElif -- ^ accept @elif@
301
- -> ParsecFieldGrammar' a -- ^ grammar
302
- -> (a -> c ) -- ^ condition extractor
307
+ :: forall a c proxy v .
308
+ proxy v
309
+ -> HasElif -- ^ accept @elif@
310
+ -> ParsecFieldGrammar' v a -- ^ grammar
311
+ -> (a -> c ) -- ^ condition extractor
303
312
-> [Field Position ]
304
313
-> ParseResult (CondTree ConfVar c a )
305
- parseCondTree hasElif grammar cond = go
314
+ parseCondTree _ hasElif grammar cond = go
306
315
where
307
316
go fields = do
308
317
let (fs, ss) = partitionFields fields
@@ -432,8 +441,9 @@ sectionizeFields fs = case classifyFields fs of
432
441
data Syntax = OldSyntax | NewSyntax
433
442
deriving (Eq , Show )
434
443
444
+ -- TODO:
435
445
libFieldNames :: [FieldName ]
436
- libFieldNames = fieldGrammarKnownFieldList (libraryFieldGrammar Nothing )
446
+ libFieldNames = fieldGrammarKnownFieldList (libraryFieldGrammar Nothing :: ParsecFieldGrammar' SpecVersionOld Library )
437
447
438
448
-------------------------------------------------------------------------------
439
449
-- Suplementary build information
@@ -467,11 +477,11 @@ parseHookedBuildInfo' lexWarnings fs = do
467
477
parseLib :: Fields Position -> ParseResult (Maybe BuildInfo )
468
478
parseLib fields
469
479
| Map. null fields = pure Nothing
470
- | otherwise = Just <$> parseFieldGrammar fields buildInfoFieldGrammar
480
+ | otherwise = Just <$> parseFieldGrammar fields ( buildInfoFieldGrammar :: ParsecFieldGrammar' SpecVersion22 BuildInfo )
471
481
472
482
parseExe :: (UnqualComponentName , Fields Position ) -> ParseResult (UnqualComponentName , BuildInfo )
473
483
parseExe (n, fields) = do
474
- bi <- parseFieldGrammar fields buildInfoFieldGrammar
484
+ bi <- parseFieldGrammar fields ( buildInfoFieldGrammar :: ParsecFieldGrammar' SpecVersion22 BuildInfo )
475
485
pure (n, bi)
476
486
477
487
stanzas :: [Field Position ] -> ParseResult (Fields Position , [(UnqualComponentName , Fields Position )])
0 commit comments