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

Modify flag parser to allow sequential dashes #3345 #3349

Merged
merged 1 commit into from
Aug 14, 2017
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
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Bug fixes:
mismatched hashes), Stack will delete the downloaded file and
recommend either retrying or filing an issue upstream. See
[#3319](https://github.com/commercialhaskell/stack/issues/3319).
* Modified the flag parser within Stack to match the behavior of
Cabal's flag parser, which allows multiple sequential dashes. See
[#3345](https://github.com/commercialhaskell/stack/issues/3345)


## 1.5.1
Expand Down
14 changes: 5 additions & 9 deletions src/Stack/Types/FlagName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ module Stack.Types.FlagName

import Stack.Prelude
import Data.Aeson.Extended
import Data.Attoparsec.Combinators
import Data.Attoparsec.Text
import Data.Attoparsec.Text as A
import Data.Char (isLetter, isDigit, toLower)
import qualified Data.Text as T
import qualified Distribution.PackageDescription as Cabal
Expand Down Expand Up @@ -72,13 +71,10 @@ instance FromJSONKey FlagName where

-- | Attoparsec parser for a flag name
flagNameParser :: Parser FlagName
flagNameParser =
fmap (FlagName . T.pack)
(appending (many1 (satisfy isLetter))
(concating (many (alternating
(pured (satisfy isAlphaNum))
(appending (pured (satisfy separator))
(pured (satisfy isAlphaNum)))))))
flagNameParser = fmap FlagName $ do
t <- A.takeWhile1 (\c -> isAlphaNum c || separator c)
when (T.head t == '-') $ fail "flag name cannot start with dash"
return t
where separator c = c == '-' || c == '_'
isAlphaNum c = isLetter c || isDigit c

Expand Down