From 18bddbf794f1b63b92c432310030991eafd7fff6 Mon Sep 17 00:00:00 2001 From: Joshua Simmons Date: Thu, 12 Nov 2015 01:36:01 -0700 Subject: [PATCH] refactor packageNameParser and make it stricter The Cabal rule that each alphanumeric "word" between hyphens must include at least one letter is now enforced. fixes #1336 --- src/Stack/Types/PackageName.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Stack/Types/PackageName.hs b/src/Stack/Types/PackageName.hs index bf5d336d2b..b87798e9f4 100644 --- a/src/Stack/Types/PackageName.hs +++ b/src/Stack/Types/PackageName.hs @@ -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) @@ -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