@@ -8,6 +8,7 @@ module Distribution.Types.ModuleRenaming (
8
8
isDefaultRenaming ,
9
9
) where
10
10
11
+ import Distribution.CabalSpecVersion
11
12
import Distribution.Compat.Prelude hiding (empty )
12
13
import Prelude ()
13
14
@@ -67,6 +68,19 @@ isDefaultRenaming :: ModuleRenaming -> Bool
67
68
isDefaultRenaming DefaultRenaming = True
68
69
isDefaultRenaming _ = False
69
70
71
+ -- | For versions < 3.0 white spaces were not skipped after the '('
72
+ -- and ')' tokens in the mixin field. This parser checks the cabal file version
73
+ -- and does the correct skipping of spaces.
74
+ betweenParens :: CabalParsing m => m a -> m a
75
+ betweenParens p = do
76
+ csv <- askCabalSpecVersion
77
+ if csv >= CabalSpecV3_0
78
+ then P. between (P. char ' (' >> P. spaces) (P. char ' )' >> P. spaces) p
79
+ else P. between (P. char ' (' ) (P. char ' )' ) p
80
+
81
+ -- TODO: Give a sensible error on input "( A as B) instead of (A as B)
82
+ -- for cabal files that are declared to be older than 3.0.
83
+
70
84
instance Binary ModuleRenaming where
71
85
72
86
instance NFData ModuleRenaming where rnf = genericRnf
@@ -87,18 +101,18 @@ instance Parsec ModuleRenaming where
87
101
-- NB: try not necessary as the first token is obvious
88
102
parsec = P. choice [ parseRename, parseHiding, return DefaultRenaming ]
89
103
where
104
+ cma = P. char ' ,' >> P. spaces
90
105
parseRename = do
91
- rns <- P. between ( P. char ' ( ' ) ( P. char ' ) ' ) parseList
106
+ rns <- betweenParens parseList
92
107
P. spaces
93
108
return (ModuleRenaming rns)
94
109
parseHiding = do
95
110
_ <- P. string " hiding"
96
111
P. spaces
97
- hides <- P. between (P. char ' (' ) (P. char ' )' )
98
- (P. sepBy parsec (P. char ' ,' >> P. spaces))
112
+ hides <- betweenParens (P. sepBy parsec cma)
99
113
return (HidingRenaming hides)
100
114
parseList =
101
- P. sepBy parseEntry ( P. char ' , ' >> P. spaces)
115
+ P. sepBy parseEntry cma
102
116
parseEntry = do
103
117
orig <- parsec
104
118
P. spaces
0 commit comments