prettyprinter 1.7.1 → 1.7.2
raw patch · 17 files changed
+240/−167 lines, 17 filesdep +tasty-benchdep −faildep −gaugedep −transformersdep ~QuickCheckdep ~basedep ~base-compat
Dependencies added: tasty-bench
Dependencies removed: fail, gauge, transformers, void
Dependency ranges changed: QuickCheck, base, base-compat, quickcheck-instances, semigroups
Files
- CHANGELOG.md +16/−0
- README.md +1/−1
- app/GenerateReadme.hs +1/−1
- bench/FasterUnsafeText.hs +1/−1
- bench/Fusion.hs +3/−5
- bench/LargeOutput.hs +3/−3
- misc/version-compatibility-macros.h +2/−6
- prettyprinter.cabal +19/−36
- src/Prettyprinter.hs +4/−4
- src/Prettyprinter/Internal.hs +179/−70
- src/Prettyprinter/Render/Text.hs +0/−8
- src/Prettyprinter/Render/Tutorials/StackMachineTutorial.hs +0/−4
- src/Prettyprinter/Render/Util/SimpleDocTree.hs +2/−12
- src/Prettyprinter/Render/Util/StackMachine.hs +5/−5
- test/Doctest/Main.hs +4/−0
- test/Testsuite/Main.hs +0/−7
- test/Testsuite/StripTrailingSpace.hs +0/−4
CHANGELOG.md view
@@ -1,3 +1,19 @@+# [1.7.2] – April 2026++- [Add `PrettyAnn` type class](https://github.com/quchen/prettyprinter/pull/256)+- [Remove the MINIMAL pragma from `Pretty`](https://github.com/quchen/prettyprinter/pull/219)+- [Add instance `ann ~ Void => Pretty (Doc ann)`](https://github.com/quchen/prettyprinter/pull/234)+- [Add `Pretty` instances for 4-7 tuples](https://github.com/quchen/prettyprinter/pull/275)+- [Make it compile with MicroHs](https://github.com/quchen/prettyprinter/pull/270)+- [Drop support for GHC 7](https://github.com/quchen/prettyprinter/pull/278)+- [Remove compatibility code for GHC < 8](https://github.com/quchen/prettyprinter/pull/285)+- Documentation improvements:+ * [#229](https://github.com/quchen/prettyprinter/pull/229)+ * [#255](https://github.com/quchen/prettyprinter/pull/255)+ * [#273](https://github.com/quchen/prettyprinter/pull/273)++[1.7.2]: https://github.com/quchen/prettyprinter/compare/v1.7.1...v1.7.2+ # [1.7.1] - [Deprecate the `Data.Text.Prettyprint.*` modules](https://github.com/quchen/prettyprinter/pull/203)
README.md view
@@ -87,7 +87,7 @@ Text is not all letters and newlines. Often, we want to add more information, the simplest kind being some form of styling. An ANSI terminal supports-coloring, a web browser a plethora of different formattings.+coloring, a web browser a plethora of different formatting options. More complex uses of annotations include e.g. adding type annotations for mouse-over hovers when printing a syntax tree, adding URLs to documentation, or
app/GenerateReadme.hs view
@@ -97,7 +97,7 @@ , paragraph [multiline| Text is not all letters and newlines. Often, we want to add more information, the simplest kind being some form of styling. An ANSI terminal supports coloring, a web browser a plethora of- different formattings. |]+ different formatting options. |] , paragraph [multiline| More complex uses of annotations include e.g. adding type annotations for mouse-over hovers when printing a syntax
bench/FasterUnsafeText.hs view
@@ -4,11 +4,11 @@ -import Gauge.Main import Data.Char import Data.Text (Text) import qualified Data.Text as T import Prettyprinter.Internal+import Test.Tasty.Bench
bench/Fusion.hs view
@@ -9,21 +9,17 @@ import Control.Monad import Control.Monad.State-import Gauge.Main import Data.Text (Text) import qualified Data.Text as T import System.Random+import Test.Tasty.Bench import Prettyprinter import Prettyprinter.Render.Text import qualified Text.PrettyPrint.ANSI.Leijen as WL -#if !(APPLICATIVE_MONAD)-import Control.Applicative-#endif - main :: IO () main = defaultMain [ benchOptimize@@ -47,6 +43,8 @@ randomShortWords' :: Int -> State StdGen [Text] randomShortWords' n = replicateM n randomShortWord + -- Note: 'split' is deprecated in random >= 1.2 in favor of 'splitGen'.+ -- We could use 'splitGen' when support for GHC < 9.0 is dropped. randomShortWord :: State StdGen Text randomShortWord = do g <- get
bench/LargeOutput.hs view
@@ -10,7 +10,6 @@ import Control.DeepSeq import Control.Monad.Compat-import Gauge import Data.Char import Data.Map (Map) import qualified Data.Map as M@@ -24,6 +23,7 @@ import Test.QuickCheck import Test.QuickCheck.Gen import Test.QuickCheck.Random+import Test.Tasty.Bench import qualified Text.PrettyPrint.ANSI.Leijen as WL @@ -198,12 +198,12 @@ , bench "layoutSmart" (nf (renderWith (layoutSmart _80ColumnsLayoutOptions)) prog) , bench "layoutCompact" (nf (renderWith layoutCompact ) prog) ]- , bench "ansi-wl-pprint" (nf (($ "") . WL.displayS . WL.renderPretty 0.5 80 . WL.pretty) prog) ]+ , bench "ansi-wl-pprint" (nf (\x -> (WL.displayS . WL.renderPretty 0.5 80 . WL.pretty) x "") prog) ] , bgroup "Infinite/large page width" [ bgroup "prettyprinter" [ bench "layoutPretty" (nf (renderWith (layoutPretty unboundedLayoutOptions)) prog) , bench "layoutSmart" (nf (renderWith (layoutSmart unboundedLayoutOptions)) prog) , bench "layoutCompact" (nf (renderWith layoutCompact ) prog) ]- , bench "ansi-wl-pprint" (nf (($ "") . WL.displayS . WL.renderPretty 1 (fromIntegral progWidth + 10) . WL.pretty) prog) ]+ , bench "ansi-wl-pprint" (nf (\x -> (WL.displayS . WL.renderPretty 1 (fromIntegral progWidth + 10) . WL.pretty) x "") prog) ] ]
misc/version-compatibility-macros.h view
@@ -8,13 +8,9 @@ -- These macros allow writing CPP compatibility hacks in a way that makes their -- purpose much clearer than just demanding a specific version of a library. -#define APPLICATIVE_MONAD MIN_VERSION_base(4,8,0)-#define FOLDABLE_TRAVERSABLE_IN_PRELUDE MIN_VERSION_base(4,8,0)-#define FUNCTOR_IDENTITY_IN_BASE MIN_VERSION_base(4,8,0)-#define MONOID_IN_PRELUDE MIN_VERSION_base(4,8,0)-#define NATURAL_IN_BASE MIN_VERSION_base(4,8,0)+#define FOLDABLE_TRAVERSABLE_IN_PRELUDE !defined(__MHS__) -#define SEMIGROUP_IN_BASE MIN_VERSION_base(4,9,0)+#define LIFTA2_IN_PRELUDE MIN_VERSION_base(4,18,0) #define SEMIGROUP_MONOID_SUPERCLASS MIN_VERSION_base(4,11,0)
prettyprinter.cabal view
@@ -1,5 +1,5 @@ name: prettyprinter-version: 1.7.1+version: 1.7.2 cabal-version: >= 1.10 category: User Interfaces, Text synopsis: A modern, easy to use, well-documented, extensible pretty-printer.@@ -14,12 +14,11 @@ bug-reports: http://github.com/quchen/prettyprinter/issues homepage: http://github.com/quchen/prettyprinter build-type: Simple-tested-with: GHC==9.0.1, GHC==8.10.4, GHC==8.8.4, GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2+tested-with: GHC==9.14.1, GHC==9.12.2, GHC==9.10.3, GHC==9.8.4, GHC==9.6.7, GHC==9.4.8, GHC==9.2.8, GHC==9.0.2, GHC==8.10.7, GHC==8.8.4, GHC==8.6.5, GHC==8.4.4, GHC==8.2.2, GHC==8.0.2 source-repository head type: git- location: git://github.com/quchen/prettyprinter.git-+ location: https://github.com/quchen/prettyprinter library@@ -56,7 +55,7 @@ , Data.Text.Prettyprint.Doc.Symbols.Unicode , Data.Text.Prettyprint.Doc.Symbols.Ascii - ghc-options: -Wall -O2+ ghc-options: -Wall -O2 -Wcompat hs-source-dirs: src include-dirs: misc default-language: Haskell2010@@ -68,7 +67,7 @@ , ScopedTypeVariables build-depends:- base >= 4.5 && < 5+ base >= 4.9 && < 5 if flag(text) build-depends: text >= 1.2@@ -81,19 +80,7 @@ , Data.Text.Lazy , Data.Text.Lazy.Builder - if !impl(ghc >= 7.6)- build-depends: ghc-prim - if impl(ghc >= 8.0)- ghc-options: -Wcompat- if !impl(ghc >= 8.0)- build-depends: semigroups >= 0.17- build-depends: fail >= 4.9.0.0 && <4.10- if !impl(ghc >= 7.10)- build-depends: void >=0.4 && <0.8--- Flag buildReadme Description: Build the readme generator Default: False@@ -105,13 +92,15 @@ this is inconvenient. In this case one can disable this flag, so that @prettyprinter@ fallbacks to @String@. Default: True+ -- https://github.com/quchen/prettyprinter/issues/264+ Manual: True executable generate_readme hs-source-dirs: app main-is: GenerateReadme.hs build-depends:- base >= 4.7 && < 5+ base >= 4.9 && < 5 , prettyprinter , text@@ -133,15 +122,12 @@ hs-source-dirs: test/Doctest main-is: Main.hs build-depends:- base >= 4.7 && < 5+ base >= 4.9 && < 5 , doctest >= 0.9 , prettyprinter , QuickCheck >= 2.5 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010- if impl (ghc < 7.10)- buildable: False- -- Doctest does not support searching through directories in old versions test-suite testsuite type: exitcode-stdio-1.0@@ -154,7 +140,7 @@ , pgp-wordlist >= 0.1 , bytestring- , quickcheck-instances >= 0.3+ , quickcheck-instances >= 0.3.17 , tasty >= 0.10 , tasty-hunit >= 0.9 , tasty-quickcheck >= 0.8@@ -162,9 +148,6 @@ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall default-language: Haskell2010 - if !impl(ghc >= 8.0)- build-depends: semigroups >= 0.6- if !flag(text) buildable: False @@ -174,14 +157,13 @@ hs-source-dirs: bench main-is: Fusion.hs build-depends:- base >= 4.5 && < 5+ base >= 4.9 && < 5 , prettyprinter - , gauge >= 0.2+ , tasty-bench >= 0.2 , mtl >= 2.1 , random >= 1.0 , text- , transformers >= 0.3 , ansi-wl-pprint >= 0.6 ghc-options: -Wall -rtsopts default-language: Haskell2010@@ -192,10 +174,10 @@ benchmark faster-unsafe-text build-depends:- base >= 4.5 && < 5+ base >= 4.9 && < 5 , prettyprinter - , gauge >= 0.2+ , tasty-bench >= 0.2 , text hs-source-dirs: bench@@ -209,13 +191,13 @@ benchmark large-output build-depends:- base >= 4.5 && < 5- , base-compat >=0.9.3 && <0.12+ base >= 4.9 && < 5+ , base-compat >=0.9.3 && <0.15 , prettyprinter , ansi-wl-pprint - , gauge >= 0.2- , QuickCheck >= 2.7+ , tasty-bench >= 0.2+ , QuickCheck >= 2.8 , containers , text , deepseq@@ -226,6 +208,7 @@ default-language: Haskell2010 type: exitcode-stdio-1.0 + -- For GHC.Generics if !impl(ghc >= 7.6) build-depends: ghc-prim
src/Prettyprinter.hs view
@@ -180,7 +180,7 @@ -- -- /Modularity:/ To change the color of keywords later, you have to touch one -- point, namely the mapping in @'reAnnotateS'@, where @'Keyword'@ is mapped to--- 'Red'. If you have @'annotate Red …'@ everywher, you’ll have to do a full+-- 'Red'. If you have @'annotate Red …'@ everywhere, you’ll have to do a full -- text replacement, producing a large diff and touching lots of places for a -- very small change. --@@ -198,7 +198,7 @@ Doc, -- * Basic functionality- Pretty(..),+ Pretty(..), PrettyAnn(..), viaShow, unsafeViaShow, emptyDoc, nest, line, line', softline, softline', hardline, @@ -224,7 +224,7 @@ -- * List functions -- | The 'sep' and 'cat' functions differ in one detail: when 'group'ed, the- -- 'sep's replace newlines wich 'space's, while the 'cat's simply remove+ -- 'sep's replace newlines which 'space's, while the 'cat's simply remove -- them. If you're not sure what you want, start with the 'sep's. concatWith,@@ -321,7 +321,7 @@ -- There are 3 main ways to migrate: -- -- 1. Direct: just replace the previous package and fix the errors--- 2. Using a drop-in replacement mimicing the API of the former module, see+-- 2. Using a drop-in replacement mimicking the API of the former module, see -- the @prettyprinter-compat-<former package>@ packages -- 3. Using a converter from the old @Doc@ type to the new one, see the -- @prettyprinter-convert-<former package>@ packages
src/Prettyprinter/Internal.hs view
@@ -1,10 +1,13 @@-{-# LANGUAGE BangPatterns #-}-{-# LANGUAGE CPP #-}-{-# LANGUAGE DefaultSignatures #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE DefaultSignatures #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeOperators #-} {-# OPTIONS_HADDOCK not-home #-} @@ -22,7 +25,7 @@ Doc(..), -- * Basic functionality- Pretty(..),+ Pretty(..), PrettyAnn(..), viaShow, unsafeViaShow, unsafeTextWithoutNewlines, emptyDoc, nest, line, line', softline, softline', hardline, @@ -90,7 +93,6 @@ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Lazy as Lazy-import Data.Typeable (Typeable) import Data.Void import Data.Word import GHC.Generics (Generic)@@ -99,19 +101,15 @@ -- from the semigroups package. import Data.Semigroup -#if NATURAL_IN_BASE import Numeric.Natural-#endif #if !(FOLDABLE_TRAVERSABLE_IN_PRELUDE) import Data.Foldable (Foldable (..)) import Data.Traversable (Traversable (..))-import Prelude hiding (foldr, foldr1)+import Prelude hiding (null, foldr, foldr1) #endif -#if FUNCTOR_IDENTITY_IN_BASE import Data.Functor.Identity-#endif import Prettyprinter.Render.Util.Panic @@ -191,7 +189,7 @@ -- | Add an annotation to the enclosed 'Doc'. Can be used for example to add -- styling directives or alt texts that can then be used by the renderer. | Annotated ann (Doc ann)- deriving (Generic, Typeable)+ deriving Generic -- | -- @@@ -278,8 +276,6 @@ prettyList :: [a] -> Doc ann prettyList = align . list . map pretty - {-# MINIMAL pretty #-}- -- $ -- Issue #67: Nested lists were not aligned with »pretty«, leading to non-pretty -- output, violating the Pretty class law.@@ -294,15 +290,17 @@ -- , (1, [2, 2, 2, 2, 2, 2, 2, 2]) -- , (1, [2, 2, 2, 2, 2, 2, 2, 2]) ] ] +-- | @since 1.7.2+instance ann ~ Void => Pretty (Doc ann) where+ pretty = vacuous+ instance Pretty a => Pretty (Const a b) where pretty = pretty . getConst -#if FUNCTOR_IDENTITY_IN_BASE -- | >>> pretty (Identity 1) -- 1 instance Pretty a => Pretty (Identity a) where pretty = pretty . runIdentity-#endif -- | >>> pretty [1,2,3] -- [1, 2, 3]@@ -328,7 +326,7 @@ pretty True = "True" pretty False = "False" --- | Instead of @('pretty' '\n')@, consider using @'line'@ as a more readable+-- | Instead of @('pretty' '\\n')@, consider using @'line'@ as a more readable -- alternative. -- -- >>> pretty 'f' <> pretty 'o' <> pretty 'o'@@ -345,6 +343,51 @@ prettyList = vsep . map unsafeTextWithoutNewlines . T.splitOn "\n" #endif +-- | This class is similar to 'Pretty', but allows you to embed annotations in+-- the 'Doc'.+--+-- @since 1.7.2+class PrettyAnn ann a where++ prettyAnn :: a -> Doc ann++ default prettyAnn :: Show a => a -> Doc ann+ prettyAnn = viaShow++ prettyAnnList :: [a] -> Doc ann+ prettyAnnList = align . list . map prettyAnn++-- | @since 1.7.2+instance PrettyAnn ann (Doc ann) where+ prettyAnn = id++-- | @since 1.7.2+instance PrettyAnn ann a => PrettyAnn ann (Const a b) where+ prettyAnn = prettyAnn . getConst++-- | @since 1.7.2+instance PrettyAnn ann a => PrettyAnn ann (Identity a) where+ prettyAnn = prettyAnn . runIdentity++-- | @since 1.7.2+instance PrettyAnn ann a => PrettyAnn ann [a] where+ prettyAnn = prettyAnnList++-- | @since 1.7.2+instance PrettyAnn ann a => PrettyAnn ann (NonEmpty a) where+ prettyAnn (x:|xs) = prettyAnnList (x:xs)++-- | @since 1.7.2+instance PrettyAnn ann () where prettyAnn = pretty++-- | @since 1.7.2+instance PrettyAnn ann Bool where prettyAnn = pretty++-- | @since 1.7.2+instance PrettyAnn ann Char where+ prettyAnn = pretty+ prettyAnnList = prettyList+ -- | Convenience function to convert a 'Show'able value to a 'Doc'. If the -- 'String' does not contain newlines, consider using the more performant -- 'unsafeViaShow'.@@ -373,9 +416,7 @@ -- 10633823966279326983230456482242756608 instance Pretty Integer where pretty = unsafeViaShow -#if NATURAL_IN_BASE instance Pretty Natural where pretty = unsafeViaShow-#endif -- | >>> pretty (pi :: Float) -- 3.1415927@@ -395,37 +436,34 @@ instance (Pretty a1, Pretty a2, Pretty a3) => Pretty (a1,a2,a3) where pretty (x1,x2,x3) = tupled [pretty x1, pretty x2, pretty x3] --- -- | >>> pretty (123, "hello", False, ())--- -- (123, hello, False, ())--- instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4) => Pretty (a1,a2,a3,a4) where--- pretty (x1,x2,x3,x4) = tupled [pretty x1, pretty x2, pretty x3, pretty x4]+-- | >>> pretty (123, "hello", False, ())+-- (123, hello, False, ()) ----- -- | >>> pretty (123, "hello", False, (), 3.14)--- -- (123, hello, False, (), 3.14)--- instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5) => Pretty (a1,a2,a3,a4,a5) where--- pretty (x1,x2,x3,x4,x5) = tupled [pretty x1, pretty x2, pretty x3, pretty x4, pretty x5]+-- @since 1.7.2+instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4) => Pretty (a1,a2,a3,a4) where+ pretty (x1,x2,x3,x4) = tupled [pretty x1, pretty x2, pretty x3, pretty x4]++-- | >>> pretty (123, "hello", False, (), 3.14)+-- (123, hello, False, (), 3.14) ----- -- | >>> pretty (123, "hello", False, (), 3.14, Just 2.71)--- -- ( 123--- -- , hello--- -- , False--- -- , ()--- -- , 3.14--- -- , 2.71 )--- instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5, Pretty a6) => Pretty (a1,a2,a3,a4,a5,a6) where--- pretty (x1,x2,x3,x4,x5,x6) = tupled [pretty x1, pretty x2, pretty x3, pretty x4, pretty x5, pretty x6]+-- @since 1.7.2+instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5) => Pretty (a1,a2,a3,a4,a5) where+ pretty (x1,x2,x3,x4,x5) = tupled [pretty x1, pretty x2, pretty x3, pretty x4, pretty x5]++-- | >>> pretty (123, "hello", False, (), 3.14, Just 2.71)+-- (123, hello, False, (), 3.14, 2.71) ----- -- | >>> pretty (123, "hello", False, (), 3.14, Just 2.71, [1,2,3])--- -- ( 123--- -- , hello--- -- , False--- -- , ()--- -- , 3.14--- -- , 2.71--- -- , [1, 2, 3] )--- instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5, Pretty a6, Pretty a7) => Pretty (a1,a2,a3,a4,a5,a6,a7) where--- pretty (x1,x2,x3,x4,x5,x6,x7) = tupled [pretty x1, pretty x2, pretty x3, pretty x4, pretty x5, pretty x6, pretty x7]+-- @since 1.7.2+instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5, Pretty a6) => Pretty (a1,a2,a3,a4,a5,a6) where+ pretty (x1,x2,x3,x4,x5,x6) = tupled [pretty x1, pretty x2, pretty x3, pretty x4, pretty x5, pretty x6] +-- | >>> pretty (123, "hello", False, (), 3.14, Just 2.71, [1,2,3])+-- (123, hello, False, (), 3.14, 2.71, [1, 2, 3])+--+-- @since 1.7.2+instance (Pretty a1, Pretty a2, Pretty a3, Pretty a4, Pretty a5, Pretty a6, Pretty a7) => Pretty (a1,a2,a3,a4,a5,a6,a7) where+ pretty (x1,x2,x3,x4,x5,x6,x7) = tupled [pretty x1, pretty x2, pretty x3, pretty x4, pretty x5, pretty x6, pretty x7]+ -- | Ignore 'Nothing's, print 'Just' contents. -- -- >>> pretty (Just True)@@ -452,10 +490,12 @@ -- hello world -- -- Manually use @'hardline'@ if you /definitely/ want newlines.-instance Pretty Text where pretty = vsep . map unsafeTextWithoutNewlines . T.splitOn "\n"+instance Pretty Text where+ pretty = vsep . map unsafeTextWithoutNewlines . T.splitOn "\n" -- | (lazy 'Text' instance, identical to the strict version)-instance Pretty Lazy.Text where pretty = pretty . Lazy.toStrict+instance Pretty Lazy.Text+ where pretty = pretty . Lazy.toStrict #endif -- | Finding a good example for printing something that does not exist is hard,@@ -465,8 +505,81 @@ -- [] instance Pretty Void where pretty = absurd +-- | @since 1.7.2+instance PrettyAnn ann Int where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Int8 where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Int16 where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Int32 where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Int64 where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Word where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Word8 where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Word16 where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Word32 where prettyAnn = pretty+-- | @since 1.7.2+instance PrettyAnn ann Word64 where prettyAnn = pretty +-- | @since 1.7.2+instance PrettyAnn ann Integer where prettyAnn = pretty +-- | @since 1.7.2+instance PrettyAnn ann Natural where prettyAnn = pretty++-- | @since 1.7.2+instance PrettyAnn ann Float where prettyAnn = pretty++-- | @since 1.7.2+instance PrettyAnn ann Double where prettyAnn = pretty++-- | @since 1.7.2+instance (PrettyAnn ann a1, PrettyAnn ann a2) => PrettyAnn ann (a1,a2) where+ prettyAnn (x1,x2) = tupled [prettyAnn x1, prettyAnn x2]++-- | @since 1.7.2+instance (PrettyAnn ann a1, PrettyAnn ann a2, PrettyAnn ann a3) => PrettyAnn ann (a1,a2,a3) where+ prettyAnn (x1,x2,x3) = tupled [prettyAnn x1, prettyAnn x2, prettyAnn x3]++-- | @since 1.7.2+instance (PrettyAnn ann a1, PrettyAnn ann a2, PrettyAnn ann a3, PrettyAnn ann a4) => PrettyAnn ann (a1,a2,a3,a4) where+ prettyAnn (x1,x2,x3,x4) = tupled [prettyAnn x1, prettyAnn x2, prettyAnn x3, prettyAnn x4]++-- | @since 1.7.2+instance (PrettyAnn ann a1, PrettyAnn ann a2, PrettyAnn ann a3, PrettyAnn ann a4, PrettyAnn ann a5) => PrettyAnn ann (a1,a2,a3,a4,a5) where+ prettyAnn (x1,x2,x3,x4,x5) = tupled [prettyAnn x1, prettyAnn x2, prettyAnn x3, prettyAnn x4, prettyAnn x5]++-- | @since 1.7.2+instance (PrettyAnn ann a1, PrettyAnn ann a2, PrettyAnn ann a3, PrettyAnn ann a4, PrettyAnn ann a5, PrettyAnn ann a6) => PrettyAnn ann (a1,a2,a3,a4,a5,a6) where+ prettyAnn (x1,x2,x3,x4,x5,x6) = tupled [prettyAnn x1, prettyAnn x2, prettyAnn x3, prettyAnn x4, prettyAnn x5, prettyAnn x6]++-- | @since 1.7.2+instance (PrettyAnn ann a1, PrettyAnn ann a2, PrettyAnn ann a3, PrettyAnn ann a4, PrettyAnn ann a5, PrettyAnn ann a6, PrettyAnn ann a7) => PrettyAnn ann (a1,a2,a3,a4,a5,a6,a7) where+ prettyAnn (x1,x2,x3,x4,x5,x6,x7) = tupled [prettyAnn x1, prettyAnn x2, prettyAnn x3, prettyAnn x4, prettyAnn x5, prettyAnn x6, prettyAnn x7]++-- | @since 1.7.2+instance PrettyAnn ann a => PrettyAnn ann (Maybe a) where+ prettyAnn = maybe mempty prettyAnn+ prettyAnnList = prettyAnnList . catMaybes++#ifdef MIN_VERSION_text+-- | @since 1.7.2+instance PrettyAnn ann Text where prettyAnn = pretty++-- | @since 1.7.2+instance PrettyAnn ann Lazy.Text where prettyAnn = pretty+#endif++-- | @since 1.7.2+instance PrettyAnn ann Void where prettyAnn = absurd+++ -- | @(unsafeTextWithoutNewlines s)@ contains the literal string @s@. -- -- The string must not contain any newline characters, since this is an@@ -856,7 +969,7 @@ -- list [1,20,300,4000] -- -- If there is not enough space, then the input is split into lines entry-wise--- therwise they are laid out vertically, with separators put in the front:+-- otherwise they are laid out vertically, with separators put in the front: -- -- >>> putDocW 10 doc -- list [1@@ -1362,7 +1475,7 @@ -- @ -- -- it should not be used without caution, for each invocation traverses the--- entire contained document. If possible, it is preferrable to unannotate after+-- entire contained document. If possible, it is preferable to unannotate after -- producing the layout by using 'unAnnotateS'. unAnnotate :: Doc ann -> Doc xxx unAnnotate = alterAnnotations (const [])@@ -1373,7 +1486,7 @@ -- generally annotated document. -- -- Since this traverses the entire @'Doc'@ tree, including parts that are not--- rendered due to other layouts fitting better, it is preferrable to reannotate+-- rendered due to other layouts fitting better, it is preferable to reannotate -- after producing the layout by using @'reAnnotateS'@. -- -- Since @'reAnnotate'@ has the right type and satisfies @'reAnnotate id = id'@,@@ -1394,7 +1507,7 @@ -- not vice-versa. -- -- Since this traverses the entire @'Doc'@ tree, including parts that are not--- rendered due to other layouts fitting better, it is preferrable to reannotate+-- rendered due to other layouts fitting better, it is preferable to reannotate -- after producing the layout by using @'alterAnnotationsS'@. alterAnnotations :: (ann -> [ann']) -> Doc ann -> Doc ann' alterAnnotations re = go@@ -1448,7 +1561,6 @@ SAnnPush ann rest -> SAnnPush (re ann) (go rest) data AnnotationRemoval = Remove | DontRemove- deriving Typeable -- | Change the annotation of a document to a different annotation, or none at -- all. 'alterAnnotations' for 'SimpleDocStream'.@@ -1493,7 +1605,7 @@ -- This value should only be used if profiling shows it is significantly -- faster than using 'Shallow'. | Deep- deriving (Eq, Ord, Show, Typeable)+ deriving (Eq, Ord, Show) -- | @('fuse' depth doc)@ combines text nodes so they can be rendered more -- efficiently. A fused document is always laid out identical to its unfused@@ -1594,7 +1706,7 @@ -- | Remove a previously pushed annotation. | SAnnPop (SimpleDocStream ann)- deriving (Eq, Ord, Show, Generic, Typeable)+ deriving (Eq, Ord, Show, Generic) -- | Remove all trailing space characters. --@@ -1680,7 +1792,6 @@ = AnnotationLevel !Int | RecordedWhitespace [Int] !Int -- ^ [Newline with indentation i] Spaces- deriving Typeable @@ -1744,14 +1855,12 @@ -> Maybe Int -> SimpleDocStream ann -> Bool)- deriving Typeable -- | List of nesting level/document pairs yet to be laid out. data LayoutPipeline ann = Nil | Cons !Int (Doc ann) (LayoutPipeline ann) | UndoAnn (LayoutPipeline ann)- deriving Typeable -- | Maximum number of characters that fit in one line. The layout algorithms -- will try not to exceed the set limit by inserting line breaks when applicable@@ -1772,7 +1881,7 @@ | Unbounded -- ^ Layouters should not introduce line breaks on their own. - deriving (Eq, Ord, Show, Typeable)+ deriving (Eq, Ord, Show) defaultPageWidth :: PageWidth defaultPageWidth = AvailablePerLine 80 1@@ -1794,7 +1903,7 @@ -- | Options to influence the layout algorithms. newtype LayoutOptions = LayoutOptions { layoutPageWidth :: PageWidth }- deriving (Eq, Ord, Show, Typeable)+ deriving (Eq, Ord, Show) -- | The default layout options, suitable when you just want some output, and -- don’t particularly care about the details. Used by the 'Show' instance, for@@ -1808,9 +1917,9 @@ -- | This is the default layout algorithm, and it is used by 'show', 'putDoc' -- and 'hPutDoc'. ----- @'layoutPretty'@ commits to rendering something in a certain way if the next--- element fits the layout constraints; in other words, it has one--- 'SimpleDocStream' element lookahead when rendering. Consider using the+-- @'layoutPretty'@ commits to rendering something in a certain way if the+-- remainder of the current line fits the layout constraints; in other words,+-- it has up to one line of lookahead when rendering. Consider using the -- smarter, but a bit less performant, @'layoutSmart'@ algorithm if the results -- seem to run off to the right before having lots of line breaks. layoutPretty@@ -1841,8 +1950,8 @@ layoutPretty (LayoutOptions Unbounded) = layoutUnbounded -- | A layout algorithm with more lookahead than 'layoutPretty', that introduces--- line breaks earlier if the content does not (or will not, rather) fit into--- one line.+-- line breaks earlier if the content does not (or will not, rather) fit within+-- the page width. -- -- Consider the following python-ish document, --@@ -1869,7 +1978,7 @@ -- |------------------------| -- -- Note that this exceeds the desired 26 character page width. The same--- document, rendered with @'layoutSmart'@, fits the layout contstraints:+-- document, rendered with @'layoutSmart'@, fits the layout constraints: -- -- >>> go layoutSmart doc -- |------------------------|@@ -1984,7 +2093,7 @@ where -- * current column >= current nesting level- -- * current column - current indentaion = number of chars inserted in line+ -- * current column - current indentation = number of chars inserted in line best :: Int -- Current nesting level -> Int -- Current column, i.e. "where the cursor is"
src/Prettyprinter/Render/Text.hs view
@@ -28,14 +28,6 @@ import Prettyprinter.Internal import Prettyprinter.Render.Util.Panic -#if !(SEMIGROUP_IN_BASE)-import Data.Semigroup-#endif--#if !(APPLICATIVE_MONAD)-import Control.Applicative-#endif- -- $setup -- -- (Definitions for the doctests)
src/Prettyprinter/Render/Tutorials/StackMachineTutorial.hs view
@@ -28,10 +28,6 @@ import Prettyprinter.Render.Util.Panic import Prettyprinter.Render.Util.StackMachine -#if !(APPLICATIVE_MONAD)-import Control.Applicative-#endif- -- * The type of available markup -- -- $standalone-text
src/Prettyprinter/Render/Util/SimpleDocTree.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} #include "version-compatibility-macros.h"@@ -27,7 +26,6 @@ import Control.Applicative import Data.Text (Text) import qualified Data.Text as T-import Data.Typeable (Typeable) import GHC.Generics import Prettyprinter@@ -36,10 +34,6 @@ import qualified Control.Monad.Fail as Fail -#if !(MONOID_IN_PRELUDE)-import Data.Monoid (Monoid (..))-#endif- #if !(FOLDABLE_TRAVERSABLE_IN_PRELUDE) import Data.Foldable (Foldable (..)) import Data.Traversable (Traversable (..))@@ -104,7 +98,6 @@ -- -- Hand-written to avoid a dependency on a parser lib. newtype UniqueParser s a = UniqueParser { runParser :: s -> Maybe (a, s) }- deriving Typeable instance Functor (UniqueParser s) where fmap f (UniqueParser mx) = UniqueParser (\s ->@@ -123,9 +116,6 @@ let UniqueParser p' = f a' p' s' ) -#if !(APPLICATIVE_MONAD)- return = pure-#endif #if FAIL_IN_MONAD fail = Fail.fail #endif@@ -144,7 +134,7 @@ | TokLine Int | TokAnnPush ann | TokAnnPop- deriving (Eq, Ord, Show, Typeable)+ deriving (Eq, Ord, Show) -- | A 'SimpleDocStream' is a linked list of different annotated cons cells -- ('SText' and then some further 'SimpleDocStream', 'SLine' and then some@@ -168,7 +158,7 @@ -- | Horizontal concatenation of multiple documents. | STConcat [SimpleDocTree ann]- deriving (Eq, Ord, Show, Generic, Typeable)+ deriving (Eq, Ord, Show, Generic) -- | Alter the document’s annotations. --
src/Prettyprinter/Render/Util/StackMachine.hs view
@@ -31,7 +31,6 @@ -import Control.Applicative import Data.Text (Text) import qualified Data.Text as T @@ -42,7 +41,11 @@ import Data.Monoid #endif +#if !(LIFTA2_IN_PRELUDE)+import Control.Applicative (liftA2)+#endif + -- $setup -- -- (Definitions for the doctests)@@ -129,9 +132,6 @@ in (f1 x2, w12, s2)) instance Monoid output => Monad (StackMachine output style) where-#if !(APPLICATIVE_MONAD)- return = pure-#endif StackMachine r >>= f = StackMachine (\s -> let (x1, w1, s1) = r s StackMachine r1 = f x1@@ -163,6 +163,6 @@ writeOutput :: output -> StackMachine output style () writeOutput w = StackMachine (\styles -> ((), w, styles)) --- | Run the renderer and retrive the writing end+-- | Run the renderer and retrieve the writing end execStackMachine :: [styles] -> StackMachine output styles a -> (output, [styles]) execStackMachine styles (StackMachine r) = let (_, w, s) = r styles in (w, s)
test/Doctest/Main.hs view
@@ -2,5 +2,9 @@ import Test.DocTest +-- Silence -Wunused-packages:+import Prettyprinter ()+import Test.QuickCheck ()+ main :: IO () main = doctest [ "src" , "-Imisc"]
test/Testsuite/Main.hs view
@@ -27,13 +27,6 @@ import StripTrailingSpace -#if !(APPLICATIVE_MONAD)-import Control.Applicative-#endif-#if !(MONOID_IN_PRELUDE)-import Data.Monoid (mconcat)-#endif- main :: IO ()
test/Testsuite/StripTrailingSpace.hs view
@@ -16,10 +16,6 @@ import Test.Tasty import Test.Tasty.HUnit -#if !(APPLICATIVE_MONAD)-import Control.Applicative-#endif- box :: Text -> Text