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