module Prettyprinter.Internal.Debug where
import Data.Text (Text)
import Prettyprinter.Internal (PageWidth, Doc)
import qualified Prettyprinter.Internal as Doc
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)
deriving Int -> Diag ann -> ShowS
forall ann. Show ann => Int -> Diag ann -> ShowS
forall ann. Show ann => [Diag ann] -> ShowS
forall ann. Show ann => Diag ann -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Diag ann] -> ShowS
$cshowList :: forall ann. Show ann => [Diag ann] -> ShowS
show :: Diag ann -> String
$cshow :: forall ann. Show ann => Diag ann -> String
showsPrec :: Int -> Diag ann -> ShowS
$cshowsPrec :: forall ann. Show ann => Int -> Diag ann -> ShowS
Show
diag :: Doc ann -> Diag ann
diag :: forall ann. Doc ann -> Diag ann
diag = forall ann. [Int] -> [PageWidth] -> [Int] -> Doc ann -> Diag ann
diag' [Int
10] [PageWidth
Doc.defaultPageWidth] [Int
10]
diag'
:: [Int]
-> [PageWidth]
-> [Int]
-> Doc ann
-> Diag ann
diag' :: forall ann. [Int] -> [PageWidth] -> [Int] -> Doc ann -> Diag ann
diag' [Int]
columns [PageWidth]
pageWidths [Int]
nestings = forall ann. Doc ann -> Diag ann
go
where
go :: Doc ann -> Diag ann
go Doc ann
doc = case Doc ann
doc of
Doc ann
Doc.Fail -> forall ann. Diag ann
Fail
Doc ann
Doc.Empty -> forall ann. Diag ann
Empty
Doc.Char Char
c -> forall ann. Char -> Diag ann
Char Char
c
Doc.Text Int
l Text
t -> forall ann. Int -> Text -> Diag ann
Text Int
l Text
t
Doc ann
Doc.Line -> forall ann. Diag ann
Line
Doc.FlatAlt Doc ann
a Doc ann
b -> forall ann. Diag ann -> Diag ann -> Diag ann
FlatAlt (Doc ann -> Diag ann
go Doc ann
a) (Doc ann -> Diag ann
go Doc ann
b)
Doc.Cat Doc ann
a Doc ann
b -> forall ann. Diag ann -> Diag ann -> Diag ann
Cat (Doc ann -> Diag ann
go Doc ann
a) (Doc ann -> Diag ann
go Doc ann
b)
Doc.Nest Int
i Doc ann
d -> forall ann. Int -> Diag ann -> Diag ann
Nest Int
i (Doc ann -> Diag ann
go Doc ann
d)
Doc.Union Doc ann
a Doc ann
b -> forall ann. Diag ann -> Diag ann -> Diag ann
Union (Doc ann -> Diag ann
go Doc ann
a) (Doc ann -> Diag ann
go Doc ann
b)
Doc.Column Int -> Doc ann
f -> forall ann. [(Int, Diag ann)] -> Diag ann
Column (forall a ann. (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply Int -> Doc ann
f [Int]
columns)
Doc.WithPageWidth PageWidth -> Doc ann
f -> forall ann. [(PageWidth, Diag ann)] -> Diag ann
WithPageWidth (forall a ann. (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply PageWidth -> Doc ann
f [PageWidth]
pageWidths)
Doc.Nesting Int -> Doc ann
f -> forall ann. [(Int, Diag ann)] -> Diag ann
Nesting (forall a ann. (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply Int -> Doc ann
f [Int]
nestings)
Doc.Annotated ann
ann Doc ann
d -> forall ann. ann -> Diag ann -> Diag ann
Annotated ann
ann (Doc ann -> Diag ann
go Doc ann
d)
apply :: (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply :: forall a ann. (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply a -> Doc ann
f = forall a b. (a -> b) -> [a] -> [b]
map (\a
x -> (a
x, forall ann. Doc ann -> Diag ann
go (a -> Doc ann
f a
x)))