Skip to content

Commit caf4ed4

Browse files
committed
Modify flag parser to allow sequential dashes #3345
1 parent 8a1523f commit caf4ed4

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Bug fixes:
8282
mismatched hashes), Stack will delete the downloaded file and
8383
recommend either retrying or filing an issue upstream. See
8484
[#3319](https://github.com/commercialhaskell/stack/issues/3319).
85+
* Modified the flag parser within Stack to match the behavior of
86+
Cabal's flag parser, which allows multiple sequential dashes. See
87+
[#3345](https://github.com/commercialhaskell/stack/issues/3345)
8588

8689

8790
## 1.5.1

src/Stack/Types/FlagName.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ module Stack.Types.FlagName
2424

2525
import Stack.Prelude
2626
import Data.Aeson.Extended
27-
import Data.Attoparsec.Combinators
28-
import Data.Attoparsec.Text
27+
import Data.Attoparsec.Text as A
2928
import Data.Char (isLetter, isDigit, toLower)
3029
import qualified Data.Text as T
3130
import qualified Distribution.PackageDescription as Cabal
@@ -72,13 +71,10 @@ instance FromJSONKey FlagName where
7271

7372
-- | Attoparsec parser for a flag name
7473
flagNameParser :: Parser FlagName
75-
flagNameParser =
76-
fmap (FlagName . T.pack)
77-
(appending (many1 (satisfy isLetter))
78-
(concating (many (alternating
79-
(pured (satisfy isAlphaNum))
80-
(appending (pured (satisfy separator))
81-
(pured (satisfy isAlphaNum)))))))
74+
flagNameParser = fmap FlagName $ do
75+
t <- A.takeWhile1 (\c -> isAlphaNum c || separator c)
76+
when (T.head t == '-') $ fail "flag name cannot start with dash"
77+
return t
8278
where separator c = c == '-' || c == '_'
8379
isAlphaNum c = isLetter c || isDigit c
8480

0 commit comments

Comments
 (0)