GenericPretty 1.1.9 → 1.2.0
raw patch · 6 files changed
+55/−102 lines, 6 filesdep +prettydep ~ghcPVP ok
version bump matches the API change (PVP)
Dependencies added: pretty
Dependency ranges changed: ghc
API changes (from Hackage documentation)
- Text.PrettyPrint.MyPretty: Style :: Mode -> Int -> Float -> Style
- Text.PrettyPrint.MyPretty: data Style
- Text.PrettyPrint.MyPretty: lineLength :: Style -> Int
- Text.PrettyPrint.MyPretty: mode :: Style -> Mode
- Text.PrettyPrint.MyPretty: renderStyle :: Style -> Doc -> String
- Text.PrettyPrint.MyPretty: ribbonsPerLine :: Style -> Float
- Text.PrettyPrint.MyPretty: style :: Style
+ Text.PrettyPrint.GenericPretty: instance Out Integer
+ Text.PrettyPrint.GenericPretty: instance Out Rational
- Text.PrettyPrint.GenericPretty: class Out a
+ Text.PrettyPrint.GenericPretty: class Out a where docPrec n x = sep $ out1 (from x) Pref n False doc x = sep $ out1 (from x) Pref 0 False docList = docListWith doc
Files
- GenericPretty.cabal +10/−16
- README +24/−26
- TestSuite/CustomTest.hs +1/−1
- TestSuite/ZigZagTest.hs +1/−1
- Text/PrettyPrint/GenericPretty.hs +19/−10
- Text/PrettyPrint/MyPretty.hs +0/−48
GenericPretty.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented. -Version: 1.1.9 +Version: 1.2.0 -- A short (one-line) description of the package. Synopsis: A generic, derivable, haskell pretty printer. @@ -25,22 +25,16 @@ <http://dx.doi.org/10.1145/1863523.1863529>. Changes from the original paper in the GHC implementation are described here: - <http://www.haskell.org/haskellwiki/Generics#Changes_from_the_paper>. + <http://www.haskell.org/haskellwiki/GHC.Generics#Changes_from_the_paper>. . This package requires the use of the new GHC.Generics features - <http://www.haskell.org/haskellwiki/Generics>, present from GHC 7.2. + <http://www.haskell.org/haskellwiki/GHC.Generics>, present from GHC 7.2. Use of these features is indicated by the DeriveGeneric pragma. or the flag -XDeriveGeneric. . - Pretty printing produces values of type Pretty.Doc, using - the Pretty library - <http://www.haskell.org/ghc/docs/7.0.4/html/libraries/ghc-7.0.4/Pretty.html>. - . - The Pretty library plans to incorporate a Style datatype to control details - of printing (such as line length). The library MyPretty is provided as a - thin wrapper around the Pretty library, to support Style related features. - Once the Pretty library supports Style, MyPretty will become obsolete and - be replaced by Pretty. + Pretty printing produces values of type Text.PrettyPrint.Doc, using + the Text.PrettyPrint library + <http://www.haskell.org/ghc/docs/latest/html/libraries/pretty-1.1.1.0/Text-PrettyPrint.html>. . The output provided is a pretty printed version of that provided by Prelude.show. That is, rendering the document provided by this pretty @@ -57,7 +51,7 @@ <http://www.haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package> -- URL for the project homepage or repository. -Homepage: https://github.com/HaggisMcMutton/GenericPretty +Homepage: https://github.com/RazvanRanca/GenericPretty -- The license under which the package is released. License: BSD3 @@ -89,10 +83,10 @@ Library -- Modules exported by the library. - Exposed-modules: Text.PrettyPrint.GenericPretty Text.PrettyPrint.MyPretty + Exposed-modules: Text.PrettyPrint.GenericPretty -- Packages needed in order to build this package. - Build-depends: base >= 3 && < 5, ghc-prim, ghc >= 7.2 + Build-depends: base >= 3 && < 5, ghc-prim, pretty, ghc >= 7.4 -- Modules not exported by this package. -- Other-modules: @@ -102,4 +96,4 @@ source-repository head type: git - location: git@github.com:HaggisMcMutton/GenericPretty.git+ location: git@github.com:RazvanRanca/GenericPretty.git
README view
@@ -18,24 +18,18 @@ http://dx.doi.org/10.1145/1863523.1863529. Changes from the original paper in the GHC implementation are described here: - http://www.haskell.org/haskellwiki/Generics#Changes_from_the_paper. + http://www.haskell.org/haskellwiki/GHC.Generics#Changes_from_the_paper. This package requires the use of the new GHC.Generics features: - http://www.haskell.org/haskellwiki/Generics + http://www.haskell.org/haskellwiki/GHC.Generics present from GHC 7.2. Use of these features is indicated by the DeriveGeneric pragma or the flag -XDeriveGeneric. -Pretty printing produces values of type Pretty.Doc, using -the Pretty library - http://www.haskell.org/ghc/docs/7.0.4/html/libraries/ghc-7.0.4/Pretty.html. - -The Pretty library plans to incorporate a Style datatype to control details -of printing (such as line length). The library MyPretty is provided as a -thin wrapper around the Pretty library, to support Style related features. -Once the Pretty library supports Style, MyPretty will become obsolete and -be replaced by Pretty. - +Pretty printing produces values of type Text.PrettyPrint.Doc, using +the Text.PrettyPrint library + http://www.haskell.org/ghc/docs/latest/html/libraries/pretty-1.1.1.0/Text-PrettyPrint.html. + The output provided is a pretty printed version of that provided by Prelude.show. That is, rendering the document provided by this pretty printer yields an output identical to that of Prelude.show, except @@ -52,12 +46,17 @@ ===================== Installation Instructions =============================== =============================================================================== -The package is installed in the same way as any other package. The steps are: - 0. Make sure you have a version of ghc >= 7.2 installed and that you can +The package is installed in the same way as any other package. +If you have cabal, you can simply do: + $ cabal update + $ cabal install GenericPretty + +Otherwise, the steps are: + 0. Make sure you have a version of ghc >= 7.4 installed and that you can use the 'runhaskell' command from the command line. - 1. Download and unpack "GenericPretty-1.1.9.tar.gz" - 2. Move to the correct directory: - $ cd GenericPretty-1.1.9 + 1. Download and unpack "GenericPretty-1.2.0.tar.gz" + 2. Move to the correct directory: + $ cd GenericPretty-1.2.0 3. Run the following haskell commands to install the library globally: $ runhaskell Setup configure $ runhaskell Setup build @@ -150,7 +149,7 @@ {-# LANGUAGE DeriveGeneric #-} import Text.PrettyPrint.GenericPretty -import Text.PrettyPrint.MyPretty +import Text.PrettyPrint data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic) @@ -165,7 +164,7 @@ main = ppStyle zigStyle tree1 -------------------------------------- -We import "MyPretty" to gain access to the "Style" functionality. +We import "Text.PrettyPrint" to gain access to the "Style" functionality. Then we proceed to define the 'zigStyle' using a maximum line length of 30, 1.5 ribbonsPerLine and the ZigZagMode. @@ -202,7 +201,7 @@ {-# LANGUAGE DeriveGeneric #-} import Text.PrettyPrint.GenericPretty -import Text.PrettyPrint.MyPretty +import Text.PrettyPrint data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic) @@ -218,7 +217,7 @@ main = pp tree1 ------------------------------ -Here we import the library 'MyPretty' and use it directly to define doc. +Here we import the library 'Text.PrettyPrint' and use it directly to define doc. We then define 'docPrec' in terms of 'doc', ignoring the precedence parameter. We could have manually defined 'docList' as well if we wanted. As it is now, 'docList' is inferred from 'doc'. @@ -246,10 +245,9 @@ (customLeaf -14141414)) (customLeaf 7777777))) ----------------------------------- -The syntax used in the definition is the one used in both the Pretty and the -Text.PrettyPrint.HughesPJ libraries: - http://www.haskell.org/ghc/docs/7.0.4/html/libraries/ghc-7.0.4/Pretty.html - http://hackage.haskell.org/packages/archive/pretty/1.1.0.0/doc/html/Text-PrettyPrint-HughesPJ.html +The details of the syntax used above can be found in the +Text.PrettyPrint library: + http://www.haskell.org/ghc/docs/latest/html/libraries/pretty-1.1.1.0/Text-PrettyPrint.html =============================================================================== ========================= Further Info ======================================== @@ -260,7 +258,7 @@ examples integrated with QuickCheck can be found in 'TestSuite/Tests.hs'. Further information can be found in the API: - http://hackage.haskell.org/packages/archive/GenericPretty/1.1.9/doc/html/Text-PrettyPrint-GenericPretty.html + http://hackage.haskell.org/packages/archive/GenericPretty/latest/doc/html/Text-PrettyPrint-GenericPretty.html and in the source code itself. ===============================================================================
TestSuite/CustomTest.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE DeriveGeneric #-} import Text.PrettyPrint.GenericPretty -import Text.PrettyPrint.MyPretty +import Text.PrettyPrint data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic)
TestSuite/ZigZagTest.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE DeriveGeneric #-} import Text.PrettyPrint.GenericPretty -import Text.PrettyPrint.MyPretty +import Text.PrettyPrint data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic)
Text/PrettyPrint/GenericPretty.hs view
@@ -12,7 +12,7 @@ For examples of usage please see the README file included in the package. - For more information see the HackageDB project page: <http://hackage.haskell.org/package/GenericPretty-1.1.9> + For more information see the HackageDB project page: <http://hackage.haskell.org/package/GenericPretty> -} module Text.PrettyPrint.GenericPretty @@ -20,14 +20,13 @@ Out(..), pp, ppLen, ppStyle, pretty, prettyLen, prettyStyle, fullPP, Generic, - outputIO, outputStr + outputIO, outputStr, ) where import Data.List import GHC.Generics import Data.Char -import FastString -import Text.PrettyPrint.MyPretty +import Text.PrettyPrint -- | The class 'Out' is the equivalent of 'Prelude.Show' -- @@ -274,10 +273,9 @@ act where decode :: TextDetails -> String - decode (PStr s1) = unpackFS s1 - decode (LStr s1 _) = unpackLitString s1 - decode (Chr c) = [c] decode (Str s) = s + decode (PStr s1) = s1 + decode (Chr c) = [c] -- | Utility function that handles the text conversion for 'fullPP'. -- @@ -287,10 +285,9 @@ outputStr td str = decode td ++ str where decode :: TextDetails -> String - decode (PStr s1) = unpackFS s1 - decode (LStr s1 _) = unpackLitString s1 - decode (Chr c) = [c] decode (Str s) = s + decode (PStr s1) = s1 + decode (Chr c) = [c] -- | Customizable pretty printer -- @@ -370,6 +367,12 @@ | n/=0 && x<0 = parens $ int x | otherwise = int x doc = docPrec 0 + +instance Out Integer where + docPrec n x + | n/=0 && x<0 = parens $ integer x + | otherwise = integer x + doc = docPrec 0 instance Out Float where docPrec n x @@ -381,6 +384,12 @@ docPrec n x | n/=0 && x<0 = parens $ double x | otherwise = double x + doc = docPrec 0 + +instance Out Rational where + docPrec n x + | n/=0 && x<0 = parens $ rational x + | otherwise = rational x doc = docPrec 0 instance Out a => Out [a] where
− Text/PrettyPrint/MyPretty.hs
@@ -1,48 +0,0 @@-{-| MyPretty is a library that can be used in conjuncture with "Text.PrettyPrint.GenericPretty". - - The Pretty library(<http://www.haskell.org/ghc/docs/7.0.4/html/libraries/ghc-7.0.4/Pretty.html>) - plans to incorporate a 'Style' datatype to control details - of printing (such as line length). The library MyPretty is provided as a - thin wrapper around the Pretty library, to support 'Style' related features. - Once the Pretty library supports 'Style', MyPretty will become obsolete and - be replaced by Pretty. - - This library can be imported if the user wants to make custom pretty printing definitions for - his types or define a custom printing 'Style'. - The syntax used for defining custom documents is that of Pretty and Text.PrettyPrint.HughesPJ. - - For an example of a custom definition for a data type and usage of a custom Style - see the README file and the haskell source files under TestSuite, both included in the package. --} -module Text.PrettyPrint.MyPretty( - module Pretty, - Style(..), renderStyle, style - )where - -import Pretty hiding (render) -import FastString - --- | A rendering style -data Style - = Style { mode :: Mode -- ^ The rendering mode - , lineLength :: Int -- ^ Length of line, in chars - , ribbonsPerLine :: Float -- ^ Ratio of ribbon length to line length - } - --- | Render a document using a particular Style. -renderStyle :: Style -> Doc -> String -renderStyle s = fullRender (mode s) (lineLength s) (ribbonsPerLine s) outputStr "" - where - outputStr :: TextDetails -> String -> String - outputStr td str = decode td ++ str - where - decode :: TextDetails -> String - decode (PStr s1) = unpackFS s1 - decode (LStr s1 _) = unpackLitString s1 - decode (Chr c) = [c] - decode (Str s) = s - --- | The default 'Syle' --- (mode=PageMode, lineLength=80, ribbonsPerLine=1.5) -style :: Style -style = Style {mode = PageMode, lineLength = 80, ribbonsPerLine = 1.5}