The abstract type of documents. A Doc represents a *set* of layouts. A Doc with no occurrences of Union or NoDoc represents just one layout.
Moduleghc-9.10.3GHC2021
GHC.Utils.Ppr
John Hughes's and Simon Peyton Jones's Pretty Printer Combinators
Based on The Design of a Pretty-printing Library in Advanced Functional Programming, Johan Jeuring and Erik Meijer (eds), LNCS 925 http://www.cse.chalmers.se/~rjmh/Papers/pretty.ps
- 4 types
- 59 values
- Packageghc-9.10.3
- Exports63
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourcePpr.hs
The document type
2 declarationsConstructing documents
0 declarationsConverting values into documents
A document of height and width 1, containing a literal character.
Some text with any width. (text s = sizedText (length s) s)
Some text, but without any width. Use for non-printing text such as a HTML or Latex tags
Empty text (one line high but no width). (emptyText = text "")
Simple derived documents
Wrapping documents in delimiters
Combining documents
List version of <>.
List version of <+>.
Above, except that if the last line of the first argument stops at least one position before the first line of the second begins, these two lines are overlapped. For example:
text "hi" $$ nest 5 (text "there")lays out as
hi thererather than
hi
thereList version of $$.
"Paragraph fill" version of sep.
"Paragraph fill" version of cat.
Nest (or indent) a document by a given number of positions (which may also be negative). nest satisfies the laws:
nest 0 x = xnest k (nest k' x) = nest (k+k') xnest k (x <> y) = nest k z <> nest k ynest k (x $$ y) = nest k x $$ nest k ynest k empty = empty
The side condition on the last law is needed because empty is a left identity for <>.
hang d1 n d2 = sep [d1, nest n d2]punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn-1 <> p, dn]Predicates on documents
2 declarationsReturns True if the document is empty
Get the first character of a document. We also return a new document, equivalent to the original one but faster to render. Use it to avoid work duplication.
Rendering documents
0 declarationsRendering with a particular style
A rendering style.
Constructors
Stylemode :: ModeThe rendering mode
lineLength :: IntLength of line, in chars
ribbonsPerLine :: FloatRatio of line length to ribbon length
The default style (mode=PageMode False, lineLength=100, ribbonsPerLine=1.5).
Render the Doc to a String using the given Style.
Rendering mode.
Constructors
PageModeNormal
asciiSpace :: Bool
ZigZagModeWith zig-zag cuts
LeftModeNo indentation, infinitely long lines
OneLineModeAll on one line
General rendering
fullRender :: ModeRendering mode
-> IntLine length
-> FloatRibbons per line
-> (TextDetails -> a -> a)What to do with text
-> aWhat to do at the end
-> DocThe document
-> aResult
The general rendering interface.
Default TextDetails printer