Skip to content

Commit

Permalink
refactor packageNameParser and make it stricter
Browse files Browse the repository at this point in the history
The Cabal rule that each alphanumeric "word" between hyphens must include at
least one letter is now enforced.

fixes commercialhaskell#1336
  • Loading branch information
kadoban committed Nov 12, 2015
1 parent 2f00f7b commit 18bddbf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Stack/Types/PackageName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import qualified Data.ByteString.Char8 as S8
import Data.Char (isLetter)
import Data.Data
import Data.Hashable
import Data.List (intercalate)
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Text (Text)
Expand Down Expand Up @@ -88,14 +89,13 @@ instance FromJSON PackageName where
-- | Attoparsec parser for a package name from bytestring.
packageNameParser :: Parser PackageName
packageNameParser =
fmap (PackageName . S8.pack)
(appending (many1 (satisfy isAlphaNum))
(concating (many (alternating
(pured (satisfy isAlphaNum))
(appending (pured (satisfy (== '-')))
(pured (satisfy isLetter)))))))
fmap (PackageName . S8.pack . intercalate "-")
(sepBy1 word (char '-'))
where
isAlphaNum c = isLetter c || isDigit c
word = concat <$> sequence [many digit,
pured letter,
many (alternating letter digit)]
letter = satisfy isLetter

-- | Make a package name.
mkPackageName :: String -> Q Exp
Expand Down

0 comments on commit 18bddbf

Please sign in to comment.