Permalink
Browse files

Make Text.PrettyPrint the recommended module

  • Loading branch information...
David Terei
David Terei committed Jul 19, 2011
1 parent 0f978d7 commit 6169601cfb864d8b25c0f1cb32f44a7a7949db93
Showing with 68 additions and 18 deletions.
  1. +46 −3 Text/PrettyPrint.hs
  2. +22 −15 Text/PrettyPrint/HughesPJ.hs
View
@@ -11,13 +11,56 @@
-- The default interface to the pretty-printing library. Provides a collection
-- of pretty printer combinators.
--
--- This should be used as opposed to the "Text.PrettyPrint.HughesPJ" module that
--- contains the actual implementation that this module simply re-exports.
+-- This module should be used as opposed to the "Text.PrettyPrint.HughesPJ"
+-- module. Both are equivalent though as this module simply re-exports the
+-- other.
--
-----------------------------------------------------------------------------
module Text.PrettyPrint (
- module Text.PrettyPrint.HughesPJ
+
+ -- * The document type
+ Doc,
+
+ -- * Constructing documents
+
+ -- ** Converting values into documents
+ char, text, ptext, sizedText, zeroWidthText,
+ int, integer, float, double, rational,
+
+ -- ** Simple derived documents
+ semi, comma, colon, space, equals,
+ lparen, rparen, lbrack, rbrack, lbrace, rbrace,
+
+ -- ** Wrapping documents in delimiters
+ parens, brackets, braces, quotes, doubleQuotes,
+
+ -- ** Combining documents
+ empty,
+ (<>), (<+>), hcat, hsep,
+ ($$), ($+$), vcat,
+ sep, cat,
+ fsep, fcat,
+ nest,
+ hang, punctuate,
+
+ -- * Predicates on documents
+ isEmpty,
+
+ -- * Rendering documents
+
+ -- ** Default rendering
+ render,
+
+ -- ** Rendering with a particular style
+ Style(..),
+ style,
+ renderStyle,
+
+ -- ** General rendering
+ fullRender,
+ Mode(..), TextDetails(..)
+
) where
import Text.PrettyPrint.HughesPJ
@@ -173,7 +173,7 @@ Relative to John's original paper, there are the following new features:
module Text.PrettyPrint.HughesPJ (
-- * The document type
- Doc, -- Abstract
+ Doc,
-- * Constructing documents
@@ -373,13 +373,13 @@ instance Show Doc where
render :: Doc -> String
-- | The general rendering interface.
-fullRender :: Mode -- ^Rendering mode
- -> Int -- ^Line length
- -> Float -- ^Ribbons per line
- -> (TextDetails -> a -> a) -- ^What to do with text
- -> a -- ^What to do at the end
- -> Doc -- ^The document
- -> a -- ^Result
+fullRender :: Mode -- ^ Rendering mode
+ -> Int -- ^ Line length
+ -> Float -- ^ Ribbons per line
+ -> (TextDetails -> a -> a) -- ^ What to do with text
+ -> a -- ^ What to do at the end
+ -> Doc -- ^ The document
+ -> a -- ^ Result
-- | Render the document as a string using a specified style.
renderStyle :: Style -> Doc -> String
@@ -396,10 +396,10 @@ style :: Style
style = Style { lineLength = 100, ribbonsPerLine = 1.5, mode = PageMode }
-- | Rendering mode.
-data Mode = PageMode -- ^Normal
- | ZigZagMode -- ^With zig-zag cuts
- | LeftMode -- ^No indentation, infinitely long lines
- | OneLineMode -- ^All on one line
+data Mode = PageMode -- ^ Normal
+ | ZigZagMode -- ^ With zig-zag cuts
+ | LeftMode -- ^ No indentation, infinitely long lines
+ | OneLineMode -- ^ All on one line
-- ---------------------------------------------------------------------------
-- The Doc calculus
@@ -561,9 +561,16 @@ reduceDoc (Above p g q) = above p g (reduceDoc q)
reduceDoc p = p
-data TextDetails = Chr Char
- | Str String
- | PStr String
+-- | The TextDetails data type
+--
+-- A TextDetails represents a *fragement* of text that will be
+-- output at some point.
+data TextDetails = Chr Char -- ^ A single Char fragment
+ | Str String -- ^ A whole String fragment
+ | PStr String -- ^ Used to represent a Fast String fragment
+ -- but now deprecated and identical to the
+ -- Str constructor.
+
space_text, nl_text :: TextDetails
space_text = Chr ' '
nl_text = Chr '\n'

0 comments on commit 6169601

Please sign in to comment.