From 9c431665da46791823339b810af417703d0894b3 Mon Sep 17 00:00:00 2001 From: Finley McIlwaine Date: Wed, 8 May 2024 03:36:34 -0700 Subject: [PATCH] Remove CabalParsing class, specialize to ParsecParser --- Cabal-syntax/src/Distribution/Backpack.hs | 4 +- .../Distribution/FieldGrammar/FieldDescrs.hs | 13 +- .../src/Distribution/FieldGrammar/Newtypes.hs | 6 +- Cabal-syntax/src/Distribution/ModuleName.hs | 14 +-- .../PackageDescription/Configuration.hs | 2 +- Cabal-syntax/src/Distribution/Parsec.hs | 112 ++++++++---------- Cabal-syntax/src/Distribution/System.hs | 2 +- .../src/Distribution/Types/Dependency.hs | 2 +- Cabal-syntax/src/Distribution/Types/Flag.hs | 10 +- .../src/Distribution/Types/LibraryName.hs | 2 +- Cabal-syntax/src/Distribution/Types/Mixin.hs | 2 +- .../src/Distribution/Types/ModuleRenaming.hs | 7 +- .../Distribution/Types/MungedPackageName.hs | 2 +- .../Types/PkgconfigVersionRange.hs | 2 +- .../src/Distribution/Types/Version.hs | 4 +- .../Types/VersionRange/Internal.hs | 14 +-- Cabal/src/Distribution/Simple/BuildTarget.hs | 8 +- .../src/Distribution/Simple/Glob/Internal.hs | 6 +- Cabal/src/Distribution/Verbosity.hs | 2 +- .../Client/CmdInstall/ClientInstallFlags.hs | 2 +- .../CmdInstall/ClientInstallTargetSelector.hs | 2 +- .../src/Distribution/Client/Compat/Prelude.hs | 2 +- .../src/Distribution/Client/Setup.hs | 2 +- .../src/Distribution/Client/Targets.hs | 2 +- .../Distribution/Client/Types/AllowNewer.hs | 4 +- changelog.d/pr-10081 | 11 ++ 26 files changed, 120 insertions(+), 119 deletions(-) create mode 100644 changelog.d/pr-10081 diff --git a/Cabal-syntax/src/Distribution/Backpack.hs b/Cabal-syntax/src/Distribution/Backpack.hs index b30028bc41c..bd9f8de8e9f 100644 --- a/Cabal-syntax/src/Distribution/Backpack.hs +++ b/Cabal-syntax/src/Distribution/Backpack.hs @@ -228,7 +228,7 @@ dispOpenModuleSubstEntry (k, v) = pretty k <<>> Disp.char '=' <<>> pretty v -- | Inverse to 'dispModSubst'. -- -- @since 2.2 -parsecOpenModuleSubst :: CabalParsing m => m OpenModuleSubst +parsecOpenModuleSubst :: ParsecParser OpenModuleSubst parsecOpenModuleSubst = fmap Map.fromList . flip P.sepBy (P.char ',') @@ -237,7 +237,7 @@ parsecOpenModuleSubst = -- | Inverse to 'dispModSubstEntry'. -- -- @since 2.2 -parsecOpenModuleSubstEntry :: CabalParsing m => m (ModuleName, OpenModule) +parsecOpenModuleSubstEntry :: ParsecParser (ModuleName, OpenModule) parsecOpenModuleSubstEntry = do k <- parsec diff --git a/Cabal-syntax/src/Distribution/FieldGrammar/FieldDescrs.hs b/Cabal-syntax/src/Distribution/FieldGrammar/FieldDescrs.hs index e03ae749570..bcb69e397e3 100644 --- a/Cabal-syntax/src/Distribution/FieldGrammar/FieldDescrs.hs +++ b/Cabal-syntax/src/Distribution/FieldGrammar/FieldDescrs.hs @@ -29,7 +29,7 @@ import qualified Text.PrettyPrint as Disp -- strict pair data SP s = SP { pPretty :: !(s -> Disp.Doc) - , pParse :: !(forall m. P.CabalParsing m => s -> m s) + , pParse :: !(s -> P.ParsecParser s) } -- | A collection of field parsers and pretty-printers. @@ -40,7 +40,7 @@ instance Applicative (FieldDescrs s) where pure _ = F mempty f <*> x = F (mappend (runF f) (runF x)) -singletonF :: P.FieldName -> (s -> Disp.Doc) -> (forall m. P.CabalParsing m => s -> m s) -> FieldDescrs s a +singletonF :: P.FieldName -> (s -> Disp.Doc) -> (s -> P.ParsecParser s) -> FieldDescrs s a singletonF fn f g = F $ Map.singleton fn (SP f g) -- | Lookup a field value pretty-printer. @@ -48,13 +48,12 @@ fieldDescrPretty :: FieldDescrs s a -> P.FieldName -> Maybe (s -> Disp.Doc) fieldDescrPretty (F m) fn = pPretty <$> Map.lookup fn m -- | Lookup a field value parser. -fieldDescrParse :: P.CabalParsing m => FieldDescrs s a -> P.FieldName -> Maybe (s -> m s) +fieldDescrParse :: FieldDescrs s a -> P.FieldName -> Maybe (s -> P.ParsecParser s) fieldDescrParse (F m) fn = (\f -> pParse f) <$> Map.lookup fn m fieldDescrsToList - :: P.CabalParsing m - => FieldDescrs s a - -> [(P.FieldName, s -> Disp.Doc, s -> m s)] + :: FieldDescrs s a + -> [(P.FieldName, s -> Disp.Doc, s -> P.ParsecParser s)] fieldDescrsToList = map mk . Map.toList . runF where mk (name, SP ppr parse) = (name, ppr, parse) @@ -111,7 +110,7 @@ instance FieldGrammar ParsecPretty FieldDescrs where availableSince _ _ = id hiddenField _ = F mempty -parsecFreeText :: P.CabalParsing m => m String +parsecFreeText :: P.ParsecParser String parsecFreeText = dropDotLines <$ C.spaces <*> many C.anyChar where -- Example package with dot lines diff --git a/Cabal-syntax/src/Distribution/FieldGrammar/Newtypes.hs b/Cabal-syntax/src/Distribution/FieldGrammar/Newtypes.hs index d39e77ebbeb..8071a9c988d 100644 --- a/Cabal-syntax/src/Distribution/FieldGrammar/Newtypes.hs +++ b/Cabal-syntax/src/Distribution/FieldGrammar/Newtypes.hs @@ -96,8 +96,8 @@ data NoCommaFSep = NoCommaFSep class Sep sep where prettySep :: Proxy sep -> [Doc] -> Doc - parseSep :: CabalParsing m => Proxy sep -> m a -> m [a] - parseSepNE :: CabalParsing m => Proxy sep -> m a -> m (NonEmpty a) + parseSep :: Proxy sep -> ParsecParser a -> ParsecParser [a] + parseSepNE :: Proxy sep -> ParsecParser a -> ParsecParser (NonEmpty a) instance Sep CommaVCat where prettySep _ = vcat . punctuate comma @@ -449,7 +449,7 @@ instance Pretty TestedWith where pretty x = case unpack x of (compiler, vr) -> pretty compiler <+> pretty vr -parsecTestedWith :: CabalParsing m => m (CompilerFlavor, VersionRange) +parsecTestedWith :: ParsecParser (CompilerFlavor, VersionRange) parsecTestedWith = do name <- lexemeParsec ver <- parsec <|> pure anyVersion diff --git a/Cabal-syntax/src/Distribution/ModuleName.hs b/Cabal-syntax/src/Distribution/ModuleName.hs index 90082d29f06..23f99243354 100644 --- a/Cabal-syntax/src/Distribution/ModuleName.hs +++ b/Cabal-syntax/src/Distribution/ModuleName.hs @@ -57,27 +57,27 @@ instance Pretty ModuleName where instance Parsec ModuleName where parsec = parsecModuleName -parsecModuleName :: forall m. CabalParsing m => m ModuleName +parsecModuleName :: ParsecParser ModuleName parsecModuleName = state0 DList.empty where - upper :: m Char + upper :: ParsecParser Char !upper = P.satisfy isUpper - ch :: m Char + ch :: ParsecParser Char !ch = P.satisfy (\c -> validModuleChar c || c == '.') - alt :: m ModuleName -> m ModuleName -> m ModuleName + alt :: ParsecParser ModuleName -> ParsecParser ModuleName -> ParsecParser ModuleName !alt = (<|>) - state0 :: DList.DList Char -> m ModuleName + state0 :: DList.DList Char -> ParsecParser ModuleName state0 acc = do c <- upper state1 (DList.snoc acc c) - state1 :: DList.DList Char -> m ModuleName + state1 :: DList.DList Char -> ParsecParser ModuleName state1 acc = state1' acc `alt` return (fromString (DList.toList acc)) - state1' :: DList.DList Char -> m ModuleName + state1' :: DList.DList Char -> ParsecParser ModuleName state1' acc = do c <- ch case c of diff --git a/Cabal-syntax/src/Distribution/PackageDescription/Configuration.hs b/Cabal-syntax/src/Distribution/PackageDescription/Configuration.hs index e811c361221..cf415f382f3 100644 --- a/Cabal-syntax/src/Distribution/PackageDescription/Configuration.hs +++ b/Cabal-syntax/src/Distribution/PackageDescription/Configuration.hs @@ -108,7 +108,7 @@ simplifyWithSysParams os arch cinfo cond = (cond', flags) -- -- | Parse a configuration condition from a string. -parseCondition :: CabalParsing m => m (Condition ConfVar) +parseCondition :: ParsecParser (Condition ConfVar) parseCondition = condOr where condOr = sepByNonEmpty condAnd (oper "||") >>= return . foldl1 COr diff --git a/Cabal-syntax/src/Distribution/Parsec.hs b/Cabal-syntax/src/Distribution/Parsec.hs index 4c6e31e5aaa..c7db32febc9 100644 --- a/Cabal-syntax/src/Distribution/Parsec.hs +++ b/Cabal-syntax/src/Distribution/Parsec.hs @@ -18,14 +18,14 @@ module Distribution.Parsec , eitherParsec , explicitEitherParsec , explicitEitherParsec' - - -- * CabalParsing and diagnostics - , CabalParsing (..) + , parsecHaskellString + , askCabalSpecVersion -- ** Warnings , PWarnType (..) , PWarning (..) , showPWarning + , parsecWarning -- ** Errors , PError (..) @@ -79,23 +79,13 @@ import qualified Text.Parsec as Parsec -- -- For parsing @.cabal@ like file structure, see "Distribution.Fields". class Parsec a where - parsec :: CabalParsing m => m a - --- | Parsing class which --- --- * can report Cabal parser warnings. --- --- * knows @cabal-version@ we work with -class (P.CharParsing m, MonadPlus m, Fail.MonadFail m) => CabalParsing m where - parsecWarning :: PWarnType -> String -> m () - - parsecHaskellString :: m String - parsecHaskellString = stringLiteral + parsec :: ParsecParser a - askCabalSpecVersion :: m CabalSpecVersion +parsecHaskellString :: ParsecParser String +parsecHaskellString = stringLiteral -- | 'parsec' /could/ consume trailing spaces, this function /will/ consume. -lexemeParsec :: (CabalParsing m, Parsec a) => m a +lexemeParsec :: Parsec a => ParsecParser a lexemeParsec = parsec <* P.spaces newtype ParsecParser a = PP @@ -172,12 +162,14 @@ instance P.CharParsing ParsecParser where anyChar = liftParsec P.anyChar string = liftParsec . P.string -instance CabalParsing ParsecParser where - parsecWarning t w = liftParsec $ do - spos <- Parsec.getPosition - Parsec.modifyState - (PWarning t (Position (Parsec.sourceLine spos) (Parsec.sourceColumn spos)) w :) - askCabalSpecVersion = PP pure +parsecWarning :: PWarnType -> String -> ParsecParser () +parsecWarning t w = liftParsec $ do + spos <- Parsec.getPosition + Parsec.modifyState + (PWarning t (Position (Parsec.sourceLine spos) (Parsec.sourceColumn spos)) w :) + +askCabalSpecVersion :: ParsecParser CabalSpecVersion +askCabalSpecVersion = PP pure -- | Parse a 'String' with 'lexemeParsec'. simpleParsec :: Parsec a => String -> Maybe a @@ -261,14 +253,14 @@ instance Parsec Bool where "Boolean values are case sensitive, use 'True' or 'False'." -- | @[^ ,]@ -parsecToken :: CabalParsing m => m String +parsecToken :: ParsecParser String parsecToken = parsecHaskellString <|> ((P.munch1 (\x -> not (isSpace x) && x /= ',') P. "identifier") >>= checkNotDoubleDash) -- | @[^ ]@ -parsecToken' :: CabalParsing m => m String +parsecToken' :: ParsecParser String parsecToken' = parsecHaskellString <|> ((P.munch1 (not . isSpace) P. "token") >>= checkNotDoubleDash) -checkNotDoubleDash :: CabalParsing m => String -> m String +checkNotDoubleDash :: String -> ParsecParser String checkNotDoubleDash s = do when (s == "--") $ parsecWarning PWTDoubleDash $ @@ -280,11 +272,11 @@ checkNotDoubleDash s = do return s -parsecFilePath :: CabalParsing m => m FilePath +parsecFilePath :: ParsecParser FilePath parsecFilePath = parsecToken -- | Parse a benchmark/test-suite types. -parsecStandard :: (CabalParsing m, Parsec ver) => (ver -> String -> a) -> m a +parsecStandard :: Parsec ver => (ver -> String -> a) -> ParsecParser a parsecStandard f = do cs <- some $ P.try (component <* P.char '-') ver <- parsec @@ -298,10 +290,10 @@ parsecStandard f = do -- each component must contain an alphabetic character, to avoid -- ambiguity in identifiers like foo-1 (the 1 is the version number). -parsecCommaList :: CabalParsing m => m a -> m [a] +parsecCommaList :: ParsecParser a -> ParsecParser [a] parsecCommaList p = P.sepBy (p <* P.spaces) (P.char ',' *> P.spaces P. "comma") -parsecCommaNonEmpty :: CabalParsing m => m a -> m (NonEmpty a) +parsecCommaNonEmpty :: ParsecParser a -> ParsecParser (NonEmpty a) parsecCommaNonEmpty p = P.sepByNonEmpty (p <* P.spaces) (P.char ',' *> P.spaces P. "comma") -- | Like 'parsecCommaList' but accept leading or trailing comma. @@ -311,7 +303,7 @@ parsecCommaNonEmpty p = P.sepByNonEmpty (p <* P.spaces) (P.char ',' *> P.spaces -- (comma p)* -- leading comma -- (p comma)* -- trailing comma -- @ -parsecLeadingCommaList :: CabalParsing m => m a -> m [a] +parsecLeadingCommaList :: ParsecParser a -> ParsecParser [a] parsecLeadingCommaList p = do c <- P.optional comma case c of @@ -324,7 +316,7 @@ parsecLeadingCommaList p = do -- | -- -- @since 3.4.0.0 -parsecLeadingCommaNonEmpty :: CabalParsing m => m a -> m (NonEmpty a) +parsecLeadingCommaNonEmpty :: ParsecParser a -> ParsecParser (NonEmpty a) parsecLeadingCommaNonEmpty p = do c <- P.optional comma case c of @@ -334,7 +326,7 @@ parsecLeadingCommaNonEmpty p = do lp = p <* P.spaces comma = P.char ',' *> P.spaces P. "comma" -parsecOptCommaList :: CabalParsing m => m a -> m [a] +parsecOptCommaList :: ParsecParser a -> ParsecParser [a] parsecOptCommaList p = P.sepBy (p <* P.spaces) (P.optional comma) where comma = P.char ',' *> P.spaces @@ -352,7 +344,7 @@ parsecOptCommaList p = P.sepBy (p <* P.spaces) (P.optional comma) -- @ -- -- @since 3.0.0.0 -parsecLeadingOptCommaList :: CabalParsing m => m a -> m [a] +parsecLeadingOptCommaList :: ParsecParser a -> ParsecParser [a] parsecLeadingOptCommaList p = do c <- P.optional comma case c of @@ -370,14 +362,14 @@ parsecLeadingOptCommaList p = do Just _ -> (x :) <$> P.sepEndBy lp comma -- | Content isn't unquoted -parsecQuoted :: CabalParsing m => m a -> m a +parsecQuoted :: ParsecParser a -> ParsecParser a parsecQuoted = P.between (P.char '"') (P.char '"') -- | @parsecMaybeQuoted p = 'parsecQuoted' p <|> p@. -parsecMaybeQuoted :: CabalParsing m => m a -> m a +parsecMaybeQuoted :: ParsecParser a -> ParsecParser a parsecMaybeQuoted p = parsecQuoted p <|> p -parsecUnqualComponentName :: forall m. CabalParsing m => m String +parsecUnqualComponentName :: ParsecParser String parsecUnqualComponentName = state0 DList.empty where -- @@ -412,7 +404,7 @@ parsecUnqualComponentName = state0 DList.empty -- putPretty $ fromTM re -- @ - state0 :: DList.DList Char -> m String + state0 :: DList.DList Char -> ParsecParser String state0 acc = do c <- ch -- <|> fail ("Invalid component, after " ++ DList.toList acc) case () of @@ -422,10 +414,10 @@ parsecUnqualComponentName = state0 DList.empty | c == '-' -> fail ("Empty component, after " ++ DList.toList acc) | otherwise -> fail ("Internal error, after " ++ DList.toList acc) - state1 :: DList.DList Char -> m String + state1 :: DList.DList Char -> ParsecParser String state1 acc = state1' acc `alt` return (DList.toList acc) - state1' :: DList.DList Char -> m String + state1' :: DList.DList Char -> ParsecParser String state1' acc = do c <- ch case () of @@ -434,79 +426,79 @@ parsecUnqualComponentName = state0 DList.empty | c == '-' -> state0 (DList.snoc acc c) | otherwise -> fail ("Internal error, after " ++ DList.toList acc) - ch :: m Char + ch :: ParsecParser Char !ch = P.satisfy (\c -> isAlphaNum c || c == '-') - alt :: m String -> m String -> m String + alt :: ParsecParser String -> ParsecParser String -> ParsecParser String !alt = (<|>) -stringLiteral :: forall m. P.CharParsing m => m String +stringLiteral :: ParsecParser String stringLiteral = lit where - lit :: m String + lit :: ParsecParser String lit = foldr (maybe id (:)) "" <$> P.between (P.char '"') (P.char '"' P. "end of string") (many stringChar) P. "string" - stringChar :: m (Maybe Char) + stringChar :: ParsecParser (Maybe Char) stringChar = Just <$> stringLetter <|> stringEscape P. "string character" - stringLetter :: m Char + stringLetter :: ParsecParser Char stringLetter = P.satisfy (\c -> (c /= '"') && (c /= '\\') && (c > '\026')) - stringEscape :: m (Maybe Char) + stringEscape :: ParsecParser (Maybe Char) stringEscape = P.char '\\' *> esc where - esc :: m (Maybe Char) + esc :: ParsecParser (Maybe Char) esc = Nothing <$ escapeGap <|> Nothing <$ escapeEmpty <|> Just <$> escapeCode - escapeEmpty, escapeGap :: m Char + escapeEmpty, escapeGap :: ParsecParser Char escapeEmpty = P.char '&' escapeGap = P.skipSpaces1 *> (P.char '\\' P. "end of string gap") -escapeCode :: forall m. P.CharParsing m => m Char +escapeCode :: ParsecParser Char escapeCode = (charEsc <|> charNum <|> charAscii <|> charControl) P. "escape code" where - charControl, charNum :: m Char + charControl, charNum :: ParsecParser Char charControl = (\c -> toEnum (fromEnum c - fromEnum '@')) <$> (P.char '^' *> (P.upper <|> P.char '@')) charNum = toEnum <$> num where - num :: m Int + num :: ParsecParser Int num = bounded 10 maxchar <|> (P.char 'o' *> bounded 8 maxchar) <|> (P.char 'x' *> bounded 16 maxchar) maxchar = fromEnum (maxBound :: Char) - bounded :: Int -> Int -> m Int + bounded :: Int -> Int -> ParsecParser Int bounded base bnd = foldl' (\x d -> base * x + digitToInt d) 0 <$> bounded' (take base thedigits) (map digitToInt $ showIntAtBase base intToDigit bnd "") where - thedigits :: [m Char] + thedigits :: [ParsecParser Char] thedigits = map P.char ['0' .. '9'] ++ map P.oneOf (transpose [['A' .. 'F'], ['a' .. 'f']]) - toomuch :: m a + toomuch :: ParsecParser a toomuch = P.unexpected "out-of-range numeric escape sequence" - bounded', bounded'' :: [m Char] -> [Int] -> m [Char] + bounded', bounded'' :: [ParsecParser Char] -> [Int] -> ParsecParser [Char] bounded' dps@(zero : _) bds = P.skipSome zero *> ([] <$ P.notFollowedBy (P.choice dps) <|> bounded'' dps bds) <|> bounded'' dps bds bounded' [] _ = error "bounded called with base 0" bounded'' dps [] = [] <$ P.notFollowedBy (P.choice dps) <|> toomuch bounded'' dps (bd : bds) = - let anyd :: m Char + let anyd :: ParsecParser Char anyd = P.choice dps - nomore :: m () + nomore :: ParsecParser () nomore = P.notFollowedBy anyd <|> toomuch (low, ex, high) = case splitAt bd dps of @@ -521,13 +513,13 @@ escapeCode = (charEsc <|> charNum <|> charAscii <|> charControl) P. "escape c | n <= 0 = pure [] | otherwise = ((:) <$> p <*> atMost (n - 1) p) <|> pure [] - charEsc :: m Char + charEsc :: ParsecParser Char charEsc = P.choice $ parseEsc <$> escMap parseEsc (c, code) = code <$ P.char c escMap = zip "abfnrtv\\\"\'" "\a\b\f\n\r\t\v\\\"\'" - charAscii :: m Char + charAscii :: ParsecParser Char charAscii = P.choice $ parseAscii <$> asciiMap parseAscii (asc, code) = P.try $ code <$ P.string asc diff --git a/Cabal-syntax/src/Distribution/System.hs b/Cabal-syntax/src/Distribution/System.hs index e1e75aa2315..a72c6b966e1 100644 --- a/Cabal-syntax/src/Distribution/System.hs +++ b/Cabal-syntax/src/Distribution/System.hs @@ -326,7 +326,7 @@ buildPlatform = Platform buildArch buildOS -- Utils: -parsecIdent :: CabalParsing m => m String +parsecIdent :: ParsecParser String parsecIdent = (:) <$> firstChar <*> rest where firstChar = P.satisfy isAlpha diff --git a/Cabal-syntax/src/Distribution/Types/Dependency.hs b/Cabal-syntax/src/Distribution/Types/Dependency.hs index 10d0506b57e..643979e23f0 100644 --- a/Cabal-syntax/src/Distribution/Types/Dependency.hs +++ b/Cabal-syntax/src/Distribution/Types/Dependency.hs @@ -158,7 +158,7 @@ instance Parsec Dependency where (spaces *> char '}') (NES.fromNonEmpty <$> parsecCommaNonEmpty parseLib) -versionGuardMultilibs :: CabalParsing m => m () +versionGuardMultilibs :: ParsecParser () versionGuardMultilibs = do csv <- askCabalSpecVersion when (csv < CabalSpecV3_0) $ diff --git a/Cabal-syntax/src/Distribution/Types/Flag.hs b/Cabal-syntax/src/Distribution/Types/Flag.hs index eff71748d9f..f3828098166 100644 --- a/Cabal-syntax/src/Distribution/Types/Flag.hs +++ b/Cabal-syntax/src/Distribution/Types/Flag.hs @@ -286,7 +286,7 @@ dispFlagAssignment :: FlagAssignment -> Disp.Doc dispFlagAssignment = Disp.hsep . map (Disp.text . showFlagValue) . unFlagAssignment -- | Parses a flag assignment. -parsecFlagAssignment :: CabalParsing m => m FlagAssignment +parsecFlagAssignment :: ParsecParser FlagAssignment parsecFlagAssignment = mkFlagAssignment <$> sepByEnding (onFlag <|> offFlag) P.skipSpaces1 where onFlag = do @@ -298,7 +298,7 @@ parsecFlagAssignment = mkFlagAssignment <$> sepByEnding (onFlag <|> offFlag) P.s f <- parsec return (f, False) - sepByEnding :: CabalParsing m => m a -> m b -> m [a] + sepByEnding :: ParsecParser a -> ParsecParser b -> ParsecParser [a] sepByEnding p sep = afterSeparator where element = (:) <$> p <*> afterElement @@ -310,7 +310,7 @@ parsecFlagAssignment = mkFlagAssignment <$> sepByEnding (onFlag <|> offFlag) P.s -- The flags have to explicitly start with minus or plus. -- -- @since 3.4.0.0 -parsecFlagAssignmentNonEmpty :: CabalParsing m => m FlagAssignment +parsecFlagAssignmentNonEmpty :: ParsecParser FlagAssignment parsecFlagAssignmentNonEmpty = mkFlagAssignment <$> sepByEnding1 (onFlag <|> offFlag) P.skipSpaces1 where onFlag = do @@ -322,7 +322,7 @@ parsecFlagAssignmentNonEmpty = mkFlagAssignment <$> sepByEnding1 (onFlag <|> off f <- parsec return (f, False) - sepByEnding1 :: CabalParsing m => m a -> m b -> m [a] + sepByEnding1 :: ParsecParser a -> ParsecParser b -> ParsecParser [a] sepByEnding1 p sep = element where element = (:) <$> p <*> afterElement @@ -359,7 +359,7 @@ legacyShowFlagValue (f, False) = '-' : unFlagName f -- We need this as far as we support custom setups older than 2.2.0.0 -- -- @since 3.4.0.0 -legacyParsecFlagAssignment :: CabalParsing m => m FlagAssignment +legacyParsecFlagAssignment :: ParsecParser FlagAssignment legacyParsecFlagAssignment = mkFlagAssignment <$> P.sepBy (onFlag <|> offFlag) P.skipSpaces1 diff --git a/Cabal-syntax/src/Distribution/Types/LibraryName.hs b/Cabal-syntax/src/Distribution/Types/LibraryName.hs index 2b8f53f4f89..29751698992 100644 --- a/Cabal-syntax/src/Distribution/Types/LibraryName.hs +++ b/Cabal-syntax/src/Distribution/Types/LibraryName.hs @@ -42,7 +42,7 @@ prettyLibraryNameComponent :: LibraryName -> Disp.Doc prettyLibraryNameComponent LMainLibName = Disp.text "lib" prettyLibraryNameComponent (LSubLibName str) = Disp.text "lib:" <<>> pretty str -parsecLibraryNameComponent :: CabalParsing m => m LibraryName +parsecLibraryNameComponent :: ParsecParser LibraryName parsecLibraryNameComponent = do _ <- P.string "lib" parseComposite <|> parseSingle diff --git a/Cabal-syntax/src/Distribution/Types/Mixin.hs b/Cabal-syntax/src/Distribution/Types/Mixin.hs index 63fa6e30fd5..245cb9e0a54 100644 --- a/Cabal-syntax/src/Distribution/Types/Mixin.hs +++ b/Cabal-syntax/src/Distribution/Types/Mixin.hs @@ -68,7 +68,7 @@ instance Parsec Mixin where incl <- parsec return (mkMixin pn ln incl) -versionGuardMultilibs :: CabalParsing m => m () +versionGuardMultilibs :: ParsecParser () versionGuardMultilibs = do csv <- askCabalSpecVersion when (csv < CabalSpecV3_4) $ diff --git a/Cabal-syntax/src/Distribution/Types/ModuleRenaming.hs b/Cabal-syntax/src/Distribution/Types/ModuleRenaming.hs index 022a321a055..6e1fc817285 100644 --- a/Cabal-syntax/src/Distribution/Types/ModuleRenaming.hs +++ b/Cabal-syntax/src/Distribution/Types/ModuleRenaming.hs @@ -102,12 +102,11 @@ instance Parsec ModuleRenaming where P.space *> fail "space after parenthesis, use cabal-version: 3.0 or higher" moduleRenamingParsec - :: CabalParsing m - => (forall a. m a -> m a) + :: (forall a. ParsecParser a -> ParsecParser a) -- ^ between parens - -> m ModuleName + -> ParsecParser ModuleName -- ^ module name parser - -> m ModuleRenaming + -> ParsecParser ModuleRenaming moduleRenamingParsec bp mn = -- NB: try not necessary as the first token is obvious P.choice [parseRename, parseHiding, return DefaultRenaming] diff --git a/Cabal-syntax/src/Distribution/Types/MungedPackageName.hs b/Cabal-syntax/src/Distribution/Types/MungedPackageName.hs index 78b648993d4..b2b5d655f3e 100644 --- a/Cabal-syntax/src/Distribution/Types/MungedPackageName.hs +++ b/Cabal-syntax/src/Distribution/Types/MungedPackageName.hs @@ -136,7 +136,7 @@ zdashcode s = go s (Nothing :: Maybe Int) [] go ('z' : z) (Just n) r = go z (Just (n + 1)) ('z' : r) go (c : z) _ r = go z Nothing (c : r) -parseZDashCode :: CabalParsing m => m [String] +parseZDashCode :: ParsecParser [String] parseZDashCode = do ns <- toList <$> P.sepByNonEmpty (some (P.satisfy (/= '-'))) (P.char '-') return (go ns) diff --git a/Cabal-syntax/src/Distribution/Types/PkgconfigVersionRange.hs b/Cabal-syntax/src/Distribution/Types/PkgconfigVersionRange.hs index fe74f70c7be..176f6e3d4d7 100644 --- a/Cabal-syntax/src/Distribution/Types/PkgconfigVersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/PkgconfigVersionRange.hs @@ -77,7 +77,7 @@ instance Parsec PkgconfigVersionRange where else versionRangeToPkgconfigVersionRange <$> versionRangeParser P.integral csv -- "modern" parser of @pkg-config@ package versions. -pkgconfigParser :: CabalParsing m => m PkgconfigVersionRange +pkgconfigParser :: ParsecParser PkgconfigVersionRange pkgconfigParser = P.spaces >> expr where -- every parser here eats trailing space diff --git a/Cabal-syntax/src/Distribution/Types/Version.hs b/Cabal-syntax/src/Distribution/Types/Version.hs index 90ad33b1048..eefc8a0991f 100644 --- a/Cabal-syntax/src/Distribution/Types/Version.hs +++ b/Cabal-syntax/src/Distribution/Types/Version.hs @@ -110,10 +110,10 @@ instance Parsec Version where -- | An integral without leading zeroes. -- -- @since 3.0 -versionDigitParser :: CabalParsing m => m Int +versionDigitParser :: ParsecParser Int versionDigitParser = (some d >>= toNumber) P. "version digit (integral without leading zeroes)" where - toNumber :: CabalParsing m => [Int] -> m Int + toNumber :: [Int] -> ParsecParser Int toNumber [0] = return 0 toNumber (0 : _) = P.unexpected "Version digit with leading zero" toNumber xs diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs b/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs index 7d7101d8660..347fcbf15ed 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs @@ -341,7 +341,7 @@ instance Parsec VersionRange where -- versions, 'PkgConfigVersionRange'. -- -- @since 3.0 -versionRangeParser :: forall m. CabalParsing m => m Int -> CabalSpecVersion -> m VersionRange +versionRangeParser :: ParsecParser Int -> CabalSpecVersion -> ParsecParser VersionRange versionRangeParser digitParser csv = expr where expr = do @@ -489,7 +489,7 @@ versionRangeParser digitParser csv = expr , prettyShow (foldr1 unionVersionRanges (fmap op vs)) ] - verSet :: CabalParsing m => m (NonEmpty Version) + verSet :: ParsecParser (NonEmpty Version) verSet = do _ <- P.char '{' P.spaces @@ -498,22 +498,22 @@ versionRangeParser digitParser csv = expr pure vs -- a plain version without tags or wildcards - verPlain :: CabalParsing m => m Version + verPlain :: ParsecParser Version verPlain = mkVersion <$> toList <$> P.sepByNonEmpty digitParser (P.char '.') -- either wildcard or normal version - verOrWild :: CabalParsing m => m (Bool, Version) + verOrWild :: ParsecParser (Bool, Version) verOrWild = do x <- digitParser verLoop (DList.singleton x) -- trailing: wildcard (.y.*) or normal version (optional tags) (.y.z-tag) - verLoop :: CabalParsing m => DList.DList Int -> m (Bool, Version) + verLoop :: DList.DList Int -> ParsecParser (Bool, Version) verLoop acc = verLoop' acc <|> (tags *> pure (False, mkVersion (DList.toList acc))) - verLoop' :: CabalParsing m => DList.DList Int -> m (Bool, Version) + verLoop' :: DList.DList Int -> ParsecParser (Bool, Version) verLoop' acc = do _ <- P.char '.' let digit = digitParser >>= verLoop . DList.snoc acc @@ -528,7 +528,7 @@ versionRangeParser digitParser csv = expr P.spaces return a - tags :: CabalParsing m => m () + tags :: ParsecParser () tags = do ts <- many $ P.char '-' *> some (P.satisfy isAlphaNum) case ts of diff --git a/Cabal/src/Distribution/Simple/BuildTarget.hs b/Cabal/src/Distribution/Simple/BuildTarget.hs index cb5293b18b3..502ffa065eb 100644 --- a/Cabal/src/Distribution/Simple/BuildTarget.hs +++ b/Cabal/src/Distribution/Simple/BuildTarget.hs @@ -218,7 +218,7 @@ readUserBuildTarget targetstr = Left _ -> Left (UserBuildTargetUnrecognised targetstr) Right tgt -> Right tgt where - parseTargetApprox :: CabalParsing m => m UserBuildTarget + parseTargetApprox :: ParsecParser UserBuildTarget parseTargetApprox = do -- read one, two, or three tokens, where last could be "hs-string" ts <- tokens @@ -227,17 +227,17 @@ readUserBuildTarget targetstr = (a, Just (b, Nothing)) -> UserBuildTargetDouble a b (a, Just (b, Just c)) -> UserBuildTargetTriple a b c - tokens :: CabalParsing m => m (String, Maybe (String, Maybe String)) + tokens :: ParsecParser (String, Maybe (String, Maybe String)) tokens = (\s -> (s, Nothing)) <$> parsecHaskellString <|> (,) <$> token <*> P.optional (P.char ':' *> tokens2) - tokens2 :: CabalParsing m => m (String, Maybe String) + tokens2 :: ParsecParser (String, Maybe String) tokens2 = (\s -> (s, Nothing)) <$> parsecHaskellString <|> (,) <$> token <*> P.optional (P.char ':' *> (parsecHaskellString <|> token)) - token :: CabalParsing m => m String + token :: ParsecParser String token = P.munch1 (\x -> not (isSpace x) && x /= ':') data UserBuildTargetProblem diff --git a/Cabal/src/Distribution/Simple/Glob/Internal.hs b/Cabal/src/Distribution/Simple/Glob/Internal.hs index 13661cf97d5..473e4678506 100644 --- a/Cabal/src/Distribution/Simple/Glob/Internal.hs +++ b/Cabal/src/Distribution/Simple/Glob/Internal.hs @@ -76,14 +76,14 @@ instance Pretty Glob where instance Parsec Glob where parsec = parsecPath where - parsecPath :: CabalParsing m => m Glob + parsecPath :: ParsecParser Glob parsecPath = do glob <- parsecGlob dirSep *> (GlobDir glob <$> parsecPath <|> pure (GlobDir glob GlobDirTrailing)) <|> pure (GlobFile glob) -- We could support parsing recursive directory search syntax -- @**@ here too, rather than just in 'parseFileGlob' - dirSep :: CabalParsing m => m () + dirSep :: ParsecParser () dirSep = () <$ P.char '/' <|> P.try @@ -93,7 +93,7 @@ instance Parsec Glob where P.notFollowedBy (P.satisfy isGlobEscapedChar) ) - parsecGlob :: CabalParsing m => m GlobPieces + parsecGlob :: ParsecParser GlobPieces parsecGlob = some parsecPiece where parsecPiece = P.choice [literal, wildcard, union] diff --git a/Cabal/src/Distribution/Verbosity.hs b/Cabal/src/Distribution/Verbosity.hs index bab48bbed21..02f5941cf3d 100644 --- a/Cabal/src/Distribution/Verbosity.hs +++ b/Cabal/src/Distribution/Verbosity.hs @@ -199,7 +199,7 @@ instance Parsec Verbosity where instance Pretty Verbosity where pretty = PP.text . showForCabal -parsecVerbosity :: CabalParsing m => m Verbosity +parsecVerbosity :: ParsecParser Verbosity parsecVerbosity = parseIntVerbosity <|> parseStringVerbosity where parseIntVerbosity = do diff --git a/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallFlags.hs b/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallFlags.hs index d5bbd5309f7..6e6b6fac69b 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallFlags.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallFlags.hs @@ -113,7 +113,7 @@ clientInstallOptions _ = $ reqArg "DIR" (succeedReadE Flag) flagToList ] -parsecInstallMethod :: CabalParsing m => m InstallMethod +parsecInstallMethod :: ParsecParser InstallMethod parsecInstallMethod = do name <- P.munch1 isAlpha case name of diff --git a/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs b/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs index 7879602a913..a0ce9aadf62 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall/ClientInstallTargetSelector.hs @@ -33,7 +33,7 @@ parseWithoutProjectTargetSelector verbosity input = Just uri -> return (WoURI uri) Nothing -> dieWithException verbosity $ ProjectTargetSelector input err where - parser :: CabalParsing m => m WithoutProjectTargetSelector + parser :: ParsecParser WithoutProjectTargetSelector parser = do pid <- parsec cn <- optional (char ':' *> parsec) diff --git a/cabal-install/src/Distribution/Client/Compat/Prelude.hs b/cabal-install/src/Distribution/Client/Compat/Prelude.hs index 42d048c9b61..1c69e9d2f72 100644 --- a/cabal-install/src/Distribution/Client/Compat/Prelude.hs +++ b/cabal-install/src/Distribution/Client/Compat/Prelude.hs @@ -18,6 +18,6 @@ import Distribution.Client.Compat.Orphans () import Distribution.Compat.Prelude.Internal import Prelude () -import Distribution.Parsec as X (CabalParsing, Parsec (..), eitherParsec, explicitEitherParsec, simpleParsec) +import Distribution.Parsec as X (Parsec (..), eitherParsec, explicitEitherParsec, simpleParsec) import Distribution.Pretty as X (Pretty (..), prettyShow) import Distribution.Verbosity as X (Verbosity) diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 8fea76bae3b..ca594d02355 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -1035,7 +1035,7 @@ writeGhcEnvironmentFilesPolicyPrinter = \case (Flag WriteGhcEnvironmentFilesOnlyForGhc844AndNewer) -> ["ghc8.4.4+"] NoFlag -> [] -relaxDepsParser :: CabalParsing m => m (Maybe RelaxDeps) +relaxDepsParser :: ParsecParser (Maybe RelaxDeps) relaxDepsParser = do rs <- P.sepBy parsec (P.char ',') if null rs diff --git a/cabal-install/src/Distribution/Client/Targets.hs b/cabal-install/src/Distribution/Client/Targets.hs index 1a37c9c73b9..d834be05ae8 100644 --- a/cabal-install/src/Distribution/Client/Targets.hs +++ b/cabal-install/src/Distribution/Client/Targets.hs @@ -693,7 +693,7 @@ instance Parsec UserConstraint where ] return (UserConstraint scope prop) where - parseConstraintScope :: forall m. CabalParsing m => m UserConstraintScope + parseConstraintScope :: ParsecParser UserConstraintScope parseConstraintScope = do pn <- parsec P.choice diff --git a/cabal-install/src/Distribution/Client/Types/AllowNewer.hs b/cabal-install/src/Distribution/Client/Types/AllowNewer.hs index 0a5700174b8..d04bdf045f4 100644 --- a/cabal-install/src/Distribution/Client/Types/AllowNewer.hs +++ b/cabal-install/src/Distribution/Client/Types/AllowNewer.hs @@ -102,13 +102,13 @@ instance Parsec RelaxedDep where parsec = P.char '*' *> relaxedDepStarP <|> (parsec >>= relaxedDepPkgidP) -- continuation after * -relaxedDepStarP :: CabalParsing m => m RelaxedDep +relaxedDepStarP :: ParsecParser RelaxedDep relaxedDepStarP = RelaxedDep RelaxDepScopeAll <$ P.char ':' <*> modP <*> parsec <|> pure (RelaxedDep RelaxDepScopeAll RelaxDepModNone RelaxDepSubjectAll) -- continuation after package identifier -relaxedDepPkgidP :: CabalParsing m => PackageIdentifier -> m RelaxedDep +relaxedDepPkgidP :: PackageIdentifier -> ParsecParser RelaxedDep relaxedDepPkgidP pid@(PackageIdentifier pn v) | pn == mkPackageName "all" , v == nullVersion = diff --git a/changelog.d/pr-10081 b/changelog.d/pr-10081 new file mode 100644 index 00000000000..b7ab3c3507e --- /dev/null +++ b/changelog.d/pr-10081 @@ -0,0 +1,11 @@ +synopsis: Remove the `CabalParsing` class +packages: Cabal-syntax +prs: #10081 +issues: #10080 + +description: { + +- The `CabalParsing` class has been removed. All bindings which were previously + overloaded in `CabalParsing` will have been specialized to `ParsecParser`. + +}