!."      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                  ! Safeb prettyprinter Raise a hard " if there is a   in a . prettyprinter Raise a hard "H when an annotation terminator is encountered in an unannotated region. prettyprinterRaise a hard generic " when the  to  conversion fails. prettyprinter Raise a hard " when the to 4 parser finishes without consuming the full input.Safe 2378X_Om prettyprinter+Options to influence the layout algorithms.  prettyprinterMaximum 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 (e.g. via =).  prettyprinter9Layouters should not exceed the specified space per line.The #c is the number of characters, including whitespace, that fit in a line. A typical value is 80.The $ is the ribbon with, i.e. the fraction of the total page width that can be printed on. This allows limiting the length of printable text per line. Values must be between 0 and 1, and 0.4 to 1 is typical.  prettyprinter8Layouters should not introduce line breaks on their own.  prettyprinter8List of nesting level/document pairs yet to be laid out. prettyprinterDecide whether a # fits the constraints given, namely page widthminimum nesting level to fit in:width in which to fit the first line; Nothing is unbounded prettyprinterThe data type SimpleDocStreamE represents laid out documents and is used by the display functions.A simplified view is that ' = [],, and the layout functions pick one of the Hs based on which one fits the layout constraints best. This means that " has all complexity contained in 'f resolved, making it very easy to convert it to other formats, such as plain text or terminal output.To write your own '= to X converter, it is therefore sufficient to convert from e. The Render submodules provide some built-in converters to do so, and helpers to create own ones. prettyprinter9Some layout algorithms use the Since the frequently used % of the 'J, which scales linearly with its length, we cache it in this constructor. prettyprinterInt( = indentation level for the (next) line prettyprinter,Add an annotation to the remaining document. prettyprinter&Remove a previously pushed annotation. prettyprinter Fusion depth parameter, used by d. prettyprinter]Do not dive deep into nested documents, fusing mostly concatenations of text nodes together.  prettyprinterRecurse into all parts of the '], including different layout alternatives, and location-sensitive values such as created by T which cannot be fused before, but only during, the layout process. As a result, the performance cost of using deep fusion is often hard to predict, and depends on the interplay between page layout and document to prettyprint.YThis value should only be used if profiling shows it is significantly faster than using .$ prettyprinterOverloaded conversion to '.Laws: output should be pretty. :-)% prettyprinter,pretty 1 <+> pretty "hello" <+> pretty 1.234 1 hello 1.234& prettyprinter& is only used to define the  instance $ a => $ [a]#. In normal circumstances only the % function is used.prettyList [1, 23, 456] [1, 23, 456]' prettyprinterThe abstract data type ' annI represents pretty documents that have been annotated with data of type ann.#More specifically, a value of type ' represents a non-empty set of possible layouts of a document. The layout functions select one of these possibilities, taking into account things like the width of the output document.The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as7color information (e.g. when rendering to the terminal)1mouseover text (e.g. when rendering to rich HTML)Gwhether to show something or not (to allow simple or detailed versions)The simplest way to display a ' is via the & class.)putStrLn (show (vsep ["hello", "world"]))helloworld( prettyprinterkOccurs when flattening a line. The layouter will reject this document, choosing a more suitable rendering.) prettyprinter-The empty document; conceptually the unit of .* prettyprinterinvariant: not '\n'+ prettyprinter;Invariants: at least two characters long, does not contain '\n'!. For empty documents, there is Empty%; for singleton documents, there is Char&; newlines should be replaced by e.g. Line.Since the frequently used % of ' is  O(length)#, we cache it in this constructor., prettyprinterHard line break- prettyprinterLay out the first ', but when flattened (via ?o), fall back to the second. The flattened version should in general be higher and narrower than the fallback.. prettyprinterConcatenation of two documents/ prettyprinter(Document indented by a number of columns0 prettyprinterInvariant: The first lines of first document should be longer than the first lines of the second one, so the layout algorithm can pick the one that fits best. Used to implement layout alternatives for ?.1 prettyprinter*React on the current cursor position, see S2 prettyprinter#React on the document's width, see V3 prettyprinter(React on the current nesting level, see T4 prettyprinter"Add an annotation to the enclosed 'h. Can be used for example to add styling directives or alt texts that can then be used by the renderer.5 prettyprinter"Convenience function to convert a &able value to a ' . If the '@ does not contain newlines, consider using the more performant 6.6 prettyprinter"Convenience function to convert a &2able value /that must not contain newlines/ to a ' . If there may be newlines, use 5 instead.7 prettyprinter(unsafeTextWithoutNewlines s) contains the literal string s.WThe string must not contain any newline characters, since this is an invariant of the ' constructor.8 prettyprinter The empty document behaves like (% "")q, so it has a height of 1. This may lead to surprising behaviour if we expect it to bear no weight inside e.g. O0, where we get an empty line of output from it (parens for visibility only):(vsep ["hello", parens emptyDoc, "world"]hello()worldTogether with , 8 forms the ( '.9 prettyprinter(9 i x) lays out the document x2 with the current indentation level increased by iK. Negative values are allowed, and decrease the nesting level accordingly.?vsep [nest 4 (vsep ["lorem", "ipsum", "dolor"]), "sit", "amet"]lorem ipsum dolorsitamet See also C, B and D.: prettyprinterThe :N document advances to the next line and indents to the current nesting level.3let doc = "lorem ipsum" <> line <> "dolor sit amet"doc lorem ipsumdolor sit amet: behaves like space if the line break is undone by ?: group doclorem ipsum dolor sit amet; prettyprinter; is like :, but behaves like )! if the line break is undone by ? (instead of space).4let doc = "lorem ipsum" <> line' <> "dolor sit amet"doc lorem ipsumdolor sit amet group doclorem ipsumdolor sit amet< prettyprintersoftline behaves like space8 if the resulting output fits the page, otherwise like :.9Here, we have enough space to put everything in one line:7let doc = "lorem ipsum" <> softline <> "dolor sit amet"putDocW 80 doclorem ipsum dolor sit ametFIf we narrow the page to width 10, the layouter produces a line break:putDocW 10 doc lorem ipsumdolor sit amet < = ? : = prettyprinter= is like <, but behaves like )? if the resulting output does not fit on the page (instead of space). In other words, : is to ; how < is to =./With enough space, we get direct concatenation:3let doc = "ThisWord" <> softline' <> "IsWayTooLong"putDocW 80 docThisWordIsWayTooLongFIf we narrow the page to width 10, the layouter produces a line break:putDocW 10 docThisWord IsWayTooLong = = ? ; > prettyprinterA > is always% laid out as a line break, even when ?ged or when there is plenty of space. Note that it might still be simply discarded if it is part of a A inside a ?.7let doc = "lorem ipsum" <> hardline <> "dolor sit amet"putDocW 1000 doc lorem ipsumdolor sit amet group doc lorem ipsumdolor sit amet? prettyprinter(? x) tries laying out x[ into a single line by removing the contained line breaks; if this does not fit the page, x' is laid out without any changes. The ?B function is key to layouts that adapt to available space nicely.See O, :, or A8 for examples that are related, or make good use of it.@ prettyprinter!Choose the first element of each Union&, and discard the first field of all FlatAlts.The result is *z if the element might change depending on the layout algorithm (i.e. contains differently renderable sub-documents), and +8 if the document is static (e.g. contains only a plain )B node). See [Group: special flattening] for further explanations.A prettyprinter(A x fallback) renders as x by default, but falls back to fallback when ?(ed. Since the layout algorithms rely on ?U having an effect of shortening the width of the contained text, careless usage of A< with wide fallbacks might lead to unappealingly long lines.AC is particularly useful for defining conditional separators such as  softHyphen = A ) "-" softline = A space : 7We can use this to render Haskell's do-notation nicely:!let open = flatAlt "" "{ "!let close = flatAlt "" " }"!let separator = flatAlt "" "; "Mlet prettyDo xs = group ("do" <+> align (encloseSep open close separator xs))\let statements = ["name:_ <- getArgs", "let greet = \"Hello, \" <> name", "putStrLn greet"]$This is put into a single line with {;} style if it fits, putDocW 80 (prettyDo statements)Gdo { name:_ <- getArgs; let greet = "Hello, " <> name; putStrLn greet }OWhen there is not enough space the statements are broken up into lines nicely, putDocW 10 (prettyDo statements)do name:_ <- getArgs let greet = "Hello, " <> name putStrLn greetB prettyprinter(B x) lays out the document xX with the nesting level set to the current column. It is used for example to implement C.qAs an example, we will put a document right above another one, regardless of the current nesting level. Without BGment, the second line is put simply below everything we've had so far,#"lorem" <+> vsep ["ipsum", "dolor"] lorem ipsumdolor If we add an B to the mix, the K*'s contents all start in the same column,+"lorem" <+> align (vsep ["ipsum", "dolor"]) lorem ipsum dolorC prettyprinter(C i x) lays out the document x" with a nesting level set to the current column plus iK. Negative values are allowed, and decrease the nesting level accordingly.2let doc = reflow "Indenting these words with hang"$putDocW 24 ("prefix" <+> hang 4 doc)prefix Indenting these words with hangThis differs from 9, which is based on the current nesting level plus i/. When you're not sure, try the more efficient 9) first. In our example, this would yield2let doc = reflow "Indenting these words with nest"$putDocW 24 ("prefix" <+> nest 4 doc)prefix Indenting these words with nest C i doc = B (9 i doc) D prettyprinter(D i x) indents document x with i4 spaces, starting from the current cursor position.;let doc = reflow "The indent function indents these words!"%putDocW 24 ("prefix" <> indent 4 doc)prefix The indent function indents these words! D i d = C i ({i spaces} <> d) E prettyprinter(E l r sep xs) concatenates the documents xs separated by sep), and encloses the resulting document by l and r.>The documents are laid out horizontally if that fits the page,\let doc = "list" <+> align (encloseSep lbracket rbracket comma (map pretty [1,20,300,4000]))putDocW 80 doclist [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:putDocW 10 doclist [1 ,20 ,300 ,4000] Note that doc contains an explicit call to B0 so that the list items are aligned vertically.FFor putting separators at the end of entries instead, have a look at R.F prettyprinterHaskell-inspired variant of E% with braces and comma as separator.+let doc = list (map pretty [1,20,300,4000])putDocW 80 doc[1, 20, 300, 4000]putDocW 10 doc[ 1, 20, 300, 4000 ]G prettyprinterHaskell-inspired variant of E* with parentheses and comma as separator.-let doc = tupled (map pretty [1,20,300,4000])putDocW 80 doc(1, 20, 300, 4000)putDocW 10 doc( 1, 20, 300, 4000 )H prettyprinter(x H y) concatenates document x and y with a space in between."hello" <+> "world" hello world x H y = x  space  y I prettyprinter>Concatenate all documents element-wise with a binary function. I _ [] = ) I (**) [x,y,z] = x ** y ** z *Multiple convenience definitions based on I$ are alredy predefined, for example J = I (H) L = I (\x y -> x  <  y) 1This is also useful to define customized joiners,@concatWith (surround dot) ["Data", "Text", "Prettyprint", "Doc"]Data.Text.Prettyprint.DocJ prettyprinter(J xs) concatenates all documents xs horizontally with H,, i.e. it puts a space between all entries.2let docs = Util.words "lorem ipsum dolor sit amet" hsep docslorem ipsum dolor sit ametJN does not introduce line breaks on its own, even when the page is too narrow:putDocW 5 (hsep docs)lorem ipsum dolor sit amet*For automatic line breaks, consider using L instead.K prettyprinter(K xs) concatenates all documents xs above each other. If a ?$ undoes the line breaks inserted by vsep&, the documents are separated with a space instead.Using K alone yields."prefix" <+> vsep ["text", "to", "lay", "out"] prefix texttolayout?ing a K separates the documents with a space< if it fits the page (and does nothing otherwise). See the M) convenience function for this use case.The BH function can be used to align the documents under their first element:6"prefix" <+> align (vsep ["text", "to", "lay", "out"]) prefix text to lay outSince ?ing a K is rather common, M is a built-in for doing that.L prettyprinter(L xs) concatenates the documents xs horizontally with H. as long as it fits the page, then inserts a :0 and continues doing that for all documents in xs. (: means that if ?(ed, the documents are separated with a space instead of newlines. Use P if you do not want a space.)(Let's print some words to fill the line:Elet docs = take 20 (cycle ["lorem", "ipsum", "dolor", "sit", "amet"])%putDocW 80 ("Docs:" <+> fillSep docs)MDocs: lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor#sit amet lorem ipsum dolor sit amet8The same document, printed at a width of only 40, yields%putDocW 40 ("Docs:" <+> fillSep docs)&Docs: lorem ipsum dolor sit amet lorem&ipsum dolor sit amet lorem ipsum dolor#sit amet lorem ipsum dolor sit ametM prettyprinter(M xs) tries laying out the documents xs separated with spacejs, and if this does not fit the page, separates them with newlines. This is what differentiates it from K9, which always lays out its contents beneath each other.7let doc = "prefix" <+> sep ["text", "to", "lay", "out"]putDocW 80 docprefix text to lay out>With a narrower layout, the entries are separated by newlines:putDocW 20 doc prefix texttolayout M = ? . K N prettyprinter(N xs) concatenates all documents xs horizontally with  (i.e. without any spacing).>It is provided only for consistency, since it is identical to ,.)let docs = Util.words "lorem ipsum dolor" hcat docsloremipsumdolorO prettyprinter(O xs)' vertically concatenates the documents xs . If it is ? ed, the line breaks are removed.In other words O is like K0, with newlines removed instead of replaced by spaces.)let docs = Util.words "lorem ipsum dolor" vcat docsloremipsumdolorgroup (vcat docs)loremipsumdolorSince ?ing a O is rather common, Q is a built-in shortcut for it.P prettyprinter(P xs) concatenates documents xs horizontally with . as long as it fits the page, then inserts a ;0 and continues doing that for all documents in xs. This is similar to how an ordinary word processor lays out the text if you just keep typing after you hit the maximum line length.(; means that if ?Ged, the documents are separated with nothing instead of newlines. See L if you want a space instead.)Observe the difference between L and P. L concatenates the entries spaced when ?ed,Glet docs = take 20 (cycle (["lorem", "ipsum", "dolor", "sit", "amet"]))0putDocW 40 ("Grouped:" <+> group (fillSep docs))#Grouped: lorem ipsum dolor sit amet&lorem ipsum dolor sit amet lorem ipsum$dolor sit amet lorem ipsum dolor sitametOn the other hand, P) concatenates the entries directly when ?ed,0putDocW 40 ("Grouped:" <+> group (fillCat docs))$Grouped: loremipsumdolorsitametlorem'ipsumdolorsitametloremipsumdolorsitametloremipsumdolorsitametQ prettyprinter(Q xs) tries laying out the documents xs separated with nothing, and if this does not fit the page, separates them with newlines. This is what differentiates it from O9, which always lays out its contents beneath each other.)let docs = Util.words "lorem ipsum dolor"!putDocW 80 ("Docs:" <+> cat docs)Docs: loremipsumdolorDWhen there is enough space, the documents are put above one another,!putDocW 10 ("Docs:" <+> cat docs) Docs: loremipsumdolor Q = ? . O R prettyprinter(R p xs) appends p! to all but the last document in xs.Dlet docs = punctuate comma (Util.words "lorem ipsum dolor sit amet")putDocW 80 (hsep docs)lorem, ipsum, dolor, sit, ametiThe separators are put at the end of the entries, which we can see if we position the result vertically:putDocW 20 (vsep docs)lorem,ipsum,dolor,sit,amet]If you want put the commas in front of their elements instead of at the end, you should use G or, in general, E.S prettyprinter:Layout a document depending on which column it starts at. B is implemented in terms of S.6column (\l -> "Columns are" <+> pretty l <> "-based.")Columns are 0-based.@let doc = "prefix" <+> column (\l -> "| <- column" <+> pretty l)"vsep [indent n doc | n <- [0,4,8]]prefix | <- column 7 prefix | <- column 11 prefix | <- column 15T prettyprinter+Layout a document depending on the current 9 ing level. B is implemented in terms of T.Hlet doc = "prefix" <+> nesting (\l -> brackets ("Nested:" <+> pretty l))"vsep [indent n doc | n <- [0,4,8]]prefix [Nested: 0] prefix [Nested: 4] prefix [Nested: 8]U prettyprinter(U doc f) lays out the document doc<, and makes the column width of it available to a function.Ilet annotate doc = width (brackets doc) (\w -> " <- width:" <+> pretty w)[align (vsep (map annotate ["---", "------", indent 3 "---", vsep ["---", indent 4 "---"]]))[---] <- width: 5[------] <- width: 8[ ---] <- width: 8[--- ---] <- width: 8V prettyprinterILayout a document depending on the page width, if one has been specified.glet prettyPageWidth (AvailablePerLine l r) = "Width:" <+> pretty l <> ", ribbon fraction:" <+> pretty r=let doc = "prefix" <+> pageWidth (brackets . prettyPageWidth)/putDocW 32 (vsep [indent n doc | n <- [0,4,8]])(prefix [Width: 32, ribbon fraction: 1.0], prefix [Width: 32, ribbon fraction: 1.0]0 prefix [Width: 32, ribbon fraction: 1.0]W prettyprinter(W i x) lays out the document x. It then appends spaces until the width is equal to i. If the width of x) is already larger, nothing is appended.GThis function is quite useful in practice to output a list of bindings:Wlet types = [("empty","Doc"), ("nest","Int -> Doc -> Doc"), ("fillSep","[Doc] -> Doc")]Blet ptype (name, tp) = fill 5 (pretty name) <+> "::" <+> pretty tp("let" <+> align (vcat (map ptype types))let empty :: Doc nest :: Int -> Doc -> Doc fillSep :: [Doc] -> DocX prettyprinter(X i x) first lays out the document x. It then appends spaces until the width is equal to i. If the width of x is already larger than i$, the nesting level is increased by i and a line is appended. When we redefine ptype in the example given in W to use X+, we get a useful variation of the output:Wlet types = [("empty","Doc"), ("nest","Int -> Doc -> Doc"), ("fillSep","[Doc] -> Doc")]Glet ptype (name, tp) = fillBreak 5 (pretty name) <+> "::" <+> pretty tp("let" <+> align (vcat (map ptype types))let empty :: Doc nest :: Int -> Doc -> Doc fillSep :: [Doc] -> DocY prettyprinter6Insert a number of spaces. Negative values count as 0.Z prettyprinter(Z n one many) is one if n is 1, and many8 otherwise. A typical use case is adding a plural "s".let things = [True]let amount = length thingsMpretty things <+> "has" <+> pretty amount <+> plural "entry" "entries" amount[True] has 1 entry[ prettyprinter([ l r x) encloses document x between documents l and r using .enclose "A" "Z" ""AZ [ l r x = l  x  r \ prettyprinter(\ x l r) surrounds document x with l and r.surround "" "A" "Z"AZ)This is merely an argument reordering of [", but allows for definitions like@concatWith (surround ".") ["Data", "Text", "Prettyprint", "Doc"]Data.Text.Prettyprint.Doc] prettyprinterAdd an annotation to a '. This annotation can then be used by the renderer to e.g. add color to certain parts of the output. For a full tutorial example on how to use it, see the ?Data.Text.Prettyprint.Doc.Render.Tutorials.StackMachineTutorial or @Data.Text.Prettyprint.Doc.Render.Tutorials.TreeRenderingTutorial modules.This function is only relevant for custom formats with their own annotations, and not relevant for basic prettyprinting. The predefined renderers, e.g. %Data.Text.Prettyprint.Doc.Render.Text., should be enough for the most common needs.^ prettyprinterRemove all annotations. Although ^) is idempotent with respect to rendering, ^ . ^ = ^ it should not be used without caution, for each invocation traverses the entire contained document. If possible, it is preferrable to unannotate after producing the layout by using a._ prettyprinterChange the annotation of a 'ument.kUseful in particular to embed documents with one form of annotation in a more generlly annotated document. Since this traverses the entire ' tree, including parts that are not rendered due to other layouts fitting better, it is preferrable to reannotate after producing the layout by using b.Since _" has the right type and satisfies 'reAnnotate id = id', it is used to define the - instance of '.` prettyprinterChange the annotations of a 'Uument. Individual annotations can be removed, changed, or replaced by multiple ones.)This is a general function that combines ^ and _, and it is useful for mapping semantic annotations (such as this is a keyword) to display annotations (such as this is red and underlined), because some backends may not care about certain annotations, while others may.MAnnotations earlier in the new list will be applied earlier, i.e. returning  [Bold, Green]N will result in a bold document that contains green text, and not vice-versa. Since this traverses the entire ' tree, including parts that are not rendered due to other layouts fitting better, it is preferrable to reannotate after producing the layout by using c.a prettyprinterRemove all annotations. ^ for .b prettyprinter%Change the annotation of a document. _ for .c prettyprinterPChange the annotation of a document to a different annotation, or none at all. ` for .Note that the '] version is more flexible, since it allows changing a single annotation to multiple ones. (# restores this flexibility again.)d prettyprinter(d depth doc) combines text nodes so they can be rendered more efficiently. A fused document is always laid out identical to its unfused version.When laying a 'ument out to a , every component of the input is translated directly to the simpler output format. This sometimes yields undesirable chunking when many pieces have been concatenated together. For example"a" <> "b" <> pretty 'c' <> "d"abcd(results in a chain of four entries in a :, although this is fully equivalent to the tightly packed"abcd" :: Doc annabcdwhich is only a single $ entry, and can be processed faster.#It is therefore a good idea to run dF on concatenations of lots of small strings that are used many times,>let oftenUsed = fuse Shallow ("a" <> "b" <> pretty 'c' <> "d")hsep (replicate 5 oftenUsed)abcd abcd abcd abcd abcde prettyprinter%Remove all trailing space characters.VThis has some performance impact, because it does an entire additional pass over the .No trimming will be done inside annotations, which are considered to contain no (trimmable) whitespace, since the annotation might actually be aboute the whitespace, for example a renderer that colors the background of trailing whitespace, as e.g. git diff can be configured to do.f prettyprinterThe default layout options, suitable when you just want some output, and don t particularly care about the details. Used by the & instance, for example.defaultLayoutOptions9LayoutOptions {layoutPageWidth = AvailablePerLine 80 1.0}g prettyprinter8This is the default layout algorithm, and it is used by ., putDoc and hPutDoc.g commits to rendering something in a certain way if the next element fits the layout constraints; in other words, it has one [ element lookahead when rendering. Consider using the smarter, but a bit less performant, hZ algorithm if the results seem to run off to the right before having lots of line breaks.h prettyprinter,A layout algorithm with more lookahead than gh, that introduces line breaks earlier if the content does not (or will not, rather) fit into one line.+Considre the following python-ish document,4let fun x = hang 2 ("fun(" <> softline' <> x) <> ")"Llet doc = (fun . fun . fun . fun . fun) (align (list ["abcdef", "ghijklm"]))gwhich we ll be rendering using the following pipeline (where the layout algorithm has been left open),import Data.Text.IO as T,import Data.Text.Prettyprint.Doc.Render.Text6let hr = pipe <> pretty (replicate (26-2) '-') <> pipeulet go layouter x = (T.putStrLn . renderStrict . layouter (LayoutOptions (AvailablePerLine 26 1))) (vsep [hr, x, hr])If we render this using g7 with a page width of 26 characters per line, all the fun: calls fit into the first line so they will be put there,go layoutPretty doc|------------------------|fun(fun(fun(fun(fun( [ abcdef" , ghijklm ])))))|------------------------|^Note that this exceeds the desired 26 character page width. The same document, rendered with h, fits the layout contstraints:go layoutSmart doc |------------------------|fun( fun( fun( fun( fun( [ abcdef , ghijklm ])))))|------------------------|The key difference between g and h is that the latter will check the potential document up to the end of the current indentation level, instead of just having one element lookahead.i prettyprinter"The Wadler/Leijen layout algorithmj prettyprinter(layoutCompact x) lays out the document x without adding any indentation. Since no 'pretty' printing is involved, this layouter is very fast. The resulting output contains fewer characters than a prettyprinted version and can be used for output that is read by other programs.Jlet doc = hang 4 (vsep ["lorem", "ipsum", hang 4 (vsep ["dolor", "sit"])])doclorem ipsum dolor sit=let putDocCompact = renderIO System.IO.stdout . layoutCompactputDocCompact docloremipsumdolorsitk prettyprinter Render a  to a /, useful to write &' instances based on the prettyprinter.  instance & MyType where 0 _ = k . g f . % l prettyprinterDTransform a document based on its annotations, possibly leveraging 1 effects.m prettyprinter(Collect all annotations from a document.n prettyprinter!Alter the document s annotations.This instance makes + more flexible (because it can be used in --polymorphic values), but 2* is much less readable compared to using  reAnnotateST in code that only works for B anyway. Consider using the latter when the type does not matter.o prettyprinter(. doc) prettyprints document doc with f, ignoring all annotations.p prettyprinter!Alter the document s annotations.This instance makes '+ more flexible (because it can be used in --polymorphic values), but 2* is much less readable compared to using _ in code that only works for 'B anyway. Consider using the latter when the type does not matter.q prettyprinter ) = 8 , = N "mappend "hello" "world" :: Doc ann helloworldr prettyprinter x  y = N [x, y] "hello" <> "world" :: Doc ann helloworlds prettyprinterFinding a good example for printing something that does not exist is hard, so here is an example of printing a list full of nothing.pretty ([] :: [Void])[]t prettyprinter(lazy '+ instance, identical to the strict version)u prettyprinter'Automatically converts all newlines to :.pretty ("hello\nworld" :: Text)helloworld Note that : can be undone by ?:'group (pretty ("hello\nworld" :: Text)) hello world Manually use > if you  definitely want newlines.v prettyprinterIgnore + s, print * contents.pretty (Just True)True'braces (pretty (Nothing :: Maybe Bool)){})pretty [Just 1, Nothing, Just 3, Nothing][1, 3]w prettyprinterpretty (123, "hello", False)(123, hello, False)x prettyprinterpretty (123, "hello") (123, hello)y prettyprinterpretty (exp 1 :: Double)2.718281828459045z prettyprinterpretty (pi :: Float) 3.1415927| prettyprinterpretty (2^123 :: Integer)&10633823966279326983230456482242756608 prettyprinterpretty (123 :: Int)123 prettyprinter Instead of (% '\n'), consider using :! as a more readable alternative.&pretty 'f' <> pretty 'o' <> pretty 'o'foopretty ("string" :: String)string prettyprinter pretty TrueTrue prettyprinter pretty ()()The argument is not used,pretty (error "Strict?" :: ())() prettyprinterpretty [1,2,3] [1, 2, 3] prettyprinterpretty (Identity 1)1 prettyprinterpretty ("hello\nworld")helloworldThis instance uses the $ ') instance, and uses the same newline to : conversion. 9 prettyprinterChange of nesting levelA prettyprinterDefault prettyprinterFallback when ?edC prettyprinter@Change of nesting level, relative to the start of the first lineD prettyprinter+Number of spaces to increase indentation byE prettyprinterleft delimiter prettyprinterright delimiter prettyprinter separator prettyprinterinput documentsR prettyprinterPunctuation, e.g. commaW prettyprinter6Append spaces until the document is at least this wideX prettyprinter6Append spaces until the document is at least this wideZ prettyprinter1 case prettyprinter other cases[ prettyprinterL prettyprinterR prettyprinterx prettyprinterLxRe  !"#$%&'*+(),-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijke  !"#$%&'*+(),-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijkSafe= prettyprinter Render a  to a '.kkSafekkSafe'*+(),-./01234'*+(),-./01234Safe prettyprinter squotes ""'' prettyprinter dquotes """" prettyprinter parens ""() prettyprinter angles ""<> prettyprinter brackets ""[] prettyprinter braces ""{} prettyprintersquote' prettyprinterdquote" prettyprinterlparen( prettyprinterrparen) prettyprinterlangle< prettyprinterrangle> prettyprinterlbracket[ prettyprinterrbracket] prettyprinterlbrace{ prettyprinterrbrace} prettyprintersemi; prettyprintercolon: prettyprintercomma, prettyprinter"a" <> space <> "b"a bThis is mostly used via H, "a" <+> "b"a b prettyprinterdot. prettyprinterslash/ prettyprinter backslash\ prettyprinterequals= prettyprinterpipe|Daan Leijen (c) 2000, http://www.cs.uu.nl/~daan Max Bolingbroke (c) 2008, http://blog.omega-prime.co.uk David Luposchainsky (c) 2016, http://github.com/quchen#BSD-style (see the file LICENSE.md)/David Luposchainsky <dluposchainsky () google> experimentalportableSafea  $%&'5689:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXZ[\]^_`abcdefghja'$%&5689:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXZ[\]^_`abcd   fgjheSafe_ prettyprinterWriterT output StateT [style] a!, but with a strict Writer value.The output, type is used to append data chunks to, the styleA is the member of a stack of styles to model nested styles with. prettyprinter'Simplest possible stack-based renderer./For example, here is a document annotated with ()f, and the behaviour is to write >>> at the beginning, and <<< at the end of the annotated region:0let doc = "hello" <+> annotate () "world" <> "!"0let sdoc = layoutPretty defaultLayoutOptions docHT.putStrLn (renderSimplyDecorated id (\() -> ">>>") (\() -> "<<<") sdoc)hello >>>world<<<!%The monoid will be concatenated in a right associative fashion. prettyprinter Version of  that allows for 1 effects. prettyprinter#Add a new style to the style stack. prettyprinterGet the topmost style.&If the stack is empty, this raises an ". prettyprinter4View the topmost style, but do not modify the stack.&If the stack is empty, this raises an ". prettyprinter!Append a value to the output end. prettyprinter,Run the renderer and retrive the writing end prettyprinter Render plain 3 prettyprinterHow to render an annotation prettyprinter$How to render the removed annotation prettyprinter Render plain 3 prettyprinterHow to render an annotation prettyprinter$How to render the removed annotationSafe237_E prettyprinterA 6 is a linked list of different annotated cons cells ( and then some further ,  and then some further 5, &). This format is very suitable as a target for a layout engine, but not very useful for rendering to a structured format such as HTML, where we don t want to do a lookahead until the end of some markup. These formats benefit from a tree-like structure that explicitly marks its contents as annotated.  is that format. prettyprinter9Some layout algorithms use the Since the frequently used % of the 3J, which scales linearly with its length, we cache it in this constructor. prettyprinterInt( = indentation level for the (next) line prettyprinter Annotate the contained document. prettyprinter/Horizontal concatenation of multiple documents.4 prettyprinterDA type for parsers of unique results. Token stream s, results a.3Hand-written to avoid a dependency on a parser lib. prettyprinter&Simplest possible tree-based renderer./For example, here is a document annotated with ()K, and the behaviour is to surround annotated regions with >>> and <<<:0let doc = "hello" <+> annotate () "world" <> "!"<let stdoc = treeForm (layoutPretty defaultLayoutOptions doc)JT.putStrLn (renderSimplyDecorated id (\() x -> ">>>" <> x <> "<<<") stdoc)hello >>>world<<<! prettyprinter Version of  that allows for 1 effects.5 prettyprinter0Get the next token, consuming it in the process. prettyprinter Convert a  to its  representation. prettyprinterRemove all annotations. ^ for . prettyprinter%Change the annotation of a document. _ for . prettyprinterPChange the annotation of a document to a different annotation, or none at all. ` for .!Note that this is as powerful as `@, allowing one annotation to become multiple ones, contrary to c, which cannot do this. prettyprinterDTransform a document based on its annotations, possibly leveraging 1 effects. prettyprinter(Collect all annotations from a document. prettyprinter!Alter the document s annotations.This instance makes + more flexible (because it can be used in --polymorphic values), but 2* is much less readable compared to using  in code that only works for B anyway. Consider using the latter when the type does not matter. prettyprinter Render plain 3 prettyprinter+How to modify an element with an annotation prettyprinter Render plain 3 prettyprinter+How to modify an element with an annotation Safe_P prettyprinter)To render the HTML, we first convert the  to the @ format, which makes enveloping sub-documents in markup easier.This function is the entry main API function of the renderer; as such, it is only glue for the internal functions. This is similar to  1 from the stack machine tutorial in its purpose. prettyprinter Render a  to a 6R; this is the workhorse of the tree-based rendering approach, and equivalent to  * in the stack machine rendering tutorial. prettyprinter Convert a  to a function that encloses a 6M in HTML tags. This is where the translation of style to raw output happens. Safe_a prettyprinterThe  type defines a stack machine suitable for many rendering needs. It has two auxiliary parameters: the type of the end result, and the type of the document s annotations.Most I creations will look like this definition: a recursive walk through the R, pushing styles on the stack and popping them off again, and writing raw output.@The equivalent to this in the tree based rendering approach is . prettyprinter Convert a q annotation to a pair of opening and closing tags. This is where the translation of style to raw output happens. prettyprinter2We can now wrap our stack machine definition from [ in a nicer interface; on successful conversion, we run the builder to give us the final 7, and before we do that we check that the style stack is empty (i.e. there are no unmatched style applications) after the machine is run.1This function does only a bit of plumbing around g, and is the main API function of a stack machine renderer. The tree renderer equivalent to this is . Safe_sV prettyprinter( sdoc) takes the output sdoc; from a rendering function and transforms it to lazy text.Ilet render = TL.putStrLn . renderLazy . layoutPretty defaultLayoutOptionsPlet doc = "lorem" <+> align (vsep ["ipsum dolor", parens "foo bar", "sit amet"]) render doclorem ipsum dolor (foo bar) sit amet prettyprinter( sdoc) takes the output sdoc= from a rendering function and transforms it to strict text. prettyprinter( h sdoc) writes sdoc to the file h.LrenderIO System.IO.stdout (layoutPretty defaultLayoutOptions "hello\nworld")helloworld%This function is more efficient than 8 h ( sdoc)E, since it writes to the handle directly, skipping the intermediate 3 representation. prettyprinter( doc) prettyprints document doc to standard output. Uses the f.putDoc ("hello" <+> "world") hello world  =  9  prettyprinterLike , but instead of using 9F, print to a user-provided handle, e.g. a file or a socket. Uses the f. main = : filename (h ->  h doc) where doc = O4 ["vertical", "text"] filename = "someFile.txt"  h doc =  h (g f doc)  Safe prettyprinter4Double 99-66  quotes, as used in German typography.putDoc (d9966quotes "")   prettyprinter5Double 66-99  quotes, as used in English typography.putDoc (d6699quotes "")    prettyprinter2Single 9-6  quotes, as used in German typography.putDoc (s96quotes "")    prettyprinter3Single 6-9  quotes, as used in English typography.putDoc (s69quotes "")    prettyprinterDDouble guillemets, pointing outwards (without adding any spacing).putDoc (dGuillemetsOut "")  prettyprinterCDouble guillemets, pointing inwards (without adding any spacing).putDoc (dGuillemetsIn "")  prettyprinterDSingle 9guillemets :, pointing outwards (without adding any spacing).putDoc (sGuillemetsOut "") 9 : prettyprinterCSingle :guillemets 9, pointing inwards (without adding any spacing).putDoc (sGuillemetsIn "") : 9 prettyprinter Bottom 99  style double quotes.putDoc b99dquote  prettyprinterTop 66  style double quotes.putDoc t66dquote  prettyprinterTop 99  style double quotes.putDoc t99dquote  prettyprinterBottom 9  style single quote.putDoc b9quote  prettyprinterTop 66  style single quote.putDoc t6quote  prettyprinterTop 9  style single quote.putDoc t9quote  prettyprinter Right-pointing double guillemetsputDoc rdGuillemet prettyprinterLeft-pointing double guillemetsputDoc ldGuillemet prettyprinter Right-pointing single guillemetsputDoc rsGuillemet : prettyprinterLeft-pointing single guillemetsputDoc lsGuillemet 9 prettyprinter putDoc bullet " prettyprinter putDoc endash  prettyprinter putDoc euro  prettyprinter putDoc cent prettyprinter putDoc yen prettyprinter putDoc pound           Safe prettyprinterSplit an input into word-sized 's.+putDoc (tupled (words "Lorem ipsum dolor"))(Lorem, ipsum, dolor)  prettyprintervInsert soft linebreaks between words, so that text is broken into multiple lines when it exceeds the available width.putDocW 32 (reflow "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")Lorem ipsum dolor sit amet,consectetur adipisicing elit, sed do eiusmod tempor incididuntut labore et dolore magnaaliqua.   = L .  ! prettyprinterRender a document with a certain width. Useful for quick-and-dirty testing of layout behaviour. Used heavily in the doctests of this package, for example.Klet doc = reflow "Lorem ipsum dolor sit amet, consectetur adipisicing elit"putDocW 20 docLorem ipsum dolor sit amet, consecteturadipisicing elitputDocW 30 docLorem ipsum dolor sit amet,consectetur adipisicing elit ! !; !"#$%&''()* +,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                           !" !#$%&'()*+,-,./0'1'2'345$6>78$9:$;>$<=>?@AB+prettyprinter-1.2.1.1-G1ohLXOgHGIVWiPQmSHwOData.Text.Prettyprint.Doc+Data.Text.Prettyprint.Doc.Render.Util.Panic"Data.Text.Prettyprint.Doc.Internal'Data.Text.Prettyprint.Doc.Render.String'Data.Text.Prettyprint.Doc.Symbols.Ascii2Data.Text.Prettyprint.Doc.Render.Util.StackMachine3Data.Text.Prettyprint.Doc.Render.Util.SimpleDocTree@Data.Text.Prettyprint.Doc.Render.Tutorials.TreeRenderingTutorial?Data.Text.Prettyprint.Doc.Render.Tutorials.StackMachineTutorial%Data.Text.Prettyprint.Doc.Render.Text)Data.Text.Prettyprint.Doc.Symbols.UnicodeData.Text.Prettyprint.Doc.UtilSFailSimpleDocStream SimpleDocTree&Data.Text.Prettyprint.Doc.Render.ShowS'Data.Text.Prettyprint.Doc.Internal.TyperenderrenderStackMachine renderTreebaseGHC.Base<>panicUncaughtFailpanicUnpairedPop"panicSimpleDocTreeConversionFailedpanicInputNotFullyConsumedpanicPeekedEmptypanicPoppedEmpty LayoutOptionslayoutPageWidth PageWidthAvailablePerLine UnboundedLayoutPipelineNilConsUndoAnnFittingPredicateWhitespaceStrippingStateWssAnnotationLevelWssWithheldWhitespaceSEmptySCharSTextSLineSAnnPushSAnnPop FusionDepthShallowDeepAnnotationRemovalRemove DontRemovePrettypretty prettyListDocFailEmptyCharTextLineFlatAltCatNestUnionColumn WithPageWidthNesting AnnotatedviaShow unsafeViaShowunsafeTextWithoutNewlinesemptyDocnestlineline'softline softline'hardlinegroupchangesUponFlatteningflatAltalignhangindent encloseSeplisttupled<+> concatWithhsepvsepfillSepsephcatvcatfillCatcat punctuatecolumnnestingwidth pageWidthfill fillBreakspacespluralenclosesurroundannotate unAnnotate reAnnotatealterAnnotations unAnnotateS reAnnotateSalterAnnotationsSfuseremoveTrailingWhitespacedefaultLayoutOptions layoutPretty layoutSmartlayoutWadlerLeijen layoutCompact renderShowS$fTraversableSimpleDocStream$fFoldableSimpleDocStream$fFunctorSimpleDocStream $fShowDoc $fFunctorDoc $fMonoidDoc$fSemigroupDoc $fPrettyVoid $fPrettyText $fPrettyText0 $fPrettyMaybe $fPretty(,,) $fPretty(,)$fPrettyDouble $fPrettyFloat$fPrettyNatural$fPrettyInteger$fPrettyWord64$fPrettyWord32$fPrettyWord16 $fPrettyWord8 $fPrettyWord $fPrettyInt64 $fPrettyInt32 $fPrettyInt16 $fPrettyInt8 $fPrettyInt $fPrettyChar $fPrettyBool $fPretty()$fPrettyNonEmpty $fPretty[]$fPrettyIdentity $fPrettyConst $fIsStringDoc$fEqFusionDepth$fOrdFusionDepth$fShowFusionDepth$fEqSimpleDocStream$fOrdSimpleDocStream$fShowSimpleDocStream$fGenericSimpleDocStream $fEqPageWidth$fOrdPageWidth$fShowPageWidth $fGenericDoc$fEqLayoutOptions$fOrdLayoutOptions$fShowLayoutOptions renderStringsquotesdquotesparensanglesbracketsbracessquotedquotelparenrparenlangleranglelbracketrbracketlbracerbracesemicoloncommaspacedotslash backslashequalspipe StackMachinerenderSimplyDecoratedrenderSimplyDecoratedA pushStyleunsafePopStyleunsafePeekStyle writeOutputexecStackMachine$fMonadStackMachine$fApplicativeStackMachine$fFunctorStackMachineSTEmptySTCharSTTextSTLineSTAnnSTConcattreeForm unAnnotateST reAnnotateSTalterAnnotationsST$fAlternativeUniqueParser$fMonadFailUniqueParser$fMonadUniqueParser$fApplicativeUniqueParser$fFunctorUniqueParser$fTraversableSimpleDocTree$fFoldableSimpleDocTree$fFunctorSimpleDocTree$fEqSimpleDocTok$fOrdSimpleDocTok$fShowSimpleDocTok$fEqSimpleDocTree$fOrdSimpleDocTree$fShowSimpleDocTree$fGenericSimpleDocTreeColorRedGreenBlue SimpleHtmlBoldItalics ParagraphHeadlinebolditalics paragraphheadlinecolorencloseInTagForhtmlTag renderLazy renderStrictrenderIOputDochPutDoc d9966quotes d6699quotes s96quotes s69quotesdGuillemetsOut dGuillemetsInsGuillemetsOut sGuillemetsIn b99dquote t66dquote t99dquoteb9quotet6quotet9quote rdGuillemet ldGuillemet rsGuillemet lsGuillemetbulletendasheurocentyenpoundwordsreflowputDocWGHC.Errerrorghc-prim GHC.TypesIntDouble text-1.2.3.1 Data.TextlengthGHC.ShowShowStringMonoidmempty GHC.MaybeJustNothingmconcatFunctorshowShowS showsPrec ApplicativefmapData.Text.Internal UniqueParser nextTokenData.Text.Internal.BuilderBuilderData.Text.Internal.Lazy Data.Text.IOhPutStrGHC.IO.Handle.FDstdout System.IOwithFile