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

Disallow spaces around colon in Parsec Dependency #6538

Merged
merged 1 commit into from
Feb 14, 2020
Merged
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
38 changes: 33 additions & 5 deletions Cabal/Distribution/Types/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions Cabal/tests/ParserTests/regressions/issue-5846.format
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/MultipleLibraries/cabal.out
Original file line number Diff line number Diff line change
Expand Up @@ -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