----------------------------------------------------------------------------
-- |
-- Module      :  Prettyprinter.Combinators
-- Copyright   :  (c) Sergey Vinokurov 2018
-- License     :  Apache-2.0 (see LICENSE)
-- Maintainer  :  serg.foo@gmail.com
----------------------------------------------------------------------------

{-# LANGUAGE CPP                 #-}
{-# LANGUAGE DeriveTraversable   #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Prettyprinter.Combinators
  ( Pretty(..)
  , PP.Doc
  , putDocLn
  , render
  , renderLazy
  , renderString
  , docFromString
  , docFromText
  , PP.viaShow

  , MapEntry(..)
  , (-->)
  , ppMapEntryWith
  , ppMapEntryWithSep
  , ppList
  , (##)
  , ppDictHeader
  , ppDictAssocList

  , ppTuple
  , ppTupleWith
  , ppListWith
  , ppFoldableHeader
  , ppFoldableHeaderWith
  , ppNE
  , ppNEWith
  , ppMap
  , ppMapWith
  , ppSet
  , ppSetWith
  , ppBimap
  , ppBimapWith
  , ppIntSet
  , ppIntSetWith
  , ppIntMap
  , ppIntMapWith
  , ppHashSet
  , ppHashSetWith
  , ppHashMap
  , ppHashMapWith
  , ppVector
  , ppVectorWith
  , ppDList
  , ppDListWith
  , ppListWithDelim
  , ppAssocList
  , ppAssocListWith
  , ppAssocListWithSep
  , ppByteString
  , ppByteStringLazy
  , ppShortByteString
  , ppCallStack
  , ppCallStackGHC
  ) where

import Data.Bimap (Bimap)
import Data.Bimap qualified as BM
import Data.ByteString.Char8 qualified as C8
import Data.ByteString.Lazy.Char8 qualified as CL8
import Data.ByteString.Short qualified as ShortBS
import Data.DList (DList)
import Data.DList qualified as DL
import Data.Foldable
import Data.HashMap.Strict (HashMap)
import Data.HashMap.Strict qualified as HM
import Data.HashSet (HashSet)
import Data.HashSet qualified as HS
import Data.IntMap (IntMap)
import Data.IntMap qualified as IM
import Data.IntSet (IntSet)
import Data.IntSet qualified as IS
import Data.List.NonEmpty (NonEmpty(..))
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as M
import Data.Set (Set)
import Data.Vector (Vector)
import Data.Vector qualified as V
import GHC.Stack (CallStack, SrcLoc(..), getCallStack, prettySrcLoc)

#if !MIN_VERSION_base(4, 11, 0)
import Data.Semigroup ((<>))
#endif

import Data.Text qualified as T
import Data.Text.Lazy qualified as TL
import Prettyprinter (Pretty(..), Doc, (<+>))
import Prettyprinter qualified as PP
import Prettyprinter.Combinators.Basic
import Prettyprinter.MetaDoc
import Prettyprinter.Render.Text qualified as PP.Render

putDocLn :: Doc ann -> IO ()
putDocLn :: Doc ann -> IO ()
putDocLn Doc ann
x = do
  Doc ann -> IO ()
forall ann. Doc ann -> IO ()
PP.Render.putDoc Doc ann
x
  String -> IO ()
putStrLn String
""

render :: Doc ann -> T.Text
render :: Doc ann -> Text
render = Text -> Text
TL.toStrict (Text -> Text) -> (Doc ann -> Text) -> Doc ann -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc ann -> Text
forall ann. Doc ann -> Text
renderLazy

renderLazy :: Doc ann -> TL.Text
renderLazy :: Doc ann -> Text
renderLazy = SimpleDocStream ann -> Text
forall ann. SimpleDocStream ann -> Text
PP.Render.renderLazy (SimpleDocStream ann -> Text)
-> (Doc ann -> SimpleDocStream ann) -> Doc ann -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayoutOptions -> Doc ann -> SimpleDocStream ann
forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
PP.layoutPretty LayoutOptions
PP.defaultLayoutOptions

renderString :: Doc ann -> String
renderString :: Doc ann -> String
renderString = Text -> String
TL.unpack (Text -> String) -> (Doc ann -> Text) -> Doc ann -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc ann -> Text
forall ann. Doc ann -> Text
renderLazy

docFromString :: String -> Doc ann
docFromString :: String -> Doc ann
docFromString = Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (Text -> Doc ann) -> (String -> Text) -> String -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
TL.pack

docFromText :: T.Text -> Doc ann
docFromText :: Text -> Doc ann
docFromText = Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty


infixr 0 :->

data MapEntry k v = k :-> v
  deriving (MapEntry k v -> MapEntry k v -> Bool
(MapEntry k v -> MapEntry k v -> Bool)
-> (MapEntry k v -> MapEntry k v -> Bool) -> Eq (MapEntry k v)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k v. (Eq k, Eq v) => MapEntry k v -> MapEntry k v -> Bool
/= :: MapEntry k v -> MapEntry k v -> Bool
$c/= :: forall k v. (Eq k, Eq v) => MapEntry k v -> MapEntry k v -> Bool
== :: MapEntry k v -> MapEntry k v -> Bool
$c== :: forall k v. (Eq k, Eq v) => MapEntry k v -> MapEntry k v -> Bool
Eq, Eq (MapEntry k v)
Eq (MapEntry k v)
-> (MapEntry k v -> MapEntry k v -> Ordering)
-> (MapEntry k v -> MapEntry k v -> Bool)
-> (MapEntry k v -> MapEntry k v -> Bool)
-> (MapEntry k v -> MapEntry k v -> Bool)
-> (MapEntry k v -> MapEntry k v -> Bool)
-> (MapEntry k v -> MapEntry k v -> MapEntry k v)
-> (MapEntry k v -> MapEntry k v -> MapEntry k v)
-> Ord (MapEntry k v)
MapEntry k v -> MapEntry k v -> Bool
MapEntry k v -> MapEntry k v -> Ordering
MapEntry k v -> MapEntry k v -> MapEntry k v
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k v. (Ord k, Ord v) => Eq (MapEntry k v)
forall k v. (Ord k, Ord v) => MapEntry k v -> MapEntry k v -> Bool
forall k v.
(Ord k, Ord v) =>
MapEntry k v -> MapEntry k v -> Ordering
forall k v.
(Ord k, Ord v) =>
MapEntry k v -> MapEntry k v -> MapEntry k v
min :: MapEntry k v -> MapEntry k v -> MapEntry k v
$cmin :: forall k v.
(Ord k, Ord v) =>
MapEntry k v -> MapEntry k v -> MapEntry k v
max :: MapEntry k v -> MapEntry k v -> MapEntry k v
$cmax :: forall k v.
(Ord k, Ord v) =>
MapEntry k v -> MapEntry k v -> MapEntry k v
>= :: MapEntry k v -> MapEntry k v -> Bool
$c>= :: forall k v. (Ord k, Ord v) => MapEntry k v -> MapEntry k v -> Bool
> :: MapEntry k v -> MapEntry k v -> Bool
$c> :: forall k v. (Ord k, Ord v) => MapEntry k v -> MapEntry k v -> Bool
<= :: MapEntry k v -> MapEntry k v -> Bool
$c<= :: forall k v. (Ord k, Ord v) => MapEntry k v -> MapEntry k v -> Bool
< :: MapEntry k v -> MapEntry k v -> Bool
$c< :: forall k v. (Ord k, Ord v) => MapEntry k v -> MapEntry k v -> Bool
compare :: MapEntry k v -> MapEntry k v -> Ordering
$ccompare :: forall k v.
(Ord k, Ord v) =>
MapEntry k v -> MapEntry k v -> Ordering
$cp1Ord :: forall k v. (Ord k, Ord v) => Eq (MapEntry k v)
Ord, Int -> MapEntry k v -> ShowS
[MapEntry k v] -> ShowS
MapEntry k v -> String
(Int -> MapEntry k v -> ShowS)
-> (MapEntry k v -> String)
-> ([MapEntry k v] -> ShowS)
-> Show (MapEntry k v)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k v. (Show k, Show v) => Int -> MapEntry k v -> ShowS
forall k v. (Show k, Show v) => [MapEntry k v] -> ShowS
forall k v. (Show k, Show v) => MapEntry k v -> String
showList :: [MapEntry k v] -> ShowS
$cshowList :: forall k v. (Show k, Show v) => [MapEntry k v] -> ShowS
show :: MapEntry k v -> String
$cshow :: forall k v. (Show k, Show v) => MapEntry k v -> String
showsPrec :: Int -> MapEntry k v -> ShowS
$cshowsPrec :: forall k v. (Show k, Show v) => Int -> MapEntry k v -> ShowS
Show, a -> MapEntry k b -> MapEntry k a
(a -> b) -> MapEntry k a -> MapEntry k b
(forall a b. (a -> b) -> MapEntry k a -> MapEntry k b)
-> (forall a b. a -> MapEntry k b -> MapEntry k a)
-> Functor (MapEntry k)
forall a b. a -> MapEntry k b -> MapEntry k a
forall a b. (a -> b) -> MapEntry k a -> MapEntry k b
forall k a b. a -> MapEntry k b -> MapEntry k a
forall k a b. (a -> b) -> MapEntry k a -> MapEntry k b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> MapEntry k b -> MapEntry k a
$c<$ :: forall k a b. a -> MapEntry k b -> MapEntry k a
fmap :: (a -> b) -> MapEntry k a -> MapEntry k b
$cfmap :: forall k a b. (a -> b) -> MapEntry k a -> MapEntry k b
Functor, MapEntry k a -> Bool
(a -> m) -> MapEntry k a -> m
(a -> b -> b) -> b -> MapEntry k a -> b
(forall m. Monoid m => MapEntry k m -> m)
-> (forall m a. Monoid m => (a -> m) -> MapEntry k a -> m)
-> (forall m a. Monoid m => (a -> m) -> MapEntry k a -> m)
-> (forall a b. (a -> b -> b) -> b -> MapEntry k a -> b)
-> (forall a b. (a -> b -> b) -> b -> MapEntry k a -> b)
-> (forall b a. (b -> a -> b) -> b -> MapEntry k a -> b)
-> (forall b a. (b -> a -> b) -> b -> MapEntry k a -> b)
-> (forall a. (a -> a -> a) -> MapEntry k a -> a)
-> (forall a. (a -> a -> a) -> MapEntry k a -> a)
-> (forall a. MapEntry k a -> [a])
-> (forall a. MapEntry k a -> Bool)
-> (forall a. MapEntry k a -> Int)
-> (forall a. Eq a => a -> MapEntry k a -> Bool)
-> (forall a. Ord a => MapEntry k a -> a)
-> (forall a. Ord a => MapEntry k a -> a)
-> (forall a. Num a => MapEntry k a -> a)
-> (forall a. Num a => MapEntry k a -> a)
-> Foldable (MapEntry k)
forall a. Eq a => a -> MapEntry k a -> Bool
forall a. Num a => MapEntry k a -> a
forall a. Ord a => MapEntry k a -> a
forall m. Monoid m => MapEntry k m -> m
forall a. MapEntry k a -> Bool
forall a. MapEntry k a -> Int
forall a. MapEntry k a -> [a]
forall a. (a -> a -> a) -> MapEntry k a -> a
forall k a. Eq a => a -> MapEntry k a -> Bool
forall k a. Num a => MapEntry k a -> a
forall k a. Ord a => MapEntry k a -> a
forall m a. Monoid m => (a -> m) -> MapEntry k a -> m
forall k m. Monoid m => MapEntry k m -> m
forall k a. MapEntry k a -> Bool
forall k a. MapEntry k a -> Int
forall k a. MapEntry k a -> [a]
forall b a. (b -> a -> b) -> b -> MapEntry k a -> b
forall a b. (a -> b -> b) -> b -> MapEntry k a -> b
forall k a. (a -> a -> a) -> MapEntry k a -> a
forall k m a. Monoid m => (a -> m) -> MapEntry k a -> m
forall k b a. (b -> a -> b) -> b -> MapEntry k a -> b
forall k a b. (a -> b -> b) -> b -> MapEntry k a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: MapEntry k a -> a
$cproduct :: forall k a. Num a => MapEntry k a -> a
sum :: MapEntry k a -> a
$csum :: forall k a. Num a => MapEntry k a -> a
minimum :: MapEntry k a -> a
$cminimum :: forall k a. Ord a => MapEntry k a -> a
maximum :: MapEntry k a -> a
$cmaximum :: forall k a. Ord a => MapEntry k a -> a
elem :: a -> MapEntry k a -> Bool
$celem :: forall k a. Eq a => a -> MapEntry k a -> Bool
length :: MapEntry k a -> Int
$clength :: forall k a. MapEntry k a -> Int
null :: MapEntry k a -> Bool
$cnull :: forall k a. MapEntry k a -> Bool
toList :: MapEntry k a -> [a]
$ctoList :: forall k a. MapEntry k a -> [a]
foldl1 :: (a -> a -> a) -> MapEntry k a -> a
$cfoldl1 :: forall k a. (a -> a -> a) -> MapEntry k a -> a
foldr1 :: (a -> a -> a) -> MapEntry k a -> a
$cfoldr1 :: forall k a. (a -> a -> a) -> MapEntry k a -> a
foldl' :: (b -> a -> b) -> b -> MapEntry k a -> b
$cfoldl' :: forall k b a. (b -> a -> b) -> b -> MapEntry k a -> b
foldl :: (b -> a -> b) -> b -> MapEntry k a -> b
$cfoldl :: forall k b a. (b -> a -> b) -> b -> MapEntry k a -> b
foldr' :: (a -> b -> b) -> b -> MapEntry k a -> b
$cfoldr' :: forall k a b. (a -> b -> b) -> b -> MapEntry k a -> b
foldr :: (a -> b -> b) -> b -> MapEntry k a -> b
$cfoldr :: forall k a b. (a -> b -> b) -> b -> MapEntry k a -> b
foldMap' :: (a -> m) -> MapEntry k a -> m
$cfoldMap' :: forall k m a. Monoid m => (a -> m) -> MapEntry k a -> m
foldMap :: (a -> m) -> MapEntry k a -> m
$cfoldMap :: forall k m a. Monoid m => (a -> m) -> MapEntry k a -> m
fold :: MapEntry k m -> m
$cfold :: forall k m. Monoid m => MapEntry k m -> m
Foldable, Functor (MapEntry k)
Foldable (MapEntry k)
Functor (MapEntry k)
-> Foldable (MapEntry k)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> MapEntry k a -> f (MapEntry k b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    MapEntry k (f a) -> f (MapEntry k a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> MapEntry k a -> m (MapEntry k b))
-> (forall (m :: * -> *) a.
    Monad m =>
    MapEntry k (m a) -> m (MapEntry k a))
-> Traversable (MapEntry k)
(a -> f b) -> MapEntry k a -> f (MapEntry k b)
forall k. Functor (MapEntry k)
forall k. Foldable (MapEntry k)
forall k (m :: * -> *) a.
Monad m =>
MapEntry k (m a) -> m (MapEntry k a)
forall k (f :: * -> *) a.
Applicative f =>
MapEntry k (f a) -> f (MapEntry k a)
forall k (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MapEntry k a -> m (MapEntry k b)
forall k (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MapEntry k a -> f (MapEntry k b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
MapEntry k (m a) -> m (MapEntry k a)
forall (f :: * -> *) a.
Applicative f =>
MapEntry k (f a) -> f (MapEntry k a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MapEntry k a -> m (MapEntry k b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MapEntry k a -> f (MapEntry k b)
sequence :: MapEntry k (m a) -> m (MapEntry k a)
$csequence :: forall k (m :: * -> *) a.
Monad m =>
MapEntry k (m a) -> m (MapEntry k a)
mapM :: (a -> m b) -> MapEntry k a -> m (MapEntry k b)
$cmapM :: forall k (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MapEntry k a -> m (MapEntry k b)
sequenceA :: MapEntry k (f a) -> f (MapEntry k a)
$csequenceA :: forall k (f :: * -> *) a.
Applicative f =>
MapEntry k (f a) -> f (MapEntry k a)
traverse :: (a -> f b) -> MapEntry k a -> f (MapEntry k b)
$ctraverse :: forall k (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MapEntry k a -> f (MapEntry k b)
$cp2Traversable :: forall k. Foldable (MapEntry k)
$cp1Traversable :: forall k. Functor (MapEntry k)
Traversable)

ppMapEntryWith
  :: (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith :: (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith = Doc ann
-> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
forall ann k v.
Doc ann
-> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWithSep Doc ann
"->"

ppMapEntryWithSep
  :: Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWithSep :: Doc ann
-> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWithSep Doc ann
sep k -> Doc ann
f v -> Doc ann
g (k
x :-> v
y) =
  Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
PP.group (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ k -> Doc ann
f k
x Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
PP.nest Int
4 (Doc ann
sep Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
forall ann. Doc ann
PP.line Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
PP.align (v -> Doc ann
g v
y))

instance (Pretty k, Pretty v) => Pretty (MapEntry k v) where
  pretty :: MapEntry k v -> Doc ann
pretty = (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

infixr 0 -->

-- | Helper to make constructing 'MapEntry' pairs easier by calling
-- pretty on value.
(-->) :: Pretty v => T.Text -> v -> MapEntry T.Text (Doc ann)
--> :: Text -> v -> MapEntry Text (Doc ann)
(-->) Text
k v
v = Text
k Text -> Doc ann -> MapEntry Text (Doc ann)
forall k v. k -> v -> MapEntry k v
:-> v -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v
v

ppDictHeader :: Doc ann -> [MapEntry T.Text (Doc ann)] -> Doc ann
ppDictHeader :: Doc ann -> [MapEntry Text (Doc ann)] -> Doc ann
ppDictHeader Doc ann
header [MapEntry Text (Doc ann)]
entries =
  Doc ann
header Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
## [MapEntry Text (Doc ann)] -> Doc ann
forall ann. [MapEntry Text (Doc ann)] -> Doc ann
ppDictAssocList [MapEntry Text (Doc ann)]
entries

ppDictAssocList :: [MapEntry T.Text (Doc ann)] -> Doc ann
ppDictAssocList :: [MapEntry Text (Doc ann)] -> Doc ann
ppDictAssocList [MapEntry Text (Doc ann)]
entries = Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lbrace Doc ann
forall ann. Doc ann
PP.rbrace [Doc ann]
entries'
  where
    entries' :: [Doc ann]
entries' = ((MapEntry Text (Doc ann) -> Doc ann)
 -> [MapEntry Text (Doc ann)] -> [Doc ann])
-> [MapEntry Text (Doc ann)]
-> (MapEntry Text (Doc ann) -> Doc ann)
-> [Doc ann]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (MapEntry Text (Doc ann) -> Doc ann)
-> [MapEntry Text (Doc ann)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map [MapEntry Text (Doc ann)]
entries ((MapEntry Text (Doc ann) -> Doc ann) -> [Doc ann])
-> (MapEntry Text (Doc ann) -> Doc ann) -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ \MapEntry Text (Doc ann)
entry ->
      (Text -> Doc ann)
-> (Doc ann -> Doc ann) -> MapEntry Text (Doc ann) -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith (Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
PP.fillBreak Int
maxWidth (Doc ann -> Doc ann) -> (Text -> Doc ann) -> Text -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty) Doc ann -> Doc ann
forall a. a -> a
id MapEntry Text (Doc ann)
entry Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
`PP.flatAlt`
      (Text -> Doc ann)
-> (Doc ann -> Doc ann) -> MapEntry Text (Doc ann) -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Doc ann -> Doc ann
forall a. a -> a
id MapEntry Text (Doc ann)
entry
    maxWidth :: Int
maxWidth = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ (MapEntry Text (Doc ann) -> Int)
-> [MapEntry Text (Doc ann)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\(Text
k :-> Doc ann
_) -> Text -> Int
T.length Text
k) [MapEntry Text (Doc ann)]
entries

ppList :: Pretty a => [a] -> Doc ann
ppList :: [a] -> Doc ann
ppList = (a -> Doc ann) -> [a] -> Doc ann
forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppListWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppListWith :: (a -> Doc ann) -> [a] -> Doc ann
ppListWith :: (a -> Doc ann) -> [a] -> Doc ann
ppListWith a -> Doc ann
f = Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lbracket Doc ann
forall ann. Doc ann
PP.rbracket ([Doc ann] -> Doc ann) -> ([a] -> [Doc ann]) -> [a] -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc ann) -> [a] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc ann
f

ppTuple :: Pretty a => [a] -> Doc ann
ppTuple :: [a] -> Doc ann
ppTuple = (a -> Doc ann) -> [a] -> Doc ann
forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppTupleWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppTupleWith :: (a -> Doc ann) -> [a] -> Doc ann
ppTupleWith :: (a -> Doc ann) -> [a] -> Doc ann
ppTupleWith a -> Doc ann
f = Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lparen Doc ann
forall ann. Doc ann
PP.rparen ([Doc ann] -> Doc ann) -> ([a] -> [Doc ann]) -> [a] -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc ann) -> [a] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc ann
f

ppFoldableHeader :: (Pretty a, Foldable f) => Doc ann -> f a -> Doc ann
ppFoldableHeader :: Doc ann -> f a -> Doc ann
ppFoldableHeader = (a -> Doc ann) -> Doc ann -> f a -> Doc ann
forall (f :: * -> *) a ann.
Foldable f =>
(a -> Doc ann) -> Doc ann -> f a -> Doc ann
ppFoldableHeaderWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppFoldableHeaderWith
  :: Foldable f
  => (a -> Doc ann) -> Doc ann -> f a -> Doc ann
ppFoldableHeaderWith :: (a -> Doc ann) -> Doc ann -> f a -> Doc ann
ppFoldableHeaderWith a -> Doc ann
f Doc ann
header f a
entries =
  Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
PP.nest Int
2 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$
  Doc ann
header Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
forall ann. Doc ann
PP.line Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
PP.vsep ((a -> Doc ann) -> [a] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map ((Doc ann
"-" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
PP.<+>) (Doc ann -> Doc ann) -> (a -> Doc ann) -> a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
PP.align (Doc ann -> Doc ann) -> (a -> Doc ann) -> a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Doc ann
f) ([a] -> [Doc ann]) -> [a] -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f a
entries)

ppNE :: Pretty a => NonEmpty a -> Doc ann
ppNE :: NonEmpty a -> Doc ann
ppNE = (a -> Doc ann) -> NonEmpty a -> Doc ann
forall a ann. (a -> Doc ann) -> NonEmpty a -> Doc ann
ppNEWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppNEWith :: (a -> Doc ann) -> NonEmpty a -> Doc ann
ppNEWith :: (a -> Doc ann) -> NonEmpty a -> Doc ann
ppNEWith a -> Doc ann
f = Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lbracket Doc ann
forall ann. Doc ann
PP.rbracket ([Doc ann] -> Doc ann)
-> (NonEmpty a -> [Doc ann]) -> NonEmpty a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc ann) -> [a] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc ann
f ([a] -> [Doc ann])
-> (NonEmpty a -> [a]) -> NonEmpty a -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList

ppMap :: (Pretty a, Pretty b) => Map a b -> Doc ann
ppMap :: Map a b -> Doc ann
ppMap = (a -> Doc ann) -> (b -> Doc ann) -> Map a b -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> Map k v -> Doc ann
ppMapWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty b -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Map k v -> Doc ann
ppMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Map k v -> Doc ann
ppMapWith k -> Doc ann
f v -> Doc ann
g = (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith k -> Doc ann
f v -> Doc ann
g ([(k, v)] -> Doc ann)
-> (Map k v -> [(k, v)]) -> Map k v -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
M.toList

ppSet :: Pretty a => Set a -> Doc ann
ppSet :: Set a -> Doc ann
ppSet = (a -> Doc ann) -> Set a -> Doc ann
forall a ann. (a -> Doc ann) -> Set a -> Doc ann
ppSetWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppSetWith :: (a -> Doc ann) -> Set a -> Doc ann
ppSetWith :: (a -> Doc ann) -> Set a -> Doc ann
ppSetWith a -> Doc ann
f = Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lbrace Doc ann
forall ann. Doc ann
PP.rbrace ([Doc ann] -> Doc ann) -> (Set a -> [Doc ann]) -> Set a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc ann) -> [a] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc ann
f ([a] -> [Doc ann]) -> (Set a -> [a]) -> Set a -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList

ppBimap :: (Pretty k, Pretty v) => Bimap k v -> Doc ann
ppBimap :: Bimap k v -> Doc ann
ppBimap = (k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
ppBimapWith k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppBimapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
ppBimapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
ppBimapWith k -> Doc ann
f v -> Doc ann
g = Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
forall ann k v.
Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWithSep Doc ann
"<->" k -> Doc ann
f v -> Doc ann
g ([(k, v)] -> Doc ann)
-> (Bimap k v -> [(k, v)]) -> Bimap k v -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bimap k v -> [(k, v)]
forall a b. Bimap a b -> [(a, b)]
BM.toList

ppIntSet :: IntSet -> Doc ann
ppIntSet :: IntSet -> Doc ann
ppIntSet = (Int -> Doc ann) -> IntSet -> Doc ann
forall ann. (Int -> Doc ann) -> IntSet -> Doc ann
ppIntSetWith Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppIntSetWith :: (Int -> Doc ann) -> IntSet -> Doc ann
ppIntSetWith :: (Int -> Doc ann) -> IntSet -> Doc ann
ppIntSetWith Int -> Doc ann
f = Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lbrace Doc ann
forall ann. Doc ann
PP.rbrace ([Doc ann] -> Doc ann)
-> (IntSet -> [Doc ann]) -> IntSet -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Doc ann) -> [Int] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Doc ann
f ([Int] -> [Doc ann]) -> (IntSet -> [Int]) -> IntSet -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
IS.toList

ppIntMap :: Pretty a => IntMap a -> Doc ann
ppIntMap :: IntMap a -> Doc ann
ppIntMap = (Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann
forall ann a.
(Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann
ppIntMapWith Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppIntMapWith :: (Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann
ppIntMapWith :: (Int -> Doc ann) -> (a -> Doc ann) -> IntMap a -> Doc ann
ppIntMapWith Int -> Doc ann
f a -> Doc ann
g = (Int -> Doc ann) -> (a -> Doc ann) -> [(Int, a)] -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith Int -> Doc ann
f a -> Doc ann
g ([(Int, a)] -> Doc ann)
-> (IntMap a -> [(Int, a)]) -> IntMap a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntMap a -> [(Int, a)]
forall a. IntMap a -> [(Int, a)]
IM.toList

ppHashSet :: Pretty a => HashSet a -> Doc ann
ppHashSet :: HashSet a -> Doc ann
ppHashSet = (a -> Doc ann) -> HashSet a -> Doc ann
forall a ann. (a -> Doc ann) -> HashSet a -> Doc ann
ppHashSetWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppHashSetWith :: (a -> Doc ann) -> HashSet a -> Doc ann
ppHashSetWith :: (a -> Doc ann) -> HashSet a -> Doc ann
ppHashSetWith a -> Doc ann
f = Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lbrace Doc ann
forall ann. Doc ann
PP.rbrace ([Doc ann] -> Doc ann)
-> (HashSet a -> [Doc ann]) -> HashSet a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Doc ann) -> [a] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc ann
f ([a] -> [Doc ann]) -> (HashSet a -> [a]) -> HashSet a -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashSet a -> [a]
forall a. HashSet a -> [a]
HS.toList

ppHashMap :: (Pretty k, Pretty v) => HashMap k v -> Doc ann
ppHashMap :: HashMap k v -> Doc ann
ppHashMap = (k -> Doc ann) -> (v -> Doc ann) -> HashMap k v -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> HashMap k v -> Doc ann
ppHashMapWith k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppHashMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> HashMap k v -> Doc ann
ppHashMapWith :: (k -> Doc ann) -> (v -> Doc ann) -> HashMap k v -> Doc ann
ppHashMapWith k -> Doc ann
f v -> Doc ann
g = (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith k -> Doc ann
f v -> Doc ann
g ([(k, v)] -> Doc ann)
-> (HashMap k v -> [(k, v)]) -> HashMap k v -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k v -> [(k, v)]
forall k v. HashMap k v -> [(k, v)]
HM.toList

ppVector :: Pretty a => Vector a -> Doc ann
ppVector :: Vector a -> Doc ann
ppVector = (a -> Doc ann) -> Vector a -> Doc ann
forall a ann. (a -> Doc ann) -> Vector a -> Doc ann
ppVectorWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppVectorWith :: (a -> Doc ann) -> Vector a -> Doc ann
ppVectorWith :: (a -> Doc ann) -> Vector a -> Doc ann
ppVectorWith a -> Doc ann
f = (a -> Doc ann) -> [a] -> Doc ann
forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppListWith a -> Doc ann
f ([a] -> Doc ann) -> (Vector a -> [a]) -> Vector a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Vector a -> [a]
V.toList

ppDList :: Pretty a => DList a -> Doc ann
ppDList :: DList a -> Doc ann
ppDList = (a -> Doc ann) -> DList a -> Doc ann
forall a ann. (a -> Doc ann) -> DList a -> Doc ann
ppDListWith a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppDListWith :: (a -> Doc ann) -> DList a -> Doc ann
ppDListWith :: (a -> Doc ann) -> DList a -> Doc ann
ppDListWith a -> Doc ann
f = (a -> Doc ann) -> [a] -> Doc ann
forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppListWith a -> Doc ann
f ([a] -> Doc ann) -> (DList a -> [a]) -> DList a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList a -> [a]
forall a. DList a -> [a]
DL.toList

ppListWithDelim
  :: forall f ann. Foldable f
  => Doc ann
  -> Doc ann
  -> f (Doc ann)
  -> Doc ann
ppListWithDelim :: Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim = Doc ann -> Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelimSep Doc ann
separator
  where
    separator :: Doc ann
    separator :: Doc ann
separator = Doc ann
","

ppAssocList :: (Pretty k, Pretty v) => [(k, v)] -> Doc ann
ppAssocList :: [(k, v)] -> Doc ann
ppAssocList =
  (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppAssocListWith :: (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith :: (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith =
  Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
forall ann k v.
Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWithSep Doc ann
"->"

ppAssocListWithSep
  :: Doc ann
  -> (k -> Doc ann)
  -> (v -> Doc ann)
  -> [(k, v)]
  -> Doc ann
ppAssocListWithSep :: Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWithSep Doc ann
sep k -> Doc ann
f v -> Doc ann
g =
  Doc ann -> Doc ann -> [Doc ann] -> Doc ann
forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim Doc ann
forall ann. Doc ann
PP.lbrace Doc ann
forall ann. Doc ann
PP.rbrace ([Doc ann] -> Doc ann)
-> ([(k, v)] -> [Doc ann]) -> [(k, v)] -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k, v) -> Doc ann) -> [(k, v)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (Doc ann
-> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
forall ann k v.
Doc ann
-> (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWithSep Doc ann
sep k -> Doc ann
f v -> Doc ann
g (MapEntry k v -> Doc ann)
-> ((k, v) -> MapEntry k v) -> (k, v) -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (k -> v -> MapEntry k v) -> (k, v) -> MapEntry k v
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry k -> v -> MapEntry k v
forall k v. k -> v -> MapEntry k v
(:->))

ppByteString :: C8.ByteString -> Doc ann
ppByteString :: ByteString -> Doc ann
ppByteString = MetaDoc ann -> Doc ann
forall ann. MetaDoc ann -> Doc ann
mdPayload (MetaDoc ann -> Doc ann)
-> (ByteString -> MetaDoc ann) -> ByteString -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> MetaDoc ann
forall ann. ByteString -> MetaDoc ann
strictByteStringMetaDoc

ppByteStringLazy :: CL8.ByteString -> Doc ann
ppByteStringLazy :: ByteString -> Doc ann
ppByteStringLazy = MetaDoc ann -> Doc ann
forall ann. MetaDoc ann -> Doc ann
mdPayload (MetaDoc ann -> Doc ann)
-> (ByteString -> MetaDoc ann) -> ByteString -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> MetaDoc ann
forall ann. ByteString -> MetaDoc ann
lazyByteStringMetaDoc

ppShortByteString :: ShortBS.ShortByteString -> Doc ann
ppShortByteString :: ShortByteString -> Doc ann
ppShortByteString = MetaDoc ann -> Doc ann
forall ann. MetaDoc ann -> Doc ann
mdPayload (MetaDoc ann -> Doc ann)
-> (ShortByteString -> MetaDoc ann) -> ShortByteString -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> MetaDoc ann
forall ann. ShortByteString -> MetaDoc ann
shortByteStringMetaDoc

ppCallStack :: CallStack -> Doc ann
ppCallStack :: CallStack -> Doc ann
ppCallStack =
  [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
PP.vcat ([Doc ann] -> Doc ann)
-> (CallStack -> [Doc ann]) -> CallStack -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  ((String, SrcLoc) -> Doc ann) -> [(String, SrcLoc)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (\(String
name, SrcLoc
loc) -> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
PP.hcat
        [ String -> Doc ann
forall ann. String -> Doc ann
docFromString (SrcLoc -> String
srcLocModule SrcLoc
loc)
        , Doc ann
"."
        , String -> Doc ann
forall ann. String -> Doc ann
docFromString String
name
        , Doc ann
":"
        , Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (SrcLoc -> Int
srcLocStartLine SrcLoc
loc)
        , Doc ann
":"
        , Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (SrcLoc -> Int
srcLocStartCol SrcLoc
loc)
        ]
        ) ([(String, SrcLoc)] -> [Doc ann])
-> (CallStack -> [(String, SrcLoc)]) -> CallStack -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  CallStack -> [(String, SrcLoc)]
getCallStack

-- | Pretty-print a CallStack just as GHC would.
ppCallStackGHC :: CallStack -> Doc ann
ppCallStackGHC :: CallStack -> Doc ann
ppCallStackGHC =
  [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
PP.vcat ([Doc ann] -> Doc ann)
-> (CallStack -> [Doc ann]) -> CallStack -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  ((String, SrcLoc) -> Doc ann) -> [(String, SrcLoc)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (\(String
name, SrcLoc
loc) ->
        String -> Doc ann
forall ann. String -> Doc ann
docFromString String
name Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
", called at" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> String -> Doc ann
forall ann. String -> Doc ann
docFromString (SrcLoc -> String
prettySrcLoc SrcLoc
loc)) ([(String, SrcLoc)] -> [Doc ann])
-> (CallStack -> [(String, SrcLoc)]) -> CallStack -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  CallStack -> [(String, SrcLoc)]
getCallStack