[project @ 1996-03-19 08:58:34 by partain]
[ghc-hetmet.git] / ghc / compiler / utils / Unpretty.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[Unpretty]{Unpretty-printing data type}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module Unpretty (
10         Unpretty(..),
11
12         uppNil, uppStr, uppPStr, uppChar, uppInt, uppInteger,
13         uppSP, uppLbrack, uppRbrack, uppLparen, uppRparen,
14         uppSemi, uppComma, uppEquals,
15
16         uppCat, uppBeside, uppBesides, uppAbove, uppAboves,
17         uppNest, uppSep, uppInterleave, uppIntersperse,
18         uppShow,
19         uppAppendFile,
20
21         -- abstract type, to complete the interface...
22         CSeq
23    ) where
24
25 CHK_Ubiq() -- debugging consistency check
26
27 import CharSeq
28 \end{code}
29
30 Same interface as @Pretty@, but doesn't do anything.
31
32 The pretty type is redefined here:
33 \begin{code}
34 type Unpretty = CSeq
35 \end{code}
36
37 %************************************************
38 %*                                              *
39         \subsection{The interface}
40 %*                                              *
41 %************************************************
42
43 \begin{code}
44 uppNil          :: Unpretty
45 uppSP, uppLbrack, uppRbrack, uppLparen, uppRparen, uppSemi, uppComma, uppEquals :: Unpretty
46
47 uppStr          :: [Char] -> Unpretty
48 uppPStr         :: FAST_STRING -> Unpretty
49 uppChar         :: Char -> Unpretty
50 uppInt          :: Int -> Unpretty
51 uppInteger      :: Integer -> Unpretty
52
53 uppBeside       :: Unpretty -> Unpretty -> Unpretty
54 uppBesides      :: [Unpretty] -> Unpretty
55 ppBesideSP      :: Unpretty -> Unpretty -> Unpretty
56 uppCat          :: [Unpretty] -> Unpretty               -- i.e., ppBesidesSP
57
58 uppAbove        :: Unpretty -> Unpretty -> Unpretty
59 uppAboves       :: [Unpretty] -> Unpretty
60
61 uppInterleave   :: Unpretty -> [Unpretty] -> Unpretty
62 uppIntersperse  :: Unpretty -> [Unpretty] -> Unpretty   -- no spaces between
63 uppSep          :: [Unpretty] -> Unpretty
64 uppNest         :: Int -> Unpretty -> Unpretty
65
66 uppShow         :: Int -> Unpretty -> [Char]
67
68 uppAppendFile   :: _FILE -> Int -> Unpretty -> PrimIO ()
69 \end{code}
70
71 %************************************************
72 %*                                              *
73         \subsection{The representation}
74 %*                                              *
75 %************************************************
76
77 \begin{code}
78 uppShow _ p     = cShow p
79
80 uppAppendFile f _ p = cAppendFile f p
81
82 uppNil          = cNil
83 uppStr s        = cStr s
84 uppPStr s       = cPStr s
85 uppChar c       = cCh c
86 uppInt n        = cInt n
87
88 uppInteger n    = cStr (show n)
89
90 uppSP           = cCh ' '
91 uppLbrack       = cCh '['
92 uppRbrack       = cCh ']'
93 uppLparen       = cCh '('
94 uppRparen       = cCh ')'
95 uppSemi         = cCh ';'
96 uppComma        = cCh ','
97 uppEquals       = cCh '='
98
99 uppInterleave sep ps = uppSep (pi ps)
100   where
101    pi []        = []
102    pi [x]       = [x]
103    pi (x:xs)    = (cAppend{-uppBeside-} x sep) : pi xs
104 \end{code}
105
106 \begin{code}
107 uppIntersperse sep ps = uppBesides (pi ps)
108   where
109    pi []        = []
110    pi [x]       = [x]
111    pi (x:xs)    = (cAppend{-uppBeside-} x sep) : pi xs
112 \end{code}
113
114 \begin{code}
115 uppBeside p1 p2  = p1 `cAppend` p2
116
117 uppBesides []     = cNil{-uppNil-}
118 uppBesides [p]    = p
119 uppBesides (p:ps) = p `cAppend`{-uppBeside-} uppBesides ps
120 \end{code}
121
122 \begin{code}
123 ppBesideSP p1 p2 = p1 `cAppend` (cCh ' ') `cAppend` p2
124 \end{code}
125
126 @uppCat@ is the name I (WDP) happen to have been using for @ppBesidesSP@.
127
128 \begin{code}
129 uppCat []     = cNil{-uppNil-}
130 uppCat [p]    = p
131 uppCat (p:ps) = ppBesideSP p (uppCat ps)
132
133 uppAbove p1 p2 = p1 `cAppend` (cCh '\n') `cAppend` p2
134
135 uppAboves []     = cNil{-uppNil-}
136 uppAboves [p]    = p
137 uppAboves (p:ps) = p `cAppend` (cCh '\n') `cAppend` (uppAboves ps)
138
139 uppNest n p = p
140
141 uppSep ps = uppBesides ps
142 \end{code}