Skip to content

Commit 8eb37c0

Browse files
committed
hackage-server/BuildReports: Fix parsing of flag assignments
Eventually this should really just use the Cabal `FlagAssignment` type but here I have opted to instead just stay with the status quo and update the parser. Fixes #1383.
1 parent 2b8e5f6 commit 8eb37c0

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/Distribution/Server/Features/BuildReports/BuildReport.hs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,19 @@ newtype FlagAss1 = FlagAss1 (FlagName,Bool)
366366
instance Newtype (FlagName,Bool) FlagAss1
367367

368368
instance Parsec FlagAss1 where
369-
parsec = do
370-
-- this is subtly different from Cabal's 'FlagName' parser
371-
name <- P.munch1 (\c -> Char.isAlphaNum c || c == '_' || c == '-')
372-
case name of
373-
('-':flag) -> return $ FlagAss1 (mkFlagName flag, False)
374-
flag -> return $ FlagAss1 (mkFlagName flag, True)
369+
parsec = fmap FlagAss1 (posPolarity <|> negPolarity <|> noPolarity)
370+
where
371+
posPolarity = do
372+
P.char '+'
373+
(,) <$> flagName <*> pure True
374+
negPolarity = do
375+
P.char '-'
376+
(,) <$> flagName <*> pure False
377+
noPolarity =
378+
(,) <$> flagName <*> pure True
379+
380+
-- this is subtly different from Cabal's 'FlagName' parser
381+
flagName = mkFlagName <$> P.munch1 (\c -> Char.isAlphaNum c || c == '_' || c == '-')
375382

376383
instance Pretty FlagAss1 where
377384
pretty (FlagAss1 (fn, True)) = Disp.text (unFlagName fn)

0 commit comments

Comments
 (0)