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

{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}

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

  , renderWith
  , renderLazyWith
  , renderStringWith
  , PP.defaultLayoutOptions
  , PP.LayoutOptions(..)
  , PP.PageWidth(..)

  , 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

#ifdef HAVE_ENUMMAPSET
  , ppEnumSet
  , ppEnumSetWith
  , ppEnumMap
  , ppEnumMapWith
#endif
  ) 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.Text qualified as T
import Data.Text.Lazy qualified as TL
import Data.Vector.Generic qualified as G
import GHC.Stack (CallStack, SrcLoc(..), getCallStack, prettySrcLoc)
import Prettyprinter (Pretty(..), Doc, (<+>))
import Prettyprinter qualified as PP
import Prettyprinter.Combinators.Basic
import Prettyprinter.MetaDoc
import Prettyprinter.Render.Text qualified as PP.Render

#ifdef HAVE_ENUMMAPSET
import Data.EnumMap (EnumMap)
import Data.EnumMap qualified as EM
import Data.EnumSet (EnumSet)
import Data.EnumSet qualified as ES
#endif

putDocLn :: Doc ann -> IO ()
putDocLn :: forall ann. 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 :: forall ann. Doc ann -> Text
render = LayoutOptions -> Doc ann -> Text
forall ann. LayoutOptions -> Doc ann -> Text
renderWith LayoutOptions
PP.defaultLayoutOptions

renderLazy :: Doc ann -> TL.Text
renderLazy :: forall ann. Doc ann -> Text
renderLazy = LayoutOptions -> Doc ann -> Text
forall ann. LayoutOptions -> Doc ann -> Text
renderLazyWith LayoutOptions
PP.defaultLayoutOptions

renderString :: Doc ann -> String
renderString :: forall ann. Doc ann -> String
renderString = LayoutOptions -> Doc ann -> String
forall ann. LayoutOptions -> Doc ann -> String
renderStringWith LayoutOptions
PP.defaultLayoutOptions

renderWith :: PP.LayoutOptions -> Doc ann -> T.Text
renderWith :: forall ann. LayoutOptions -> Doc ann -> Text
renderWith LayoutOptions
opt = Text -> Text
TL.toStrict (Text -> Text) -> (Doc ann -> Text) -> Doc ann -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayoutOptions -> Doc ann -> Text
forall ann. LayoutOptions -> Doc ann -> Text
renderLazyWith LayoutOptions
opt

renderLazyWith :: PP.LayoutOptions -> Doc ann -> TL.Text
renderLazyWith :: forall ann. LayoutOptions -> Doc ann -> Text
renderLazyWith LayoutOptions
opt = 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
opt

renderStringWith :: PP.LayoutOptions -> Doc ann -> String
renderStringWith :: forall ann. LayoutOptions -> Doc ann -> String
renderStringWith LayoutOptions
opt = Text -> String
TL.unpack (Text -> String) -> (Doc ann -> Text) -> Doc ann -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayoutOptions -> Doc ann -> Text
forall ann. LayoutOptions -> Doc ann -> Text
renderLazyWith LayoutOptions
opt


docFromString :: String -> Doc ann
docFromString :: forall ann. String -> Doc ann
docFromString = Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Text -> 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 :: forall ann. Text -> Doc ann
docFromText = Text -> Doc ann
forall ann. 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
$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
/= :: 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
$ccompare :: forall k v.
(Ord k, Ord v) =>
MapEntry k v -> MapEntry k v -> Ordering
compare :: MapEntry k v -> MapEntry k v -> Ordering
$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
>= :: MapEntry k v -> MapEntry k v -> Bool
$cmax :: 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
$cmin :: 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
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
$cshowsPrec :: forall k v. (Show k, Show v) => Int -> MapEntry k v -> ShowS
showsPrec :: Int -> MapEntry k v -> ShowS
$cshow :: forall k v. (Show k, Show v) => MapEntry k v -> String
show :: MapEntry k v -> String
$cshowList :: forall k v. (Show k, Show v) => [MapEntry k v] -> ShowS
showList :: [MapEntry k v] -> ShowS
Show, (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
$cfmap :: forall k a b. (a -> b) -> MapEntry k a -> MapEntry k b
fmap :: forall a b. (a -> b) -> MapEntry k a -> MapEntry k b
$c<$ :: forall k a b. a -> MapEntry k b -> MapEntry k a
<$ :: forall a b. a -> MapEntry k b -> MapEntry k a
Functor, (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
$cfold :: forall k m. Monoid m => MapEntry k m -> m
fold :: forall m. Monoid m => MapEntry k m -> 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
foldMap' :: forall m a. Monoid m => (a -> m) -> MapEntry k a -> m
$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
foldr' :: forall a b. (a -> b -> 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
foldl' :: forall b a. (b -> a -> b) -> b -> MapEntry k a -> b
$cfoldr1 :: forall k a. (a -> a -> a) -> MapEntry k a -> a
foldr1 :: forall a. (a -> a -> a) -> MapEntry k a -> a
$cfoldl1 :: forall k a. (a -> a -> a) -> MapEntry k a -> a
foldl1 :: forall a. (a -> a -> a) -> MapEntry k a -> a
$ctoList :: forall k a. MapEntry k a -> [a]
toList :: forall a. MapEntry k a -> [a]
$cnull :: forall k a. MapEntry k a -> Bool
null :: forall a. MapEntry k a -> Bool
$clength :: forall k a. MapEntry k a -> Int
length :: forall a. MapEntry k a -> Int
$celem :: forall k a. Eq a => a -> MapEntry k a -> Bool
elem :: forall a. Eq a => a -> MapEntry k a -> Bool
$cmaximum :: forall k a. Ord a => MapEntry k a -> a
maximum :: forall a. Ord a => MapEntry k a -> a
$cminimum :: forall k a. Ord a => MapEntry k a -> a
minimum :: forall a. Ord a => MapEntry k a -> a
$csum :: forall k a. Num a => MapEntry k a -> a
sum :: forall a. Num a => MapEntry k a -> a
$cproduct :: forall k a. Num a => MapEntry k a -> a
product :: forall a. Num a => MapEntry k a -> a
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)
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)
$ctraverse :: forall k (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MapEntry k a -> f (MapEntry k b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MapEntry k a -> f (MapEntry k b)
$csequenceA :: forall k (f :: * -> *) a.
Applicative f =>
MapEntry k (f a) -> f (MapEntry k a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
MapEntry k (f a) -> f (MapEntry k a)
$cmapM :: forall k (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MapEntry k a -> m (MapEntry k b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MapEntry k a -> m (MapEntry k b)
$csequence :: forall k (m :: * -> *) a.
Monad m =>
MapEntry k (m a) -> m (MapEntry k a)
sequence :: forall (m :: * -> *) a.
Monad m =>
MapEntry k (m a) -> m (MapEntry k a)
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 = 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 :: 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) =
  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 :: forall ann. 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 ann. k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall ann. 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)
--> :: forall v ann. Pretty v => 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 ann. 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 :: forall ann. 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 :: forall ann. [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 ann. 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 ann. 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 a. Ord a => [a] -> a
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 :: forall a ann. Pretty a => [a] -> Doc ann
ppList = (a -> Doc ann) -> [a] -> Doc ann
forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppListWith a -> Doc ann
forall ann. a -> Doc ann
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 = 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 :: forall a ann. Pretty a => [a] -> Doc ann
ppTuple = (a -> Doc ann) -> [a] -> Doc ann
forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppTupleWith a -> Doc ann
forall ann. a -> Doc ann
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 = 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 :: forall a (f :: * -> *) ann.
(Pretty a, Foldable f) =>
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 ann. 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 :: 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 =
  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
"-" 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 a. f a -> [a]
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 = (a -> Doc ann) -> NonEmpty a -> Doc ann
forall a ann. (a -> Doc ann) -> NonEmpty a -> Doc ann
ppNEWith a -> Doc ann
forall ann. a -> Doc ann
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 = 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 a. NonEmpty a -> [a]
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 = (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 ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty b -> Doc ann
forall ann. 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 :: forall k ann v.
(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 :: forall a ann. Pretty a => 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 ann. a -> Doc ann
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 = 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 a. Set a -> [a]
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 = (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 ann. k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall ann. 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 :: forall k ann v.
(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 :: forall ann. IntSet -> Doc ann
ppIntSet = (Int -> Doc ann) -> IntSet -> Doc ann
forall ann. (Int -> Doc ann) -> IntSet -> Doc ann
ppIntSetWith Int -> Doc ann
forall ann. Int -> Doc ann
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 = 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 :: forall a ann. Pretty a => 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 ann. Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty a -> Doc ann
forall ann. a -> Doc ann
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 = (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

#ifdef HAVE_ENUMMAPSET
ppEnumSet :: (Enum a, Pretty a) => EnumSet a -> Doc ann
ppEnumSet :: forall a ann. (Enum a, Pretty a) => EnumSet a -> Doc ann
ppEnumSet = (a -> Doc ann) -> EnumSet a -> Doc ann
forall a ann. Enum a => (a -> Doc ann) -> EnumSet a -> Doc ann
ppEnumSetWith a -> Doc ann
forall ann. a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppEnumSetWith :: Enum a => (a -> Doc ann) -> EnumSet a -> Doc ann
ppEnumSetWith :: forall a ann. Enum a => (a -> Doc ann) -> EnumSet a -> Doc ann
ppEnumSetWith 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)
-> (EnumSet a -> [Doc ann]) -> EnumSet 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]) -> (EnumSet a -> [a]) -> EnumSet a -> [Doc ann]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EnumSet a -> [a]
forall k. Enum k => EnumSet k -> [k]
ES.toList

ppEnumMap :: (Enum k, Pretty k, Pretty v) => EnumMap k v -> Doc ann
ppEnumMap :: forall k v ann.
(Enum k, Pretty k, Pretty v) =>
EnumMap k v -> Doc ann
ppEnumMap = (k -> Doc ann) -> (v -> Doc ann) -> EnumMap k v -> Doc ann
forall k ann v.
Enum k =>
(k -> Doc ann) -> (v -> Doc ann) -> EnumMap k v -> Doc ann
ppEnumMapWith k -> Doc ann
forall ann. k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall ann. v -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty

ppEnumMapWith :: Enum k => (k -> Doc ann) -> (v -> Doc ann) -> EnumMap k v -> Doc ann
ppEnumMapWith :: forall k ann v.
Enum k =>
(k -> Doc ann) -> (v -> Doc ann) -> EnumMap k v -> Doc ann
ppEnumMapWith 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)
-> (EnumMap k v -> [(k, v)]) -> EnumMap k v -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EnumMap k v -> [(k, v)]
forall k a. Enum k => EnumMap k a -> [(k, a)]
EM.toList
#endif

ppHashSet :: Pretty a => HashSet a -> Doc ann
ppHashSet :: forall a ann. Pretty a => 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 ann. a -> Doc ann
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 = 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 :: forall k v ann. (Pretty k, Pretty v) => 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 ann. k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall ann. 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 :: forall k ann v.
(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 :: (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 = (a -> Doc ann) -> v a -> Doc ann
forall (v :: * -> *) a ann.
Vector v a =>
(a -> Doc ann) -> v a -> Doc ann
ppVectorWith a -> Doc ann
forall ann. a -> Doc ann
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 = (a -> Doc ann) -> [a] -> Doc ann
forall a ann. (a -> Doc ann) -> [a] -> Doc ann
ppListWith a -> Doc ann
f ([a] -> Doc ann) -> (v a -> [a]) -> v a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v a -> [a]
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 = (a -> Doc ann) -> DList a -> Doc ann
forall a ann. (a -> Doc ann) -> DList a -> Doc ann
ppDListWith a -> Doc ann
forall ann. a -> Doc ann
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 = (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 :: forall (f :: * -> *) ann.
Foldable f =>
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 :: forall k v ann. (Pretty k, Pretty v) => [(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 ann. k -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty v -> Doc ann
forall ann. v -> Doc ann
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 =
  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 :: 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 =
  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 :: forall ann. 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 :: forall ann. 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 :: forall ann. 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 :: forall ann. 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 ann. Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (SrcLoc -> Int
srcLocStartLine SrcLoc
loc)
        , Doc ann
":"
        , Int -> Doc ann
forall 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 :: forall ann. 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