prettyprinter-combinators 0.1.2 → 0.1.3
raw patch · 6 files changed
+100/−22 lines, 6 filesdep +enummapsetdep ~basedep ~template-haskell
Dependencies added: enummapset
Dependency ranges changed: base, template-haskell
Files
- Changelog.md +6/−0
- prettyprinter-combinators.cabal +16/−2
- src/Prettyprinter/Combinators.hs +50/−10
- src/Prettyprinter/Generics.hs +25/−7
- src/Prettyprinter/MetaDoc.hs +1/−3
- src/Prettyprinter/Show.hs +2/−0
Changelog.md view
@@ -1,3 +1,9 @@+# 0.1.3++- Add functions for rendering with specified layout options+- Add pretty functions for types of `enummapset` package, could be disabled with `enummapset` flag+- Fix build with GHC 9.10+ # 0.1.2 - Fix build with GHC 9.8
prettyprinter-combinators.cabal view
@@ -3,7 +3,7 @@ name: prettyprinter-combinators version:- 0.1.2+ 0.1.3 synopsis: Some useful combinators for the prettyprinter package description:@@ -29,11 +29,12 @@ , GHC == 9.4.7 , GHC == 9.6.3 , GHC == 9.8.1+ , GHC == 9.10.1 build-type: Simple -extra-source-files:+extra-doc-files: Changelog.md Readme.md @@ -42,6 +43,14 @@ type: git location: https://github.com/sergv/prettyprinter-combinators.git +flag enummapset+ description:+ Depend on enummapset package to provide instances and functions for it+ default:+ True+ manual:+ True+ common ghc-options default-language: GHC2021@@ -96,3 +105,8 @@ , text , unordered-containers , vector++ if flag(enummapset)+ build-depends:+ , enummapset+ cpp-options: -DHAVE_ENUMMAPSET
src/Prettyprinter/Combinators.hs view
@@ -20,6 +20,13 @@ , docFromText , PP.viaShow + , renderWith+ , renderLazyWith+ , renderStringWith+ , PP.defaultLayoutOptions+ , PP.LayoutOptions(..)+ , PP.PageWidth(..)+ , MapEntry(..) , (-->) , ppMapEntryWith@@ -63,6 +70,13 @@ , ppShortByteString , ppCallStack , ppCallStackGHC++#ifdef HAVE_ENUMMAPSET+ , ppEnumSet+ , ppEnumSetWith+ , ppEnumMap+ , ppEnumMapWith+#endif ) where import Data.Bimap (Bimap)@@ -85,35 +99,47 @@ import Data.Map.Strict (Map) import Data.Map.Strict qualified as M import Data.Set (Set)-import Data.Vector.Generic qualified as G-import GHC.Stack (CallStack, SrcLoc(..), getCallStack, prettySrcLoc)--#if !MIN_VERSION_base(4, 11, 0)-import Data.Semigroup ((<>))-#endif- import Data.Text qualified as T import Data.Text.Lazy qualified as TL+import Data.Vector.Generic qualified as G+import GHC.Stack (CallStack, SrcLoc(..), getCallStack, prettySrcLoc) import Prettyprinter (Pretty(..), Doc, (<+>)) import Prettyprinter qualified as PP import Prettyprinter.Combinators.Basic import Prettyprinter.MetaDoc import Prettyprinter.Render.Text qualified as PP.Render +#ifdef HAVE_ENUMMAPSET+import Data.EnumMap (EnumMap)+import Data.EnumMap qualified as EM+import Data.EnumSet (EnumSet)+import Data.EnumSet qualified as ES+#endif+ putDocLn :: Doc ann -> IO () putDocLn x = do PP.Render.putDoc x putStrLn "" render :: Doc ann -> T.Text-render = TL.toStrict . renderLazy+render = renderWith PP.defaultLayoutOptions renderLazy :: Doc ann -> TL.Text-renderLazy = PP.Render.renderLazy . PP.layoutPretty PP.defaultLayoutOptions+renderLazy = renderLazyWith PP.defaultLayoutOptions renderString :: Doc ann -> String-renderString = TL.unpack . renderLazy+renderString = renderStringWith PP.defaultLayoutOptions +renderWith :: PP.LayoutOptions -> Doc ann -> T.Text+renderWith opt = TL.toStrict . renderLazyWith opt++renderLazyWith :: PP.LayoutOptions -> Doc ann -> TL.Text+renderLazyWith opt = PP.Render.renderLazy . PP.layoutPretty opt++renderStringWith :: PP.LayoutOptions -> Doc ann -> String+renderStringWith opt = TL.unpack . renderLazyWith opt++ docFromString :: String -> Doc ann docFromString = pretty . TL.pack @@ -214,6 +240,20 @@ ppIntMapWith :: (Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann ppIntMapWith f g = ppAssocListWith f g . IM.toList++#ifdef HAVE_ENUMMAPSET+ppEnumSet :: (Enum a, Pretty a) => EnumSet a -> Doc ann+ppEnumSet = ppEnumSetWith pretty++ppEnumSetWith :: Enum a => (a -> Doc ann) -> EnumSet a -> Doc ann+ppEnumSetWith f = ppListWithDelim PP.lbrace PP.rbrace . map f . ES.toList++ppEnumMap :: (Enum k, Pretty k, Pretty v) => EnumMap k v -> Doc ann+ppEnumMap = ppEnumMapWith pretty pretty++ppEnumMapWith :: Enum k => (k -> Doc ann) -> (v -> Doc ann) -> EnumMap k v -> Doc ann+ppEnumMapWith f g = ppAssocListWith f g . EM.toList+#endif ppHashSet :: Pretty a => HashSet a -> Doc ann ppHashSet = ppHashSetWith pretty
src/Prettyprinter/Generics.hs view
@@ -18,6 +18,7 @@ ( ppGeneric , PPGeneric(..) , PPGenericOverride(..)+ -- * Reexports , Pretty(..) , Generic ) where@@ -27,19 +28,22 @@ import Data.ByteString.Lazy.Char8 qualified as CL8 import Data.ByteString.Short qualified as ShortBS import Data.DList (DList)-import Data.DList qualified as DList+import Data.DList qualified as DL+#ifdef HAVE_ENUMMAPSET+import Data.EnumMap (EnumMap)+import Data.EnumSet (EnumSet)+#endif import Data.Foldable import Data.Functor.Compose import Data.HashMap.Strict (HashMap) import Data.HashSet (HashSet) import Data.Int import Data.IntMap (IntMap)-import Data.IntSet qualified as IntSet+import Data.IntSet (IntSet) import Data.Kind import Data.List.NonEmpty (NonEmpty) import Data.Map (Map) import Data.Proxy-import Data.Semigroup qualified as Semigroup import Data.Set (Set) import Data.Text (Text) import Data.Text qualified as T@@ -282,7 +286,7 @@ instance {-# OVERLAPS #-} PPGenericOverride a => PPGenericOverride (Ratio a) where {-# INLINABLE ppGenericOverride #-} ppGenericOverride (x :% y) =- ppGenericOverride x Semigroup.<> atomicMetaDoc "/" <> ppGenericOverride y+ ppGenericOverride x <> atomicMetaDoc "/" <> ppGenericOverride y instance {-# OVERLAPS #-} PPGenericOverride CallStack where {-# INLINE ppGenericOverride #-}@@ -375,6 +379,10 @@ instance {-# OVERLAPS #-} PPGenericOverride TH.BndrVis where ppGenericOverride = gpretty . from #endif +#if MIN_VERSION_template_haskell(2, 22, 0)+instance {-# OVERLAPS #-} PPGenericOverride TH.NamespaceSpecifier where ppGenericOverride = gpretty . from+#endif+ instance {-# OVERLAPS #-} ( PPGenericOverride a , PPGenericOverride b@@ -428,7 +436,7 @@ ppGenericOverride = atomicMetaDoc . ppBimapWith ppGenericOverrideDoc ppGenericOverrideDoc -instance {-# OVERLAPS #-} PPGenericOverride IntSet.IntSet where+instance {-# OVERLAPS #-} PPGenericOverride IntSet where ppGenericOverride = atomicMetaDoc . ppIntSetWith ppGenericOverrideDoc @@ -436,6 +444,16 @@ ppGenericOverride = atomicMetaDoc . ppIntMapWith ppGenericOverrideDoc ppGenericOverrideDoc +#ifdef HAVE_ENUMMAPSET+instance {-# OVERLAPS #-} (Enum a, PPGenericOverride a) => PPGenericOverride (EnumSet a) where+ ppGenericOverride =+ atomicMetaDoc . ppEnumSetWith ppGenericOverrideDoc++instance {-# OVERLAPS #-} (Enum k, PPGenericOverride k, PPGenericOverride v) => PPGenericOverride (EnumMap k v ) where+ ppGenericOverride =+ atomicMetaDoc . ppEnumMapWith ppGenericOverrideDoc ppGenericOverrideDoc+#endif+ instance {-# OVERLAPS #-} PPGenericOverride v => PPGenericOverride (HashSet v) where ppGenericOverride = atomicMetaDoc . ppHashSetWith ppGenericOverrideDoc@@ -480,7 +498,7 @@ instance GPretty x => GFields (M1 S ('MetaSel a b c d) x) where {-# INLINABLE gfields #-}- gfields = DList.singleton . gpretty . unM1+ gfields = DL.singleton . gpretty . unM1 instance (GFields f, GFields g) => GFields (f :*: g) where {-# INLINABLE gfields #-}@@ -500,7 +518,7 @@ instance (KnownSymbol name, GPretty a) => GCollectRecord (M1 S ('MetaSel ('Just name) su ss ds) a) where {-# INLINABLE gcollectRecord #-} gcollectRecord (M1 x) =- DList.singleton (T.pack (symbolVal (Proxy @name)) :-> gpretty x)+ DL.singleton (T.pack (symbolVal (Proxy @name)) :-> gpretty x) instance (GCollectRecord f, GCollectRecord g) => GCollectRecord (f :*: g) where {-# INLINABLE gcollectRecord #-}
src/Prettyprinter/MetaDoc.hs view
@@ -46,7 +46,6 @@ import Data.ByteString.Lazy.Char8 qualified as CL8 import Data.ByteString.Short qualified as ShortBS import Data.Int-import Data.Semigroup as Semigroup import Data.Text qualified as T import Data.Text.Lazy qualified as TL import Data.Word@@ -62,8 +61,7 @@ (<>) = max instance Monoid DocKind where- mempty = minBound- mappend = (Semigroup.<>)+ mempty = minBound data MetaDoc ann = MetaDoc { mdPayload :: Doc ann
src/Prettyprinter/Show.hs view
@@ -13,6 +13,8 @@ module Prettyprinter.Show ( ppShow , PPShow(..)+ -- * Reexports+ , Pretty(..) ) where import Data.Text qualified as T