Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more liberal white space parsing in the the mixin field #5293

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cabal/Distribution/CabalSpecVersion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ data CabalSpecVersion
| CabalSpecV1_24
| CabalSpecV2_0
| CabalSpecV2_2
| CabalSpecV3_0
deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic)

cabalSpecLatest :: CabalSpecVersion
cabalSpecLatest = CabalSpecV2_2
cabalSpecLatest = CabalSpecV3_0

cabalSpecFeatures :: CabalSpecVersion -> Set.Set CabalFeature
cabalSpecFeatures CabalSpecOld = Set.empty
Expand All @@ -30,13 +31,15 @@ cabalSpecFeatures CabalSpecV2_2 = Set.fromList
[ Elif
, CommonStanzas
]
cabalSpecFeatures CabalSpecV3_0 = cabalSpecFeatures CabalSpecV2_2

cabalSpecSupports :: CabalSpecVersion -> [Int] -> Bool
cabalSpecSupports CabalSpecOld v = v < [1,21]
cabalSpecSupports CabalSpecV1_22 v = v < [1,23]
cabalSpecSupports CabalSpecV1_24 v = v < [1,25]
cabalSpecSupports CabalSpecV2_0 v = v < [2,1]
cabalSpecSupports CabalSpecV2_2 _ = True
cabalSpecSupports CabalSpecV2_2 v = v < [2,3]
cabalSpecSupports CabalSpecV3_0 _ = True

specHasCommonStanzas :: CabalSpecVersion -> HasCommonStanzas
specHasCommonStanzas CabalSpecV2_2 = HasCommonStanzas
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/PackageDescription/Parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ parseGenericPackageDescription bs = do
setCabalSpecVersion ver
-- if we get too new version, fail right away
case ver of
Just v | v > mkVersion [2,2] -> parseFailure zeroPos
Just v | v > mkVersion [3,0] -> parseFailure zeroPos
"Unsupported cabal-version. See https://github.com/haskell/cabal/issues/4899."
_ -> pure ()

Expand Down
22 changes: 18 additions & 4 deletions Cabal/Distribution/Types/ModuleRenaming.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Distribution.Types.ModuleRenaming (
isDefaultRenaming,
) where

import Distribution.CabalSpecVersion
import Distribution.Compat.Prelude hiding (empty)
import Prelude ()

Expand Down Expand Up @@ -67,6 +68,19 @@ isDefaultRenaming :: ModuleRenaming -> Bool
isDefaultRenaming DefaultRenaming = True
isDefaultRenaming _ = False

-- | For versions < 3.0 white spaces were not skipped after the '('
-- and ')' tokens in the mixin field. This parser checks the cabal file version
-- and does the correct skipping of spaces.
betweenParens :: CabalParsing m => m a -> m a
betweenParens p = do
csv <- askCabalSpecVersion
if csv >= CabalSpecV3_0
then P.between (P.char '(' >> P.spaces) (P.char ')' >> P.spaces) p
else P.between (P.char '(') (P.char ')') p

-- TODO: Give a sensible error on input "( A as B) instead of (A as B)
-- for cabal files that are declared to be older than 3.0.

instance Binary ModuleRenaming where

instance NFData ModuleRenaming where rnf = genericRnf
Expand All @@ -87,18 +101,18 @@ instance Parsec ModuleRenaming where
-- NB: try not necessary as the first token is obvious
parsec = P.choice [ parseRename, parseHiding, return DefaultRenaming ]
where
cma = P.char ',' >> P.spaces
parseRename = do
rns <- P.between (P.char '(') (P.char ')') parseList
rns <- betweenParens parseList
P.spaces
return (ModuleRenaming rns)
parseHiding = do
_ <- P.string "hiding"
P.spaces
hides <- P.between (P.char '(') (P.char ')')
(P.sepBy parsec (P.char ',' >> P.spaces))
hides <- betweenParens (P.sepBy parsec cma)
return (HidingRenaming hides)
parseList =
P.sepBy parseEntry (P.char ',' >> P.spaces)
P.sepBy parseEntry cma
parseEntry = do
orig <- parsec
P.spaces
Expand Down