Skip to content

Commit 0efb2ea

Browse files
committed
Introduce CharParsing, redo leading-comma PR
1 parent 195702f commit 0efb2ea

Some content is hidden

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

43 files changed

+1199
-431
lines changed

Cabal/Cabal.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,11 @@ library
309309
build-depends:
310310
transformers,
311311
mtl >= 2.1 && <2.3,
312+
text >= 1.2.2.2 && <1.3,
312313
parsec >= 3.1.9 && <3.2
313314
exposed-modules:
314-
Distribution.Compat.Parsec
315+
Distribution.Compat.Parsing
316+
Distribution.Compat.CharParsing
315317
Distribution.FieldGrammar
316318
Distribution.FieldGrammar.Class
317319
Distribution.FieldGrammar.Parsec

Cabal/Distribution/CabalSpecVersion.hs

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,56 @@
1-
{-# LANGUAGE FlexibleContexts, RankNTypes #-}
1+
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
23
module Distribution.CabalSpecVersion where
34

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
542

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+
-------------------------------------------------------------------------------
4446

45-
type CabalSpecLatest = CabalSpecV22
47+
data CabalFeature
48+
= Elif
49+
| CommonStanzas
50+
deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic)
4651

4752
-------------------------------------------------------------------------------
48-
-- "Booleans"
53+
-- Booleans
4954
-------------------------------------------------------------------------------
5055

5156
data HasElif = HasElif | NoElif

0 commit comments

Comments
 (0)