Skip to content

Commit 9705f68

Browse files
authored
Merge pull request #4971 from phadej/leading-comma-2
Leading comma 2
2 parents a85ef47 + a316340 commit 9705f68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1469
-404
lines changed

Cabal/Cabal.cabal

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ extra-source-files:
3838
tests/ParserTests/errors/common2.errors
3939
tests/ParserTests/errors/common3.cabal
4040
tests/ParserTests/errors/common3.errors
41+
tests/ParserTests/errors/leading-comma.cabal
42+
tests/ParserTests/errors/leading-comma.errors
4143
tests/ParserTests/regressions/Octree-0.5.cabal
4244
tests/ParserTests/regressions/Octree-0.5.format
4345
tests/ParserTests/regressions/common.cabal
@@ -55,10 +57,14 @@ extra-source-files:
5557
tests/ParserTests/regressions/haddock-api-2.18.1-check.cabal
5658
tests/ParserTests/regressions/issue-774.cabal
5759
tests/ParserTests/regressions/issue-774.format
60+
tests/ParserTests/regressions/leading-comma.cabal
61+
tests/ParserTests/regressions/leading-comma.format
5862
tests/ParserTests/regressions/nothing-unicode.cabal
5963
tests/ParserTests/regressions/nothing-unicode.format
6064
tests/ParserTests/regressions/shake.cabal
6165
tests/ParserTests/regressions/shake.format
66+
tests/ParserTests/regressions/wl-pprint-indef.cabal
67+
tests/ParserTests/regressions/wl-pprint-indef.format
6268
tests/ParserTests/warnings/bom.cabal
6369
tests/ParserTests/warnings/bool.cabal
6470
tests/ParserTests/warnings/deprecatedfield.cabal
@@ -148,6 +154,7 @@ library
148154
Distribution.Backpack.ModSubst
149155
Distribution.Backpack.ModuleShape
150156
Distribution.Backpack.PreModuleShape
157+
Distribution.CabalSpecVersion
151158
Distribution.Utils.IOData
152159
Distribution.Utils.LogProgress
153160
Distribution.Utils.MapAccum
@@ -302,9 +309,11 @@ library
302309
build-depends:
303310
transformers,
304311
mtl >= 2.1 && <2.3,
312+
text >= 1.2.2.2 && <1.3,
305313
parsec >= 3.1.9 && <3.2
306314
exposed-modules:
307-
Distribution.Compat.Parsec
315+
Distribution.Compat.Parsing
316+
Distribution.Compat.CharParsing
308317
Distribution.FieldGrammar
309318
Distribution.FieldGrammar.Class
310319
Distribution.FieldGrammar.Parsec
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
module Distribution.CabalSpecVersion where
4+
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
42+
43+
-------------------------------------------------------------------------------
44+
-- Features
45+
-------------------------------------------------------------------------------
46+
47+
data CabalFeature
48+
= Elif
49+
| CommonStanzas
50+
deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic)
51+
52+
-------------------------------------------------------------------------------
53+
-- Booleans
54+
-------------------------------------------------------------------------------
55+
56+
data HasElif = HasElif | NoElif
57+
deriving (Eq, Show)
58+
59+
data HasCommonStanzas = HasCommonStanzas | NoCommonStanzas
60+
deriving (Eq, Show)

0 commit comments

Comments
 (0)