-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathLeijen.hs
More file actions
193 lines (140 loc) · 4.23 KB
/
Leijen.hs
File metadata and controls
193 lines (140 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
{-# LANGUAGE CPP #-}
module Text.PrettyPrint.Leijen {-# DEPRECATED "Compatibility module for users of wl-pprint - use \"Prettyprinter\" instead" #-} (
Doc, putDoc, hPutDoc, empty, char, text, (<>), nest, line, linebreak, group,
softline, softbreak, align, hang, indent, encloseSep, list, tupled,
semiBraces, (<+>), (<$>), (</>), (<$$>), (<//>), hsep, vsep, fillSep, sep,
hcat, vcat, fillCat, cat, punctuate, fill, fillBreak, enclose, squotes,
dquotes, parens, angles, braces, brackets, lparen, rparen, langle, rangle,
lbrace, rbrace, lbracket, rbracket, squote, dquote, semi, colon, comma,
space, dot, backslash, equals, string, int, integer, float, double,
rational, Pretty(..), SimpleDoc, renderPretty, renderCompact, displayS,
displayIO, bool, column, nesting, width
) where
import Prelude hiding ((<$>))
import qualified Data.Text.Lazy as TL
import System.IO
import Prettyprinter (Pretty (..))
import qualified Prettyprinter as New
import qualified Prettyprinter.Render.Text as NewT
#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup
#endif
type Doc = New.Doc ()
type SimpleDoc = New.SimpleDocStream ()
putDoc :: Doc -> IO ()
putDoc = NewT.putDoc
hPutDoc :: Handle -> Doc -> IO ()
hPutDoc = NewT.hPutDoc
empty :: Doc
empty = New.emptyDoc
char :: Char -> Doc
char = New.pretty
text :: String -> Doc
text = New.pretty
nest :: Int -> Doc -> Doc
nest = New.nest
line :: Doc
line = New.line
linebreak :: Doc
linebreak = New.flatAlt New.line mempty
group :: Doc -> Doc
group = New.group
softline :: Doc
softline = New.softline
softbreak :: Doc
softbreak = New.group linebreak
align :: Doc -> Doc
align = New.align
hang :: Int -> Doc -> Doc
hang = New.hang
indent :: Int -> Doc -> Doc
indent = New.indent
encloseSep :: Doc -> Doc -> Doc -> [Doc] -> Doc
encloseSep = New.encloseSep
list :: [Doc] -> Doc
list = New.list
tupled :: [Doc] -> Doc
tupled = New.tupled
semiBraces :: [Doc] -> Doc
semiBraces = New.encloseSep New.lbrace New.rbrace New.semi
(<+>), (<$>), (</>), (<$$>), (<//>) :: Doc -> Doc -> Doc
(<+>) = (New.<+>)
(<$>) = \x y -> x <> New.line <> y
(</>) = \x y -> x <> softline <> y
(<$$>) = \x y -> x <> linebreak <> y
(<//>) = \x y -> x <> softbreak <> y
hsep, vsep, fillSep, sep, hcat, vcat, fillCat, cat :: [Doc] -> Doc
hsep = New.hsep
vsep = New.vsep
fillSep = New.fillSep
sep = New.sep
hcat = New.hcat
vcat = New.vcat
fillCat = New.fillCat
cat = New.cat
punctuate :: Doc -> [Doc] -> [Doc]
punctuate = New.punctuate
fill :: Int -> Doc -> Doc
fill = New.fill
fillBreak :: Int -> Doc -> Doc
fillBreak = New.fillBreak
enclose :: Doc -> Doc -> Doc -> Doc
enclose = New.enclose
squotes, dquotes, parens, angles, braces, brackets :: Doc -> Doc
squotes = New.squotes
dquotes = New.dquotes
parens = New.parens
angles = New.angles
braces = New.braces
brackets = New.brackets
lparen, rparen, langle, rangle, lbrace, rbrace, lbracket, rbracket, squote,
dquote, semi, colon, comma, space, dot, backslash, equals :: Doc
lparen = New.lparen
rparen = New.rparen
langle = New.langle
rangle = New.rangle
lbrace = New.lbrace
rbrace = New.rbrace
lbracket = New.lbracket
rbracket = New.rbracket
squote = New.squote
dquote = New.dquote
semi = New.semi
colon = New.colon
comma = New.comma
space = New.space
dot = New.dot
backslash = New.backslash
equals = New.equals
string :: String -> Doc
string = New.pretty
int :: Int -> Doc
int = New.pretty
integer :: Integer -> Doc
integer = New.pretty
float :: Float -> Doc
float = New.pretty
double :: Double -> Doc
double = New.pretty
rational :: Rational -> Doc
rational = New.pretty . show
renderPretty :: Float -> Int -> Doc -> SimpleDoc
renderPretty ribbonFraction pageWidth
= New.layoutPretty New.LayoutOptions
{ New.layoutPageWidth = New.AvailablePerLine pageWidth (realToFrac ribbonFraction) }
renderCompact :: Doc -> SimpleDoc
renderCompact = New.layoutCompact
displayS :: SimpleDoc -> ShowS
displayS sdoc =
let rendered = NewT.renderLazy sdoc
in (TL.unpack rendered ++)
displayIO :: Handle -> SimpleDoc -> IO ()
displayIO = NewT.renderIO
bool :: Bool -> Doc
bool = New.pretty
column :: (Int -> Doc) -> Doc
column = New.column
nesting :: (Int -> Doc) -> Doc
nesting = New.nesting
width :: Doc -> (Int -> Doc) -> Doc
width = New.width