adamc@1
|
1 (* Copyright (c) 2008, Adam Chlipala
|
adamc@1
|
2 * All rights reserved.
|
adamc@1
|
3 *
|
adamc@1
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@1
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@1
|
6 *
|
adamc@1
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@1
|
8 * this list of conditions and the following disclaimer.
|
adamc@1
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@1
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@1
|
11 * and/or other materials provided with the distribution.
|
adamc@1
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@1
|
13 * derived from this software without specific prior written permission.
|
adamc@1
|
14 *
|
adamc@1
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@1
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@1
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@1
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
adamc@1
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@1
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@1
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@1
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@1
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@1
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@1
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@1
|
26 *)
|
adamc@1
|
27
|
adamc@244
|
28 (* Pretty-printing Ur/Web *)
|
adamc@1
|
29
|
adamc@4
|
30 structure SourcePrint :> SOURCE_PRINT = struct
|
adamc@1
|
31
|
adamc@1
|
32 open Print.PD
|
adamc@1
|
33 open Print
|
adamc@1
|
34
|
adamc@4
|
35 open Source
|
adamc@1
|
36
|
adamc@1
|
37 fun p_kind' par (k, _) =
|
adamc@1
|
38 case k of
|
adamc@1
|
39 KType => string "Type"
|
adamc@1
|
40 | KArrow (k1, k2) => parenIf par (box [p_kind' true k1,
|
adamc@1
|
41 space,
|
adamc@1
|
42 string "->",
|
adamc@1
|
43 space,
|
adamc@1
|
44 p_kind k2])
|
adamc@1
|
45 | KName => string "Name"
|
adamc@1
|
46 | KRecord k => box [string "{", p_kind k, string "}"]
|
adamc@82
|
47 | KUnit => string "Unit"
|
adamc@18
|
48 | KWild => string "_"
|
adamc@207
|
49 | KTuple ks => box [string "(",
|
adamc@207
|
50 p_list_sep (box [space, string "*", space]) p_kind ks,
|
adamc@207
|
51 string ")"]
|
adamc@1
|
52
|
adamc@623
|
53 | KVar x => string x
|
adamc@623
|
54 | KFun (x, k) => box [string x,
|
adamc@623
|
55 space,
|
adamc@623
|
56 string "-->",
|
adamc@623
|
57 space,
|
adamc@623
|
58 p_kind k]
|
adamc@623
|
59
|
adamc@1
|
60 and p_kind k = p_kind' false k
|
adamc@1
|
61
|
adamc@1
|
62 fun p_explicitness e =
|
adamc@1
|
63 case e of
|
adamc@1
|
64 Explicit => string "::"
|
adamc@1
|
65 | Implicit => string ":::"
|
adamc@1
|
66
|
adamc@1
|
67 fun p_con' par (c, _) =
|
adamc@1
|
68 case c of
|
adamc@1
|
69 CAnnot (c, k) => box [string "(",
|
adamc@1
|
70 p_con c,
|
adamc@1
|
71 space,
|
adamc@1
|
72 string "::",
|
adamc@1
|
73 space,
|
adamc@1
|
74 p_kind k,
|
adamc@1
|
75 string ")"]
|
adamc@1
|
76
|
adamc@1
|
77 | TFun (t1, t2) => parenIf par (box [p_con' true t1,
|
adamc@1
|
78 space,
|
adamc@1
|
79 string "->",
|
adamc@1
|
80 space,
|
adamc@1
|
81 p_con t2])
|
adamc@1
|
82 | TCFun (e, x, k, c) => parenIf par (box [string x,
|
adamc@1
|
83 space,
|
adamc@1
|
84 p_explicitness e,
|
adamc@1
|
85 space,
|
adamc@1
|
86 p_kind k,
|
adamc@1
|
87 space,
|
adamc@1
|
88 string "->",
|
adamc@1
|
89 space,
|
adamc@1
|
90 p_con c])
|
adamc@1
|
91 | TRecord (CRecord xcs, _) => box [string "{",
|
adamc@1
|
92 p_list (fn (x, c) =>
|
adamc@20
|
93 box [p_name x,
|
adamc@1
|
94 space,
|
adamc@1
|
95 string ":",
|
adamc@1
|
96 space,
|
adamc@1
|
97 p_con c]) xcs,
|
adamc@1
|
98 string "}"]
|
adamc@1
|
99 | TRecord c => box [string "$",
|
adamc@1
|
100 p_con' true c]
|
adamc@628
|
101 | TDisjoint (c1, c2, c3) => parenIf par (box [string "[",
|
adamc@628
|
102 p_con c1,
|
adamc@628
|
103 space,
|
adamc@628
|
104 string "~",
|
adamc@628
|
105 space,
|
adamc@628
|
106 p_con c2,
|
adamc@628
|
107 string "]",
|
adamc@628
|
108 space,
|
adamc@628
|
109 string "=>",
|
adamc@628
|
110 space,
|
adamc@628
|
111 p_con c3])
|
adamc@1
|
112
|
adamc@34
|
113 | CVar (ss, s) => p_list_sep (string ".") string (ss @ [s])
|
adamc@1
|
114 | CApp (c1, c2) => parenIf par (box [p_con c1,
|
adamc@1
|
115 space,
|
adamc@1
|
116 p_con' true c2])
|
adamc@67
|
117 | CAbs (x, NONE, c) => parenIf par (box [string "fn",
|
adamc@67
|
118 space,
|
adamc@67
|
119 string x,
|
adamc@67
|
120 space,
|
adamc@67
|
121 string "=>",
|
adamc@67
|
122 space,
|
adamc@67
|
123 p_con c])
|
adamc@67
|
124 | CAbs (x, SOME k, c) => parenIf par (box [string "fn",
|
adamc@67
|
125 space,
|
adamc@67
|
126 string x,
|
adamc@67
|
127 space,
|
adamc@67
|
128 string "::",
|
adamc@67
|
129 space,
|
adamc@67
|
130 p_kind k,
|
adamc@67
|
131 space,
|
adamc@67
|
132 string "=>",
|
adamc@67
|
133 space,
|
adamc@67
|
134 p_con c])
|
adamc@628
|
135
|
adamc@1
|
136
|
adamc@1
|
137 | CName s => box [string "#", string s]
|
adamc@1
|
138
|
adamc@1
|
139 | CRecord xcs => box [string "[",
|
adamc@1
|
140 p_list (fn (x, c) =>
|
adamc@1
|
141 box [p_con x,
|
adamc@1
|
142 space,
|
adamc@1
|
143 string "=",
|
adamc@1
|
144 space,
|
adamc@1
|
145 p_con c]) xcs,
|
adamc@1
|
146 string "]"]
|
adamc@1
|
147 | CConcat (c1, c2) => parenIf par (box [p_con' true c1,
|
adamc@1
|
148 space,
|
adamc@1
|
149 string "++",
|
adamc@1
|
150 space,
|
adamc@1
|
151 p_con c2])
|
adamc@621
|
152 | CMap => string "map"
|
adamc@82
|
153
|
adamc@82
|
154 | CUnit => string "()"
|
adamc@82
|
155
|
adamc@18
|
156 | CWild k => box [string "(_",
|
adamc@18
|
157 space,
|
adamc@18
|
158 string "::",
|
adamc@18
|
159 space,
|
adamc@223
|
160 p_kind k,
|
adamc@223
|
161 string ")"]
|
adamc@207
|
162
|
adamc@207
|
163 | CTuple cs => box [string "(",
|
adamc@207
|
164 p_list p_con cs,
|
adamc@207
|
165 string ")"]
|
adamc@207
|
166 | CProj (c, n) => box [p_con c,
|
adamc@207
|
167 string ".",
|
adamc@207
|
168 string (Int.toString n)]
|
adamc@623
|
169
|
adamc@623
|
170 | CKAbs (x, c) => box [string x,
|
adamc@623
|
171 space,
|
adamc@623
|
172 string "==>",
|
adamc@623
|
173 space,
|
adamc@623
|
174 p_con c]
|
adamc@623
|
175 | TKFun (x, c) => box [string x,
|
adamc@623
|
176 space,
|
adamc@623
|
177 string "-->",
|
adamc@623
|
178 space,
|
adamc@623
|
179 p_con c]
|
adamc@1
|
180
|
adamc@1
|
181 and p_con c = p_con' false c
|
adamc@1
|
182
|
adamc@20
|
183 and p_name (all as (c, _)) =
|
adamc@20
|
184 case c of
|
adamc@20
|
185 CName s => string s
|
adamc@20
|
186 | _ => p_con all
|
adamc@20
|
187
|
adamc@170
|
188 fun p_pat' par (p, _) =
|
adamc@170
|
189 case p of
|
adamc@170
|
190 PWild => string "_"
|
adamc@170
|
191 | PVar s => string s
|
adamc@173
|
192 | PPrim p => Prim.p_t p
|
adamc@170
|
193 | PCon (ms, x, NONE) => p_list_sep (string ".") string (ms @ [x])
|
adamc@170
|
194 | PCon (ms, x, SOME p) => parenIf par (box [p_list_sep (string ".") string (ms @ [x]),
|
adamc@170
|
195 space,
|
adamc@170
|
196 p_pat' true p])
|
adamc@174
|
197 | PRecord (xps, flex) =>
|
adamc@174
|
198 let
|
adamc@175
|
199 val pps = map (fn (x, p) => box [string x, space, string "=", space, p_pat p]) xps
|
adamc@174
|
200 in
|
adamc@174
|
201 box [string "{",
|
adamc@174
|
202 p_list_sep (box [string ",", space]) (fn x => x)
|
adamc@174
|
203 (if flex then
|
adamc@175
|
204 pps @ [string "..."]
|
adamc@174
|
205 else
|
adamc@175
|
206 pps),
|
adamc@174
|
207 string "}"]
|
adamc@174
|
208 end
|
adamc@170
|
209
|
adamc@174
|
210 and p_pat x = p_pat' false x
|
adamc@170
|
211
|
adamc@8
|
212 fun p_exp' par (e, _) =
|
adamc@8
|
213 case e of
|
adamc@8
|
214 EAnnot (e, t) => box [string "(",
|
adamc@8
|
215 p_exp e,
|
adamc@8
|
216 space,
|
adamc@8
|
217 string ":",
|
adamc@8
|
218 space,
|
adamc@8
|
219 p_con t,
|
adamc@8
|
220 string ")"]
|
adamc@8
|
221
|
adamc@14
|
222 | EPrim p => Prim.p_t p
|
adamc@403
|
223 | EVar (ss, s, _) => p_list_sep (string ".") string (ss @ [s])
|
adamc@8
|
224 | EApp (e1, e2) => parenIf par (box [p_exp e1,
|
adamc@8
|
225 space,
|
adamc@8
|
226 p_exp' true e2])
|
adamc@8
|
227 | EAbs (x, NONE, e) => parenIf par (box [string "fn",
|
adamc@8
|
228 space,
|
adamc@8
|
229 string x,
|
adamc@8
|
230 space,
|
adamc@8
|
231 string "=>",
|
adamc@8
|
232 space,
|
adamc@8
|
233 p_exp e])
|
adamc@8
|
234 | EAbs (x, SOME t, e) => parenIf par (box [string "fn",
|
adamc@8
|
235 space,
|
adamc@8
|
236 string x,
|
adamc@8
|
237 space,
|
adamc@8
|
238 string ":",
|
adamc@8
|
239 space,
|
adamc@8
|
240 p_con t,
|
adamc@8
|
241 space,
|
adamc@8
|
242 string "=>",
|
adamc@8
|
243 space,
|
adamc@8
|
244 p_exp e])
|
adamc@8
|
245 | ECApp (e, c) => parenIf par (box [p_exp e,
|
adamc@8
|
246 space,
|
adamc@8
|
247 string "[",
|
adamc@8
|
248 p_con c,
|
adamc@8
|
249 string "]"])
|
adamc@8
|
250 | ECAbs (exp, x, k, e) => parenIf par (box [string "fn",
|
adamc@8
|
251 space,
|
adamc@8
|
252 string x,
|
adamc@8
|
253 space,
|
adamc@8
|
254 p_explicitness exp,
|
adamc@8
|
255 space,
|
adamc@8
|
256 p_kind k,
|
adamc@8
|
257 space,
|
adamc@8
|
258 string "=>",
|
adamc@8
|
259 space,
|
adamc@8
|
260 p_exp e])
|
adamc@85
|
261 | EDisjoint (c1, c2, e) => parenIf par (box [p_con c1,
|
adamc@85
|
262 space,
|
adamc@85
|
263 string "~",
|
adamc@85
|
264 space,
|
adamc@85
|
265 p_con c2,
|
adamc@85
|
266 space,
|
adamc@85
|
267 string "=>",
|
adamc@85
|
268 space,
|
adamc@85
|
269 p_exp e])
|
adamc@8
|
270
|
adamc@12
|
271 | ERecord xes => box [string "{",
|
adamc@12
|
272 p_list (fn (x, e) =>
|
adamc@21
|
273 box [p_name x,
|
adamc@12
|
274 space,
|
adamc@12
|
275 string "=",
|
adamc@12
|
276 space,
|
adamc@12
|
277 p_exp e]) xes,
|
adamc@12
|
278 string "}"]
|
adamc@12
|
279 | EField (e, c) => box [p_exp' true e,
|
adamc@12
|
280 string ".",
|
adamc@12
|
281 p_con' true c]
|
adamc@445
|
282 | EConcat (e1, e2) => parenIf par (box [p_exp' true e1,
|
adamc@445
|
283 space,
|
adamc@445
|
284 string "++",
|
adamc@445
|
285 space,
|
adamc@445
|
286 p_exp' true e2])
|
adamc@149
|
287 | ECut (e, c) => parenIf par (box [p_exp' true e,
|
adamc@149
|
288 space,
|
adamc@149
|
289 string "--",
|
adamc@149
|
290 space,
|
adamc@149
|
291 p_con' true c])
|
adamc@493
|
292 | ECutMulti (e, c) => parenIf par (box [p_exp' true e,
|
adamc@493
|
293 space,
|
adamc@493
|
294 string "---",
|
adamc@493
|
295 space,
|
adamc@493
|
296 p_con' true c])
|
adamc@170
|
297 | ECase (e, pes) => parenIf par (box [string "case",
|
adamc@170
|
298 space,
|
adamc@171
|
299 p_exp e,
|
adamc@170
|
300 space,
|
adamc@170
|
301 string "of",
|
adamc@170
|
302 space,
|
adamc@170
|
303 p_list_sep (box [space, string "|", space])
|
adamc@170
|
304 (fn (p, e) => box [p_pat p,
|
adamc@170
|
305 space,
|
adamc@170
|
306 string "=>",
|
adamc@170
|
307 space,
|
adamc@170
|
308 p_exp e]) pes])
|
adamc@170
|
309
|
adamc@219
|
310 | EWild => string "_"
|
adamc@210
|
311
|
adamc@446
|
312 | ELet (ds, e) => box [string "let",
|
adamc@446
|
313 newline,
|
adamc@446
|
314 box [p_list_sep newline p_edecl ds],
|
adamc@446
|
315 newline,
|
adamc@446
|
316 string "in",
|
adamc@446
|
317 newline,
|
adamc@446
|
318 box [p_exp e],
|
adamc@446
|
319 newline,
|
adamc@446
|
320 string "end"]
|
adamc@446
|
321
|
adamc@623
|
322 | EKAbs (x, e) => box [string x,
|
adamc@623
|
323 space,
|
adamc@623
|
324 string "-->",
|
adamc@623
|
325 space,
|
adamc@623
|
326 p_exp e]
|
adamc@623
|
327
|
adamc@8
|
328 and p_exp e = p_exp' false e
|
adamc@8
|
329
|
adamc@446
|
330 and p_edecl (d, _) =
|
adamc@446
|
331 case d of
|
adamc@446
|
332 EDVal vi => box [string "val",
|
adamc@446
|
333 space,
|
adamc@446
|
334 p_vali vi]
|
adamc@446
|
335 | EDValRec vis => box [string "val",
|
adamc@446
|
336 space,
|
adamc@446
|
337 string "rec",
|
adamc@446
|
338 space,
|
adamc@446
|
339 p_list_sep (box [newline, string "and", space]) p_vali vis]
|
adamc@446
|
340
|
adamc@446
|
341 and p_vali (x, co, e) =
|
adamc@446
|
342 case co of
|
adamc@446
|
343 NONE => box [string x,
|
adamc@446
|
344 space,
|
adamc@446
|
345 string "=",
|
adamc@446
|
346 space,
|
adamc@446
|
347 p_exp e]
|
adamc@446
|
348 | SOME t => box [string x,
|
adamc@446
|
349 space,
|
adamc@446
|
350 string ":",
|
adamc@446
|
351 space,
|
adamc@446
|
352 p_con t,
|
adamc@446
|
353 space,
|
adamc@446
|
354 string "=",
|
adamc@446
|
355 space,
|
adamc@446
|
356 p_exp e]
|
adamc@446
|
357
|
adamc@446
|
358
|
adamc@191
|
359 fun p_datatype (x, xs, cons) =
|
adamc@156
|
360 box [string "datatype",
|
adamc@156
|
361 space,
|
adamc@156
|
362 string x,
|
adamc@191
|
363 p_list_sep (box []) (fn x => box [space, string x]) xs,
|
adamc@156
|
364 space,
|
adamc@156
|
365 string "=",
|
adamc@156
|
366 space,
|
adamc@156
|
367 p_list_sep (box [space, string "|", space])
|
adamc@156
|
368 (fn (x, NONE) => string x
|
adamc@156
|
369 | (x, SOME t) => box [string x, space, string "of", space, p_con t])
|
adamc@156
|
370 cons]
|
adamc@156
|
371
|
adamc@30
|
372 fun p_sgn_item (sgi, _) =
|
adamc@30
|
373 case sgi of
|
adamc@30
|
374 SgiConAbs (x, k) => box [string "con",
|
adamc@30
|
375 space,
|
adamc@30
|
376 string x,
|
adamc@30
|
377 space,
|
adamc@30
|
378 string "::",
|
adamc@30
|
379 space,
|
adamc@30
|
380 p_kind k]
|
adamc@30
|
381 | SgiCon (x, NONE, c) => box [string "con",
|
adamc@30
|
382 space,
|
adamc@30
|
383 string x,
|
adamc@30
|
384 space,
|
adamc@30
|
385 string "=",
|
adamc@30
|
386 space,
|
adamc@30
|
387 p_con c]
|
adamc@30
|
388 | SgiCon (x, SOME k, c) => box [string "con",
|
adamc@30
|
389 space,
|
adamc@30
|
390 string x,
|
adamc@30
|
391 space,
|
adamc@30
|
392 string "::",
|
adamc@30
|
393 space,
|
adamc@30
|
394 p_kind k,
|
adamc@30
|
395 space,
|
adamc@30
|
396 string "=",
|
adamc@30
|
397 space,
|
adamc@30
|
398 p_con c]
|
adamc@156
|
399 | SgiDatatype x => p_datatype x
|
adamc@156
|
400 | SgiDatatypeImp (x, ms, x') =>
|
adamc@156
|
401 box [string "datatype",
|
adamc@156
|
402 space,
|
adamc@156
|
403 string x,
|
adamc@156
|
404 space,
|
adamc@156
|
405 string "=",
|
adamc@156
|
406 space,
|
adamc@156
|
407 string "datatype",
|
adamc@156
|
408 space,
|
adamc@156
|
409 p_list_sep (string ".") string (ms @ [x'])]
|
adamc@30
|
410 | SgiVal (x, c) => box [string "val",
|
adamc@30
|
411 space,
|
adamc@30
|
412 string x,
|
adamc@30
|
413 space,
|
adamc@30
|
414 string ":",
|
adamc@30
|
415 space,
|
adamc@30
|
416 p_con c]
|
adamc@30
|
417 | SgiStr (x, sgn) => box [string "structure",
|
adamc@30
|
418 space,
|
adamc@30
|
419 string x,
|
adamc@30
|
420 space,
|
adamc@30
|
421 string ":",
|
adamc@30
|
422 space,
|
adamc@30
|
423 p_sgn sgn]
|
adamc@59
|
424 | SgiSgn (x, sgn) => box [string "signature",
|
adamc@59
|
425 space,
|
adamc@59
|
426 string x,
|
adamc@59
|
427 space,
|
adamc@59
|
428 string "=",
|
adamc@59
|
429 space,
|
adamc@59
|
430 p_sgn sgn]
|
adamc@58
|
431 | SgiInclude sgn => box [string "include",
|
adamc@58
|
432 space,
|
adamc@58
|
433 p_sgn sgn]
|
adamc@88
|
434 | SgiConstraint (c1, c2) => box [string "constraint",
|
adamc@88
|
435 space,
|
adamc@88
|
436 p_con c1,
|
adamc@88
|
437 space,
|
adamc@88
|
438 string "~",
|
adamc@88
|
439 space,
|
adamc@88
|
440 p_con c2]
|
adamc@563
|
441 | SgiClassAbs (x, k) => box [string "class",
|
adamc@563
|
442 space,
|
adamc@563
|
443 string x,
|
adamc@563
|
444 space,
|
adamc@563
|
445 string "::",
|
adamc@563
|
446 space,
|
adamc@563
|
447 p_kind k]
|
adamc@563
|
448 | SgiClass (x, k, c) => box [string "class",
|
adamc@563
|
449 space,
|
adamc@563
|
450 string x,
|
adamc@563
|
451 space,
|
adamc@563
|
452 string "::",
|
adamc@563
|
453 space,
|
adamc@563
|
454 p_kind k,
|
adamc@563
|
455 space,
|
adamc@563
|
456 string "=",
|
adamc@563
|
457 space,
|
adamc@563
|
458 p_con c]
|
adamc@563
|
459
|
adamc@30
|
460 and p_sgn (sgn, _) =
|
adamc@30
|
461 case sgn of
|
adamc@30
|
462 SgnConst sgis => box [string "sig",
|
adamc@30
|
463 newline,
|
adamc@30
|
464 p_list_sep newline p_sgn_item sgis,
|
adamc@30
|
465 newline,
|
adamc@30
|
466 string "end"]
|
adamc@30
|
467 | SgnVar x => string x
|
adamc@40
|
468 | SgnFun (x, sgn, sgn') => box [string "functor",
|
adamc@40
|
469 space,
|
adamc@40
|
470 string "(",
|
adamc@40
|
471 string x,
|
adamc@40
|
472 space,
|
adamc@40
|
473 string ":",
|
adamc@40
|
474 p_sgn sgn,
|
adamc@40
|
475 string ")",
|
adamc@40
|
476 space,
|
adamc@40
|
477 string ":",
|
adamc@40
|
478 space,
|
adamc@40
|
479 p_sgn sgn']
|
adamc@42
|
480 | SgnWhere (sgn, x, c) => box [p_sgn sgn,
|
adamc@42
|
481 space,
|
adamc@42
|
482 string "where",
|
adamc@42
|
483 space,
|
adamc@42
|
484 string "con",
|
adamc@42
|
485 space,
|
adamc@42
|
486 string x,
|
adamc@42
|
487 space,
|
adamc@42
|
488 string "=",
|
adamc@42
|
489 space,
|
adamc@42
|
490 p_con c]
|
adamc@59
|
491 | SgnProj (m, ms, x) => p_list_sep (string ".") string (m :: ms @ [x])
|
adamc@59
|
492
|
adamc@42
|
493
|
adamc@123
|
494
|
adamc@1
|
495 fun p_decl ((d, _) : decl) =
|
adamc@1
|
496 case d of
|
adamc@1
|
497 DCon (x, NONE, c) => box [string "con",
|
adamc@1
|
498 space,
|
adamc@1
|
499 string x,
|
adamc@1
|
500 space,
|
adamc@1
|
501 string "=",
|
adamc@1
|
502 space,
|
adamc@1
|
503 p_con c]
|
adamc@1
|
504 | DCon (x, SOME k, c) => box [string "con",
|
adamc@1
|
505 space,
|
adamc@1
|
506 string x,
|
adamc@1
|
507 space,
|
adamc@1
|
508 string "::",
|
adamc@1
|
509 space,
|
adamc@1
|
510 p_kind k,
|
adamc@1
|
511 space,
|
adamc@1
|
512 string "=",
|
adamc@1
|
513 space,
|
adamc@1
|
514 p_con c]
|
adamc@156
|
515 | DDatatype x => p_datatype x
|
adamc@156
|
516 | DDatatypeImp (x, ms, x') =>
|
adamc@156
|
517 box [string "datatype",
|
adamc@156
|
518 space,
|
adamc@156
|
519 string x,
|
adamc@156
|
520 space,
|
adamc@156
|
521 string "=",
|
adamc@156
|
522 space,
|
adamc@156
|
523 string "datatype",
|
adamc@156
|
524 space,
|
adamc@156
|
525 p_list_sep (string ".") string (ms @ [x'])]
|
adamc@123
|
526 | DVal vi => box [string "val",
|
adamc@123
|
527 space,
|
adamc@123
|
528 p_vali vi]
|
adamc@123
|
529 | DValRec vis => box [string "val",
|
adamc@123
|
530 space,
|
adamc@123
|
531 string "rec",
|
adamc@123
|
532 space,
|
adamc@123
|
533 p_list_sep (box [newline, string "and", space]) p_vali vis]
|
adamc@1
|
534
|
adamc@30
|
535 | DSgn (x, sgn) => box [string "signature",
|
adamc@30
|
536 space,
|
adamc@30
|
537 string x,
|
adamc@30
|
538 space,
|
adamc@30
|
539 string "=",
|
adamc@30
|
540 space,
|
adamc@30
|
541 p_sgn sgn]
|
adamc@30
|
542 | DStr (x, NONE, str) => box [string "structure",
|
adamc@30
|
543 space,
|
adamc@30
|
544 string x,
|
adamc@30
|
545 space,
|
adamc@30
|
546 string "=",
|
adamc@30
|
547 space,
|
adamc@30
|
548 p_str str]
|
adamc@30
|
549 | DStr (x, SOME sgn, str) => box [string "structure",
|
adamc@30
|
550 space,
|
adamc@30
|
551 string x,
|
adamc@30
|
552 space,
|
adamc@30
|
553 string ":",
|
adamc@30
|
554 space,
|
adamc@30
|
555 p_sgn sgn,
|
adamc@30
|
556 space,
|
adamc@30
|
557 string "=",
|
adamc@30
|
558 space,
|
adamc@30
|
559 p_str str]
|
adamc@48
|
560 | DFfiStr (x, sgn) => box [string "extern",
|
adamc@48
|
561 space,
|
adamc@48
|
562 string "structure",
|
adamc@48
|
563 space,
|
adamc@48
|
564 string x,
|
adamc@48
|
565 space,
|
adamc@48
|
566 string ":",
|
adamc@48
|
567 space,
|
adamc@48
|
568 p_sgn sgn]
|
adamc@61
|
569 | DOpen (m, ms) => box [string "open",
|
adamc@61
|
570 space,
|
adamc@61
|
571 p_list_sep (string ".") string (m :: ms)]
|
adamc@88
|
572 | DConstraint (c1, c2) => box [string "constraint",
|
adamc@88
|
573 space,
|
adamc@88
|
574 p_con c1,
|
adamc@88
|
575 space,
|
adamc@88
|
576 string "~",
|
adamc@88
|
577 space,
|
adamc@88
|
578 p_con c2]
|
adamc@88
|
579 | DOpenConstraints (m, ms) => box [string "open",
|
adamc@88
|
580 space,
|
adamc@88
|
581 string "constraints",
|
adamc@88
|
582 space,
|
adamc@88
|
583 p_list_sep (string ".") string (m :: ms)]
|
adamc@30
|
584
|
adamc@109
|
585 | DExport str => box [string "export",
|
adamc@109
|
586 space,
|
adamc@109
|
587 p_str str]
|
adamc@203
|
588 | DTable (x, c) => box [string "table",
|
adamc@203
|
589 space,
|
adamc@203
|
590 string x,
|
adamc@203
|
591 space,
|
adamc@203
|
592 string ":",
|
adamc@203
|
593 space,
|
adamc@203
|
594 p_con c]
|
adamc@338
|
595 | DSequence x => box [string "sequence",
|
adamc@338
|
596 space,
|
adamc@338
|
597 string x]
|
adamc@563
|
598 | DClass (x, k, c) => box [string "class",
|
adamc@563
|
599 space,
|
adamc@563
|
600 string x,
|
adamc@563
|
601 space,
|
adamc@563
|
602 string "=",
|
adamc@563
|
603 space,
|
adamc@563
|
604 p_con c]
|
adamc@100
|
605
|
adamc@271
|
606 | DDatabase s => box [string "database",
|
adamc@271
|
607 space,
|
adamc@271
|
608 string s]
|
adamc@271
|
609
|
adamc@459
|
610 | DCookie (x, c) => box [string "cookie",
|
adamc@459
|
611 space,
|
adamc@459
|
612 string x,
|
adamc@459
|
613 space,
|
adamc@459
|
614 string ":",
|
adamc@459
|
615 space,
|
adamc@459
|
616 p_con c]
|
adamc@459
|
617
|
adamc@30
|
618 and p_str (str, _) =
|
adamc@30
|
619 case str of
|
adamc@30
|
620 StrConst ds => box [string "struct",
|
adamc@30
|
621 newline,
|
adamc@30
|
622 p_list_sep newline p_decl ds,
|
adamc@30
|
623 newline,
|
adamc@30
|
624 string "end"]
|
adamc@30
|
625 | StrVar x => string x
|
adamc@34
|
626 | StrProj (str, x) => box [p_str str,
|
adamc@34
|
627 string ".",
|
adamc@34
|
628 string x]
|
adamc@40
|
629 | StrFun (x, sgn, NONE, str) => box [string "functor",
|
adamc@40
|
630 space,
|
adamc@40
|
631 string "(",
|
adamc@40
|
632 string x,
|
adamc@40
|
633 space,
|
adamc@40
|
634 string ":",
|
adamc@40
|
635 p_sgn sgn,
|
adamc@40
|
636 string ")",
|
adamc@40
|
637 space,
|
adamc@40
|
638 string "=>",
|
adamc@40
|
639 space,
|
adamc@40
|
640 p_str str]
|
adamc@40
|
641 | StrFun (x, sgn, SOME sgn', str) => box [string "functor",
|
adamc@40
|
642 space,
|
adamc@40
|
643 string "(",
|
adamc@40
|
644 string x,
|
adamc@40
|
645 space,
|
adamc@40
|
646 string ":",
|
adamc@40
|
647 p_sgn sgn,
|
adamc@40
|
648 string ")",
|
adamc@40
|
649 space,
|
adamc@40
|
650 string ":",
|
adamc@40
|
651 space,
|
adamc@40
|
652 p_sgn sgn',
|
adamc@40
|
653 space,
|
adamc@40
|
654 string "=>",
|
adamc@40
|
655 space,
|
adamc@40
|
656 p_str str]
|
adamc@44
|
657 | StrApp (str1, str2) => box [p_str str1,
|
adamc@44
|
658 string "(",
|
adamc@44
|
659 p_str str2,
|
adamc@44
|
660 string ")"]
|
adamc@30
|
661
|
adamc@1
|
662 val p_file = p_list_sep newline p_decl
|
adamc@1
|
663
|
adamc@1
|
664 end
|