Skip to content

Commit

Permalink
Merge pull request #3349 from commercialhaskell/3345-fix-flag-parser
Browse files Browse the repository at this point in the history
Modify flag parser to allow sequential dashes #3345
  • Loading branch information
snoyberg committed Aug 14, 2017
2 parents 776b55f + caf4ed4 commit 37459ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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

0 comments on commit 37459ef

Please sign in to comment.