From c6dab7a7d6231b1b8ec424063106dfc11a687162 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Fri, 14 Feb 2020 10:03:08 +0200 Subject: [PATCH] Disallow spaces around colon in Parsec Dependency --- Cabal/Distribution/Types/Dependency.hs | 38 ++++++++++++++++--- .../ParserTests/regressions/issue-5846.format | 8 ++-- .../PackageTests/MultipleLibraries/cabal.out | 2 +- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Cabal/Distribution/Types/Dependency.hs b/Cabal/Distribution/Types/Dependency.hs index 73a99e43b00..08d4779dfd3 100644 --- a/Cabal/Distribution/Types/Dependency.hs +++ b/Cabal/Distribution/Types/Dependency.hs @@ -57,9 +57,9 @@ instance NFData Dependency where rnf = genericRnf instance Pretty Dependency where pretty (Dependency name ver sublibs) = pretty name - <+> optionalMonoid - (sublibs /= Set.singleton LMainLibName) - (PP.colon <+> PP.braces prettySublibs) + <<>> optionalMonoid + (sublibs /= Set.singleton LMainLibName) + (PP.colon <<>> PP.braces prettySublibs) <+> pretty ver where optionalMonoid True x = x @@ -81,12 +81,40 @@ versionGuardMultilibs expr = do else expr +-- | +-- +-- >>> simpleParsec "mylib:sub" :: Maybe Dependency +-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub")])) +-- +-- >>> simpleParsec "mylib:{sub1,sub2}" :: Maybe Dependency +-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")])) +-- +-- >>> simpleParsec "mylib:{ sub1 , sub2 }" :: Maybe Dependency +-- Just (Dependency (PackageName "mylib") AnyVersion (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")])) +-- +-- >>> simpleParsec "mylib:{ sub1 , sub2 } ^>= 42" :: Maybe Dependency +-- Just (Dependency (PackageName "mylib") (MajorBoundVersion (mkVersion [42])) (fromList [LSubLibName (UnqualComponentName "sub1"),LSubLibName (UnqualComponentName "sub2")])) +-- +-- Spaces around colon are not allowed: +-- +-- >>> simpleParsec "mylib: sub" :: Maybe Dependency +-- Nothing +-- +-- >>> simpleParsec "mylib :sub" :: Maybe Dependency +-- Nothing +-- +-- >>> simpleParsec "mylib: {sub1,sub2}" :: Maybe Dependency +-- Nothing +-- +-- >>> simpleParsec "mylib :{sub1,sub2}" :: Maybe Dependency +-- Nothing +-- instance Parsec Dependency where parsec = do - name <- lexemeParsec + name <- parsec libs <- option [LMainLibName] - $ (char ':' *> spaces *>) + $ (char ':' *>) $ versionGuardMultilibs $ pure <$> parseLib name <|> parseMultipleLibs name diff --git a/Cabal/tests/ParserTests/regressions/issue-5846.format b/Cabal/tests/ParserTests/regressions/issue-5846.format index 7ddb6afaee1..bd742612afd 100644 --- a/Cabal/tests/ParserTests/regressions/issue-5846.format +++ b/Cabal/tests/ParserTests/regressions/issue-5846.format @@ -5,7 +5,7 @@ version: 5846 library default-language: Haskell2010 build-depends: - lib1 : {a, b} -any, - lib2 : {c} -any, - lib3 : {d} >=1, - lib4 : {a, b} >=1 + lib1:{a, b} -any, + lib2:{c} -any, + lib3:{d} >=1, + lib4:{a, b} >=1 diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/cabal.out b/cabal-testsuite/PackageTests/MultipleLibraries/cabal.out index 7e51c00ef04..78899c26837 100644 --- a/cabal-testsuite/PackageTests/MultipleLibraries/cabal.out +++ b/cabal-testsuite/PackageTests/MultipleLibraries/cabal.out @@ -9,4 +9,4 @@ Preprocessing library 'privatelib' for d-0.1.0.0.. Building library 'privatelib' for d-0.1.0.0.. Configuring library for p-0.1.0.0.. cabal: Encountered missing or private dependencies: - d : {privatelib} ==0.1.0.0 + d:{privatelib} ==0.1.0.0