Prettyprinter.Internal.Debug

prettyprinter-1.7.1: A modern, easy to use, well-documented, extensible pretty-printer.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Prettyprinter.Internal.Debug

Description

Warning: internal module! This means that the API may change arbitrarily between versions without notice. Depending on this module may lead to unexpected breakages, so proceed with caution!

This module provides debugging helpers for inspecting `Doc`s.

Use the `pretty-simple` package to get a nicer layout for `show`n `Diag`s:

    > Text.Pretty.Simple.pPrintNoColor . diag $ align (vcat ["foo", "bar"])
    Column
       [
           ( 10
           , Nesting
               [
                   ( 10
                   , Cat ( Text 3 "foo" )
                       ( Cat ( FlatAlt Line Empty ) ( Text 3 "bar" ) )
                   )
               ]
           )
       ]

Synopsis

- data Diag ann
  - = Fail
  - | Empty
  - | Char !Char
  - | Text !Int !Text
  - | Line
  - | FlatAlt (Diag ann) (Diag ann)
  - | Cat (Diag ann) (Diag ann)
  - | Nest !Int (Diag ann)
  - | Union (Diag ann) (Diag ann)
  - | Column [(Int, Diag ann)]
  - | WithPageWidth [(PageWidth, Diag ann)]
  - | Nesting [(Int, Diag ann)]
  - | Annotated ann (Diag ann)
- diag :: Doc ann -> Diag ann
- diag' :: [Int] -> [PageWidth] -> [Int] -> Doc ann -> Diag ann

# Documentation

data Diag ann #

A variant of `Doc` for debugging.

Unlike in the `Doc` type, the `Column`, `WithPageWidth` and `Nesting` constructors don't contain functions but are "sampled" to allow simple inspection with `show`.

Constructors

Fail |
Empty |
Char !Char |
Text !Int !Text |
Line |
FlatAlt (Diag ann) (Diag ann) |
Cat (Diag ann) (Diag ann) |
Nest !Int (Diag ann) |
Union (Diag ann) (Diag ann) |
Column [(Int, Diag ann)] | `Doc`: `(Int -> Diag ann)`
WithPageWidth [(PageWidth, Diag ann)] | `Doc`: `(PageWidth -> Diag ann)`
Nesting [(Int, Diag ann)] | `Doc`: `(Int -> Diag ann)`
Annotated ann (Diag ann) |

#### Instances

Instances details

Show ann => Show (Diag ann) # |
Instance details Defined in Prettyprinter.Internal.Debug Methods showsPrec :: Int -> Diag ann -> ShowS # show :: Diag ann -> String # showList :: [Diag ann] -> ShowS #

diag :: Doc ann -> Diag ann #

Convert a `Doc` to its diagnostic representation.

The functions in the `Column`, `WithPageWidth` and `Nesting` constructors are sampled with some default values.

Use `diag'` to control the function inputs yourself.

    >>> diag $ Doc.align (Doc.vcat ["foo", "bar"])
    Column [(10,Nesting [(10,Cat (Text 3 "foo") (Cat (FlatAlt Line Empty) (Text 3 "bar")))])]

diag' #

Arguments

:: [Int] | Cursor positions for the `Column` constructor
-> [PageWidth] | For `WithPageWidth`
-> [Int] | Nesting levels for `Nesting`
-> Doc ann |
-> Diag ann |