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

{-# LANGUAGE CPP                 #-}
{-# LANGUAGE DeriveTraversable   #-}
{-# 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.Generic qualified as G
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 :: forall ann. Doc ann -> IO ()
putDocLn Doc ann
x = do
  forall ann. Doc ann -> IO ()
PP.Render.putDoc Doc ann
x
  String -> IO ()
putStrLn String
""

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

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

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

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

docFromText :: T.Text -> Doc ann
docFromText :: forall ann. Text -> Doc ann
docFromText = 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
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, MapEntry k v -> MapEntry k v -> Bool
MapEntry k v -> MapEntry k v -> Ordering
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
Ord, Int -> MapEntry k v -> ShowS
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, 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
<$ :: forall a b. a -> MapEntry k b -> MapEntry k a
$c<$ :: forall k a b. a -> MapEntry k b -> MapEntry k a
fmap :: forall a b. (a -> b) -> MapEntry k a -> MapEntry k b
$cfmap :: forall k a b. (a -> b) -> MapEntry k a -> MapEntry k b
Functor, forall a. MapEntry k a -> Bool
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 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 :: forall a. Num a => MapEntry k a -> a
$cproduct :: forall k a. Num a => MapEntry k a -> a
sum :: forall a. Num a => MapEntry k a -> a
$csum :: forall k a. Num a => MapEntry k a -> a
minimum :: forall a. Ord a => MapEntry k a -> a
$cminimum :: forall k a. Ord a => MapEntry k a -> a
maximum :: forall a. Ord a => MapEntry k a -> a
$cmaximum :: forall k a. Ord a => MapEntry k a -> a
elem :: forall a. Eq a => a -> MapEntry k a -> Bool
$celem :: forall k a. Eq a => a -> MapEntry k a -> Bool
length :: forall a. MapEntry k a -> Int
$clength :: forall k a. MapEntry k a -> Int
null :: forall a. MapEntry k a -> Bool
$cnull :: forall k a. MapEntry k a -> Bool
toList :: forall a. MapEntry k a -> [a]
$ctoList :: forall k a. MapEntry k a -> [a]
foldl1 :: forall a. (a -> a -> a) -> MapEntry k a -> a
$cfoldl1 :: forall k a. (a -> a -> a) -> MapEntry k a -> a
foldr1 :: forall a. (a -> a -> a) -> MapEntry k a -> a
$cfoldr1 :: forall k a. (a -> a -> a) -> MapEntry k a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> MapEntry k a -> b
$cfoldl' :: forall k b a. (b -> a -> b) -> b -> MapEntry k a -> b
foldl :: forall b a. (b -> a -> b) -> b -> MapEntry k a -> b
$cfoldl :: forall k b a. (b -> a -> b) -> b -> MapEntry k a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> MapEntry k a -> b
$cfoldr' :: forall k a b. (a -> b -> b) -> b -> MapEntry k a -> b
foldr :: forall a b. (a -> b -> b) -> b -> MapEntry k a -> b
$cfoldr :: forall k a b. (a -> b -> b) -> b -> MapEntry k a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> MapEntry k a -> m
$cfoldMap' :: forall k m a. Monoid m => (a -> m) -> MapEntry k a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> MapEntry k a -> m
$cfoldMap :: forall k m a. Monoid m => (a -> m) -> MapEntry k a -> m
fold :: forall m. Monoid m => MapEntry k m -> m
$cfold :: forall k m. Monoid m => MapEntry k m -> m
Foldable, 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 (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MapEntry k a -> f (MapEntry k b)
sequence :: forall (m :: * -> *) a.
Monad m =>
MapEntry k (m a) -> m (MapEntry k a)
$csequence :: forall k (m :: * -> *) a.
Monad m =>
MapEntry k (m a) -> m (MapEntry k a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(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 :: forall (f :: * -> *) a.
Applicative f =>
MapEntry k (f a) -> f (MapEntry k a)
$csequenceA :: forall k (f :: * -> *) a.
Applicative f =>
MapEntry k (f a) -> f (MapEntry k a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(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)
Traversable)

ppMapEntryWith
  :: (k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith :: forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith = 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 :: 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 (k
x :-> v
y) =
  forall ann. Doc ann -> Doc ann
PP.group forall a b. (a -> b) -> a -> b
$ k -> Doc ann
f k
x forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall ann. Int -> Doc ann -> Doc ann
PP.nest Int
4 (Doc ann
sep forall a. Semigroup a => a -> a -> a
<> forall ann. Doc ann
PP.line forall a. Semigroup a => a -> a -> a
<> 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 :: forall ann. MapEntry k v -> Doc ann
pretty = forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> MapEntry k v -> Doc ann
ppMapEntryWith forall a ann. Pretty a => a -> Doc ann
pretty 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)
--> :: forall v ann. Pretty v => Text -> v -> MapEntry Text (Doc ann)
(-->) Text
k v
v = Text
k forall k v. k -> v -> MapEntry k v
:-> forall a ann. Pretty a => a -> Doc ann
pretty v
v

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

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

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

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

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

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

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

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

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

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

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

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

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

ppBimapWith :: (k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
ppBimapWith :: forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> Bimap k v -> Doc ann
ppBimapWith k -> Doc ann
f v -> Doc ann
g = 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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Bimap a b -> [(a, b)]
BM.toList

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

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

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

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

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

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

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

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

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

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

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

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

ppListWithDelim
  :: forall f ann. Foldable f
  => Doc ann
  -> Doc ann
  -> f (Doc ann)
  -> Doc ann
ppListWithDelim :: forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim = 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 :: forall k v ann. (Pretty k, Pretty v) => [(k, v)] -> Doc ann
ppAssocList =
  forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith forall a ann. Pretty a => a -> Doc ann
pretty forall a ann. Pretty a => a -> Doc ann
pretty

ppAssocListWith :: (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith :: forall k ann v.
(k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWith =
  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 :: forall ann k v.
Doc ann -> (k -> Doc ann) -> (v -> Doc ann) -> [(k, v)] -> Doc ann
ppAssocListWithSep Doc ann
sep k -> Doc ann
f v -> Doc ann
g =
  forall (f :: * -> *) ann.
Foldable f =>
Doc ann -> Doc ann -> f (Doc ann) -> Doc ann
ppListWithDelim forall ann. Doc ann
PP.lbrace forall ann. Doc ann
PP.rbrace forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (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 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall k v. k -> v -> MapEntry k v
(:->))

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

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

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

ppCallStack :: CallStack -> Doc ann
ppCallStack :: forall ann. CallStack -> Doc ann
ppCallStack =
  forall ann. [Doc ann] -> Doc ann
PP.vcat forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  forall a b. (a -> b) -> [a] -> [b]
map (\(String
name, SrcLoc
loc) -> forall ann. [Doc ann] -> Doc ann
PP.hcat
        [ forall ann. String -> Doc ann
docFromString (SrcLoc -> String
srcLocModule SrcLoc
loc)
        , Doc ann
"."
        , forall ann. String -> Doc ann
docFromString String
name
        , Doc ann
":"
        , forall a ann. Pretty a => a -> Doc ann
pretty (SrcLoc -> Int
srcLocStartLine SrcLoc
loc)
        , Doc ann
":"
        , forall a ann. Pretty a => a -> Doc ann
pretty (SrcLoc -> Int
srcLocStartCol SrcLoc
loc)
        ]
        ) 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 :: forall ann. CallStack -> Doc ann
ppCallStackGHC =
  forall ann. [Doc ann] -> Doc ann
PP.vcat forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  forall a b. (a -> b) -> [a] -> [b]
map (\(String
name, SrcLoc
loc) ->
        forall ann. String -> Doc ann
docFromString String
name forall a. Semigroup a => a -> a -> a
<> Doc ann
", called at" forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall ann. String -> Doc ann
docFromString (SrcLoc -> String
prettySrcLoc SrcLoc
loc)) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
  CallStack -> [(String, SrcLoc)]
getCallStack