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
|
<HTML>
<HEAD>
<TITLE>The Hugs-GHC Extension Libraries: Pretty </TITLE>
</HEAD>
<BODY>
<A HREF="libs-9.html">Previous</A>
Next
<A HREF="libs.html#toc10">Table of Contents</A>
<HR>
<H2><A NAME="s10">10. Pretty </A></H2>
<P>This library contains Simon Peyton Jones' implementation of John
Hughes's pretty printer combinators.</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
module Pretty where
infixl 6 <>
infixl 6 <+>
infixl 5 $$, $+$
data Doc -- the Document datatype
-- The primitive Doc values
empty :: Doc
text :: String -> Doc
char :: Char -> Doc
int :: Int -> Doc
integer :: Integer -> Doc
float :: Float -> Doc
double :: Double -> Doc
rational :: Rational -> Doc
semi, comma, colon, space, equals :: Doc
lparen, rparen, lbrack, rbrack, lbrace, rbrace :: Doc
parens, brackets, braces :: Doc -> Doc
quotes, doubleQuotes :: Doc -> Doc
-- Combining Doc values
(<>) :: Doc -> Doc -> Doc -- Beside
hcat :: [Doc] -> Doc -- List version of <>
(<+>) :: Doc -> Doc -> Doc -- Beside, separated by space
hsep :: [Doc] -> Doc -- List version of <+>
($$) :: Doc -> Doc -> Doc -- Above; if there is no
-- overlap it "dovetails" the two
vcat :: [Doc] -> Doc -- List version of $$
cat :: [Doc] -> Doc -- Either hcat or vcat
sep :: [Doc] -> Doc -- Either hsep or vcat
fcat :: [Doc] -> Doc -- ``Paragraph fill'' version of cat
fsep :: [Doc] -> Doc -- ``Paragraph fill'' version of sep
nest :: Int -> Doc -> Doc -- Nested
hang :: Doc -> Int -> Doc -> Doc
punctuate :: Doc -> [Doc] -> [Doc]
-- punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn-1 <> p, dn]
-- Displaying Doc values
instance Show Doc
render :: Doc -> String -- Uses default style
renderStyle :: Style -> Doc -> String
data Style = Style { lineLength :: Int, -- In chars
ribbonsPerLine :: Float, -- Ratio of ribbon length
-- to line length
mode :: Mode
}
data Mode = PageMode -- Normal
| ZigZagMode -- With zig-zag cuts
| LeftMode -- No indentation, infinitely long lines
| OneLineMode -- All on one line
</PRE>
</CODE></BLOCKQUOTE>
</P>
<HR>
<A HREF="libs-9.html">Previous</A>
Next
<A HREF="libs.html#toc10">Table of Contents</A>
</BODY>
</HTML>
|