packages feed

cabal-gild 1.0.2.0 → 1.0.2.1

raw patch · 20 files changed

+411/−90 lines, 20 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- CabalGild.Action.AttachComments: fields :: Ord p => [Field p] -> State [Comment p] [Field (p, [Comment p])]
- CabalGild.Action.EvaluatePragmas: fields :: MonadWalk m => FilePath -> [Field [Comment a]] -> m [Field [Comment a]]
- CabalGild.Action.FormatFields: fields :: Monoid cs => CabalSpecVersion -> [Field cs] -> [Field cs]
- CabalGild.Action.RemovePositions: fields :: [Field (p, [Comment p])] -> [Field [Comment ()]]
+ CabalGild.Action.StripBlanks: field :: Field a -> Field a
+ CabalGild.Action.StripBlanks: fieldLine :: FieldLine a -> FieldLine a
+ CabalGild.Action.StripBlanks: name :: Name a -> Name a
+ CabalGild.Action.StripBlanks: run :: Applicative m => ([Field a], cs) -> m ([Field a], cs)
+ CabalGild.Action.StripBlanks: sectionArg :: SectionArg a -> SectionArg a
+ CabalGild.Type.Dependency: Dependency :: Dependency -> Dependency
+ CabalGild.Type.Dependency: [unwrap] :: Dependency -> Dependency
+ CabalGild.Type.Dependency: instance Distribution.Parsec.Parsec CabalGild.Type.Dependency.Dependency
+ CabalGild.Type.Dependency: instance Distribution.Pretty.Pretty CabalGild.Type.Dependency.Dependency
+ CabalGild.Type.Dependency: instance GHC.Classes.Eq CabalGild.Type.Dependency.Dependency
+ CabalGild.Type.Dependency: instance GHC.Classes.Ord CabalGild.Type.Dependency.Dependency
+ CabalGild.Type.Dependency: instance GHC.Show.Show CabalGild.Type.Dependency.Dependency
+ CabalGild.Type.Dependency: newtype Dependency
+ CabalGild.Type.ExeDependency: ExeDependency :: ExeDependency -> ExeDependency
+ CabalGild.Type.ExeDependency: [unwrap] :: ExeDependency -> ExeDependency
+ CabalGild.Type.ExeDependency: instance Distribution.Parsec.Parsec CabalGild.Type.ExeDependency.ExeDependency
+ CabalGild.Type.ExeDependency: instance Distribution.Pretty.Pretty CabalGild.Type.ExeDependency.ExeDependency
+ CabalGild.Type.ExeDependency: instance GHC.Classes.Eq CabalGild.Type.ExeDependency.ExeDependency
+ CabalGild.Type.ExeDependency: instance GHC.Classes.Ord CabalGild.Type.ExeDependency.ExeDependency
+ CabalGild.Type.ExeDependency: instance GHC.Show.Show CabalGild.Type.ExeDependency.ExeDependency
+ CabalGild.Type.ExeDependency: newtype ExeDependency
+ CabalGild.Type.ForeignLibOption: ForeignLibOption :: ForeignLibOption -> ForeignLibOption
+ CabalGild.Type.ForeignLibOption: [unwrap] :: ForeignLibOption -> ForeignLibOption
+ CabalGild.Type.ForeignLibOption: instance Distribution.Parsec.Parsec CabalGild.Type.ForeignLibOption.ForeignLibOption
+ CabalGild.Type.ForeignLibOption: instance Distribution.Pretty.Pretty CabalGild.Type.ForeignLibOption.ForeignLibOption
+ CabalGild.Type.ForeignLibOption: instance GHC.Classes.Eq CabalGild.Type.ForeignLibOption.ForeignLibOption
+ CabalGild.Type.ForeignLibOption: instance GHC.Classes.Ord CabalGild.Type.ForeignLibOption.ForeignLibOption
+ CabalGild.Type.ForeignLibOption: instance GHC.Show.Show CabalGild.Type.ForeignLibOption.ForeignLibOption
+ CabalGild.Type.ForeignLibOption: newtype ForeignLibOption
+ CabalGild.Type.Language: Language :: Language -> Language
+ CabalGild.Type.Language: [unwrap] :: Language -> Language
+ CabalGild.Type.Language: instance Distribution.Parsec.Parsec CabalGild.Type.Language.Language
+ CabalGild.Type.Language: instance Distribution.Pretty.Pretty CabalGild.Type.Language.Language
+ CabalGild.Type.Language: instance GHC.Classes.Eq CabalGild.Type.Language.Language
+ CabalGild.Type.Language: instance GHC.Classes.Ord CabalGild.Type.Language.Language
+ CabalGild.Type.Language: instance GHC.Show.Show CabalGild.Type.Language.Language
+ CabalGild.Type.Language: newtype Language
+ CabalGild.Type.LegacyExeDependency: LegacyExeDependency :: LegacyExeDependency -> LegacyExeDependency
+ CabalGild.Type.LegacyExeDependency: [unwrap] :: LegacyExeDependency -> LegacyExeDependency
+ CabalGild.Type.LegacyExeDependency: instance Distribution.Parsec.Parsec CabalGild.Type.LegacyExeDependency.LegacyExeDependency
+ CabalGild.Type.LegacyExeDependency: instance Distribution.Pretty.Pretty CabalGild.Type.LegacyExeDependency.LegacyExeDependency
+ CabalGild.Type.LegacyExeDependency: instance GHC.Classes.Eq CabalGild.Type.LegacyExeDependency.LegacyExeDependency
+ CabalGild.Type.LegacyExeDependency: instance GHC.Classes.Ord CabalGild.Type.LegacyExeDependency.LegacyExeDependency
+ CabalGild.Type.LegacyExeDependency: instance GHC.Show.Show CabalGild.Type.LegacyExeDependency.LegacyExeDependency
+ CabalGild.Type.LegacyExeDependency: newtype LegacyExeDependency
+ CabalGild.Type.ModuleReexport: ModuleReexport :: ModuleReexport -> ModuleReexport
+ CabalGild.Type.ModuleReexport: [unwrap] :: ModuleReexport -> ModuleReexport
+ CabalGild.Type.ModuleReexport: instance Distribution.Parsec.Parsec CabalGild.Type.ModuleReexport.ModuleReexport
+ CabalGild.Type.ModuleReexport: instance Distribution.Pretty.Pretty CabalGild.Type.ModuleReexport.ModuleReexport
+ CabalGild.Type.ModuleReexport: instance GHC.Classes.Eq CabalGild.Type.ModuleReexport.ModuleReexport
+ CabalGild.Type.ModuleReexport: instance GHC.Classes.Ord CabalGild.Type.ModuleReexport.ModuleReexport
+ CabalGild.Type.ModuleReexport: instance GHC.Show.Show CabalGild.Type.ModuleReexport.ModuleReexport
+ CabalGild.Type.ModuleReexport: newtype ModuleReexport
+ CabalGild.Type.PkgconfigDependency: PkgconfigDependency :: PkgconfigDependency -> PkgconfigDependency
+ CabalGild.Type.PkgconfigDependency: [unwrap] :: PkgconfigDependency -> PkgconfigDependency
+ CabalGild.Type.PkgconfigDependency: instance Distribution.Parsec.Parsec CabalGild.Type.PkgconfigDependency.PkgconfigDependency
+ CabalGild.Type.PkgconfigDependency: instance Distribution.Pretty.Pretty CabalGild.Type.PkgconfigDependency.PkgconfigDependency
+ CabalGild.Type.PkgconfigDependency: instance GHC.Classes.Eq CabalGild.Type.PkgconfigDependency.PkgconfigDependency
+ CabalGild.Type.PkgconfigDependency: instance GHC.Classes.Ord CabalGild.Type.PkgconfigDependency.PkgconfigDependency
+ CabalGild.Type.PkgconfigDependency: instance GHC.Show.Show CabalGild.Type.PkgconfigDependency.PkgconfigDependency
+ CabalGild.Type.PkgconfigDependency: newtype PkgconfigDependency
+ CabalGild.Type.PkgconfigVersionRange: PkgconfigVersionRange :: PkgconfigVersionRange -> PkgconfigVersionRange
+ CabalGild.Type.PkgconfigVersionRange: [unwrap] :: PkgconfigVersionRange -> PkgconfigVersionRange
+ CabalGild.Type.PkgconfigVersionRange: instance Distribution.Parsec.Parsec CabalGild.Type.PkgconfigVersionRange.PkgconfigVersionRange
+ CabalGild.Type.PkgconfigVersionRange: instance Distribution.Pretty.Pretty CabalGild.Type.PkgconfigVersionRange.PkgconfigVersionRange
+ CabalGild.Type.PkgconfigVersionRange: instance GHC.Classes.Eq CabalGild.Type.PkgconfigVersionRange.PkgconfigVersionRange
+ CabalGild.Type.PkgconfigVersionRange: instance GHC.Classes.Ord CabalGild.Type.PkgconfigVersionRange.PkgconfigVersionRange
+ CabalGild.Type.PkgconfigVersionRange: instance GHC.Show.Show CabalGild.Type.PkgconfigVersionRange.PkgconfigVersionRange
+ CabalGild.Type.PkgconfigVersionRange: newtype PkgconfigVersionRange
+ CabalGild.Type.TestedWith: TestedWith :: TestedWith -> TestedWith
+ CabalGild.Type.TestedWith: [unwrap] :: TestedWith -> TestedWith
+ CabalGild.Type.TestedWith: instance Distribution.Parsec.Parsec CabalGild.Type.TestedWith.TestedWith
+ CabalGild.Type.TestedWith: instance Distribution.Pretty.Pretty CabalGild.Type.TestedWith.TestedWith
+ CabalGild.Type.TestedWith: instance GHC.Classes.Eq CabalGild.Type.TestedWith.TestedWith
+ CabalGild.Type.TestedWith: instance GHC.Classes.Ord CabalGild.Type.TestedWith.TestedWith
+ CabalGild.Type.TestedWith: instance GHC.Show.Show CabalGild.Type.TestedWith.TestedWith
+ CabalGild.Type.TestedWith: newtype TestedWith
+ CabalGild.Type.VersionRange: Any :: VersionRange a
+ CabalGild.Type.VersionRange: Earlier :: a -> VersionRange a
+ CabalGild.Type.VersionRange: Intersect :: VersionRange a -> VersionRange a -> VersionRange a
+ CabalGild.Type.VersionRange: Later :: a -> VersionRange a
+ CabalGild.Type.VersionRange: This :: a -> VersionRange a
+ CabalGild.Type.VersionRange: Union :: VersionRange a -> VersionRange a -> VersionRange a
+ CabalGild.Type.VersionRange: data VersionRange a
+ CabalGild.Type.VersionRange: fromPkgconfigVersionRange :: PkgconfigVersionRange -> VersionRange PkgconfigVersion
+ CabalGild.Type.VersionRange: fromVersionRange :: VersionRange -> VersionRange Version
+ CabalGild.Type.VersionRange: instance GHC.Classes.Eq a => GHC.Classes.Eq (CabalGild.Type.VersionRange.VersionRange a)
+ CabalGild.Type.VersionRange: instance GHC.Classes.Ord a => GHC.Classes.Ord (CabalGild.Type.VersionRange.VersionRange a)
+ CabalGild.Type.VersionRange: instance GHC.Show.Show a => GHC.Show.Show (CabalGild.Type.VersionRange.VersionRange a)

Files

README.md view
@@ -84,6 +84,10 @@   validate input or provide any checks or lints. However some quality of life   features, like automatic module discovery, are desireable. +- Formatting should be as regular as possible. Special cases for particular+  fields or sections should be avoided unless it improves quality of life. For+  example, interpreting the `build-depends` field to pretty print it is okay.+ - The command line utility should be fast enough to run on every save. It   should not need network access. 
cabal-gild.cabal view
@@ -11,7 +11,7 @@ maintainer: Taylor Fausak name: cabal-gild synopsis: Formats package descriptions.-version: 1.0.2.0+version: 1.0.2.1  source-repository head   type: git@@ -76,11 +76,11 @@     CabalGild.Action.ReflowText     CabalGild.Action.RemovePositions     CabalGild.Action.Render+    CabalGild.Action.StripBlanks     CabalGild.Class.MonadLog     CabalGild.Class.MonadRead     CabalGild.Class.MonadWalk     CabalGild.Class.MonadWrite-    CabalGild.Compat.Cabal     CabalGild.Exception.CheckFailure     CabalGild.Exception.InvalidMode     CabalGild.Exception.InvalidOption@@ -100,13 +100,23 @@     CabalGild.Type.Chunk     CabalGild.Type.Comment     CabalGild.Type.Config+    CabalGild.Type.Dependency+    CabalGild.Type.ExeDependency     CabalGild.Type.Flag+    CabalGild.Type.ForeignLibOption+    CabalGild.Type.Language+    CabalGild.Type.LegacyExeDependency     CabalGild.Type.Line     CabalGild.Type.List     CabalGild.Type.Mode+    CabalGild.Type.ModuleReexport+    CabalGild.Type.PkgconfigDependency+    CabalGild.Type.PkgconfigVersionRange     CabalGild.Type.Pragma     CabalGild.Type.Set     CabalGild.Type.SomeParsecParser+    CabalGild.Type.TestedWith+    CabalGild.Type.VersionRange    hs-source-dirs: source/library   other-modules: Paths_cabal_gild
source/library/CabalGild/Action/AttachComments.hs view
@@ -4,26 +4,19 @@ import qualified Control.Monad.Trans.State as StateT import qualified Distribution.Fields as Fields --- | High level wrapper around 'fields' that makes this action easier to--- compose with other actions.+-- | High level wrapper around 'field' that makes this action easier to compose+-- with other actions. run ::   (Applicative m, Ord p) =>   ([Fields.Field p], [Comment.Comment p]) ->   m ([Fields.Field (p, [Comment.Comment p])], [Comment.Comment p])-run (fs, cs) = pure $ StateT.runState (fields fs) cs---- | Given a bunch of fields and comments, attaches each comment to the field--- that it belongs to. It is assumed that both the fields and comments are--- already sorted by their position @p@. This precondition is not checked.-fields ::-  (Ord p) =>-  [Fields.Field p] ->-  StateT.State [Comment.Comment p] [Fields.Field (p, [Comment.Comment p])]-fields = traverse field+run (fs, cs) = pure $ StateT.runState (traverse field fs) cs --- | Attaches comments to a single field. Note that comments actually end up--- attached to the field's name. That's because the 'Field.Field' type doesn't--- have any annotations directly on it.+-- | Attaches comments to a single field. It is assumed that both the fields+-- and comments are already sorted by their position @p@. This precondition is+-- not checked. Note that comments actually end up attached to the field's+-- name. That's because the 'Field.Field' type doesn't have any annotations+-- directly on it. field ::   (Ord p) =>   Fields.Field p ->
source/library/CabalGild/Action/EvaluatePragmas.hs view
@@ -18,22 +18,14 @@ import qualified Distribution.Utils.Generic as Utils import qualified System.FilePath as FilePath --- | High level wrapper around 'fields' that makes this action easier to--- compose with other actions.+-- | High level wrapper around 'field' that makes this action easier to compose+-- with other actions. run ::   (MonadWalk.MonadWalk m) =>   FilePath ->   ([Fields.Field [Comment.Comment a]], cs) ->   m ([Fields.Field [Comment.Comment a]], cs)-run p (fs, cs) = (,) <$> fields p fs <*> pure cs---- | Evaluates pragmas modules within the given fields.-fields ::-  (MonadWalk.MonadWalk m) =>-  FilePath ->-  [Fields.Field [Comment.Comment a]] ->-  m [Fields.Field [Comment.Comment a]]-fields = traverse . field+run p (fs, cs) = (,) <$> traverse (field p) fs <*> pure cs  -- | Evaluates pragmas within the given field. Or, if the field is a section, -- evaluates pragmas recursively within the fields of the section.@@ -65,7 +57,7 @@           . fmap (ModuleName.toFieldLine [])           . Maybe.mapMaybe (toModuleName directories)           $ Maybe.mapMaybe (stripAnyExtension extensions) files-  Fields.Section n sas fs -> Fields.Section n sas <$> fields p fs+  Fields.Section n sas fs -> Fields.Section n sas <$> traverse (field p) fs  -- | These are the names of the fields that can have this action applied to -- them.
source/library/CabalGild/Action/FormatFields.hs view
@@ -2,11 +2,18 @@  module CabalGild.Action.FormatFields where -import CabalGild.Compat.Cabal () import qualified CabalGild.Extra.FieldLine as FieldLine import qualified CabalGild.Extra.Name as Name import qualified CabalGild.Extra.String as String+import qualified CabalGild.Type.Dependency as Dependency+import qualified CabalGild.Type.ExeDependency as ExeDependency+import qualified CabalGild.Type.ForeignLibOption as ForeignLibOption+import qualified CabalGild.Type.Language as Language+import qualified CabalGild.Type.LegacyExeDependency as LegacyExeDependency+import qualified CabalGild.Type.ModuleReexport as ModuleReexport+import qualified CabalGild.Type.PkgconfigDependency as PkgconfigDependency import qualified CabalGild.Type.SomeParsecParser as SPP+import qualified CabalGild.Type.TestedWith as TestedWith import qualified Data.Functor.Identity as Identity import qualified Data.Map as Map import qualified Distribution.CabalSpecVersion as CabalSpecVersion@@ -14,31 +21,17 @@ import qualified Distribution.Fields as Fields import qualified Distribution.ModuleName as ModuleName import qualified Distribution.Parsec as Parsec-import qualified Distribution.Types.Dependency as Dependency-import qualified Distribution.Types.ExeDependency as ExeDependency-import qualified Distribution.Types.ForeignLibOption as ForeignLibOption-import qualified Distribution.Types.LegacyExeDependency as LegacyExeDependency import qualified Distribution.Types.Mixin as Mixin-import qualified Distribution.Types.ModuleReexport as ModuleReexport-import qualified Distribution.Types.PkgconfigDependency as PkgconfigDependency import qualified Language.Haskell.Extension as Extension import qualified Text.PrettyPrint as PrettyPrint --- | A wrapper around 'fields' to allow this to be composed with other actions.+-- | A wrapper around 'field' to allow this to be composed with other actions. run ::   (Applicative m, Monoid cs) =>   CabalSpecVersion.CabalSpecVersion ->   ([Fields.Field cs], cs) ->   m ([Fields.Field cs], cs)-run csv (fs, cs) = pure (fields csv fs, cs)---- | A wrapper around 'field'.-fields ::-  (Monoid cs) =>-  CabalSpecVersion.CabalSpecVersion ->-  [Fields.Field cs] ->-  [Fields.Field cs]-fields = fmap . field+run csv (fs, cs) = pure (fmap (field csv) fs, cs)  -- | Formats the given field, if applicable. Otherwise returns the field as is. -- If the field is a section, the fields within the section will be recursively@@ -52,7 +45,7 @@   Fields.Field n fls -> case Map.lookup (Name.value n) parsers of     Nothing -> f     Just spp -> Fields.Field n $ fieldLines csv fls spp-  Fields.Section n sas fs -> Fields.Section n sas $ fields csv fs+  Fields.Section n sas fs -> Fields.Section n sas $ fmap (field csv) fs  -- | Attempts to parse the given field lines using the given parser. If parsing -- fails, the field lines will be returned as is. Comments within the field@@ -145,12 +138,12 @@           "mixins" =: SPP.set @Newtypes.CommaVCat @(Identity.Identity Mixin.Mixin),           "options" =: SPP.set @Newtypes.FSep @(Identity.Identity ForeignLibOption.ForeignLibOption),           "other-extensions" =: SPP.set @Newtypes.FSep @(Newtypes.MQuoted Extension.Extension),-          "other-languages" =: SPP.set @Newtypes.FSep @(Newtypes.MQuoted Extension.Language),+          "other-languages" =: SPP.set @Newtypes.FSep @(Newtypes.MQuoted Language.Language),           "other-modules" =: SPP.set @Newtypes.VCat @(Newtypes.MQuoted ModuleName.ModuleName),           "pkgconfig-depends" =: SPP.set @Newtypes.CommaFSep @(Identity.Identity PkgconfigDependency.PkgconfigDependency),           "reexported-modules" =: SPP.set @Newtypes.CommaVCat @(Identity.Identity ModuleReexport.ModuleReexport),           "setup-depends" =: SPP.set @Newtypes.CommaVCat @(Identity.Identity Dependency.Dependency),           "signatures" =: SPP.set @Newtypes.VCat @(Newtypes.MQuoted ModuleName.ModuleName),-          "tested-with" =: SPP.set @Newtypes.FSep @Newtypes.TestedWith,+          "tested-with" =: SPP.set @Newtypes.FSep @(Identity.Identity TestedWith.TestedWith),           "virtual-modules" =: SPP.set @Newtypes.VCat @(Newtypes.MQuoted ModuleName.ModuleName)         ]
source/library/CabalGild/Action/RemovePositions.hs view
@@ -3,20 +3,12 @@ import qualified CabalGild.Type.Comment as Comment import qualified Distribution.Fields as Fields --- | A wrapper around 'fields' to allow this to be composed with other actions.+-- | A wrapper around 'field' to allow this to be composed with other actions. run ::   (Applicative m) =>   ([Fields.Field (p, [Comment.Comment p])], [Comment.Comment p]) ->   m ([Fields.Field [Comment.Comment ()]], [Comment.Comment ()])-run (fs, cs) = pure (fields fs, comments cs)---- | Removes the positions from some fields and their comments. This is useful--- for two reasons: the annotations become simpler, and it's clear that the--- positions won't be used for anything else.-fields ::-  [Fields.Field (p, [Comment.Comment p])] ->-  [Fields.Field [Comment.Comment ()]]-fields = fmap field+run (fs, cs) = pure (fmap field fs, comments cs)  -- | Removes the positions from a field and its comments. field ::@@ -24,7 +16,7 @@   Fields.Field [Comment.Comment ()] field f = case f of   Fields.Field n fls -> Fields.Field (name n) $ fieldLines fls-  Fields.Section n sas fs -> Fields.Section (name n) (sectionArgs sas) $ fields fs+  Fields.Section n sas fs -> Fields.Section (name n) (sectionArgs sas) $ fmap field fs  -- | Removes the positions from a name and its comments. name ::
+ source/library/CabalGild/Action/StripBlanks.hs view
@@ -0,0 +1,41 @@+module CabalGild.Action.StripBlanks where++import qualified Data.ByteString.Char8 as Latin1+import qualified Distribution.Fields as Fields++-- | High level wrapper around 'field' that makes this action easier to compose+-- with other actions.+run ::+  (Applicative m) =>+  ([Fields.Field a], cs) ->+  m ([Fields.Field a], cs)+run (fs, cs) = pure (fmap field fs, cs)++-- | Strips blank space from the field recursively. In practice there should+-- not be any leading or trailing blank space to begin with. However the legacy+-- curly bracket syntax can introduce trailing blank space. For example with+-- @s { f : x }@ the field value will have a trailing space (@"x "@).+field :: Fields.Field a -> Fields.Field a+field f = case f of+  Fields.Field n fls ->+    Fields.Field (name n) (fmap fieldLine fls)+  Fields.Section n sas fs ->+    Fields.Section (name n) (fmap sectionArg sas) (fmap field fs)++-- | Strips blank space from the field's name.+name :: Fields.Name a -> Fields.Name a+name (Fields.Name a bs) = Fields.Name a (Latin1.strip bs)++-- | Strips blank space from the field line.+fieldLine :: Fields.FieldLine a -> Fields.FieldLine a+fieldLine (Fields.FieldLine a bs) = Fields.FieldLine a (Latin1.strip bs)++-- | Strips blank space from the section argument.+sectionArg :: Fields.SectionArg a -> Fields.SectionArg a+sectionArg sa = case sa of+  Fields.SecArgName a bs ->+    Fields.SecArgName a (Latin1.strip bs)+  Fields.SecArgStr a bs ->+    Fields.SecArgStr a (Latin1.strip bs)+  Fields.SecArgOther a bs ->+    Fields.SecArgOther a (Latin1.strip bs)
− source/library/CabalGild/Compat/Cabal.hs
@@ -1,29 +0,0 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE StandaloneDeriving #-}-{-# OPTIONS_GHC -Wno-orphans #-}---- | This module defines orphan instances for some Cabal types. These instances--- are defined in more recent versions of the @Cabal-syntax@ library.-module CabalGild.Compat.Cabal where--#if !MIN_VERSION_Cabal_syntax(3, 10, 1)-import qualified Distribution.Types.Dependency as Dependency-import qualified Distribution.Types.VersionRange.Internal as VersionRange-import qualified Distribution.Types.ExeDependency as ExeDependency-import qualified Distribution.Types.LegacyExeDependency as LegacyExeDependency-import qualified Distribution.Types.ForeignLibOption as ForeignLibOption-import qualified Distribution.Types.PkgconfigDependency as PkgconfigDependency-import qualified Distribution.Types.PkgconfigVersionRange as PkgconfigVersionRange-import qualified Distribution.Types.ModuleReexport as ModuleReexport-import qualified Language.Haskell.Extension as Extension--deriving instance Ord Dependency.Dependency-deriving instance Ord ForeignLibOption.ForeignLibOption-deriving instance Ord ExeDependency.ExeDependency-deriving instance Ord Extension.Language-deriving instance Ord LegacyExeDependency.LegacyExeDependency-deriving instance Ord ModuleReexport.ModuleReexport-deriving instance Ord PkgconfigDependency.PkgconfigDependency-deriving instance Ord PkgconfigVersionRange.PkgconfigVersionRange-deriving instance Ord VersionRange.VersionRange-#endif
source/library/CabalGild/Main.hs view
@@ -9,6 +9,7 @@ import qualified CabalGild.Action.ReflowText as ReflowText import qualified CabalGild.Action.RemovePositions as RemovePositions import qualified CabalGild.Action.Render as Render+import qualified CabalGild.Action.StripBlanks as StripBlanks import qualified CabalGild.Class.MonadLog as MonadLog import qualified CabalGild.Class.MonadRead as MonadRead import qualified CabalGild.Class.MonadWalk as MonadWalk@@ -90,7 +91,8 @@   let csv = GetCabalVersion.fromFields fields       comments = ExtractComments.fromByteString input   output <--    ( AttachComments.run+    ( StripBlanks.run+        Monad.>=> AttachComments.run         Monad.>=> ReflowText.run csv         Monad.>=> RemovePositions.run         Monad.>=> EvaluatePragmas.run (Maybe.fromMaybe (Config.stdin config) $ Config.input config)
+ source/library/CabalGild/Type/Dependency.hs view
@@ -0,0 +1,26 @@+module CabalGild.Type.Dependency where++import qualified CabalGild.Type.VersionRange as VersionRange+import qualified Data.Function as Function+import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Distribution.Types.Dependency as Dependency++-- | This type exists to provide an 'Ord' instance for+-- 'Dependency.Dependency', which was added in @Cabal-syntax-3.10.1.0@.+newtype Dependency = Dependency+  { unwrap :: Dependency.Dependency+  }+  deriving (Eq, Show)++instance Ord Dependency where+  compare =+    Function.on compare $+      (\(Dependency.Dependency pn vr lns) -> (pn, VersionRange.fromVersionRange vr, lns))+        . unwrap++instance Parsec.Parsec Dependency where+  parsec = Dependency <$> Parsec.parsec++instance Pretty.Pretty Dependency where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/ExeDependency.hs view
@@ -0,0 +1,26 @@+module CabalGild.Type.ExeDependency where++import qualified CabalGild.Type.VersionRange as VersionRange+import qualified Data.Function as Function+import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Distribution.Types.ExeDependency as ExeDependency++-- | This type exists to provide an 'Ord' instance for+-- 'ExeDependency.ExeDependency', which was added in @Cabal-syntax-3.10.1.0@.+newtype ExeDependency = ExeDependency+  { unwrap :: ExeDependency.ExeDependency+  }+  deriving (Eq, Show)++instance Ord ExeDependency where+  compare =+    Function.on compare $+      (\(ExeDependency.ExeDependency pn ucn vr) -> (pn, ucn, VersionRange.fromVersionRange vr))+        . unwrap++instance Parsec.Parsec ExeDependency where+  parsec = ExeDependency <$> Parsec.parsec++instance Pretty.Pretty ExeDependency where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/ForeignLibOption.hs view
@@ -0,0 +1,23 @@+module CabalGild.Type.ForeignLibOption where++import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Distribution.Types.ForeignLibOption as ForeignLibOption++-- | This type exists to provide an 'Ord' instance for+-- 'ForeignLibOption.ForeignLibOption', which was added in+-- @Cabal-syntax-3.10.1.0@.+newtype ForeignLibOption = ForeignLibOption+  { unwrap :: ForeignLibOption.ForeignLibOption+  }+  deriving (Eq, Show)++instance Ord ForeignLibOption where+  compare x y = case (unwrap x, unwrap y) of+    (ForeignLibOption.ForeignLibStandalone, ForeignLibOption.ForeignLibStandalone) -> EQ++instance Parsec.Parsec ForeignLibOption where+  parsec = ForeignLibOption <$> Parsec.parsec++instance Pretty.Pretty ForeignLibOption where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/Language.hs view
@@ -0,0 +1,31 @@+module CabalGild.Type.Language where++import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Language.Haskell.Extension as Extension++-- | This type exists to provide an 'Ord' instance for+-- 'Language.Language', which was added in @Cabal-syntax-3.10.1.0@.+newtype Language = Language+  { unwrap :: Extension.Language+  }+  deriving (Eq, Show)++instance Ord Language where+  compare x y = case (unwrap x, unwrap y) of+    (Extension.Haskell98, Extension.Haskell98) -> EQ+    (Extension.Haskell98, _) -> LT+    (Extension.Haskell2010, Extension.Haskell2010) -> EQ+    (Extension.Haskell2010, Extension.Haskell98) -> GT+    (Extension.Haskell2010, _) -> LT+    (Extension.GHC2021, Extension.GHC2021) -> EQ+    (Extension.GHC2021, Extension.UnknownLanguage _) -> LT+    (Extension.GHC2021, _) -> GT+    (Extension.UnknownLanguage s, Extension.UnknownLanguage t) -> compare s t+    (Extension.UnknownLanguage _, _) -> GT++instance Parsec.Parsec Language where+  parsec = Language <$> Parsec.parsec++instance Pretty.Pretty Language where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/LegacyExeDependency.hs view
@@ -0,0 +1,27 @@+module CabalGild.Type.LegacyExeDependency where++import qualified CabalGild.Type.VersionRange as VersionRange+import qualified Data.Function as Function+import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Distribution.Types.LegacyExeDependency as LegacyExeDependency++-- | This type exists to provide an 'Ord' instance for+-- 'LegacyExeDependency.LegacyExeDependency', which was added in+-- @Cabal-syntax-3.10.1.0@.+newtype LegacyExeDependency = LegacyExeDependency+  { unwrap :: LegacyExeDependency.LegacyExeDependency+  }+  deriving (Eq, Show)++instance Ord LegacyExeDependency where+  compare =+    Function.on compare $+      (\(LegacyExeDependency.LegacyExeDependency s vr) -> (s, VersionRange.fromVersionRange vr))+        . unwrap++instance Parsec.Parsec LegacyExeDependency where+  parsec = LegacyExeDependency <$> Parsec.parsec++instance Pretty.Pretty LegacyExeDependency where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/ModuleReexport.hs view
@@ -0,0 +1,25 @@+module CabalGild.Type.ModuleReexport where++import qualified Data.Function as Function+import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Distribution.Types.ModuleReexport as ModuleReexport++-- | This type exists to provide an 'Ord' instance for+-- 'ModuleReexport.ModuleReexport', which was added in @Cabal-syntax-3.10.1.0@.+newtype ModuleReexport = ModuleReexport+  { unwrap :: ModuleReexport.ModuleReexport+  }+  deriving (Eq, Show)++instance Ord ModuleReexport where+  compare =+    Function.on compare $+      (\(ModuleReexport.ModuleReexport mpn mn1 mn2) -> (mpn, mn1, mn2))+        . unwrap++instance Parsec.Parsec ModuleReexport where+  parsec = ModuleReexport <$> Parsec.parsec++instance Pretty.Pretty ModuleReexport where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/PkgconfigDependency.hs view
@@ -0,0 +1,27 @@+module CabalGild.Type.PkgconfigDependency where++import qualified CabalGild.Type.PkgconfigVersionRange as PkgconfigVersionRange+import qualified Data.Function as Function+import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Distribution.Types.PkgconfigDependency as PkgconfigDependency++-- | This type exists to provide an 'Ord' instance for+-- 'PkgconfigDependency.PkgconfigDependency', which was added in+-- @Cabal-syntax-3.10.1.0@.+newtype PkgconfigDependency = PkgconfigDependency+  { unwrap :: PkgconfigDependency.PkgconfigDependency+  }+  deriving (Eq, Show)++instance Ord PkgconfigDependency where+  compare =+    Function.on compare $+      (\(PkgconfigDependency.PkgconfigDependency pn pvr) -> (pn, PkgconfigVersionRange.PkgconfigVersionRange pvr))+        . unwrap++instance Parsec.Parsec PkgconfigDependency where+  parsec = PkgconfigDependency <$> Parsec.parsec++instance Pretty.Pretty PkgconfigDependency where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/PkgconfigVersionRange.hs view
@@ -0,0 +1,27 @@+module CabalGild.Type.PkgconfigVersionRange where++import qualified CabalGild.Type.VersionRange as VersionRange+import qualified Data.Function as Function+import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty+import qualified Distribution.Types.PkgconfigVersionRange as PkgconfigVersionRange++-- | This type exists to provide an 'Ord' instance for+-- 'PkgconfigVersionRange.PkgconfigVersionRange', which was added in+-- @Cabal-syntax-3.10.1.0@.+newtype PkgconfigVersionRange = PkgconfigVersionRange+  { unwrap :: PkgconfigVersionRange.PkgconfigVersionRange+  }+  deriving (Eq, Show)++instance Ord PkgconfigVersionRange where+  compare =+    Function.on compare $+      VersionRange.fromPkgconfigVersionRange+        . unwrap++instance Parsec.Parsec PkgconfigVersionRange where+  parsec = PkgconfigVersionRange <$> Parsec.parsec++instance Pretty.Pretty PkgconfigVersionRange where+  pretty = Pretty.pretty . unwrap
+ source/library/CabalGild/Type/TestedWith.hs view
@@ -0,0 +1,36 @@+module CabalGild.Type.TestedWith where++import qualified CabalGild.Type.VersionRange as VersionRange+import qualified Data.Function as Function+import qualified Distribution.FieldGrammar.Newtypes as Newtypes+import qualified Distribution.Parsec as Parsec+import qualified Distribution.Pretty as Pretty++-- | This type exists to provide an 'Ord' instance for 'Newtypes.TestedWith',+-- which was added in @Cabal-syntax-3.10.1.0@.+newtype TestedWith = TestedWith+  { unwrap :: Newtypes.TestedWith+  }++instance Eq TestedWith where+  (==) =+    Function.on (==) $+      fmap VersionRange.fromVersionRange+        . Newtypes.getTestedWith+        . unwrap++instance Ord TestedWith where+  compare =+    Function.on compare $+      fmap VersionRange.fromVersionRange+        . Newtypes.getTestedWith+        . unwrap++instance Parsec.Parsec TestedWith where+  parsec = TestedWith <$> Parsec.parsec++instance Pretty.Pretty TestedWith where+  pretty = Pretty.pretty . unwrap++instance Show TestedWith where+  show = show . Newtypes.getTestedWith . unwrap
+ source/library/CabalGild/Type/VersionRange.hs view
@@ -0,0 +1,40 @@+module CabalGild.Type.VersionRange where++import qualified Distribution.Types.PkgconfigVersion as PkgconfigVersion+import qualified Distribution.Types.PkgconfigVersionRange as PkgconfigVersionRange+import qualified Distribution.Types.Version as Version+import qualified Distribution.Types.VersionRange as VersionRange++-- | This type exists to provide an 'Ord' instance for+-- 'VersionRange.VersionRange', which was added in @Cabal-syntax-3.10.1.0@.+data VersionRange a+  = Any+  | This a+  | Later a+  | Earlier a+  | Union (VersionRange a) (VersionRange a)+  | Intersect (VersionRange a) (VersionRange a)+  deriving (Eq, Ord, Show)++fromPkgconfigVersionRange ::+  PkgconfigVersionRange.PkgconfigVersionRange ->+  VersionRange PkgconfigVersion.PkgconfigVersion+fromPkgconfigVersionRange x = case x of+  PkgconfigVersionRange.PcAnyVersion -> Any+  PkgconfigVersionRange.PcThisVersion v -> This v+  PkgconfigVersionRange.PcLaterVersion v -> Later v+  PkgconfigVersionRange.PcEarlierVersion v -> Earlier v+  PkgconfigVersionRange.PcOrLaterVersion v -> Union (Later v) (This v)+  PkgconfigVersionRange.PcOrEarlierVersion v -> Union (Earlier v) (This v)+  PkgconfigVersionRange.PcUnionVersionRanges v w -> Union (fromPkgconfigVersionRange v) (fromPkgconfigVersionRange w)+  PkgconfigVersionRange.PcIntersectVersionRanges v w -> Intersect (fromPkgconfigVersionRange v) (fromPkgconfigVersionRange w)++fromVersionRange :: VersionRange.VersionRange -> VersionRange Version.Version+fromVersionRange =+  VersionRange.foldVersionRange+    Any+    This+    Later+    Earlier+    Union+    Intersect
source/test-suite/Main.hs view
@@ -861,6 +861,41 @@       "library\n -- cabal-gild: discover d e\n exposed-modules:"       "library\n  -- cabal-gild: discover d e\n  exposed-modules:\n    M\n    N\n" +  Hspec.it "parses an empty brace section" $ do+    expectGilded+      "s{}"+      "s\n"++  Hspec.it "parses a brace section with a layout field" $ do+    expectGilded+      "s{f:x}"+      "s\n  f: x\n"++  Hspec.it "parses a brace section with a brace field" $ do+    expectGilded+      "s{f:{x}}"+      "s\n  f: x\n"++  Hspec.it "strips blanks from a layout field in a brace section" $ do+    expectGilded+      "s { f : x } "+      "s\n  f: x\n"++  Hspec.it "strips blanks from a brace field in a brace section" $ do+    expectGilded+      "s { f : { x } } "+      "s\n  f: x\n"++  Hspec.it "parses a brace section with multiple fields" $ do+    expectGilded+      "s { f : { x } g : { y } } "+      "s\n  f: x\n  g: y\n"++  Hspec.it "parses a nested brace section" $ do+    expectGilded+      "s{t{}}"+      "s\n  t\n"+ expectGilded :: (Stack.HasCallStack) => String -> String -> Hspec.Expectation expectGilded input expected = do   let (a, s, w) =