{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
module Text.PrettyPrint.Mainland (
Doc,
text, bool, char, string, int, integer, float, double, rational,
strictText, lazyText,
star, colon, comma, dot, equals, semi, space, spaces,
backquote, squote, dquote,
langle, rangle, lbrace, rbrace, lbracket, rbracket, lparen, rparen,
empty,
srcloc, line, softline, softbreak,
(<|>), (<+>), (</>), (<+/>), (<//>),
group, flatten,
enclose, squotes, dquotes, angles, backquotes, braces, brackets, parens,
parensIf,
folddoc, spread, stack, cat, sep,
punctuate, commasep, semisep,
enclosesep, tuple, list,
align, hang, indent,
nest, column, nesting,
width, fill, fillbreak,
faildoc, errordoc,
RDoc(..),
render, renderCompact,
displayS, prettyS, pretty, prettyCompactS, prettyCompact,
displayPragmaS, prettyPragmaS, prettyPragma,
displayLazyText, prettyLazyText,
displayPragmaLazyText, prettyPragmaLazyText,
putDoc, putDocLn, hPutDoc, hPutDocLn
) where
import Data.Loc (L(..),
Loc(..),
Located(..),
Pos(..),
posFile,
posLine)
import qualified Data.Map as Map
#if !(MIN_VERSION_base(4,9,0))
import Data.Monoid (Monoid(..), (<>))
#endif /* !(MIN_VERSION_base(4,9,0)) */
#if MIN_VERSION_base(4,9,0) && !(MIN_VERSION_base(4,11,0))
import Data.Semigroup (Semigroup(..))
#endif
import qualified Data.Set as Set
import Data.String (IsString(..))
import qualified Data.Text as T
import qualified Data.Text.Lazy.IO as TIO
import qualified Data.Text.Lazy as L
import qualified Data.Text.Lazy.Builder as B
import System.IO (Handle)
data Doc
= Empty
| Char {-# UNPACK #-} !Char
| String {-# UNPACK #-} !Int String
| Text T.Text
| LazyText L.Text
| Line
| Nest {-# UNPACK #-} !Int Doc
| SrcLoc Loc
| Doc `Cat` Doc
| Doc `Alt` Doc
| Column (Int -> Doc)
| Nesting (Int -> Doc)
#if MIN_VERSION_base(4,9,0)
instance Semigroup Doc where
<> :: Doc -> Doc -> Doc
(<>) = Doc -> Doc -> Doc
Cat
#endif
instance Monoid Doc where
mempty :: Doc
mempty = Doc
empty
#if !(MIN_VERSION_base(4,11,0))
mappend = Cat
#endif
instance IsString Doc where
fromString :: String -> Doc
fromString String
s = String -> Doc
string String
s
text :: String -> Doc
text :: String -> Doc
text String
s = Int -> String -> Doc
String (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s) String
s
bool :: Bool -> Doc
bool :: Bool -> Doc
bool Bool
b = String -> Doc
text (Bool -> String
forall a. Show a => a -> String
show Bool
b)
char :: Char -> Doc
char :: Char -> Doc
char Char
'\n' = Doc
line
char Char
c = Char -> Doc
Char Char
c
string :: String -> Doc
string :: String -> Doc
string String
"" = Doc
empty
string (Char
'\n' : String
s) = Doc
line Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
string String
s
string String
s = case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n') String
s of
(String
xs, String
ys) -> String -> Doc
text String
xs Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
string String
ys
int :: Int -> Doc
int :: Int -> Doc
int Int
i = String -> Doc
text (Int -> String
forall a. Show a => a -> String
show Int
i)
integer :: Integer -> Doc
integer :: Integer -> Doc
integer Integer
i = String -> Doc
text (Integer -> String
forall a. Show a => a -> String
show Integer
i)
float :: Float -> Doc
float :: Float -> Doc
float Float
f = String -> Doc
text (Float -> String
forall a. Show a => a -> String
show Float
f)
double :: Double -> Doc
double :: Double -> Doc
double Double
d = String -> Doc
text (Double -> String
forall a. Show a => a -> String
show Double
d)
rational :: Rational -> Doc
rational :: Rational -> Doc
rational Rational
r = String -> Doc
text (Rational -> String
forall a. Show a => a -> String
show Rational
r)
strictText :: T.Text -> Doc
strictText :: Text -> Doc
strictText = Text -> Doc
Text
lazyText :: L.Text -> Doc
lazyText :: Text -> Doc
lazyText = Text -> Doc
LazyText
star :: Doc
star :: Doc
star = Char -> Doc
char Char
'*'
colon :: Doc
colon :: Doc
colon = Char -> Doc
char Char
':'
comma :: Doc
comma :: Doc
comma = Char -> Doc
char Char
','
dot :: Doc
dot :: Doc
dot = Char -> Doc
char Char
'.'
equals :: Doc
equals :: Doc
equals = Char -> Doc
char Char
'='
semi :: Doc
semi :: Doc
semi = Char -> Doc
char Char
';'
space :: Doc
space :: Doc
space = Char -> Doc
char Char
' '
spaces :: Int -> Doc
spaces :: Int -> Doc
spaces Int
n = String -> Doc
text (Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
n Char
' ')
backquote :: Doc
backquote :: Doc
backquote = Char -> Doc
char Char
'`'
squote :: Doc
squote :: Doc
squote = Char -> Doc
char Char
'\''
dquote :: Doc
dquote :: Doc
dquote = Char -> Doc
char Char
'"'
langle :: Doc
langle :: Doc
langle = Char -> Doc
char Char
'<'
rangle :: Doc
rangle :: Doc
rangle = Char -> Doc
char Char
'>'
lbrace :: Doc
lbrace :: Doc
lbrace = Char -> Doc
char Char
'{'
rbrace :: Doc
rbrace :: Doc
rbrace = Char -> Doc
char Char
'}'
lbracket :: Doc
lbracket :: Doc
lbracket = Char -> Doc
char Char
'['
rbracket :: Doc
rbracket :: Doc
rbracket = Char -> Doc
char Char
']'
lparen :: Doc
lparen :: Doc
lparen = Char -> Doc
char Char
'('
rparen :: Doc
rparen :: Doc
rparen = Char -> Doc
char Char
')'
empty :: Doc
empty :: Doc
empty = Doc
Empty
srcloc :: Located a => a -> Doc
srcloc :: a -> Doc
srcloc a
x = Loc -> Doc
SrcLoc (a -> Loc
forall a. Located a => a -> Loc
locOf a
x)
line :: Doc
line :: Doc
line = Doc
Line
softline :: Doc
softline :: Doc
softline = Doc
space Doc -> Doc -> Doc
`Alt` Doc
line
softbreak :: Doc
softbreak :: Doc
softbreak = Doc
empty Doc -> Doc -> Doc
`Alt` Doc
line
#if !MIN_VERSION_base(4,5,0)
infixr 6 <>
#endif /* !MIN_VERSION_base(4,5,0) */
infixr 6 <+>
infixr 5 </>, <+/>, <//>
infixl 3 <|>
#if !MIN_VERSION_base(4,5,0)
(<>) :: Doc -> Doc -> Doc
x <> y = x `Cat` y
#endif /* !MIN_VERSION_base(4,5,0) */
(<+>) :: Doc -> Doc -> Doc
Doc
Empty <+> :: Doc -> Doc -> Doc
<+> Doc
y = Doc
y
Doc
x <+> Doc
Empty = Doc
x
Doc
x <+> Doc
y = Doc
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
space Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
y
(</>) :: Doc -> Doc -> Doc
Doc
Empty </> :: Doc -> Doc -> Doc
</> Doc
y = Doc
y
Doc
x </> Doc
Empty = Doc
x
Doc
x </> Doc
y = Doc
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
line Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
y
(<+/>) :: Doc -> Doc -> Doc
Doc
Empty <+/> :: Doc -> Doc -> Doc
<+/> Doc
y = Doc
y
Doc
x <+/> Doc
Empty = Doc
x
Doc
x <+/> Doc
y = Doc
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
softline Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
y
(<//>) :: Doc -> Doc -> Doc
Doc
x <//> :: Doc -> Doc -> Doc
<//> Doc
y = Doc
x Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
softbreak Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
y
(<|>) :: Doc -> Doc -> Doc
Doc
x <|> :: Doc -> Doc -> Doc
<|> Doc
y = Doc
x Doc -> Doc -> Doc
`Alt` Doc
y
group :: Doc -> Doc
group :: Doc -> Doc
group Doc
Empty = Doc
Empty
group Doc
d = Doc -> Doc
flatten Doc
d Doc -> Doc -> Doc
`Alt` Doc
d
flatten :: Doc -> Doc
flatten :: Doc -> Doc
flatten Doc
Empty = Doc
Empty
flatten (Char Char
c) = Char -> Doc
Char Char
c
flatten (String Int
l String
s) = Int -> String -> Doc
String Int
l String
s
flatten (Text Text
s) = Text -> Doc
Text Text
s
flatten (LazyText Text
s) = Text -> Doc
LazyText Text
s
flatten Doc
Line = Char -> Doc
Char Char
' '
flatten (Doc
x `Cat` Doc
y) = Doc -> Doc
flatten Doc
x Doc -> Doc -> Doc
`Cat` Doc -> Doc
flatten Doc
y
flatten (Nest Int
i Doc
x) = Int -> Doc -> Doc
Nest Int
i (Doc -> Doc
flatten Doc
x)
flatten (Doc
x `Alt` Doc
_) = Doc -> Doc
flatten Doc
x
flatten (SrcLoc Loc
loc) = Loc -> Doc
SrcLoc Loc
loc
flatten (Column Int -> Doc
f) = (Int -> Doc) -> Doc
Column (Doc -> Doc
flatten (Doc -> Doc) -> (Int -> Doc) -> Int -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc
f)
flatten (Nesting Int -> Doc
f) = (Int -> Doc) -> Doc
Nesting (Doc -> Doc
flatten (Doc -> Doc) -> (Int -> Doc) -> Int -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc
f)
enclose :: Doc -> Doc -> Doc -> Doc
enclose :: Doc -> Doc -> Doc -> Doc
enclose Doc
left Doc
right Doc
d = Doc
left Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
d Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
right
squotes :: Doc -> Doc
squotes :: Doc -> Doc
squotes = Doc -> Doc -> Doc -> Doc
enclose Doc
squote Doc
squote (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
align
dquotes :: Doc -> Doc
dquotes :: Doc -> Doc
dquotes = Doc -> Doc -> Doc -> Doc
enclose Doc
dquote Doc
dquote (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
align
angles :: Doc -> Doc
angles :: Doc -> Doc
angles = Doc -> Doc -> Doc -> Doc
enclose Doc
langle Doc
rangle (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
align
backquotes :: Doc -> Doc
backquotes :: Doc -> Doc
backquotes = Doc -> Doc -> Doc -> Doc
enclose Doc
backquote Doc
backquote (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
align
braces :: Doc -> Doc
braces :: Doc -> Doc
braces = Doc -> Doc -> Doc -> Doc
enclose Doc
lbrace Doc
rbrace (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
align
brackets :: Doc -> Doc
brackets :: Doc -> Doc
brackets = Doc -> Doc -> Doc -> Doc
enclose Doc
lbracket Doc
rbracket (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
align
parens :: Doc -> Doc
parens :: Doc -> Doc
parens = Doc -> Doc -> Doc -> Doc
enclose Doc
lparen Doc
rparen (Doc -> Doc) -> (Doc -> Doc) -> Doc -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc
align
parensIf :: Bool -> Doc -> Doc
parensIf :: Bool -> Doc -> Doc
parensIf Bool
True Doc
doc = Doc -> Doc
parens Doc
doc
parensIf Bool
False Doc
doc = Doc
doc
folddoc :: (Doc -> Doc -> Doc) -> [Doc] -> Doc
folddoc :: (Doc -> Doc -> Doc) -> [Doc] -> Doc
folddoc Doc -> Doc -> Doc
_ [] = Doc
empty
folddoc Doc -> Doc -> Doc
_ [Doc
x] = Doc
x
folddoc Doc -> Doc -> Doc
f (Doc
x:[Doc]
xs) = Doc -> Doc -> Doc
f Doc
x ((Doc -> Doc -> Doc) -> [Doc] -> Doc
folddoc Doc -> Doc -> Doc
f [Doc]
xs)
spread :: [Doc] -> Doc
spread :: [Doc] -> Doc
spread = (Doc -> Doc -> Doc) -> [Doc] -> Doc
folddoc Doc -> Doc -> Doc
(<+>)
stack :: [Doc] -> Doc
stack :: [Doc] -> Doc
stack = (Doc -> Doc -> Doc) -> [Doc] -> Doc
folddoc Doc -> Doc -> Doc
(</>)
cat :: [Doc] -> Doc
cat :: [Doc] -> Doc
cat = Doc -> Doc
group (Doc -> Doc) -> ([Doc] -> Doc) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Doc -> Doc -> Doc) -> [Doc] -> Doc
folddoc Doc -> Doc -> Doc
(<//>)
sep :: [Doc] -> Doc
sep :: [Doc] -> Doc
sep = Doc -> Doc
group (Doc -> Doc) -> ([Doc] -> Doc) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Doc -> Doc -> Doc) -> [Doc] -> Doc
folddoc Doc -> Doc -> Doc
(<+/>)
punctuate :: Doc -> [Doc] -> [Doc]
punctuate :: Doc -> [Doc] -> [Doc]
punctuate Doc
_ [] = []
punctuate Doc
_ [Doc
d] = [Doc
d]
punctuate Doc
p (Doc
d:[Doc]
ds) = (Doc
d Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
p) Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: Doc -> [Doc] -> [Doc]
punctuate Doc
p [Doc]
ds
commasep :: [Doc] -> Doc
commasep :: [Doc] -> Doc
commasep = Doc -> Doc
align (Doc -> Doc) -> ([Doc] -> Doc) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
sep ([Doc] -> Doc) -> ([Doc] -> [Doc]) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate Doc
comma
semisep :: [Doc] -> Doc
semisep :: [Doc] -> Doc
semisep = Doc -> Doc
align (Doc -> Doc) -> ([Doc] -> Doc) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
sep ([Doc] -> Doc) -> ([Doc] -> [Doc]) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate Doc
semi
enclosesep :: Doc -> Doc -> Doc -> [Doc] -> Doc
enclosesep :: Doc -> Doc -> Doc -> [Doc] -> Doc
enclosesep Doc
left Doc
right Doc
p [Doc]
ds =
case [Doc]
ds of
[] -> Doc
left Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
right
[Doc
d] -> Doc
left Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
d Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
right
[Doc]
_ -> Doc
left Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc -> Doc
align ([Doc] -> Doc
sep (Doc -> [Doc] -> [Doc]
punctuate Doc
p [Doc]
ds)) Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
right
tuple :: [Doc] -> Doc
tuple :: [Doc] -> Doc
tuple = Doc -> Doc -> Doc -> [Doc] -> Doc
enclosesep Doc
lparen Doc
rparen Doc
comma
list :: [Doc] -> Doc
list :: [Doc] -> Doc
list = Doc -> Doc -> Doc -> [Doc] -> Doc
enclosesep Doc
lbracket Doc
rbracket Doc
comma
align :: Doc -> Doc
align :: Doc -> Doc
align Doc
Empty = Doc
Empty
align Doc
d = (Int -> Doc) -> Doc
column ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
k ->
(Int -> Doc) -> Doc
nesting ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
i ->
Int -> Doc -> Doc
nest (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i) Doc
d
hang :: Int -> Doc -> Doc
hang :: Int -> Doc -> Doc
hang Int
i Doc
d = Doc -> Doc
align (Int -> Doc -> Doc
nest Int
i Doc
d)
indent :: Int -> Doc -> Doc
indent :: Int -> Doc -> Doc
indent Int
i Doc
d = Doc -> Doc
align (Int -> Doc -> Doc
nest Int
i (Int -> Doc
spaces Int
i Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
d))
nest :: Int -> Doc -> Doc
nest :: Int -> Doc -> Doc
nest Int
i Doc
d = Int -> Doc -> Doc
Nest Int
i Doc
d
column :: (Int -> Doc) -> Doc
column :: (Int -> Doc) -> Doc
column = (Int -> Doc) -> Doc
Column
nesting :: (Int -> Doc) -> Doc
nesting :: (Int -> Doc) -> Doc
nesting = (Int -> Doc) -> Doc
Nesting
width :: Doc -> (Int -> Doc) -> Doc
width :: Doc -> (Int -> Doc) -> Doc
width Doc
d Int -> Doc
f = (Int -> Doc) -> Doc
column ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
k1 -> Doc
d Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> ((Int -> Doc) -> Doc
column ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
k2 -> Int -> Doc
f (Int
k2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k1))
fill :: Int -> Doc -> Doc
fill :: Int -> Doc -> Doc
fill Int
f Doc
d = Doc -> (Int -> Doc) -> Doc
width Doc
d ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
w ->
if Int
w Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
f
then Doc
empty
else Int -> Doc
spaces (Int
f Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
w)
fillbreak :: Int -> Doc -> Doc
fillbreak :: Int -> Doc -> Doc
fillbreak Int
f Doc
d = Doc -> (Int -> Doc) -> Doc
width Doc
d ((Int -> Doc) -> Doc) -> (Int -> Doc) -> Doc
forall a b. (a -> b) -> a -> b
$ \Int
w ->
if (Int
w Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
f)
then Int -> Doc -> Doc
nest Int
f Doc
line
else Int -> Doc
spaces (Int
f Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
w)
#if MIN_VERSION_base(4,13,0)
faildoc :: MonadFail m => Doc -> m a
#else
faildoc :: Monad m => Doc -> m a
#endif
faildoc :: Doc -> m a
faildoc = String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m a) -> (Doc -> String) -> Doc -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc -> String
pretty Int
80
errordoc :: Doc -> a
errordoc :: Doc -> a
errordoc = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> (Doc -> String) -> Doc -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc -> String
pretty Int
80
data RDoc
= REmpty
| RChar {-# UNPACK #-} !Char RDoc
| RString {-# UNPACK #-} !Int String RDoc
| RText T.Text RDoc
| RLazyText L.Text RDoc
| RPos Pos RDoc
| RLine {-# UNPACK #-} !Int RDoc
render :: Int -> Doc -> RDoc
render :: Int -> Doc -> RDoc
render Int
w Doc
x = Int -> Int -> Doc -> RDoc
best Int
w Int
0 Doc
x
type RDocS = RDoc -> RDoc
data Docs
= Nil
| Cons {-# UNPACK #-} !Int Doc Docs
best :: Int -> Int -> Doc -> RDoc
best :: Int -> Int -> Doc -> RDoc
best !Int
w Int
k Doc
x = Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
True Maybe Pos
forall a. Maybe a
Nothing Maybe Pos
forall a. Maybe a
Nothing Int
k RDocS
forall a. a -> a
id (Int -> Doc -> Docs -> Docs
Cons Int
0 Doc
x Docs
Nil)
where
be :: Bool
-> Maybe Pos
-> Maybe Pos
-> Int
-> RDocS
-> Docs
-> RDoc
be :: Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
_ Maybe Pos
_ Maybe Pos
_ !Int
_ RDocS
f Docs
Nil = RDocS
f RDoc
REmpty
be Bool
nl Maybe Pos
p Maybe Pos
p' !Int
k RDocS
f (Cons Int
i Doc
d Docs
ds) =
case Doc
d of
Doc
Empty -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p Maybe Pos
p' Int
k RDocS
f Docs
ds
Char Char
c -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
False Maybe Pos
p Maybe Pos
p' (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (RDocS
f RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDocS
prag RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> RDocS
RChar Char
c) Docs
ds
String Int
l String
s -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
False Maybe Pos
p Maybe Pos
p' (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l) (RDocS
f RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDocS
prag RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> RDocS
RString Int
l String
s) Docs
ds
Text Text
s -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
False Maybe Pos
p Maybe Pos
p' (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Text -> Int
T.length Text
s) (RDocS
f RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDocS
prag RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> RDocS
RText Text
s) Docs
ds
LazyText Text
s -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
False Maybe Pos
p Maybe Pos
p' (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Text -> Int64
L.length Text
s)) (RDocS
f RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDocS
prag RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> RDocS
RLazyText Text
s) Docs
ds
Doc
Line -> (RDocS
f RDocS -> RDocS -> RDocS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> RDocS
RLine Int
i) (Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
True Maybe Pos
p'' Maybe Pos
forall a. Maybe a
Nothing Int
i RDocS
forall a. a -> a
id Docs
ds)
Doc
x `Cat` Doc
y -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p Maybe Pos
p' Int
k RDocS
f (Int -> Doc -> Docs -> Docs
Cons Int
i Doc
x (Int -> Doc -> Docs -> Docs
Cons Int
i Doc
y Docs
ds))
Nest Int
j Doc
x -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p Maybe Pos
p' Int
k RDocS
f (Int -> Doc -> Docs -> Docs
Cons (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
j) Doc
x Docs
ds)
Doc
x `Alt` Doc
y -> Int -> RDocS -> RDoc -> RDocS
better Int
k RDocS
f (Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p Maybe Pos
p' Int
k RDocS
forall a. a -> a
id (Int -> Doc -> Docs -> Docs
Cons Int
i Doc
x Docs
ds))
(Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p Maybe Pos
p' Int
k RDocS
forall a. a -> a
id (Int -> Doc -> Docs -> Docs
Cons Int
i Doc
y Docs
ds))
SrcLoc Loc
loc -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p (Maybe Pos -> Loc -> Maybe Pos
updatePos Maybe Pos
p' Loc
loc) Int
k RDocS
f Docs
ds
Column Int -> Doc
g -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p Maybe Pos
p' Int
k RDocS
f (Int -> Doc -> Docs -> Docs
Cons Int
i (Int -> Doc
g Int
k) Docs
ds)
Nesting Int -> Doc
g -> Bool -> Maybe Pos -> Maybe Pos -> Int -> RDocS -> Docs -> RDoc
be Bool
nl Maybe Pos
p Maybe Pos
p' Int
k RDocS
f (Int -> Doc -> Docs -> Docs
Cons Int
i (Int -> Doc
g Int
i) Docs
ds)
where
p'' :: Maybe Pos
prag :: RDocS
(Maybe Pos
p'', RDocS
prag) = Maybe Pos -> Maybe Pos -> (Maybe Pos, RDocS)
lineLoc Maybe Pos
p Maybe Pos
p'
lineLoc :: Maybe Pos
-> Maybe Pos
-> (Maybe Pos, RDocS)
lineLoc :: Maybe Pos -> Maybe Pos -> (Maybe Pos, RDocS)
lineLoc Maybe Pos
Nothing Maybe Pos
Nothing = (Maybe Pos
forall a. Maybe a
Nothing, RDocS
noPragma)
lineLoc Maybe Pos
Nothing (Just Pos
p) = (Pos -> Maybe Pos
forall a. a -> Maybe a
Just Pos
p, Pos -> RDocS
pragma Pos
p)
lineLoc (Just Pos
p1) (Just Pos
p2)
| Pos -> String
posFile Pos
p2 String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== Pos -> String
posFile Pos
p1 Bool -> Bool -> Bool
&&
Pos -> Int
posLine Pos
p2 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Pos -> Int
posLine Pos
p1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 = (Pos -> Maybe Pos
forall a. a -> Maybe a
Just Pos
p2, RDocS
noPragma)
| Bool
otherwise = (Pos -> Maybe Pos
forall a. a -> Maybe a
Just Pos
p2, Pos -> RDocS
pragma Pos
p2)
lineLoc (Just Pos
p1) Maybe Pos
Nothing = (Pos -> Maybe Pos
forall a. a -> Maybe a
Just (Pos -> Pos
advance Pos
p1), RDocS
noPragma)
where
advance :: Pos -> Pos
advance :: Pos -> Pos
advance (Pos String
f Int
l Int
c Int
coff) = String -> Int -> Int -> Int -> Pos
Pos String
f (Int
lInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) Int
c Int
coff
noPragma :: RDocS
noPragma :: RDocS
noPragma = RDocS
forall a. a -> a
id
pragma :: Pos -> RDocS
pragma :: Pos -> RDocS
pragma Pos
p | Bool
nl = Pos -> RDocS
RPos Pos
p
| Bool
otherwise = RDocS
forall a. a -> a
id
better :: Int -> RDocS -> RDoc -> RDoc -> RDoc
better :: Int -> RDocS -> RDoc -> RDocS
better !Int
k RDocS
f RDoc
x RDoc
y | Int -> RDoc -> Bool
fits (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k) RDoc
x = RDocS
f RDoc
x
| Bool
otherwise = RDocS
f RDoc
y
fits :: Int -> RDoc -> Bool
fits :: Int -> RDoc -> Bool
fits !Int
w RDoc
_ | Int
w Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 = Bool
False
fits !Int
_ RDoc
REmpty = Bool
True
fits !Int
w (RChar Char
_ RDoc
x) = Int -> RDoc -> Bool
fits (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) RDoc
x
fits !Int
w (RString Int
l String
_ RDoc
x) = Int -> RDoc -> Bool
fits (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
l) RDoc
x
fits !Int
w (RText Text
s RDoc
x) = Int -> RDoc -> Bool
fits (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Text -> Int
T.length Text
s) RDoc
x
fits !Int
w (RLazyText Text
s RDoc
x) = Int -> RDoc -> Bool
fits (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Text -> Int64
L.length Text
s)) RDoc
x
fits !Int
w (RPos Pos
_ RDoc
x) = Int -> RDoc -> Bool
fits Int
w RDoc
x
fits !Int
_ (RLine Int
_ RDoc
_) = Bool
True
updatePos :: Maybe Pos -> Loc -> Maybe Pos
updatePos :: Maybe Pos -> Loc -> Maybe Pos
updatePos Maybe Pos
Nothing Loc
NoLoc = Maybe Pos
forall a. Maybe a
Nothing
updatePos Maybe Pos
_ (Loc Pos
p Pos
_) = Pos -> Maybe Pos
forall a. a -> Maybe a
Just Pos
p
updatePos (Just Pos
p) Loc
NoLoc = Pos -> Maybe Pos
forall a. a -> Maybe a
Just Pos
p
renderCompact :: Doc -> RDoc
renderCompact :: Doc -> RDoc
renderCompact Doc
doc = Int -> [Doc] -> RDoc
scan Int
0 [Doc
doc]
where
scan :: Int -> [Doc] -> RDoc
scan :: Int -> [Doc] -> RDoc
scan !Int
_ [] = RDoc
REmpty
scan !Int
k (Doc
d:[Doc]
ds) =
case Doc
d of
Doc
Empty -> Int -> [Doc] -> RDoc
scan Int
k [Doc]
ds
Char Char
c -> Char -> RDocS
RChar Char
c (Int -> [Doc] -> RDoc
scan (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) [Doc]
ds)
String Int
l String
s -> Int -> String -> RDocS
RString Int
l String
s (Int -> [Doc] -> RDoc
scan (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l) [Doc]
ds)
Text Text
s -> Text -> RDocS
RText Text
s (Int -> [Doc] -> RDoc
scan (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Text -> Int
T.length Text
s) [Doc]
ds)
LazyText Text
s -> Text -> RDocS
RLazyText Text
s (Int -> [Doc] -> RDoc
scan (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Text -> Int64
L.length Text
s)) [Doc]
ds)
Doc
Line -> Int -> RDocS
RLine Int
0 (Int -> [Doc] -> RDoc
scan Int
0 [Doc]
ds)
Nest Int
_ Doc
x -> Int -> [Doc] -> RDoc
scan Int
k (Doc
xDoc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
:[Doc]
ds)
SrcLoc Loc
_ -> Int -> [Doc] -> RDoc
scan Int
k [Doc]
ds
Cat Doc
x Doc
y -> Int -> [Doc] -> RDoc
scan Int
k (Doc
xDoc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
:Doc
yDoc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
:[Doc]
ds)
Alt Doc
x Doc
_ -> Int -> [Doc] -> RDoc
scan Int
k (Doc
xDoc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
:[Doc]
ds)
Column Int -> Doc
f -> Int -> [Doc] -> RDoc
scan Int
k (Int -> Doc
f Int
kDoc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
:[Doc]
ds)
Nesting Int -> Doc
f -> Int -> [Doc] -> RDoc
scan Int
k (Int -> Doc
f Int
0Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
:[Doc]
ds)
displayS :: RDoc -> ShowS
displayS :: RDoc -> ShowS
displayS = RDoc -> ShowS
go
where
go :: RDoc -> ShowS
go :: RDoc -> ShowS
go RDoc
REmpty = ShowS
forall a. a -> a
id
go (RChar Char
c RDoc
x) = Char -> ShowS
showChar Char
c ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RString Int
_ String
s RDoc
x) = String -> ShowS
showString String
s ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RText Text
s RDoc
x) = String -> ShowS
showString (Text -> String
T.unpack Text
s) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RLazyText Text
s RDoc
x) = String -> ShowS
showString (Text -> String
L.unpack Text
s) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RPos Pos
_ RDoc
x) = RDoc -> ShowS
go RDoc
x
go (RLine Int
i RDoc
x) = String -> ShowS
showString (Char
'\n' Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
i Char
' ') ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
prettyS :: Int -> Doc -> ShowS
prettyS :: Int -> Doc -> ShowS
prettyS Int
w Doc
x = RDoc -> ShowS
displayS (Int -> Doc -> RDoc
render Int
w Doc
x)
pretty :: Int -> Doc -> String
pretty :: Int -> Doc -> String
pretty Int
w Doc
x = Int -> Doc -> ShowS
prettyS Int
w Doc
x String
""
prettyCompactS :: Doc -> ShowS
prettyCompactS :: Doc -> ShowS
prettyCompactS Doc
x = RDoc -> ShowS
displayS (Doc -> RDoc
renderCompact Doc
x)
prettyCompact :: Doc -> String
prettyCompact :: Doc -> String
prettyCompact Doc
x = Doc -> ShowS
prettyCompactS Doc
x String
""
displayPragmaS :: RDoc -> ShowS
displayPragmaS :: RDoc -> ShowS
displayPragmaS = RDoc -> ShowS
go
where
go :: RDoc -> ShowS
go :: RDoc -> ShowS
go RDoc
REmpty = ShowS
forall a. a -> a
id
go (RChar Char
c RDoc
x) = Char -> ShowS
showChar Char
c ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RString Int
_ String
s RDoc
x) = String -> ShowS
showString String
s ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RText Text
s RDoc
x) = String -> ShowS
showString (Text -> String
T.unpack Text
s) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RLazyText Text
s RDoc
x) = String -> ShowS
showString (Text -> String
L.unpack Text
s) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> ShowS
go RDoc
x
go (RPos Pos
p RDoc
x) = Pos -> ShowS
showPos Pos
p ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Char -> ShowS
showChar Char
'\n' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
RDoc -> ShowS
go RDoc
x
go (RLine Int
i RDoc
x) = case RDoc
x of
RPos Pos
p RDoc
x' -> Char -> ShowS
showChar Char
'\n' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Pos -> ShowS
showPos Pos
p ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString (Char
'\n' Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
i Char
' ') ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
RDoc -> ShowS
go RDoc
x'
RDoc
_ -> String -> ShowS
showString (Char
'\n' Char -> ShowS
forall a. a -> [a] -> [a]
: Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
i Char
' ') ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
RDoc -> ShowS
go RDoc
x
showPos :: Pos -> ShowS
showPos :: Pos -> ShowS
showPos Pos
p =
String -> ShowS
showString String
"#line " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> ShowS
forall a. Show a => a -> ShowS
shows (Pos -> Int
posLine Pos
p) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Char -> ShowS
showChar Char
' ' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Char -> ShowS
showChar Char
'"' ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> ShowS
showString (Pos -> String
posFile Pos
p) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Char -> ShowS
showChar Char
'"'
prettyPragmaS :: Int -> Doc -> ShowS
prettyPragmaS :: Int -> Doc -> ShowS
prettyPragmaS Int
w Doc
x = RDoc -> ShowS
displayPragmaS (Int -> Doc -> RDoc
render Int
w Doc
x)
prettyPragma :: Int -> Doc -> String
prettyPragma :: Int -> Doc -> String
prettyPragma Int
w Doc
x = Int -> Doc -> ShowS
prettyPragmaS Int
w Doc
x String
""
displayLazyText :: RDoc -> L.Text
displayLazyText :: RDoc -> Text
displayLazyText = Builder -> Text
B.toLazyText (Builder -> Text) -> (RDoc -> Builder) -> RDoc -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> Builder
go
where
go :: RDoc -> B.Builder
go :: RDoc -> Builder
go RDoc
REmpty = Builder
forall a. Monoid a => a
mempty
go (RChar Char
c RDoc
x) = Char -> Builder
B.singleton Char
c Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RString Int
_ String
s RDoc
x) = String -> Builder
B.fromString String
s Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RText Text
s RDoc
x) = Text -> Builder
B.fromText Text
s Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RLazyText Text
s RDoc
x) = Text -> Builder
B.fromLazyText Text
s Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RPos Pos
_ RDoc
x) = RDoc -> Builder
go RDoc
x
go (RLine Int
i RDoc
x) = String -> Builder
B.fromString (Char
'\n'Char -> ShowS
forall a. a -> [a] -> [a]
:Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
i Char
' ') Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
prettyLazyText :: Int -> Doc -> L.Text
prettyLazyText :: Int -> Doc -> Text
prettyLazyText Int
w Doc
x = RDoc -> Text
displayLazyText (Int -> Doc -> RDoc
render Int
w Doc
x)
displayPragmaLazyText :: RDoc -> L.Text
displayPragmaLazyText :: RDoc -> Text
displayPragmaLazyText = Builder -> Text
B.toLazyText (Builder -> Text) -> (RDoc -> Builder) -> RDoc -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RDoc -> Builder
go
where
go :: RDoc -> B.Builder
go :: RDoc -> Builder
go RDoc
REmpty = Builder
forall a. Monoid a => a
mempty
go (RChar Char
c RDoc
x) = Char -> Builder
B.singleton Char
c Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RText Text
s RDoc
x) = Text -> Builder
B.fromText Text
s Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RLazyText Text
s RDoc
x) = Text -> Builder
B.fromLazyText Text
s Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RString Int
_ String
s RDoc
x) = String -> Builder
B.fromString String
s Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend` RDoc -> Builder
go RDoc
x
go (RPos Pos
p RDoc
x) = Pos -> Builder
displayPos Pos
p Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
Char -> Builder
B.singleton Char
'\n' Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
RDoc -> Builder
go RDoc
x
go (RLine Int
i RDoc
x) = case RDoc
x of
RPos Pos
p RDoc
x' -> Char -> Builder
B.singleton Char
'\n' Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
Pos -> Builder
displayPos Pos
p Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
String -> Builder
B.fromString (Char
'\n'Char -> ShowS
forall a. a -> [a] -> [a]
:Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
i Char
' ') Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
RDoc -> Builder
go RDoc
x'
RDoc
_ -> String -> Builder
B.fromString (Char
'\n'Char -> ShowS
forall a. a -> [a] -> [a]
:Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
i Char
' ') Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
RDoc -> Builder
go RDoc
x
displayPos :: Pos -> B.Builder
displayPos :: Pos -> Builder
displayPos Pos
p =
String -> Builder
B.fromString String
"#line " Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
Pos -> Builder
renderPosLine Pos
p Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
Char -> Builder
B.singleton Char
' ' Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
`mappend`
Pos -> Builder
renderPosFile Pos
p
renderPosLine :: Pos -> B.Builder
renderPosLine :: Pos -> Builder
renderPosLine = RDoc -> Builder
go (RDoc -> Builder) -> (Pos -> RDoc) -> Pos -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> RDoc
renderCompact (Doc -> RDoc) -> (Pos -> Doc) -> Pos -> RDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc
int (Int -> Doc) -> (Pos -> Int) -> Pos -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pos -> Int
posLine
renderPosFile :: Pos -> B.Builder
renderPosFile :: Pos -> Builder
renderPosFile = RDoc -> Builder
go (RDoc -> Builder) -> (Pos -> RDoc) -> Pos -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> RDoc
renderCompact (Doc -> RDoc) -> (Pos -> Doc) -> Pos -> RDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Doc -> Doc -> Doc
enclose Doc
dquote Doc
dquote (Doc -> Doc) -> (Pos -> Doc) -> Pos -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
string (String -> Doc) -> (Pos -> String) -> Pos -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pos -> String
posFile
prettyPragmaLazyText :: Int -> Doc -> L.Text
prettyPragmaLazyText :: Int -> Doc -> Text
prettyPragmaLazyText Int
w Doc
x = RDoc -> Text
displayPragmaLazyText (Int -> Doc -> RDoc
render Int
w Doc
x)
putDoc :: Doc -> IO ()
putDoc :: Doc -> IO ()
putDoc = Text -> IO ()
TIO.putStr (Text -> IO ()) -> (Doc -> Text) -> Doc -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc -> Text
prettyLazyText Int
80
putDocLn :: Doc -> IO ()
putDocLn :: Doc -> IO ()
putDocLn = Text -> IO ()
TIO.putStrLn (Text -> IO ()) -> (Doc -> Text) -> Doc -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc -> Text
prettyLazyText Int
80
hPutDoc :: Handle -> Doc -> IO ()
hPutDoc :: Handle -> Doc -> IO ()
hPutDoc Handle
h = Handle -> Text -> IO ()
TIO.hPutStr Handle
h (Text -> IO ()) -> (Doc -> Text) -> Doc -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc -> Text
prettyLazyText Int
80
hPutDocLn :: Handle -> Doc -> IO ()
hPutDocLn :: Handle -> Doc -> IO ()
hPutDocLn Handle
h = Handle -> Text -> IO ()
TIO.hPutStrLn Handle
h (Text -> IO ()) -> (Doc -> Text) -> Doc -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Doc -> Text
prettyLazyText Int
80