Skip to content

Commit 0223f6a

Browse files
committed
Warn if -- token is found. Don't warn if it's "--".
Resolves #2681 Cabal files don't have trailing line comments. In many fields they simply cause parse errors, but e.g. in extra-source-files virtually everything is accepted. As there is simple work around if people actually want double-dash, let's warn about bare one.
1 parent a85ef47 commit 0223f6a

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

Cabal/Cabal.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extra-source-files:
6262
tests/ParserTests/warnings/bom.cabal
6363
tests/ParserTests/warnings/bool.cabal
6464
tests/ParserTests/warnings/deprecatedfield.cabal
65+
tests/ParserTests/warnings/doubledash.cabal
6566
tests/ParserTests/warnings/extratestmodule.cabal
6667
tests/ParserTests/warnings/gluedop.cabal
6768
tests/ParserTests/warnings/nbsp.cabal

Cabal/Distribution/Parsec/Class.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,21 @@ instance Parsec Bool where
8181

8282
-- | @[^ ,]@
8383
parsecToken :: P.Stream s Identity Char => P.Parsec s [PWarning] String
84-
parsecToken = parsecHaskellString <|> (P.munch1 (\x -> not (isSpace x) && x /= ',') P.<?> "identifier" )
84+
parsecToken = parsecHaskellString <|> ((P.munch1 (\x -> not (isSpace x) && x /= ',') P.<?> "identifier") >>= checkNotDoubleDash)
8585

8686
-- | @[^ ]@
8787
parsecToken' :: P.Stream s Identity Char => P.Parsec s [PWarning] String
88-
parsecToken' = parsecHaskellString <|> (P.munch1 (not . isSpace) P.<?> "token")
88+
parsecToken' = parsecHaskellString <|> ((P.munch1 (not . isSpace) P.<?> "token") >>= checkNotDoubleDash)
89+
90+
checkNotDoubleDash :: P.Stream s Identity Char => String -> P.Parsec s [PWarning] String
91+
checkNotDoubleDash s = do
92+
when (s == "--") $ parsecWarning PWTDoubleDash $ unwords
93+
[ "Double-dash token found."
94+
, "Note: there are no end-of-line comments in .cabal files, only whole line comments."
95+
, "Use \"--\" (quoted double dash) to silence this warning, if you actually want -- token"
96+
]
97+
98+
return s
8999

90100
parsecFilePath :: P.Stream s Identity Char => P.Parsec s [PWarning] FilePath
91101
parsecFilePath = parsecToken

Cabal/Distribution/Parsec/Common.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ data PWarnType
4646
| PWTLexNBSP
4747
| PWTLexBOM
4848
| PWTQuirkyCabalFile -- ^ legacy cabal file that we know how to patch
49+
| PWTDoubleDash -- ^ Double dash token, most likely it's a mistake - it's not a comment
4950
deriving (Eq, Ord, Show, Enum, Bounded)
5051

5152
-- | Parser warning.

Cabal/tests/ParserTests.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ warningTests = testGroup "warnings triggered"
5151
, warningTest PWTUnknownField "unknownfield.cabal"
5252
, warningTest PWTUnknownSection "unknownsection.cabal"
5353
, warningTest PWTTrailingFields "trailingfield.cabal"
54+
, warningTest PWTDoubleDash "doubledash.cabal"
5455
-- TODO: not implemented yet
5556
-- , warningTest PWTExtraTestModule "extratestmodule.cabal"
5657
]

Cabal/tests/ParserTests/regressions/encoding-0.8.cabal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Name: encoding
22
Version: 0.8
33
cabal-version: >=1.12
4+
-- double-dash files
5+
extra-source-files:
6+
-- this is comment
7+
README.md "--"
8+
"--"
49

510
custom-setup
611
setup-depends:

Cabal/tests/ParserTests/regressions/encoding-0.8.format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: encoding
22
version: 0.8
33
cabal-version: >=1.12
4+
extra-source-files:
5+
README.md
6+
"--"
7+
"--"
48

59
custom-setup
610
setup-depends: base <5,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: bool
2+
version: 1
3+
cabal-version: >= 1.6
4+
extra-source-files:
5+
README.md -- we include it
6+
7+
library
8+
build-depends: base >= 4.9 && <4.10
9+
hs-source-dirs: .

0 commit comments

Comments
 (0)