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
[Diag ann] -> ShowS
Diag ann -> String
(Int -> Diag ann -> ShowS)
-> (Diag ann -> String) -> ([Diag ann] -> ShowS) -> Show (Diag ann)
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 :: Doc ann -> Diag ann
diag = [Int] -> [PageWidth] -> [Int] -> Doc ann -> Diag ann
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' :: [Int] -> [PageWidth] -> [Int] -> Doc ann -> Diag ann
diag' [Int]
columns [PageWidth]
pageWidths [Int]
nestings = Doc ann -> Diag ann
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 -> Diag ann
forall ann. Diag ann
Fail
Doc ann
Doc.Empty -> Diag ann
forall ann. Diag ann
Empty
Doc.Char Char
c -> Char -> Diag ann
forall ann. Char -> Diag ann
Char Char
c
Doc.Text Int
l Text
t -> Int -> Text -> Diag ann
forall ann. Int -> Text -> Diag ann
Text Int
l Text
t
Doc ann
Doc.Line -> Diag ann
forall ann. Diag ann
Line
Doc.FlatAlt Doc ann
a Doc ann
b -> Diag ann -> Diag ann -> Diag ann
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 -> Diag ann -> Diag ann -> Diag ann
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 -> Int -> Diag ann -> Diag ann
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 -> Diag ann -> Diag ann -> Diag ann
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 -> [(Int, Diag ann)] -> Diag ann
forall ann. [(Int, Diag ann)] -> Diag ann
Column ((Int -> Doc ann) -> [Int] -> [(Int, Diag ann)]
forall a ann. (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply Int -> Doc ann
f [Int]
columns)
Doc.WithPageWidth PageWidth -> Doc ann
f -> [(PageWidth, Diag ann)] -> Diag ann
forall ann. [(PageWidth, Diag ann)] -> Diag ann
WithPageWidth ((PageWidth -> Doc ann) -> [PageWidth] -> [(PageWidth, Diag ann)]
forall a ann. (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply PageWidth -> Doc ann
f [PageWidth]
pageWidths)
Doc.Nesting Int -> Doc ann
f -> [(Int, Diag ann)] -> Diag ann
forall ann. [(Int, Diag ann)] -> Diag ann
Nesting ((Int -> Doc ann) -> [Int] -> [(Int, Diag ann)]
forall a ann. (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply Int -> Doc ann
f [Int]
nestings)
Doc.Annotated ann
ann Doc ann
d -> ann -> Diag ann -> Diag ann
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 :: (a -> Doc ann) -> [a] -> [(a, Diag ann)]
apply a -> Doc ann
f = (a -> (a, Diag ann)) -> [a] -> [(a, Diag ann)]
forall a b. (a -> b) -> [a] -> [b]
map (\a
x -> (a
x, Doc ann -> Diag ann
forall ann. Doc ann -> Diag ann
go (a -> Doc ann
f a
x)))