{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_HADDOCK not-home #-}
#include "version-compatibility-macros.h"
module Prettyprinter.Internal (
Doc(..),
Pretty(..),
viaShow, unsafeViaShow, unsafeTextWithoutNewlines,
emptyDoc, nest, line, line', softline, softline', hardline,
group, flatAlt,
align, hang, indent, encloseSep, list, tupled,
(<+>),
concatWith,
hsep, vsep, fillSep, sep,
hcat, vcat, fillCat, cat,
punctuate,
column, nesting, width, pageWidth,
fill, fillBreak,
plural, enclose, surround,
annotate,
unAnnotate,
reAnnotate,
alterAnnotations,
unAnnotateS,
reAnnotateS,
alterAnnotationsS,
fuse, FusionDepth(..),
SimpleDocStream(..),
PageWidth(..), defaultPageWidth,
LayoutOptions(..), defaultLayoutOptions,
layoutPretty, layoutCompact, layoutSmart,
removeTrailingWhitespace,
renderShowS,
textSpaces
) where
import Control.Applicative
import Data.Int
import Data.List.NonEmpty (NonEmpty (..))
import Data.Maybe
import Data.String (IsString (..))
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Lazy as Lazy
import Data.Typeable (Typeable)
import Data.Void
import Data.Word
import GHC.Generics (Generic)
import Data.Semigroup
#if NATURAL_IN_BASE
import Numeric.Natural
#endif
#if !(FOLDABLE_TRAVERSABLE_IN_PRELUDE)
import Data.Foldable (Foldable (..))
import Data.Traversable (Traversable (..))
import Prelude hiding (foldr, foldr1)
#endif
#if FUNCTOR_IDENTITY_IN_BASE
import Data.Functor.Identity
#endif
import Prettyprinter.Render.Util.Panic
data Doc ann =
Fail
| Empty
| Char !Char
| Text !Int !Text
| Line
| FlatAlt (Doc ann) (Doc ann)
| Cat (Doc ann) (Doc ann)
| Nest !Int (Doc ann)
| Union (Doc ann) (Doc ann)
| Column (Int -> Doc ann)
| WithPageWidth (PageWidth -> Doc ann)
| Nesting (Int -> Doc ann)
| Annotated ann (Doc ann)
deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall ann x. Rep (Doc ann) x -> Doc ann
forall ann x. Doc ann -> Rep (Doc ann) x
$cto :: forall ann x. Rep (Doc ann) x -> Doc ann
$cfrom :: forall ann x. Doc ann -> Rep (Doc ann) x
Generic, Typeable)
instance Semigroup (Doc ann) where
<> :: Doc ann -> Doc ann -> Doc ann
(<>) = forall ann. Doc ann -> Doc ann -> Doc ann
Cat
sconcat :: NonEmpty (Doc ann) -> Doc ann
sconcat (Doc ann
x :| [Doc ann]
xs) = forall ann. [Doc ann] -> Doc ann
hcat (Doc ann
xforall a. a -> [a] -> [a]
:[Doc ann]
xs)
stimes :: forall b. Integral b => b -> Doc ann -> Doc ann
stimes b
n Doc ann
x
| b
n forall a. Ord a => a -> a -> Bool
<= b
0 = forall ann. Doc ann
Empty
| b
n forall a. Eq a => a -> a -> Bool
== b
1 = Doc ann
x
| Bool
otherwise =
let n' :: Int
n' = forall a b. (Integral a, Num b) => a -> b
fromIntegral b
n
nx :: Doc ann
nx = forall ann. [Doc ann] -> Doc ann
hcat (forall a. Int -> a -> [a]
replicate Int
n' Doc ann
x)
in case Doc ann
x of
Doc ann
Fail -> forall ann. Doc ann
Fail
Doc ann
Empty -> forall ann. Doc ann
Empty
Char Char
c -> forall ann. Int -> Text -> Doc ann
Text Int
n' (Int -> Text -> Text
T.replicate Int
n' (Char -> Text
T.singleton Char
c))
Text Int
l Text
t -> forall ann. Int -> Text -> Doc ann
Text (Int
n' forall a. Num a => a -> a -> a
* Int
l) (Int -> Text -> Text
T.replicate Int
n' Text
t)
Doc ann
Line -> Doc ann
nx
FlatAlt{} -> Doc ann
nx
Cat{} -> Doc ann
nx
Nest{} -> Doc ann
nx
Union{} -> Doc ann
nx
Column{} -> Doc ann
nx
WithPageWidth{} -> Doc ann
nx
Nesting{} -> Doc ann
nx
Annotated{} -> Doc ann
nx
instance Monoid (Doc ann) where
mempty :: Doc ann
mempty = forall ann. Doc ann
emptyDoc
mappend :: Doc ann -> Doc ann -> Doc ann
mappend = forall a. Semigroup a => a -> a -> a
(<>)
mconcat :: [Doc ann] -> Doc ann
mconcat = forall ann. [Doc ann] -> Doc ann
hcat
instance IsString (Doc ann) where
fromString :: String -> Doc ann
fromString = forall a ann. Pretty a => a -> Doc ann
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
instance Functor Doc where
fmap :: forall a b. (a -> b) -> Doc a -> Doc b
fmap = forall a b. (a -> b) -> Doc a -> Doc b
reAnnotate
class Pretty a where
pretty :: a -> Doc ann
default pretty :: Show a => a -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
viaShow
prettyList :: [a] -> Doc ann
prettyList = forall ann. Doc ann -> Doc ann
align forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. [Doc ann] -> Doc ann
list forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a ann. Pretty a => a -> Doc ann
pretty
{-# MINIMAL pretty #-}
instance Pretty a => Pretty (Const a b) where
pretty :: forall ann. Const a b -> Doc ann
pretty = forall a ann. Pretty a => a -> Doc ann
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} a (b :: k). Const a b -> a
getConst
#if FUNCTOR_IDENTITY_IN_BASE
instance Pretty a => Pretty (Identity a) where
pretty :: forall ann. Identity a -> Doc ann
pretty = forall a ann. Pretty a => a -> Doc ann
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
runIdentity
#endif
instance Pretty a => Pretty [a] where
pretty :: forall ann. [a] -> Doc ann
pretty = forall a ann. Pretty a => [a] -> Doc ann
prettyList
instance Pretty a => Pretty (NonEmpty a) where
pretty :: forall ann. NonEmpty a -> Doc ann
pretty (a
x:|[a]
xs) = forall a ann. Pretty a => [a] -> Doc ann
prettyList (a
xforall a. a -> [a] -> [a]
:[a]
xs)
instance Pretty () where
pretty :: forall ann. () -> Doc ann
pretty ()
_ = Doc ann
"()"
instance Pretty Bool where
pretty :: forall ann. Bool -> Doc ann
pretty Bool
True = Doc ann
"True"
pretty Bool
False = Doc ann
"False"
instance Pretty Char where
pretty :: forall ann. Char -> Doc ann
pretty Char
'\n' = forall ann. Doc ann
line
pretty Char
c = forall ann. Char -> Doc ann
Char Char
c
#ifdef MIN_VERSION_text
prettyList :: forall ann. String -> Doc ann
prettyList = forall a ann. Pretty a => a -> Doc ann
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. a -> a
id :: Text -> Text) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
#else
prettyList = vsep . map unsafeTextWithoutNewlines . T.splitOn "\n"
#endif
viaShow :: Show a => a -> Doc ann
viaShow :: forall a ann. Show a => a -> Doc ann
viaShow = forall a ann. Pretty a => a -> Doc ann
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
unsafeViaShow :: Show a => a -> Doc ann
unsafeViaShow :: forall a ann. Show a => a -> Doc ann
unsafeViaShow = forall ann. Text -> Doc ann
unsafeTextWithoutNewlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
instance Pretty Int where pretty :: forall ann. Int -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Int8 where pretty :: forall ann. Int8 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Int16 where pretty :: forall ann. Int16 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Int32 where pretty :: forall ann. Int32 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Int64 where pretty :: forall ann. Int64 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Word where pretty :: forall ann. Word -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Word8 where pretty :: forall ann. Word8 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Word16 where pretty :: forall ann. Word16 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Word32 where pretty :: forall ann. Word32 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Word64 where pretty :: forall ann. Word64 -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Integer where pretty :: forall ann. Integer -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
#if NATURAL_IN_BASE
instance Pretty Natural where pretty :: forall ann. Natural -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
#endif
instance Pretty Float where pretty :: forall ann. Float -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance Pretty Double where pretty :: forall ann. Double -> Doc ann
pretty = forall a ann. Show a => a -> Doc ann
unsafeViaShow
instance (Pretty a1, Pretty a2) => Pretty (a1,a2) where
pretty :: forall ann. (a1, a2) -> Doc ann
pretty (a1
x1,a2
x2) = forall ann. [Doc ann] -> Doc ann
tupled [forall a ann. Pretty a => a -> Doc ann
pretty a1
x1, forall a ann. Pretty a => a -> Doc ann
pretty a2
x2]
instance (Pretty a1, Pretty a2, Pretty a3) => Pretty (a1,a2,a3) where
pretty :: forall ann. (a1, a2, a3) -> Doc ann
pretty (a1
x1,a2
x2,a3
x3) = forall ann. [Doc ann] -> Doc ann
tupled [forall a ann. Pretty a => a -> Doc ann
pretty a1
x1, forall a ann. Pretty a => a -> Doc ann
pretty a2
x2, forall a ann. Pretty a => a -> Doc ann
pretty a3
x3]
instance Pretty a => Pretty (Maybe a) where
pretty :: forall ann. Maybe a -> Doc ann
pretty = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty forall a ann. Pretty a => a -> Doc ann
pretty
prettyList :: forall ann. [Maybe a] -> Doc ann
prettyList = forall a ann. Pretty a => [a] -> Doc ann
prettyList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Maybe a] -> [a]
catMaybes
#ifdef MIN_VERSION_text
instance Pretty Text where pretty :: forall ann. Text -> Doc ann
pretty = forall ann. [Doc ann] -> Doc ann
vsep forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall ann. Text -> Doc ann
unsafeTextWithoutNewlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn Text
"\n"
instance Pretty Lazy.Text where pretty :: forall ann. Text -> Doc ann
pretty = forall a ann. Pretty a => a -> Doc ann
pretty forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
Lazy.toStrict
#endif
instance Pretty Void where pretty :: forall ann. Void -> Doc ann
pretty = forall a. Void -> a
absurd
unsafeTextWithoutNewlines :: Text -> Doc ann
unsafeTextWithoutNewlines :: forall ann. Text -> Doc ann
unsafeTextWithoutNewlines Text
text = case Text -> Maybe (Char, Text)
T.uncons Text
text of
Maybe (Char, Text)
Nothing -> forall ann. Doc ann
Empty
Just (Char
t,Text
ext)
| Text -> Bool
T.null Text
ext -> forall ann. Char -> Doc ann
Char Char
t
| Bool
otherwise -> forall ann. Int -> Text -> Doc ann
Text (Text -> Int
T.length Text
text) Text
text
emptyDoc :: Doc ann
emptyDoc :: forall ann. Doc ann
emptyDoc = forall ann. Doc ann
Empty
nest
:: Int
-> Doc ann
-> Doc ann
nest :: forall ann. Int -> Doc ann -> Doc ann
nest Int
0 Doc ann
x = Doc ann
x
nest Int
i Doc ann
x = forall ann. Int -> Doc ann -> Doc ann
Nest Int
i Doc ann
x
line :: Doc ann
line :: forall ann. Doc ann
line = forall ann. Doc ann -> Doc ann -> Doc ann
FlatAlt forall ann. Doc ann
Line (forall ann. Char -> Doc ann
Char Char
' ')
line' :: Doc ann
line' :: forall ann. Doc ann
line' = forall ann. Doc ann -> Doc ann -> Doc ann
FlatAlt forall ann. Doc ann
Line forall a. Monoid a => a
mempty
softline :: Doc ann
softline :: forall ann. Doc ann
softline = forall ann. Doc ann -> Doc ann -> Doc ann
Union (forall ann. Char -> Doc ann
Char Char
' ') forall ann. Doc ann
Line
softline' :: Doc ann
softline' :: forall ann. Doc ann
softline' = forall ann. Doc ann -> Doc ann -> Doc ann
Union forall a. Monoid a => a
mempty forall ann. Doc ann
Line
hardline :: Doc ann
hardline :: forall ann. Doc ann
hardline = forall ann. Doc ann
Line
group :: Doc ann -> Doc ann
group :: forall ann. Doc ann -> Doc ann
group Doc ann
x = case Doc ann
x of
Union{} -> Doc ann
x
FlatAlt Doc ann
a Doc ann
b -> case forall ann. Doc ann -> FlattenResult (Doc ann)
changesUponFlattening Doc ann
b of
Flattened Doc ann
b' -> forall ann. Doc ann -> Doc ann -> Doc ann
Union Doc ann
b' Doc ann
a
FlattenResult (Doc ann)
AlreadyFlat -> forall ann. Doc ann -> Doc ann -> Doc ann
Union Doc ann
b Doc ann
a
FlattenResult (Doc ann)
NeverFlat -> Doc ann
a
Doc ann
_ -> case forall ann. Doc ann -> FlattenResult (Doc ann)
changesUponFlattening Doc ann
x of
Flattened Doc ann
x' -> forall ann. Doc ann -> Doc ann -> Doc ann
Union Doc ann
x' Doc ann
x
FlattenResult (Doc ann)
AlreadyFlat -> Doc ann
x
FlattenResult (Doc ann)
NeverFlat -> Doc ann
x
data FlattenResult a
= Flattened a
| AlreadyFlat
| NeverFlat
instance Functor FlattenResult where
fmap :: forall a b. (a -> b) -> FlattenResult a -> FlattenResult b
fmap a -> b
f (Flattened a
a) = forall a. a -> FlattenResult a
Flattened (a -> b
f a
a)
fmap a -> b
_ FlattenResult a
AlreadyFlat = forall a. FlattenResult a
AlreadyFlat
fmap a -> b
_ FlattenResult a
NeverFlat = forall a. FlattenResult a
NeverFlat
changesUponFlattening :: Doc ann -> FlattenResult (Doc ann)
changesUponFlattening :: forall ann. Doc ann -> FlattenResult (Doc ann)
changesUponFlattening = \Doc ann
doc -> case Doc ann
doc of
FlatAlt Doc ann
_ Doc ann
y -> forall a. a -> FlattenResult a
Flattened (forall ann. Doc ann -> Doc ann
flatten Doc ann
y)
Doc ann
Line -> forall a. FlattenResult a
NeverFlat
Union Doc ann
x Doc ann
_ -> forall a. a -> FlattenResult a
Flattened Doc ann
x
Nest Int
i Doc ann
x -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall ann. Int -> Doc ann -> Doc ann
Nest Int
i) (forall ann. Doc ann -> FlattenResult (Doc ann)
changesUponFlattening Doc ann
x)
Annotated ann
ann Doc ann
x -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall ann. ann -> Doc ann -> Doc ann
Annotated ann
ann) (forall ann. Doc ann -> FlattenResult (Doc ann)
changesUponFlattening Doc ann
x)
Column Int -> Doc ann
f -> forall a. a -> FlattenResult a
Flattened (forall ann. (Int -> Doc ann) -> Doc ann
Column (forall ann. Doc ann -> Doc ann
flatten forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f))
Nesting Int -> Doc ann
f -> forall a. a -> FlattenResult a
Flattened (forall ann. (Int -> Doc ann) -> Doc ann
Nesting (forall ann. Doc ann -> Doc ann
flatten forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f))
WithPageWidth PageWidth -> Doc ann
f -> forall a. a -> FlattenResult a
Flattened (forall ann. (PageWidth -> Doc ann) -> Doc ann
WithPageWidth (forall ann. Doc ann -> Doc ann
flatten forall b c a. (b -> c) -> (a -> b) -> a -> c
. PageWidth -> Doc ann
f))
Cat Doc ann
x Doc ann
y -> case (forall ann. Doc ann -> FlattenResult (Doc ann)
changesUponFlattening Doc ann
x, forall ann. Doc ann -> FlattenResult (Doc ann)
changesUponFlattening Doc ann
y) of
(FlattenResult (Doc ann)
NeverFlat , FlattenResult (Doc ann)
_ ) -> forall a. FlattenResult a
NeverFlat
(FlattenResult (Doc ann)
_ , FlattenResult (Doc ann)
NeverFlat ) -> forall a. FlattenResult a
NeverFlat
(Flattened Doc ann
x' , Flattened Doc ann
y') -> forall a. a -> FlattenResult a
Flattened (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x' Doc ann
y')
(Flattened Doc ann
x' , FlattenResult (Doc ann)
AlreadyFlat ) -> forall a. a -> FlattenResult a
Flattened (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x' Doc ann
y)
(FlattenResult (Doc ann)
AlreadyFlat , Flattened Doc ann
y') -> forall a. a -> FlattenResult a
Flattened (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x Doc ann
y')
(FlattenResult (Doc ann)
AlreadyFlat , FlattenResult (Doc ann)
AlreadyFlat ) -> forall a. FlattenResult a
AlreadyFlat
Doc ann
Empty -> forall a. FlattenResult a
AlreadyFlat
Char{} -> forall a. FlattenResult a
AlreadyFlat
Text{} -> forall a. FlattenResult a
AlreadyFlat
Doc ann
Fail -> forall a. FlattenResult a
NeverFlat
where
flatten :: Doc ann -> Doc ann
flatten :: forall ann. Doc ann -> Doc ann
flatten = \Doc ann
doc -> case Doc ann
doc of
FlatAlt Doc ann
_ Doc ann
y -> forall ann. Doc ann -> Doc ann
flatten Doc ann
y
Cat Doc ann
x Doc ann
y -> forall ann. Doc ann -> Doc ann -> Doc ann
Cat (forall ann. Doc ann -> Doc ann
flatten Doc ann
x) (forall ann. Doc ann -> Doc ann
flatten Doc ann
y)
Nest Int
i Doc ann
x -> forall ann. Int -> Doc ann -> Doc ann
Nest Int
i (forall ann. Doc ann -> Doc ann
flatten Doc ann
x)
Doc ann
Line -> forall ann. Doc ann
Fail
Union Doc ann
x Doc ann
_ -> forall ann. Doc ann -> Doc ann
flatten Doc ann
x
Column Int -> Doc ann
f -> forall ann. (Int -> Doc ann) -> Doc ann
Column (forall ann. Doc ann -> Doc ann
flatten forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f)
WithPageWidth PageWidth -> Doc ann
f -> forall ann. (PageWidth -> Doc ann) -> Doc ann
WithPageWidth (forall ann. Doc ann -> Doc ann
flatten forall b c a. (b -> c) -> (a -> b) -> a -> c
. PageWidth -> Doc ann
f)
Nesting Int -> Doc ann
f -> forall ann. (Int -> Doc ann) -> Doc ann
Nesting (forall ann. Doc ann -> Doc ann
flatten forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f)
Annotated ann
ann Doc ann
x -> forall ann. ann -> Doc ann -> Doc ann
Annotated ann
ann (forall ann. Doc ann -> Doc ann
flatten Doc ann
x)
x :: Doc ann
x@Doc ann
Fail -> Doc ann
x
x :: Doc ann
x@Doc ann
Empty -> Doc ann
x
x :: Doc ann
x@Char{} -> Doc ann
x
x :: Doc ann
x@Text{} -> Doc ann
x
flatAlt
:: Doc ann
-> Doc ann
-> Doc ann
flatAlt :: forall ann. Doc ann -> Doc ann -> Doc ann
flatAlt = forall ann. Doc ann -> Doc ann -> Doc ann
FlatAlt
align :: Doc ann -> Doc ann
align :: forall ann. Doc ann -> Doc ann
align Doc ann
d = forall ann. (Int -> Doc ann) -> Doc ann
column (\Int
k -> forall ann. (Int -> Doc ann) -> Doc ann
nesting (\Int
i -> forall ann. Int -> Doc ann -> Doc ann
nest (Int
k forall a. Num a => a -> a -> a
- Int
i) Doc ann
d))
hang
:: Int
-> Doc ann
-> Doc ann
hang :: forall ann. Int -> Doc ann -> Doc ann
hang Int
i Doc ann
d = forall ann. Doc ann -> Doc ann
align (forall ann. Int -> Doc ann -> Doc ann
nest Int
i Doc ann
d)
indent
:: Int
-> Doc ann
-> Doc ann
indent :: forall ann. Int -> Doc ann -> Doc ann
indent Int
i Doc ann
d = forall ann. Int -> Doc ann -> Doc ann
hang Int
i (forall ann. Int -> Doc ann
spaces Int
i forall a. Semigroup a => a -> a -> a
<> Doc ann
d)
encloseSep
:: Doc ann
-> Doc ann
-> Doc ann
-> [Doc ann]
-> Doc ann
encloseSep :: forall ann. Doc ann -> Doc ann -> Doc ann -> [Doc ann] -> Doc ann
encloseSep Doc ann
l Doc ann
r Doc ann
s [Doc ann]
ds = case [Doc ann]
ds of
[] -> Doc ann
l forall a. Semigroup a => a -> a -> a
<> Doc ann
r
[Doc ann
d] -> Doc ann
l forall a. Semigroup a => a -> a -> a
<> Doc ann
d forall a. Semigroup a => a -> a -> a
<> Doc ann
r
[Doc ann]
_ -> forall ann. [Doc ann] -> Doc ann
cat (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall a. Semigroup a => a -> a -> a
(<>) (Doc ann
l forall a. a -> [a] -> [a]
: forall a. a -> [a]
repeat Doc ann
s) [Doc ann]
ds) forall a. Semigroup a => a -> a -> a
<> Doc ann
r
list :: [Doc ann] -> Doc ann
list :: forall ann. [Doc ann] -> Doc ann
list = forall ann. Doc ann -> Doc ann
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. Doc ann -> Doc ann -> Doc ann -> [Doc ann] -> Doc ann
encloseSep (forall ann. Doc ann -> Doc ann -> Doc ann
flatAlt Doc ann
"[ " Doc ann
"[")
(forall ann. Doc ann -> Doc ann -> Doc ann
flatAlt Doc ann
" ]" Doc ann
"]")
Doc ann
", "
tupled :: [Doc ann] -> Doc ann
tupled :: forall ann. [Doc ann] -> Doc ann
tupled = forall ann. Doc ann -> Doc ann
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. Doc ann -> Doc ann -> Doc ann -> [Doc ann] -> Doc ann
encloseSep (forall ann. Doc ann -> Doc ann -> Doc ann
flatAlt Doc ann
"( " Doc ann
"(")
(forall ann. Doc ann -> Doc ann -> Doc ann
flatAlt Doc ann
" )" Doc ann
")")
Doc ann
", "
(<+>) :: Doc ann -> Doc ann -> Doc ann
Doc ann
x <+> :: forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
y = Doc ann
x forall a. Semigroup a => a -> a -> a
<> forall ann. Char -> Doc ann
Char Char
' ' forall a. Semigroup a => a -> a -> a
<> Doc ann
y
infixr 6 <+>
concatWith :: Foldable t => (Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith :: forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith Doc ann -> Doc ann -> Doc ann
f t (Doc ann)
ds
#if !(FOLDABLE_TRAVERSABLE_IN_PRELUDE)
| foldr (\_ _ -> False) True ds = mempty
#else
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null t (Doc ann)
ds = forall a. Monoid a => a
mempty
#endif
| Bool
otherwise = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 Doc ann -> Doc ann -> Doc ann
f t (Doc ann)
ds
{-# INLINE concatWith #-}
{-# SPECIALIZE concatWith :: (Doc ann -> Doc ann -> Doc ann) -> [Doc ann] -> Doc ann #-}
hsep :: [Doc ann] -> Doc ann
hsep :: forall ann. [Doc ann] -> Doc ann
hsep = forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith forall ann. Doc ann -> Doc ann -> Doc ann
(<+>)
vsep :: [Doc ann] -> Doc ann
vsep :: forall ann. [Doc ann] -> Doc ann
vsep = forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith (\Doc ann
x Doc ann
y -> Doc ann
x forall a. Semigroup a => a -> a -> a
<> forall ann. Doc ann
line forall a. Semigroup a => a -> a -> a
<> Doc ann
y)
fillSep :: [Doc ann] -> Doc ann
fillSep :: forall ann. [Doc ann] -> Doc ann
fillSep = forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith (\Doc ann
x Doc ann
y -> Doc ann
x forall a. Semigroup a => a -> a -> a
<> forall ann. Doc ann
softline forall a. Semigroup a => a -> a -> a
<> Doc ann
y)
sep :: [Doc ann] -> Doc ann
sep :: forall ann. [Doc ann] -> Doc ann
sep = forall ann. Doc ann -> Doc ann
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. [Doc ann] -> Doc ann
vsep
hcat :: [Doc ann] -> Doc ann
hcat :: forall ann. [Doc ann] -> Doc ann
hcat = forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith forall a. Semigroup a => a -> a -> a
(<>)
vcat :: [Doc ann] -> Doc ann
vcat :: forall ann. [Doc ann] -> Doc ann
vcat = forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith (\Doc ann
x Doc ann
y -> Doc ann
x forall a. Semigroup a => a -> a -> a
<> forall ann. Doc ann
line' forall a. Semigroup a => a -> a -> a
<> Doc ann
y)
fillCat :: [Doc ann] -> Doc ann
fillCat :: forall ann. [Doc ann] -> Doc ann
fillCat = forall (t :: * -> *) ann.
Foldable t =>
(Doc ann -> Doc ann -> Doc ann) -> t (Doc ann) -> Doc ann
concatWith (\Doc ann
x Doc ann
y -> Doc ann
x forall a. Semigroup a => a -> a -> a
<> forall ann. Doc ann
softline' forall a. Semigroup a => a -> a -> a
<> Doc ann
y)
cat :: [Doc ann] -> Doc ann
cat :: forall ann. [Doc ann] -> Doc ann
cat = forall ann. Doc ann -> Doc ann
group forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. [Doc ann] -> Doc ann
vcat
punctuate
:: Doc ann
-> [Doc ann]
-> [Doc ann]
punctuate :: forall ann. Doc ann -> [Doc ann] -> [Doc ann]
punctuate Doc ann
p = [Doc ann] -> [Doc ann]
go
where
go :: [Doc ann] -> [Doc ann]
go [] = []
go [Doc ann
d] = [Doc ann
d]
go (Doc ann
d:[Doc ann]
ds) = (Doc ann
d forall a. Semigroup a => a -> a -> a
<> Doc ann
p) forall a. a -> [a] -> [a]
: [Doc ann] -> [Doc ann]
go [Doc ann]
ds
column :: (Int -> Doc ann) -> Doc ann
column :: forall ann. (Int -> Doc ann) -> Doc ann
column = forall ann. (Int -> Doc ann) -> Doc ann
Column
nesting :: (Int -> Doc ann) -> Doc ann
nesting :: forall ann. (Int -> Doc ann) -> Doc ann
nesting = forall ann. (Int -> Doc ann) -> Doc ann
Nesting
width :: Doc ann -> (Int -> Doc ann) -> Doc ann
width :: forall ann. Doc ann -> (Int -> Doc ann) -> Doc ann
width Doc ann
doc Int -> Doc ann
f
= forall ann. (Int -> Doc ann) -> Doc ann
column (\Int
colStart ->
Doc ann
doc forall a. Semigroup a => a -> a -> a
<> forall ann. (Int -> Doc ann) -> Doc ann
column (\Int
colEnd ->
Int -> Doc ann
f (Int
colEnd forall a. Num a => a -> a -> a
- Int
colStart)))
pageWidth :: (PageWidth -> Doc ann) -> Doc ann
pageWidth :: forall ann. (PageWidth -> Doc ann) -> Doc ann
pageWidth = forall ann. (PageWidth -> Doc ann) -> Doc ann
WithPageWidth
fill
:: Int
-> Doc ann
-> Doc ann
fill :: forall ann. Int -> Doc ann -> Doc ann
fill Int
n Doc ann
doc = forall ann. Doc ann -> (Int -> Doc ann) -> Doc ann
width Doc ann
doc (\Int
w -> forall ann. Int -> Doc ann
spaces (Int
n forall a. Num a => a -> a -> a
- Int
w))
fillBreak
:: Int
-> Doc ann
-> Doc ann
fillBreak :: forall ann. Int -> Doc ann -> Doc ann
fillBreak Int
f Doc ann
x = forall ann. Doc ann -> (Int -> Doc ann) -> Doc ann
width Doc ann
x (\Int
w ->
if Int
w forall a. Ord a => a -> a -> Bool
> Int
f
then forall ann. Int -> Doc ann -> Doc ann
nest Int
f forall ann. Doc ann
line'
else forall ann. Int -> Doc ann
spaces (Int
f forall a. Num a => a -> a -> a
- Int
w))
spaces :: Int -> Doc ann
spaces :: forall ann. Int -> Doc ann
spaces Int
n
| Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 = forall ann. Doc ann
Empty
| Int
n forall a. Eq a => a -> a -> Bool
== Int
1 = forall ann. Char -> Doc ann
Char Char
' '
| Bool
otherwise = forall ann. Int -> Text -> Doc ann
Text Int
n (Int -> Text
textSpaces Int
n)
plural
:: (Num amount, Eq amount)
=> doc
-> doc
-> amount
-> doc
plural :: forall amount doc.
(Num amount, Eq amount) =>
doc -> doc -> amount -> doc
plural doc
one doc
multiple amount
n
| amount
n forall a. Eq a => a -> a -> Bool
== amount
1 = doc
one
| Bool
otherwise = doc
multiple
enclose
:: Doc ann
-> Doc ann
-> Doc ann
-> Doc ann
enclose :: forall ann. Doc ann -> Doc ann -> Doc ann -> Doc ann
enclose Doc ann
l Doc ann
r Doc ann
x = Doc ann
l forall a. Semigroup a => a -> a -> a
<> Doc ann
x forall a. Semigroup a => a -> a -> a
<> Doc ann
r
surround
:: Doc ann
-> Doc ann
-> Doc ann
-> Doc ann
surround :: forall ann. Doc ann -> Doc ann -> Doc ann -> Doc ann
surround Doc ann
x Doc ann
l Doc ann
r = Doc ann
l forall a. Semigroup a => a -> a -> a
<> Doc ann
x forall a. Semigroup a => a -> a -> a
<> Doc ann
r
annotate :: ann -> Doc ann -> Doc ann
annotate :: forall ann. ann -> Doc ann -> Doc ann
annotate = forall ann. ann -> Doc ann -> Doc ann
Annotated
unAnnotate :: Doc ann -> Doc xxx
unAnnotate :: forall ann xxx. Doc ann -> Doc xxx
unAnnotate = forall ann ann'. (ann -> [ann']) -> Doc ann -> Doc ann'
alterAnnotations (forall a b. a -> b -> a
const [])
reAnnotate :: (ann -> ann') -> Doc ann -> Doc ann'
reAnnotate :: forall a b. (a -> b) -> Doc a -> Doc b
reAnnotate ann -> ann'
re = forall ann ann'. (ann -> [ann']) -> Doc ann -> Doc ann'
alterAnnotations (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. ann -> ann'
re)
alterAnnotations :: (ann -> [ann']) -> Doc ann -> Doc ann'
alterAnnotations :: forall ann ann'. (ann -> [ann']) -> Doc ann -> Doc ann'
alterAnnotations ann -> [ann']
re = Doc ann -> Doc ann'
go
where
go :: Doc ann -> Doc ann'
go = \Doc ann
doc -> case Doc ann
doc of
Doc ann
Fail -> forall ann. Doc ann
Fail
Doc ann
Empty -> forall ann. Doc ann
Empty
Char Char
c -> forall ann. Char -> Doc ann
Char Char
c
Text Int
l Text
t -> forall ann. Int -> Text -> Doc ann
Text Int
l Text
t
Doc ann
Line -> forall ann. Doc ann
Line
FlatAlt Doc ann
x Doc ann
y -> forall ann. Doc ann -> Doc ann -> Doc ann
FlatAlt (Doc ann -> Doc ann'
go Doc ann
x) (Doc ann -> Doc ann'
go Doc ann
y)
Cat Doc ann
x Doc ann
y -> forall ann. Doc ann -> Doc ann -> Doc ann
Cat (Doc ann -> Doc ann'
go Doc ann
x) (Doc ann -> Doc ann'
go Doc ann
y)
Nest Int
i Doc ann
x -> forall ann. Int -> Doc ann -> Doc ann
Nest Int
i (Doc ann -> Doc ann'
go Doc ann
x)
Union Doc ann
x Doc ann
y -> forall ann. Doc ann -> Doc ann -> Doc ann
Union (Doc ann -> Doc ann'
go Doc ann
x) (Doc ann -> Doc ann'
go Doc ann
y)
Column Int -> Doc ann
f -> forall ann. (Int -> Doc ann) -> Doc ann
Column (Doc ann -> Doc ann'
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f)
WithPageWidth PageWidth -> Doc ann
f -> forall ann. (PageWidth -> Doc ann) -> Doc ann
WithPageWidth (Doc ann -> Doc ann'
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. PageWidth -> Doc ann
f)
Nesting Int -> Doc ann
f -> forall ann. (Int -> Doc ann) -> Doc ann
Nesting (Doc ann -> Doc ann'
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f)
Annotated ann
ann Doc ann
x -> forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall ann. ann -> Doc ann -> Doc ann
Annotated (Doc ann -> Doc ann'
go Doc ann
x) (ann -> [ann']
re ann
ann)
unAnnotateS :: SimpleDocStream ann -> SimpleDocStream xxx
unAnnotateS :: forall ann xxx. SimpleDocStream ann -> SimpleDocStream xxx
unAnnotateS = forall ann xxx. SimpleDocStream ann -> SimpleDocStream xxx
go
where
go :: SimpleDocStream ann -> SimpleDocStream ann
go = \SimpleDocStream ann
doc -> case SimpleDocStream ann
doc of
SimpleDocStream ann
SFail -> forall ann. SimpleDocStream ann
SFail
SimpleDocStream ann
SEmpty -> forall ann. SimpleDocStream ann
SEmpty
SChar Char
c SimpleDocStream ann
rest -> forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c (SimpleDocStream ann -> SimpleDocStream ann
go SimpleDocStream ann
rest)
SText Int
l Text
t SimpleDocStream ann
rest -> forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
l Text
t (SimpleDocStream ann -> SimpleDocStream ann
go SimpleDocStream ann
rest)
SLine Int
l SimpleDocStream ann
rest -> forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
l (SimpleDocStream ann -> SimpleDocStream ann
go SimpleDocStream ann
rest)
SAnnPop SimpleDocStream ann
rest -> SimpleDocStream ann -> SimpleDocStream ann
go SimpleDocStream ann
rest
SAnnPush ann
_ann SimpleDocStream ann
rest -> SimpleDocStream ann -> SimpleDocStream ann
go SimpleDocStream ann
rest
reAnnotateS :: (ann -> ann') -> SimpleDocStream ann -> SimpleDocStream ann'
reAnnotateS :: forall ann ann'.
(ann -> ann') -> SimpleDocStream ann -> SimpleDocStream ann'
reAnnotateS ann -> ann'
re = SimpleDocStream ann -> SimpleDocStream ann'
go
where
go :: SimpleDocStream ann -> SimpleDocStream ann'
go = \SimpleDocStream ann
doc -> case SimpleDocStream ann
doc of
SimpleDocStream ann
SFail -> forall ann. SimpleDocStream ann
SFail
SimpleDocStream ann
SEmpty -> forall ann. SimpleDocStream ann
SEmpty
SChar Char
c SimpleDocStream ann
rest -> forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c (SimpleDocStream ann -> SimpleDocStream ann'
go SimpleDocStream ann
rest)
SText Int
l Text
t SimpleDocStream ann
rest -> forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
l Text
t (SimpleDocStream ann -> SimpleDocStream ann'
go SimpleDocStream ann
rest)
SLine Int
l SimpleDocStream ann
rest -> forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
l (SimpleDocStream ann -> SimpleDocStream ann'
go SimpleDocStream ann
rest)
SAnnPop SimpleDocStream ann
rest -> forall ann. SimpleDocStream ann -> SimpleDocStream ann
SAnnPop (SimpleDocStream ann -> SimpleDocStream ann'
go SimpleDocStream ann
rest)
SAnnPush ann
ann SimpleDocStream ann
rest -> forall ann. ann -> SimpleDocStream ann -> SimpleDocStream ann
SAnnPush (ann -> ann'
re ann
ann) (SimpleDocStream ann -> SimpleDocStream ann'
go SimpleDocStream ann
rest)
data AnnotationRemoval = Remove | DontRemove
deriving Typeable
alterAnnotationsS :: (ann -> Maybe ann') -> SimpleDocStream ann -> SimpleDocStream ann'
alterAnnotationsS :: forall ann ann'.
(ann -> Maybe ann') -> SimpleDocStream ann -> SimpleDocStream ann'
alterAnnotationsS ann -> Maybe ann'
re = [AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go []
where
go :: [AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go [AnnotationRemoval]
stack = \SimpleDocStream ann
sds -> case SimpleDocStream ann
sds of
SimpleDocStream ann
SFail -> forall ann. SimpleDocStream ann
SFail
SimpleDocStream ann
SEmpty -> forall ann. SimpleDocStream ann
SEmpty
SChar Char
c SimpleDocStream ann
rest -> forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c ([AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go [AnnotationRemoval]
stack SimpleDocStream ann
rest)
SText Int
l Text
t SimpleDocStream ann
rest -> forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
l Text
t ([AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go [AnnotationRemoval]
stack SimpleDocStream ann
rest)
SLine Int
l SimpleDocStream ann
rest -> forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
l ([AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go [AnnotationRemoval]
stack SimpleDocStream ann
rest)
SAnnPush ann
ann SimpleDocStream ann
rest -> case ann -> Maybe ann'
re ann
ann of
Maybe ann'
Nothing -> [AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go (AnnotationRemoval
Removeforall a. a -> [a] -> [a]
:[AnnotationRemoval]
stack) SimpleDocStream ann
rest
Just ann'
ann' -> forall ann. ann -> SimpleDocStream ann -> SimpleDocStream ann
SAnnPush ann'
ann' ([AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go (AnnotationRemoval
DontRemoveforall a. a -> [a] -> [a]
:[AnnotationRemoval]
stack) SimpleDocStream ann
rest)
SAnnPop SimpleDocStream ann
rest -> case [AnnotationRemoval]
stack of
[] -> forall void. void
panicPeekedEmpty
AnnotationRemoval
DontRemove:[AnnotationRemoval]
stack' -> forall ann. SimpleDocStream ann -> SimpleDocStream ann
SAnnPop ([AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go [AnnotationRemoval]
stack' SimpleDocStream ann
rest)
AnnotationRemoval
Remove:[AnnotationRemoval]
stack' -> [AnnotationRemoval] -> SimpleDocStream ann -> SimpleDocStream ann'
go [AnnotationRemoval]
stack' SimpleDocStream ann
rest
data FusionDepth =
Shallow
| Deep
deriving (FusionDepth -> FusionDepth -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FusionDepth -> FusionDepth -> Bool
$c/= :: FusionDepth -> FusionDepth -> Bool
== :: FusionDepth -> FusionDepth -> Bool
$c== :: FusionDepth -> FusionDepth -> Bool
Eq, Eq FusionDepth
FusionDepth -> FusionDepth -> Bool
FusionDepth -> FusionDepth -> Ordering
FusionDepth -> FusionDepth -> FusionDepth
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
min :: FusionDepth -> FusionDepth -> FusionDepth
$cmin :: FusionDepth -> FusionDepth -> FusionDepth
max :: FusionDepth -> FusionDepth -> FusionDepth
$cmax :: FusionDepth -> FusionDepth -> FusionDepth
>= :: FusionDepth -> FusionDepth -> Bool
$c>= :: FusionDepth -> FusionDepth -> Bool
> :: FusionDepth -> FusionDepth -> Bool
$c> :: FusionDepth -> FusionDepth -> Bool
<= :: FusionDepth -> FusionDepth -> Bool
$c<= :: FusionDepth -> FusionDepth -> Bool
< :: FusionDepth -> FusionDepth -> Bool
$c< :: FusionDepth -> FusionDepth -> Bool
compare :: FusionDepth -> FusionDepth -> Ordering
$ccompare :: FusionDepth -> FusionDepth -> Ordering
Ord, Int -> FusionDepth -> ShowS
[FusionDepth] -> ShowS
FusionDepth -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FusionDepth] -> ShowS
$cshowList :: [FusionDepth] -> ShowS
show :: FusionDepth -> String
$cshow :: FusionDepth -> String
showsPrec :: Int -> FusionDepth -> ShowS
$cshowsPrec :: Int -> FusionDepth -> ShowS
Show, Typeable)
fuse :: FusionDepth -> Doc ann -> Doc ann
fuse :: forall ann. FusionDepth -> Doc ann -> Doc ann
fuse FusionDepth
depth = forall ann. Doc ann -> Doc ann
go
where
go :: Doc ann -> Doc ann
go = \Doc ann
doc -> case Doc ann
doc of
Cat Doc ann
Empty Doc ann
x -> Doc ann -> Doc ann
go Doc ann
x
Cat Doc ann
x Doc ann
Empty -> Doc ann -> Doc ann
go Doc ann
x
Cat (Char Char
c1) (Char Char
c2) -> forall ann. Int -> Text -> Doc ann
Text Int
2 (Char -> Text
T.singleton Char
c1 forall a. Semigroup a => a -> a -> a
<> Char -> Text
T.singleton Char
c2)
Cat (Text Int
lt Text
t) (Char Char
c) -> forall ann. Int -> Text -> Doc ann
Text (Int
ltforall a. Num a => a -> a -> a
+Int
1) (Text -> Char -> Text
T.snoc Text
t Char
c)
Cat (Char Char
c) (Text Int
lt Text
t) -> forall ann. Int -> Text -> Doc ann
Text (Int
1forall a. Num a => a -> a -> a
+Int
lt) (Char -> Text -> Text
T.cons Char
c Text
t)
Cat (Text Int
l1 Text
t1) (Text Int
l2 Text
t2) -> forall ann. Int -> Text -> Doc ann
Text (Int
l1forall a. Num a => a -> a -> a
+Int
l2) (Text
t1 forall a. Semigroup a => a -> a -> a
<> Text
t2)
Cat x :: Doc ann
x@Char{} (Cat y :: Doc ann
y@Char{} Doc ann
z) -> Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat (Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x Doc ann
y)) Doc ann
z)
Cat x :: Doc ann
x@Text{} (Cat y :: Doc ann
y@Char{} Doc ann
z) -> Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat (Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x Doc ann
y)) Doc ann
z)
Cat x :: Doc ann
x@Char{} (Cat y :: Doc ann
y@Text{} Doc ann
z) -> Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat (Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x Doc ann
y)) Doc ann
z)
Cat x :: Doc ann
x@Text{} (Cat y :: Doc ann
y@Text{} Doc ann
z) -> Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat (Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x Doc ann
y)) Doc ann
z)
Cat (Cat Doc ann
x y :: Doc ann
y@Char{}) Doc ann
z -> Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x (Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
y Doc ann
z)))
Cat (Cat Doc ann
x y :: Doc ann
y@Text{}) Doc ann
z -> Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
x (Doc ann -> Doc ann
go (forall ann. Doc ann -> Doc ann -> Doc ann
Cat Doc ann
y Doc ann
z)))
Cat Doc ann
x Doc ann
y -> forall ann. Doc ann -> Doc ann -> Doc ann
Cat (Doc ann -> Doc ann
go Doc ann
x) (Doc ann -> Doc ann
go Doc ann
y)
Nest Int
i (Nest Int
j Doc ann
x) -> let !fused :: Doc ann
fused = forall ann. Int -> Doc ann -> Doc ann
Nest (Int
iforall a. Num a => a -> a -> a
+Int
j) Doc ann
x
in Doc ann -> Doc ann
go Doc ann
fused
Nest Int
_ x :: Doc ann
x@Empty{} -> Doc ann
x
Nest Int
_ x :: Doc ann
x@Text{} -> Doc ann
x
Nest Int
_ x :: Doc ann
x@Char{} -> Doc ann
x
Nest Int
0 Doc ann
x -> Doc ann -> Doc ann
go Doc ann
x
Nest Int
i Doc ann
x -> forall ann. Int -> Doc ann -> Doc ann
Nest Int
i (Doc ann -> Doc ann
go Doc ann
x)
Annotated ann
ann Doc ann
x -> forall ann. ann -> Doc ann -> Doc ann
Annotated ann
ann (Doc ann -> Doc ann
go Doc ann
x)
FlatAlt Doc ann
x1 Doc ann
x2 -> forall ann. Doc ann -> Doc ann -> Doc ann
FlatAlt (Doc ann -> Doc ann
go Doc ann
x1) (Doc ann -> Doc ann
go Doc ann
x2)
Union Doc ann
x1 Doc ann
x2 -> forall ann. Doc ann -> Doc ann -> Doc ann
Union (Doc ann -> Doc ann
go Doc ann
x1) (Doc ann -> Doc ann
go Doc ann
x2)
Doc ann
other | FusionDepth
depth forall a. Eq a => a -> a -> Bool
== FusionDepth
Shallow -> Doc ann
other
Column Int -> Doc ann
f -> forall ann. (Int -> Doc ann) -> Doc ann
Column (Doc ann -> Doc ann
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f)
WithPageWidth PageWidth -> Doc ann
f -> forall ann. (PageWidth -> Doc ann) -> Doc ann
WithPageWidth (Doc ann -> Doc ann
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. PageWidth -> Doc ann
f)
Nesting Int -> Doc ann
f -> forall ann. (Int -> Doc ann) -> Doc ann
Nesting (Doc ann -> Doc ann
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc ann
f)
Doc ann
other -> Doc ann
other
data SimpleDocStream ann =
SFail
| SEmpty
| SChar !Char (SimpleDocStream ann)
| SText !Int !Text (SimpleDocStream ann)
| SLine !Int (SimpleDocStream ann)
| SAnnPush ann (SimpleDocStream ann)
| SAnnPop (SimpleDocStream ann)
deriving (SimpleDocStream ann -> SimpleDocStream ann -> Bool
forall ann.
Eq ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleDocStream ann -> SimpleDocStream ann -> Bool
$c/= :: forall ann.
Eq ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
== :: SimpleDocStream ann -> SimpleDocStream ann -> Bool
$c== :: forall ann.
Eq ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
Eq, SimpleDocStream ann -> SimpleDocStream ann -> 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 {ann}. Ord ann => Eq (SimpleDocStream ann)
forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Ordering
forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> SimpleDocStream ann
min :: SimpleDocStream ann -> SimpleDocStream ann -> SimpleDocStream ann
$cmin :: forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> SimpleDocStream ann
max :: SimpleDocStream ann -> SimpleDocStream ann -> SimpleDocStream ann
$cmax :: forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> SimpleDocStream ann
>= :: SimpleDocStream ann -> SimpleDocStream ann -> Bool
$c>= :: forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
> :: SimpleDocStream ann -> SimpleDocStream ann -> Bool
$c> :: forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
<= :: SimpleDocStream ann -> SimpleDocStream ann -> Bool
$c<= :: forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
< :: SimpleDocStream ann -> SimpleDocStream ann -> Bool
$c< :: forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Bool
compare :: SimpleDocStream ann -> SimpleDocStream ann -> Ordering
$ccompare :: forall ann.
Ord ann =>
SimpleDocStream ann -> SimpleDocStream ann -> Ordering
Ord, Int -> SimpleDocStream ann -> ShowS
forall ann. Show ann => Int -> SimpleDocStream ann -> ShowS
forall ann. Show ann => [SimpleDocStream ann] -> ShowS
forall ann. Show ann => SimpleDocStream ann -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleDocStream ann] -> ShowS
$cshowList :: forall ann. Show ann => [SimpleDocStream ann] -> ShowS
show :: SimpleDocStream ann -> String
$cshow :: forall ann. Show ann => SimpleDocStream ann -> String
showsPrec :: Int -> SimpleDocStream ann -> ShowS
$cshowsPrec :: forall ann. Show ann => Int -> SimpleDocStream ann -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall ann x. Rep (SimpleDocStream ann) x -> SimpleDocStream ann
forall ann x. SimpleDocStream ann -> Rep (SimpleDocStream ann) x
$cto :: forall ann x. Rep (SimpleDocStream ann) x -> SimpleDocStream ann
$cfrom :: forall ann x. SimpleDocStream ann -> Rep (SimpleDocStream ann) x
Generic, Typeable)
removeTrailingWhitespace :: SimpleDocStream ann -> SimpleDocStream ann
removeTrailingWhitespace :: forall ann. SimpleDocStream ann -> SimpleDocStream ann
removeTrailingWhitespace = forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go ([Int] -> Int -> WhitespaceStrippingState
RecordedWhitespace [] Int
0)
where
commitWhitespace
:: [Int]
-> Int
-> SimpleDocStream ann
-> SimpleDocStream ann
commitWhitespace :: forall ann.
[Int] -> Int -> SimpleDocStream ann -> SimpleDocStream ann
commitWhitespace [Int]
is !Int
n SimpleDocStream ann
sds = case [Int]
is of
[] -> case Int
n of
Int
0 -> SimpleDocStream ann
sds
Int
1 -> forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
' ' SimpleDocStream ann
sds
Int
_ -> forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
n (Int -> Text
textSpaces Int
n) SimpleDocStream ann
sds
(Int
i:[Int]
is') -> let !end :: SimpleDocStream ann
end = forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine (Int
i forall a. Num a => a -> a -> a
+ Int
n) SimpleDocStream ann
sds
in forall ann. [Int] -> SimpleDocStream ann -> SimpleDocStream ann
prependEmptyLines [Int]
is' SimpleDocStream ann
end
prependEmptyLines :: [Int] -> SimpleDocStream ann -> SimpleDocStream ann
prependEmptyLines :: forall ann. [Int] -> SimpleDocStream ann -> SimpleDocStream ann
prependEmptyLines [Int]
is SimpleDocStream ann
sds0 = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\Int
_ SimpleDocStream ann
sds -> forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
0 SimpleDocStream ann
sds) SimpleDocStream ann
sds0 [Int]
is
go :: WhitespaceStrippingState -> SimpleDocStream ann -> SimpleDocStream ann
go :: forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go annLevel :: WhitespaceStrippingState
annLevel@(AnnotationLevel Int
annLvl) = \SimpleDocStream ann
sds -> case SimpleDocStream ann
sds of
SimpleDocStream ann
SFail -> forall ann. SimpleDocStream ann
SFail
SimpleDocStream ann
SEmpty -> forall ann. SimpleDocStream ann
SEmpty
SChar Char
c SimpleDocStream ann
rest -> forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go WhitespaceStrippingState
annLevel SimpleDocStream ann
rest)
SText Int
l Text
text SimpleDocStream ann
rest -> forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
l Text
text (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go WhitespaceStrippingState
annLevel SimpleDocStream ann
rest)
SLine Int
i SimpleDocStream ann
rest -> forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
i (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go WhitespaceStrippingState
annLevel SimpleDocStream ann
rest)
SAnnPush ann
ann SimpleDocStream ann
rest -> let !annLvl' :: Int
annLvl' = Int
annLvlforall a. Num a => a -> a -> a
+Int
1
in forall ann. ann -> SimpleDocStream ann -> SimpleDocStream ann
SAnnPush ann
ann (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go (Int -> WhitespaceStrippingState
AnnotationLevel Int
annLvl') SimpleDocStream ann
rest)
SAnnPop SimpleDocStream ann
rest
| Int
annLvl forall a. Ord a => a -> a -> Bool
> Int
1 -> let !annLvl' :: Int
annLvl' = Int
annLvlforall a. Num a => a -> a -> a
-Int
1
in forall ann. SimpleDocStream ann -> SimpleDocStream ann
SAnnPop (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go (Int -> WhitespaceStrippingState
AnnotationLevel Int
annLvl') SimpleDocStream ann
rest)
| Bool
otherwise -> forall ann. SimpleDocStream ann -> SimpleDocStream ann
SAnnPop (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go ([Int] -> Int -> WhitespaceStrippingState
RecordedWhitespace [] Int
0) SimpleDocStream ann
rest)
go (RecordedWhitespace [Int]
withheldLines Int
withheldSpaces) = \SimpleDocStream ann
sds -> case SimpleDocStream ann
sds of
SimpleDocStream ann
SFail -> forall ann. SimpleDocStream ann
SFail
SimpleDocStream ann
SEmpty -> forall ann. [Int] -> SimpleDocStream ann -> SimpleDocStream ann
prependEmptyLines [Int]
withheldLines forall ann. SimpleDocStream ann
SEmpty
SChar Char
c SimpleDocStream ann
rest
| Char
c forall a. Eq a => a -> a -> Bool
== Char
' ' -> forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go ([Int] -> Int -> WhitespaceStrippingState
RecordedWhitespace [Int]
withheldLines (Int
withheldSpacesforall a. Num a => a -> a -> a
+Int
1)) SimpleDocStream ann
rest
| Bool
otherwise -> forall ann.
[Int] -> Int -> SimpleDocStream ann -> SimpleDocStream ann
commitWhitespace
[Int]
withheldLines
Int
withheldSpaces
(forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go ([Int] -> Int -> WhitespaceStrippingState
RecordedWhitespace [] Int
0) SimpleDocStream ann
rest))
SText Int
textLength Text
text SimpleDocStream ann
rest ->
let stripped :: Text
stripped = (Char -> Bool) -> Text -> Text
T.dropWhileEnd (forall a. Eq a => a -> a -> Bool
== Char
' ') Text
text
strippedLength :: Int
strippedLength = Text -> Int
T.length Text
stripped
trailingLength :: Int
trailingLength = Int
textLength forall a. Num a => a -> a -> a
- Int
strippedLength
isOnlySpace :: Bool
isOnlySpace = Int
strippedLength forall a. Eq a => a -> a -> Bool
== Int
0
in if Bool
isOnlySpace
then forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go ([Int] -> Int -> WhitespaceStrippingState
RecordedWhitespace [Int]
withheldLines (Int
withheldSpaces forall a. Num a => a -> a -> a
+ Int
textLength)) SimpleDocStream ann
rest
else forall ann.
[Int] -> Int -> SimpleDocStream ann -> SimpleDocStream ann
commitWhitespace
[Int]
withheldLines
Int
withheldSpaces
(forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
strippedLength
Text
stripped
(forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go ([Int] -> Int -> WhitespaceStrippingState
RecordedWhitespace [] Int
trailingLength) SimpleDocStream ann
rest))
SLine Int
i SimpleDocStream ann
rest -> forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go ([Int] -> Int -> WhitespaceStrippingState
RecordedWhitespace (Int
iforall a. a -> [a] -> [a]
:[Int]
withheldLines) Int
0) SimpleDocStream ann
rest
SAnnPush ann
ann SimpleDocStream ann
rest -> forall ann.
[Int] -> Int -> SimpleDocStream ann -> SimpleDocStream ann
commitWhitespace
[Int]
withheldLines
Int
withheldSpaces
(forall ann. ann -> SimpleDocStream ann -> SimpleDocStream ann
SAnnPush ann
ann (forall ann.
WhitespaceStrippingState
-> SimpleDocStream ann -> SimpleDocStream ann
go (Int -> WhitespaceStrippingState
AnnotationLevel Int
1) SimpleDocStream ann
rest))
SAnnPop SimpleDocStream ann
_ -> forall a. HasCallStack => String -> a
error String
"Tried skipping spaces in unannotated data! Please report this as a bug in 'prettyprinter'."
data WhitespaceStrippingState
= AnnotationLevel !Int
| RecordedWhitespace [Int] !Int
deriving Typeable
instance Functor SimpleDocStream where
fmap :: forall ann ann'.
(ann -> ann') -> SimpleDocStream ann -> SimpleDocStream ann'
fmap = forall ann ann'.
(ann -> ann') -> SimpleDocStream ann -> SimpleDocStream ann'
reAnnotateS
instance Foldable SimpleDocStream where
foldMap :: forall m a. Monoid m => (a -> m) -> SimpleDocStream a -> m
foldMap a -> m
f = SimpleDocStream a -> m
go
where
go :: SimpleDocStream a -> m
go = \SimpleDocStream a
sds -> case SimpleDocStream a
sds of
SimpleDocStream a
SFail -> forall a. Monoid a => a
mempty
SimpleDocStream a
SEmpty -> forall a. Monoid a => a
mempty
SChar Char
_ SimpleDocStream a
rest -> SimpleDocStream a -> m
go SimpleDocStream a
rest
SText Int
_ Text
_ SimpleDocStream a
rest -> SimpleDocStream a -> m
go SimpleDocStream a
rest
SLine Int
_ SimpleDocStream a
rest -> SimpleDocStream a -> m
go SimpleDocStream a
rest
SAnnPush a
ann SimpleDocStream a
rest -> a -> m
f a
ann forall a. Monoid a => a -> a -> a
`mappend` SimpleDocStream a -> m
go SimpleDocStream a
rest
SAnnPop SimpleDocStream a
rest -> SimpleDocStream a -> m
go SimpleDocStream a
rest
instance Traversable SimpleDocStream where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> SimpleDocStream a -> f (SimpleDocStream b)
traverse a -> f b
f = SimpleDocStream a -> f (SimpleDocStream b)
go
where
go :: SimpleDocStream a -> f (SimpleDocStream b)
go = \SimpleDocStream a
sds -> case SimpleDocStream a
sds of
SimpleDocStream a
SFail -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall ann. SimpleDocStream ann
SFail
SimpleDocStream a
SEmpty -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall ann. SimpleDocStream ann
SEmpty
SChar Char
c SimpleDocStream a
rest -> forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleDocStream a -> f (SimpleDocStream b)
go SimpleDocStream a
rest
SText Int
l Text
t SimpleDocStream a
rest -> forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
l Text
t forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleDocStream a -> f (SimpleDocStream b)
go SimpleDocStream a
rest
SLine Int
i SimpleDocStream a
rest -> forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
i forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleDocStream a -> f (SimpleDocStream b)
go SimpleDocStream a
rest
SAnnPush a
ann SimpleDocStream a
rest -> forall ann. ann -> SimpleDocStream ann -> SimpleDocStream ann
SAnnPush forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
ann forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SimpleDocStream a -> f (SimpleDocStream b)
go SimpleDocStream a
rest
SAnnPop SimpleDocStream a
rest -> forall ann. SimpleDocStream ann -> SimpleDocStream ann
SAnnPop forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SimpleDocStream a -> f (SimpleDocStream b)
go SimpleDocStream a
rest
newtype FittingPredicate ann
= FittingPredicate (Int
-> Int
-> Maybe Int
-> SimpleDocStream ann
-> Bool)
deriving Typeable
data LayoutPipeline ann =
Nil
| Cons !Int (Doc ann) (LayoutPipeline ann)
| UndoAnn (LayoutPipeline ann)
deriving Typeable
data PageWidth
= AvailablePerLine !Int !Double
| Unbounded
deriving (PageWidth -> PageWidth -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PageWidth -> PageWidth -> Bool
$c/= :: PageWidth -> PageWidth -> Bool
== :: PageWidth -> PageWidth -> Bool
$c== :: PageWidth -> PageWidth -> Bool
Eq, Eq PageWidth
PageWidth -> PageWidth -> Bool
PageWidth -> PageWidth -> Ordering
PageWidth -> PageWidth -> PageWidth
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
min :: PageWidth -> PageWidth -> PageWidth
$cmin :: PageWidth -> PageWidth -> PageWidth
max :: PageWidth -> PageWidth -> PageWidth
$cmax :: PageWidth -> PageWidth -> PageWidth
>= :: PageWidth -> PageWidth -> Bool
$c>= :: PageWidth -> PageWidth -> Bool
> :: PageWidth -> PageWidth -> Bool
$c> :: PageWidth -> PageWidth -> Bool
<= :: PageWidth -> PageWidth -> Bool
$c<= :: PageWidth -> PageWidth -> Bool
< :: PageWidth -> PageWidth -> Bool
$c< :: PageWidth -> PageWidth -> Bool
compare :: PageWidth -> PageWidth -> Ordering
$ccompare :: PageWidth -> PageWidth -> Ordering
Ord, Int -> PageWidth -> ShowS
[PageWidth] -> ShowS
PageWidth -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PageWidth] -> ShowS
$cshowList :: [PageWidth] -> ShowS
show :: PageWidth -> String
$cshow :: PageWidth -> String
showsPrec :: Int -> PageWidth -> ShowS
$cshowsPrec :: Int -> PageWidth -> ShowS
Show, Typeable)
defaultPageWidth :: PageWidth
defaultPageWidth :: PageWidth
defaultPageWidth = Int -> Double -> PageWidth
AvailablePerLine Int
80 Double
1
remainingWidth :: Int -> Double -> Int -> Int -> Int
remainingWidth :: Int -> Double -> Int -> Int -> Int
remainingWidth Int
lineLength Double
ribbonFraction Int
lineIndent Int
currentColumn =
forall a. Ord a => a -> a -> a
min Int
columnsLeftInLine Int
columnsLeftInRibbon
where
columnsLeftInLine :: Int
columnsLeftInLine = Int
lineLength forall a. Num a => a -> a -> a
- Int
currentColumn
columnsLeftInRibbon :: Int
columnsLeftInRibbon = Int
lineIndent forall a. Num a => a -> a -> a
+ Int
ribbonWidth forall a. Num a => a -> a -> a
- Int
currentColumn
ribbonWidth :: Int
ribbonWidth =
(forall a. Ord a => a -> a -> a
max Int
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => a -> a -> a
min Int
lineLength forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (RealFrac a, Integral b) => a -> b
floor)
(forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
lineLength forall a. Num a => a -> a -> a
* Double
ribbonFraction)
newtype LayoutOptions = LayoutOptions { LayoutOptions -> PageWidth
layoutPageWidth :: PageWidth }
deriving (LayoutOptions -> LayoutOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LayoutOptions -> LayoutOptions -> Bool
$c/= :: LayoutOptions -> LayoutOptions -> Bool
== :: LayoutOptions -> LayoutOptions -> Bool
$c== :: LayoutOptions -> LayoutOptions -> Bool
Eq, Eq LayoutOptions
LayoutOptions -> LayoutOptions -> Bool
LayoutOptions -> LayoutOptions -> Ordering
LayoutOptions -> LayoutOptions -> LayoutOptions
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
min :: LayoutOptions -> LayoutOptions -> LayoutOptions
$cmin :: LayoutOptions -> LayoutOptions -> LayoutOptions
max :: LayoutOptions -> LayoutOptions -> LayoutOptions
$cmax :: LayoutOptions -> LayoutOptions -> LayoutOptions
>= :: LayoutOptions -> LayoutOptions -> Bool
$c>= :: LayoutOptions -> LayoutOptions -> Bool
> :: LayoutOptions -> LayoutOptions -> Bool
$c> :: LayoutOptions -> LayoutOptions -> Bool
<= :: LayoutOptions -> LayoutOptions -> Bool
$c<= :: LayoutOptions -> LayoutOptions -> Bool
< :: LayoutOptions -> LayoutOptions -> Bool
$c< :: LayoutOptions -> LayoutOptions -> Bool
compare :: LayoutOptions -> LayoutOptions -> Ordering
$ccompare :: LayoutOptions -> LayoutOptions -> Ordering
Ord, Int -> LayoutOptions -> ShowS
[LayoutOptions] -> ShowS
LayoutOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LayoutOptions] -> ShowS
$cshowList :: [LayoutOptions] -> ShowS
show :: LayoutOptions -> String
$cshow :: LayoutOptions -> String
showsPrec :: Int -> LayoutOptions -> ShowS
$cshowsPrec :: Int -> LayoutOptions -> ShowS
Show, Typeable)
defaultLayoutOptions :: LayoutOptions
defaultLayoutOptions :: LayoutOptions
defaultLayoutOptions = LayoutOptions { layoutPageWidth :: PageWidth
layoutPageWidth = PageWidth
defaultPageWidth }
layoutPretty
:: LayoutOptions
-> Doc ann
-> SimpleDocStream ann
layoutPretty :: forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutPretty (LayoutOptions pageWidth_ :: PageWidth
pageWidth_@(AvailablePerLine Int
lineLength Double
ribbonFraction)) =
forall ann.
FittingPredicate ann -> PageWidth -> Doc ann -> SimpleDocStream ann
layoutWadlerLeijen
(forall ann.
(Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool)
-> FittingPredicate ann
FittingPredicate
(\Int
lineIndent Int
currentColumn Maybe Int
_initialIndentY SimpleDocStream ann
sdoc ->
forall ann. Int -> SimpleDocStream ann -> Bool
fits
(Int -> Double -> Int -> Int -> Int
remainingWidth Int
lineLength Double
ribbonFraction Int
lineIndent Int
currentColumn)
SimpleDocStream ann
sdoc))
PageWidth
pageWidth_
where
fits :: Int
-> SimpleDocStream ann
-> Bool
fits :: forall ann. Int -> SimpleDocStream ann -> Bool
fits Int
w SimpleDocStream ann
_ | Int
w forall a. Ord a => a -> a -> Bool
< Int
0 = Bool
False
fits Int
_ SimpleDocStream ann
SFail = Bool
False
fits Int
_ SimpleDocStream ann
SEmpty = Bool
True
fits Int
w (SChar Char
_ SimpleDocStream ann
x) = forall ann. Int -> SimpleDocStream ann -> Bool
fits (Int
w forall a. Num a => a -> a -> a
- Int
1) SimpleDocStream ann
x
fits Int
w (SText Int
l Text
_t SimpleDocStream ann
x) = forall ann. Int -> SimpleDocStream ann -> Bool
fits (Int
w forall a. Num a => a -> a -> a
- Int
l) SimpleDocStream ann
x
fits Int
_ SLine{} = Bool
True
fits Int
w (SAnnPush ann
_ SimpleDocStream ann
x) = forall ann. Int -> SimpleDocStream ann -> Bool
fits Int
w SimpleDocStream ann
x
fits Int
w (SAnnPop SimpleDocStream ann
x) = forall ann. Int -> SimpleDocStream ann -> Bool
fits Int
w SimpleDocStream ann
x
layoutPretty (LayoutOptions PageWidth
Unbounded) = forall ann. Doc ann -> SimpleDocStream ann
layoutUnbounded
layoutSmart
:: LayoutOptions
-> Doc ann
-> SimpleDocStream ann
layoutSmart :: forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutSmart (LayoutOptions pageWidth_ :: PageWidth
pageWidth_@(AvailablePerLine Int
lineLength Double
ribbonFraction)) =
forall ann.
FittingPredicate ann -> PageWidth -> Doc ann -> SimpleDocStream ann
layoutWadlerLeijen (forall ann.
(Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool)
-> FittingPredicate ann
FittingPredicate forall ann. Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool
fits) PageWidth
pageWidth_
where
fits :: Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool
fits :: forall ann. Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool
fits Int
lineIndent Int
currentColumn Maybe Int
initialIndentY = forall ann. Int -> SimpleDocStream ann -> Bool
go Int
availableWidth
where
go :: Int -> SimpleDocStream ann -> Bool
go Int
w SimpleDocStream ann
_ | Int
w forall a. Ord a => a -> a -> Bool
< Int
0 = Bool
False
go Int
_ SimpleDocStream ann
SFail = Bool
False
go Int
_ SimpleDocStream ann
SEmpty = Bool
True
go Int
w (SChar Char
_ SimpleDocStream ann
x) = Int -> SimpleDocStream ann -> Bool
go (Int
w forall a. Num a => a -> a -> a
- Int
1) SimpleDocStream ann
x
go Int
w (SText Int
l Text
_t SimpleDocStream ann
x) = Int -> SimpleDocStream ann -> Bool
go (Int
w forall a. Num a => a -> a -> a
- Int
l) SimpleDocStream ann
x
go Int
_ (SLine Int
i SimpleDocStream ann
x)
| Int
minNestingLevel forall a. Ord a => a -> a -> Bool
< Int
i = Int -> SimpleDocStream ann -> Bool
go (Int
lineLength forall a. Num a => a -> a -> a
- Int
i) SimpleDocStream ann
x
| Bool
otherwise = Bool
True
go Int
w (SAnnPush ann
_ SimpleDocStream ann
x) = Int -> SimpleDocStream ann -> Bool
go Int
w SimpleDocStream ann
x
go Int
w (SAnnPop SimpleDocStream ann
x) = Int -> SimpleDocStream ann -> Bool
go Int
w SimpleDocStream ann
x
availableWidth :: Int
availableWidth = Int -> Double -> Int -> Int -> Int
remainingWidth Int
lineLength Double
ribbonFraction Int
lineIndent Int
currentColumn
minNestingLevel :: Int
minNestingLevel =
case Maybe Int
initialIndentY of
Just Int
i ->
forall a. Ord a => a -> a -> a
min Int
i Int
currentColumn
Maybe Int
Nothing ->
Int
currentColumn
layoutSmart (LayoutOptions PageWidth
Unbounded) = forall ann. Doc ann -> SimpleDocStream ann
layoutUnbounded
layoutUnbounded :: Doc ann -> SimpleDocStream ann
layoutUnbounded :: forall ann. Doc ann -> SimpleDocStream ann
layoutUnbounded =
forall ann.
FittingPredicate ann -> PageWidth -> Doc ann -> SimpleDocStream ann
layoutWadlerLeijen
(forall ann.
(Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool)
-> FittingPredicate ann
FittingPredicate
(\Int
_lineIndent Int
_currentColumn Maybe Int
_initialIndentY SimpleDocStream ann
sdoc -> Bool -> Bool
not (forall a. SimpleDocStream a -> Bool
failsOnFirstLine SimpleDocStream ann
sdoc)))
PageWidth
Unbounded
where
failsOnFirstLine :: SimpleDocStream ann -> Bool
failsOnFirstLine :: forall a. SimpleDocStream a -> Bool
failsOnFirstLine = forall a. SimpleDocStream a -> Bool
go
where
go :: SimpleDocStream ann -> Bool
go SimpleDocStream ann
sds = case SimpleDocStream ann
sds of
SimpleDocStream ann
SFail -> Bool
True
SimpleDocStream ann
SEmpty -> Bool
False
SChar Char
_ SimpleDocStream ann
s -> SimpleDocStream ann -> Bool
go SimpleDocStream ann
s
SText Int
_ Text
_ SimpleDocStream ann
s -> SimpleDocStream ann -> Bool
go SimpleDocStream ann
s
SLine Int
_ SimpleDocStream ann
_ -> Bool
False
SAnnPush ann
_ SimpleDocStream ann
s -> SimpleDocStream ann -> Bool
go SimpleDocStream ann
s
SAnnPop SimpleDocStream ann
s -> SimpleDocStream ann -> Bool
go SimpleDocStream ann
s
layoutWadlerLeijen
:: forall ann. FittingPredicate ann
-> PageWidth
-> Doc ann
-> SimpleDocStream ann
layoutWadlerLeijen :: forall ann.
FittingPredicate ann -> PageWidth -> Doc ann -> SimpleDocStream ann
layoutWadlerLeijen
(FittingPredicate Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool
fits)
PageWidth
pageWidth_
Doc ann
doc
= Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
0 Int
0 (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
0 Doc ann
doc forall ann. LayoutPipeline ann
Nil)
where
best
:: Int
-> Int
-> LayoutPipeline ann
-> SimpleDocStream ann
best :: Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best !Int
_ !Int
_ LayoutPipeline ann
Nil = forall ann. SimpleDocStream ann
SEmpty
best Int
nl Int
cc (UndoAnn LayoutPipeline ann
ds) = forall ann. SimpleDocStream ann -> SimpleDocStream ann
SAnnPop (Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc LayoutPipeline ann
ds)
best Int
nl Int
cc (Cons Int
i Doc ann
d LayoutPipeline ann
ds) = case Doc ann
d of
Doc ann
Fail -> forall ann. SimpleDocStream ann
SFail
Doc ann
Empty -> Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc LayoutPipeline ann
ds
Char Char
c -> let !cc' :: Int
cc' = Int
ccforall a. Num a => a -> a -> a
+Int
1 in forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c (Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc' LayoutPipeline ann
ds)
Text Int
l Text
t -> let !cc' :: Int
cc' = Int
ccforall a. Num a => a -> a -> a
+Int
l in forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
l Text
t (Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc' LayoutPipeline ann
ds)
Doc ann
Line -> let x :: SimpleDocStream ann
x = Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
i Int
i LayoutPipeline ann
ds
i' :: Int
i' = case SimpleDocStream ann
x of
SimpleDocStream ann
SEmpty -> Int
0
SLine{} -> Int
0
SimpleDocStream ann
_ -> Int
i
in forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
i' SimpleDocStream ann
x
FlatAlt Doc ann
x Doc ann
_ -> Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i Doc ann
x LayoutPipeline ann
ds)
Cat Doc ann
x Doc ann
y -> Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i Doc ann
x (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i Doc ann
y LayoutPipeline ann
ds))
Nest Int
j Doc ann
x -> let !ij :: Int
ij = Int
iforall a. Num a => a -> a -> a
+Int
j in Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
ij Doc ann
x LayoutPipeline ann
ds)
Union Doc ann
x Doc ann
y -> let x' :: SimpleDocStream ann
x' = Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i Doc ann
x LayoutPipeline ann
ds)
y' :: SimpleDocStream ann
y' = Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i Doc ann
y LayoutPipeline ann
ds)
in Int
-> Int
-> SimpleDocStream ann
-> SimpleDocStream ann
-> SimpleDocStream ann
selectNicer Int
nl Int
cc SimpleDocStream ann
x' SimpleDocStream ann
y'
Column Int -> Doc ann
f -> Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i (Int -> Doc ann
f Int
cc) LayoutPipeline ann
ds)
WithPageWidth PageWidth -> Doc ann
f -> Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i (PageWidth -> Doc ann
f PageWidth
pageWidth_) LayoutPipeline ann
ds)
Nesting Int -> Doc ann
f -> Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i (Int -> Doc ann
f Int
i) LayoutPipeline ann
ds)
Annotated ann
ann Doc ann
x -> forall ann. ann -> SimpleDocStream ann -> SimpleDocStream ann
SAnnPush ann
ann (Int -> Int -> LayoutPipeline ann -> SimpleDocStream ann
best Int
nl Int
cc (forall ann.
Int -> Doc ann -> LayoutPipeline ann -> LayoutPipeline ann
Cons Int
i Doc ann
x (forall ann. LayoutPipeline ann -> LayoutPipeline ann
UndoAnn LayoutPipeline ann
ds)))
selectNicer
:: Int
-> Int
-> SimpleDocStream ann
-> SimpleDocStream ann
-> SimpleDocStream ann
selectNicer :: Int
-> Int
-> SimpleDocStream ann
-> SimpleDocStream ann
-> SimpleDocStream ann
selectNicer Int
lineIndent Int
currentColumn SimpleDocStream ann
x SimpleDocStream ann
y
| Int -> Int -> Maybe Int -> SimpleDocStream ann -> Bool
fits Int
lineIndent Int
currentColumn (SimpleDocStream ann -> Maybe Int
initialIndentation SimpleDocStream ann
y) SimpleDocStream ann
x = SimpleDocStream ann
x
| Bool
otherwise = SimpleDocStream ann
y
initialIndentation :: SimpleDocStream ann -> Maybe Int
initialIndentation :: SimpleDocStream ann -> Maybe Int
initialIndentation SimpleDocStream ann
sds = case SimpleDocStream ann
sds of
SLine Int
i SimpleDocStream ann
_ -> forall a. a -> Maybe a
Just Int
i
SAnnPush ann
_ SimpleDocStream ann
s -> SimpleDocStream ann -> Maybe Int
initialIndentation SimpleDocStream ann
s
SAnnPop SimpleDocStream ann
s -> SimpleDocStream ann -> Maybe Int
initialIndentation SimpleDocStream ann
s
SimpleDocStream ann
_ -> forall a. Maybe a
Nothing
layoutCompact :: Doc ann1 -> SimpleDocStream ann2
layoutCompact :: forall ann1 ann2. Doc ann1 -> SimpleDocStream ann2
layoutCompact Doc ann1
doc = forall {ann} {ann}. Int -> [Doc ann] -> SimpleDocStream ann
scan Int
0 [Doc ann1
doc]
where
scan :: Int -> [Doc ann] -> SimpleDocStream ann
scan Int
_ [] = forall ann. SimpleDocStream ann
SEmpty
scan !Int
col (Doc ann
d:[Doc ann]
ds) = case Doc ann
d of
Doc ann
Fail -> forall ann. SimpleDocStream ann
SFail
Doc ann
Empty -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col [Doc ann]
ds
Char Char
c -> forall ann. Char -> SimpleDocStream ann -> SimpleDocStream ann
SChar Char
c (Int -> [Doc ann] -> SimpleDocStream ann
scan (Int
colforall a. Num a => a -> a -> a
+Int
1) [Doc ann]
ds)
Text Int
l Text
t -> let !col' :: Int
col' = Int
colforall a. Num a => a -> a -> a
+Int
l in forall ann.
Int -> Text -> SimpleDocStream ann -> SimpleDocStream ann
SText Int
l Text
t (Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col' [Doc ann]
ds)
FlatAlt Doc ann
x Doc ann
_ -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (Doc ann
xforall a. a -> [a] -> [a]
:[Doc ann]
ds)
Doc ann
Line -> forall ann. Int -> SimpleDocStream ann -> SimpleDocStream ann
SLine Int
0 (Int -> [Doc ann] -> SimpleDocStream ann
scan Int
0 [Doc ann]
ds)
Cat Doc ann
x Doc ann
y -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (Doc ann
xforall a. a -> [a] -> [a]
:Doc ann
yforall a. a -> [a] -> [a]
:[Doc ann]
ds)
Nest Int
_ Doc ann
x -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (Doc ann
xforall a. a -> [a] -> [a]
:[Doc ann]
ds)
Union Doc ann
_ Doc ann
y -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (Doc ann
yforall a. a -> [a] -> [a]
:[Doc ann]
ds)
Column Int -> Doc ann
f -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (Int -> Doc ann
f Int
colforall a. a -> [a] -> [a]
:[Doc ann]
ds)
WithPageWidth PageWidth -> Doc ann
f -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (PageWidth -> Doc ann
f PageWidth
Unbounded forall a. a -> [a] -> [a]
: [Doc ann]
ds)
Nesting Int -> Doc ann
f -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (Int -> Doc ann
f Int
0 forall a. a -> [a] -> [a]
: [Doc ann]
ds)
Annotated ann
_ Doc ann
x -> Int -> [Doc ann] -> SimpleDocStream ann
scan Int
col (Doc ann
xforall a. a -> [a] -> [a]
:[Doc ann]
ds)
instance Show (Doc ann) where
showsPrec :: Int -> Doc ann -> ShowS
showsPrec Int
_ Doc ann
doc = forall ann. SimpleDocStream ann -> ShowS
renderShowS (forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutPretty LayoutOptions
defaultLayoutOptions Doc ann
doc)
renderShowS :: SimpleDocStream ann -> ShowS
renderShowS :: forall ann. SimpleDocStream ann -> ShowS
renderShowS = \SimpleDocStream ann
sds -> case SimpleDocStream ann
sds of
SimpleDocStream ann
SFail -> forall void. void
panicUncaughtFail
SimpleDocStream ann
SEmpty -> forall a. a -> a
id
SChar Char
c SimpleDocStream ann
x -> Char -> ShowS
showChar Char
c forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. SimpleDocStream ann -> ShowS
renderShowS SimpleDocStream ann
x
SText Int
_l Text
t SimpleDocStream ann
x -> String -> ShowS
showString (Text -> String
T.unpack Text
t) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. SimpleDocStream ann -> ShowS
renderShowS SimpleDocStream ann
x
SLine Int
i SimpleDocStream ann
x -> String -> ShowS
showString (Char
'\n' forall a. a -> [a] -> [a]
: forall a. Int -> a -> [a]
replicate Int
i Char
' ') forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. SimpleDocStream ann -> ShowS
renderShowS SimpleDocStream ann
x
SAnnPush ann
_ SimpleDocStream ann
x -> forall ann. SimpleDocStream ann -> ShowS
renderShowS SimpleDocStream ann
x
SAnnPop SimpleDocStream ann
x -> forall ann. SimpleDocStream ann -> ShowS
renderShowS SimpleDocStream ann
x
textSpaces :: Int -> Text
textSpaces :: Int -> Text
textSpaces Int
n = Int -> Text -> Text
T.replicate Int
n (Char -> Text
T.singleton Char
' ')