|
1 | | -{-# LANGUAGE FlexibleContexts, RankNTypes #-} |
| 1 | +{-# LANGUAGE DeriveDataTypeable #-} |
| 2 | +{-# LANGUAGE DeriveGeneric #-} |
2 | 3 | module Distribution.CabalSpecVersion where |
3 | 4 |
|
4 | | -import Distribution.Parsec.Class (Parsec (..), ParsecParser) |
| 5 | +import Prelude () |
| 6 | +import Distribution.Compat.Prelude |
| 7 | +import qualified Data.Set as Set |
| 8 | + |
| 9 | +-- | Different Cabal-the-spec versions. |
| 10 | +-- |
| 11 | +-- We branch based on this at least in the parser. |
| 12 | +-- |
| 13 | +data CabalSpecVersion |
| 14 | + = CabalSpecOld |
| 15 | + | CabalSpecV20 |
| 16 | + | CabalSpecV22 |
| 17 | + deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic) |
| 18 | + |
| 19 | +cabalSpecLatest :: CabalSpecVersion |
| 20 | +cabalSpecLatest = CabalSpecV22 |
| 21 | + |
| 22 | +cabalSpecFeatures :: CabalSpecVersion -> Set.Set CabalFeature |
| 23 | +cabalSpecFeatures CabalSpecOld = Set.empty |
| 24 | +cabalSpecFeatures CabalSpecV20 = Set.empty |
| 25 | +cabalSpecFeatures CabalSpecV22 = Set.fromList |
| 26 | + [ Elif |
| 27 | + , CommonStanzas |
| 28 | + ] |
| 29 | + |
| 30 | +cabalSpecSupports :: CabalSpecVersion -> [Int] -> Bool |
| 31 | +cabalSpecSupports CabalSpecOld v = v < [1,25] |
| 32 | +cabalSpecSupports CabalSpecV20 v = v < [2,1] |
| 33 | +cabalSpecSupports CabalSpecV22 _ = True |
| 34 | + |
| 35 | +specHasCommonStanzas :: CabalSpecVersion -> HasCommonStanzas |
| 36 | +specHasCommonStanzas CabalSpecV22 = HasCommonStanzas |
| 37 | +specHasCommonStanzas _ = NoCommonStanzas |
| 38 | + |
| 39 | +specHasElif :: CabalSpecVersion -> HasElif |
| 40 | +specHasElif CabalSpecV22 = HasElif |
| 41 | +specHasElif _ = NoElif |
5 | 42 |
|
6 | | --- A class to select how to parse different fields. |
7 | | -class CabalSpecVersion v where |
8 | | - -- | @v@ can act as own proxy |
9 | | - cabalSpecVersion :: v |
10 | | - |
11 | | - -- | Parsec parser according to the spec version |
12 | | - specParsec :: Parsec a => v -> ParsecParser a |
13 | | - |
14 | | - -- given a version, whether this spec knows about it's fields |
15 | | - specKnows :: v -> [Int] -> Bool |
16 | | - |
17 | | - specHasElif :: v -> HasElif |
18 | | - specHasCommonStanzas :: v -> HasCommonStanzas |
19 | | - |
20 | | -data CabalSpecOld = CabalSpecOld |
21 | | -data CabalSpecV20 = CabalSpecV20 |
22 | | -data CabalSpecV22 = CabalSpecV22 |
23 | | - |
24 | | -instance CabalSpecVersion CabalSpecOld where |
25 | | - cabalSpecVersion = CabalSpecOld |
26 | | - specParsec _ = parsec |
27 | | - specKnows _ vs = vs < [1,25] |
28 | | - specHasElif _ = NoElif |
29 | | - specHasCommonStanzas _ = NoCommonStanzas |
30 | | - |
31 | | -instance CabalSpecVersion CabalSpecV20 where |
32 | | - cabalSpecVersion = CabalSpecV20 |
33 | | - specParsec _ = parsec |
34 | | - specKnows _ vs = vs < [2,1] |
35 | | - specHasElif _ = NoElif |
36 | | - specHasCommonStanzas _ = NoCommonStanzas |
37 | | - |
38 | | -instance CabalSpecVersion CabalSpecV22 where |
39 | | - cabalSpecVersion = CabalSpecV22 |
40 | | - specParsec _ = parsec22 |
41 | | - specKnows _ _ = True |
42 | | - specHasElif _ = HasElif |
43 | | - specHasCommonStanzas _ = HasCommonStanzas |
| 43 | +------------------------------------------------------------------------------- |
| 44 | +-- Features |
| 45 | +------------------------------------------------------------------------------- |
44 | 46 |
|
45 | | -type CabalSpecLatest = CabalSpecV22 |
| 47 | +data CabalFeature |
| 48 | + = Elif |
| 49 | + | CommonStanzas |
| 50 | + deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic) |
46 | 51 |
|
47 | 52 | ------------------------------------------------------------------------------- |
48 | | --- "Booleans" |
| 53 | +-- Booleans |
49 | 54 | ------------------------------------------------------------------------------- |
50 | 55 |
|
51 | 56 | data HasElif = HasElif | NoElif |
|
0 commit comments