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@1
|
53 and p_kind k = p_kind' false k
|
adamc@1
|
54
|
adamc@1
|
55 fun p_explicitness e =
|
adamc@1
|
56 case e of
|
adamc@1
|
57 Explicit => string "::"
|
adamc@1
|
58 | Implicit => string ":::"
|
adamc@1
|
59
|
adamc@1
|
60 fun p_con' par (c, _) =
|
adamc@1
|
61 case c of
|
adamc@1
|
62 CAnnot (c, k) => box [string "(",
|
adamc@1
|
63 p_con c,
|
adamc@1
|
64 space,
|
adamc@1
|
65 string "::",
|
adamc@1
|
66 space,
|
adamc@1
|
67 p_kind k,
|
adamc@1
|
68 string ")"]
|
adamc@1
|
69
|
adamc@1
|
70 | TFun (t1, t2) => parenIf par (box [p_con' true t1,
|
adamc@1
|
71 space,
|
adamc@1
|
72 string "->",
|
adamc@1
|
73 space,
|
adamc@1
|
74 p_con t2])
|
adamc@1
|
75 | TCFun (e, x, k, c) => parenIf par (box [string x,
|
adamc@1
|
76 space,
|
adamc@1
|
77 p_explicitness e,
|
adamc@1
|
78 space,
|
adamc@1
|
79 p_kind k,
|
adamc@1
|
80 space,
|
adamc@1
|
81 string "->",
|
adamc@1
|
82 space,
|
adamc@1
|
83 p_con c])
|
adamc@1
|
84 | TRecord (CRecord xcs, _) => box [string "{",
|
adamc@1
|
85 p_list (fn (x, c) =>
|
adamc@20
|
86 box [p_name x,
|
adamc@1
|
87 space,
|
adamc@1
|
88 string ":",
|
adamc@1
|
89 space,
|
adamc@1
|
90 p_con c]) xcs,
|
adamc@1
|
91 string "}"]
|
adamc@1
|
92 | TRecord c => box [string "$",
|
adamc@1
|
93 p_con' true c]
|
adamc@1
|
94
|
adamc@34
|
95 | CVar (ss, s) => p_list_sep (string ".") string (ss @ [s])
|
adamc@1
|
96 | CApp (c1, c2) => parenIf par (box [p_con c1,
|
adamc@1
|
97 space,
|
adamc@1
|
98 p_con' true c2])
|
adamc@67
|
99 | CAbs (x, NONE, c) => parenIf par (box [string "fn",
|
adamc@67
|
100 space,
|
adamc@67
|
101 string x,
|
adamc@67
|
102 space,
|
adamc@67
|
103 string "=>",
|
adamc@67
|
104 space,
|
adamc@67
|
105 p_con c])
|
adamc@67
|
106 | CAbs (x, SOME k, c) => parenIf par (box [string "fn",
|
adamc@67
|
107 space,
|
adamc@67
|
108 string x,
|
adamc@67
|
109 space,
|
adamc@67
|
110 string "::",
|
adamc@67
|
111 space,
|
adamc@67
|
112 p_kind k,
|
adamc@67
|
113 space,
|
adamc@67
|
114 string "=>",
|
adamc@67
|
115 space,
|
adamc@67
|
116 p_con c])
|
adamc@84
|
117 | CDisjoint (c1, c2, c3) => parenIf par (box [p_con c1,
|
adamc@84
|
118 space,
|
adamc@84
|
119 string "~",
|
adamc@84
|
120 space,
|
adamc@84
|
121 p_con c2,
|
adamc@84
|
122 space,
|
adamc@84
|
123 string "=>",
|
adamc@84
|
124 space,
|
adamc@84
|
125 p_con c3])
|
adamc@1
|
126
|
adamc@1
|
127 | CName s => box [string "#", string s]
|
adamc@1
|
128
|
adamc@1
|
129 | CRecord xcs => box [string "[",
|
adamc@1
|
130 p_list (fn (x, c) =>
|
adamc@1
|
131 box [p_con x,
|
adamc@1
|
132 space,
|
adamc@1
|
133 string "=",
|
adamc@1
|
134 space,
|
adamc@1
|
135 p_con c]) xcs,
|
adamc@1
|
136 string "]"]
|
adamc@1
|
137 | CConcat (c1, c2) => parenIf par (box [p_con' true c1,
|
adamc@1
|
138 space,
|
adamc@1
|
139 string "++",
|
adamc@1
|
140 space,
|
adamc@1
|
141 p_con c2])
|
adamc@67
|
142 | CFold => string "fold"
|
adamc@82
|
143
|
adamc@82
|
144 | CUnit => string "()"
|
adamc@82
|
145
|
adamc@18
|
146 | CWild k => box [string "(_",
|
adamc@18
|
147 space,
|
adamc@18
|
148 string "::",
|
adamc@18
|
149 space,
|
adamc@223
|
150 p_kind k,
|
adamc@223
|
151 string ")"]
|
adamc@207
|
152
|
adamc@207
|
153 | CTuple cs => box [string "(",
|
adamc@207
|
154 p_list p_con cs,
|
adamc@207
|
155 string ")"]
|
adamc@207
|
156 | CProj (c, n) => box [p_con c,
|
adamc@207
|
157 string ".",
|
adamc@207
|
158 string (Int.toString n)]
|
adamc@1
|
159
|
adamc@1
|
160 and p_con c = p_con' false c
|
adamc@1
|
161
|
adamc@20
|
162 and p_name (all as (c, _)) =
|
adamc@20
|
163 case c of
|
adamc@20
|
164 CName s => string s
|
adamc@20
|
165 | _ => p_con all
|
adamc@20
|
166
|
adamc@170
|
167 fun p_pat' par (p, _) =
|
adamc@170
|
168 case p of
|
adamc@170
|
169 PWild => string "_"
|
adamc@170
|
170 | PVar s => string s
|
adamc@173
|
171 | PPrim p => Prim.p_t p
|
adamc@170
|
172 | PCon (ms, x, NONE) => p_list_sep (string ".") string (ms @ [x])
|
adamc@170
|
173 | PCon (ms, x, SOME p) => parenIf par (box [p_list_sep (string ".") string (ms @ [x]),
|
adamc@170
|
174 space,
|
adamc@170
|
175 p_pat' true p])
|
adamc@174
|
176 | PRecord (xps, flex) =>
|
adamc@174
|
177 let
|
adamc@175
|
178 val pps = map (fn (x, p) => box [string x, space, string "=", space, p_pat p]) xps
|
adamc@174
|
179 in
|
adamc@174
|
180 box [string "{",
|
adamc@174
|
181 p_list_sep (box [string ",", space]) (fn x => x)
|
adamc@174
|
182 (if flex then
|
adamc@175
|
183 pps @ [string "..."]
|
adamc@174
|
184 else
|
adamc@175
|
185 pps),
|
adamc@174
|
186 string "}"]
|
adamc@174
|
187 end
|
adamc@170
|
188
|
adamc@174
|
189 and p_pat x = p_pat' false x
|
adamc@170
|
190
|
adamc@8
|
191 fun p_exp' par (e, _) =
|
adamc@8
|
192 case e of
|
adamc@8
|
193 EAnnot (e, t) => box [string "(",
|
adamc@8
|
194 p_exp e,
|
adamc@8
|
195 space,
|
adamc@8
|
196 string ":",
|
adamc@8
|
197 space,
|
adamc@8
|
198 p_con t,
|
adamc@8
|
199 string ")"]
|
adamc@8
|
200
|
adamc@14
|
201 | EPrim p => Prim.p_t p
|
adamc@403
|
202 | EVar (ss, s, _) => p_list_sep (string ".") string (ss @ [s])
|
adamc@8
|
203 | EApp (e1, e2) => parenIf par (box [p_exp e1,
|
adamc@8
|
204 space,
|
adamc@8
|
205 p_exp' true e2])
|
adamc@8
|
206 | EAbs (x, NONE, e) => parenIf par (box [string "fn",
|
adamc@8
|
207 space,
|
adamc@8
|
208 string x,
|
adamc@8
|
209 space,
|
adamc@8
|
210 string "=>",
|
adamc@8
|
211 space,
|
adamc@8
|
212 p_exp e])
|
adamc@8
|
213 | EAbs (x, SOME t, e) => parenIf par (box [string "fn",
|
adamc@8
|
214 space,
|
adamc@8
|
215 string x,
|
adamc@8
|
216 space,
|
adamc@8
|
217 string ":",
|
adamc@8
|
218 space,
|
adamc@8
|
219 p_con t,
|
adamc@8
|
220 space,
|
adamc@8
|
221 string "=>",
|
adamc@8
|
222 space,
|
adamc@8
|
223 p_exp e])
|
adamc@8
|
224 | ECApp (e, c) => parenIf par (box [p_exp e,
|
adamc@8
|
225 space,
|
adamc@8
|
226 string "[",
|
adamc@8
|
227 p_con c,
|
adamc@8
|
228 string "]"])
|
adamc@8
|
229 | ECAbs (exp, x, k, e) => parenIf par (box [string "fn",
|
adamc@8
|
230 space,
|
adamc@8
|
231 string x,
|
adamc@8
|
232 space,
|
adamc@8
|
233 p_explicitness exp,
|
adamc@8
|
234 space,
|
adamc@8
|
235 p_kind k,
|
adamc@8
|
236 space,
|
adamc@8
|
237 string "=>",
|
adamc@8
|
238 space,
|
adamc@8
|
239 p_exp e])
|
adamc@85
|
240 | EDisjoint (c1, c2, e) => parenIf par (box [p_con c1,
|
adamc@85
|
241 space,
|
adamc@85
|
242 string "~",
|
adamc@85
|
243 space,
|
adamc@85
|
244 p_con c2,
|
adamc@85
|
245 space,
|
adamc@85
|
246 string "=>",
|
adamc@85
|
247 space,
|
adamc@85
|
248 p_exp e])
|
adamc@8
|
249
|
adamc@12
|
250 | ERecord xes => box [string "{",
|
adamc@12
|
251 p_list (fn (x, e) =>
|
adamc@21
|
252 box [p_name x,
|
adamc@12
|
253 space,
|
adamc@12
|
254 string "=",
|
adamc@12
|
255 space,
|
adamc@12
|
256 p_exp e]) xes,
|
adamc@12
|
257 string "}"]
|
adamc@12
|
258 | EField (e, c) => box [p_exp' true e,
|
adamc@12
|
259 string ".",
|
adamc@12
|
260 p_con' true c]
|
adamc@445
|
261 | EConcat (e1, e2) => parenIf par (box [p_exp' true e1,
|
adamc@445
|
262 space,
|
adamc@445
|
263 string "++",
|
adamc@445
|
264 space,
|
adamc@445
|
265 p_exp' true e2])
|
adamc@149
|
266 | ECut (e, c) => parenIf par (box [p_exp' true e,
|
adamc@149
|
267 space,
|
adamc@149
|
268 string "--",
|
adamc@149
|
269 space,
|
adamc@149
|
270 p_con' true c])
|
adamc@71
|
271 | EFold => string "fold"
|
adamc@12
|
272
|
adamc@170
|
273 | ECase (e, pes) => parenIf par (box [string "case",
|
adamc@170
|
274 space,
|
adamc@171
|
275 p_exp e,
|
adamc@170
|
276 space,
|
adamc@170
|
277 string "of",
|
adamc@170
|
278 space,
|
adamc@170
|
279 p_list_sep (box [space, string "|", space])
|
adamc@170
|
280 (fn (p, e) => box [p_pat p,
|
adamc@170
|
281 space,
|
adamc@170
|
282 string "=>",
|
adamc@170
|
283 space,
|
adamc@170
|
284 p_exp e]) pes])
|
adamc@170
|
285
|
adamc@219
|
286 | EWild => string "_"
|
adamc@210
|
287
|
adamc@446
|
288 | ELet (ds, e) => box [string "let",
|
adamc@446
|
289 newline,
|
adamc@446
|
290 box [p_list_sep newline p_edecl ds],
|
adamc@446
|
291 newline,
|
adamc@446
|
292 string "in",
|
adamc@446
|
293 newline,
|
adamc@446
|
294 box [p_exp e],
|
adamc@446
|
295 newline,
|
adamc@446
|
296 string "end"]
|
adamc@446
|
297
|
adamc@8
|
298 and p_exp e = p_exp' false e
|
adamc@8
|
299
|
adamc@446
|
300 and p_edecl (d, _) =
|
adamc@446
|
301 case d of
|
adamc@446
|
302 EDVal vi => box [string "val",
|
adamc@446
|
303 space,
|
adamc@446
|
304 p_vali vi]
|
adamc@446
|
305 | EDValRec vis => box [string "val",
|
adamc@446
|
306 space,
|
adamc@446
|
307 string "rec",
|
adamc@446
|
308 space,
|
adamc@446
|
309 p_list_sep (box [newline, string "and", space]) p_vali vis]
|
adamc@446
|
310
|
adamc@446
|
311 and p_vali (x, co, e) =
|
adamc@446
|
312 case co of
|
adamc@446
|
313 NONE => box [string x,
|
adamc@446
|
314 space,
|
adamc@446
|
315 string "=",
|
adamc@446
|
316 space,
|
adamc@446
|
317 p_exp e]
|
adamc@446
|
318 | SOME t => box [string x,
|
adamc@446
|
319 space,
|
adamc@446
|
320 string ":",
|
adamc@446
|
321 space,
|
adamc@446
|
322 p_con t,
|
adamc@446
|
323 space,
|
adamc@446
|
324 string "=",
|
adamc@446
|
325 space,
|
adamc@446
|
326 p_exp e]
|
adamc@446
|
327
|
adamc@446
|
328
|
adamc@191
|
329 fun p_datatype (x, xs, cons) =
|
adamc@156
|
330 box [string "datatype",
|
adamc@156
|
331 space,
|
adamc@156
|
332 string x,
|
adamc@191
|
333 p_list_sep (box []) (fn x => box [space, string x]) xs,
|
adamc@156
|
334 space,
|
adamc@156
|
335 string "=",
|
adamc@156
|
336 space,
|
adamc@156
|
337 p_list_sep (box [space, string "|", space])
|
adamc@156
|
338 (fn (x, NONE) => string x
|
adamc@156
|
339 | (x, SOME t) => box [string x, space, string "of", space, p_con t])
|
adamc@156
|
340 cons]
|
adamc@156
|
341
|
adamc@30
|
342 fun p_sgn_item (sgi, _) =
|
adamc@30
|
343 case sgi of
|
adamc@30
|
344 SgiConAbs (x, k) => box [string "con",
|
adamc@30
|
345 space,
|
adamc@30
|
346 string x,
|
adamc@30
|
347 space,
|
adamc@30
|
348 string "::",
|
adamc@30
|
349 space,
|
adamc@30
|
350 p_kind k]
|
adamc@30
|
351 | SgiCon (x, NONE, c) => box [string "con",
|
adamc@30
|
352 space,
|
adamc@30
|
353 string x,
|
adamc@30
|
354 space,
|
adamc@30
|
355 string "=",
|
adamc@30
|
356 space,
|
adamc@30
|
357 p_con c]
|
adamc@30
|
358 | SgiCon (x, SOME k, c) => box [string "con",
|
adamc@30
|
359 space,
|
adamc@30
|
360 string x,
|
adamc@30
|
361 space,
|
adamc@30
|
362 string "::",
|
adamc@30
|
363 space,
|
adamc@30
|
364 p_kind k,
|
adamc@30
|
365 space,
|
adamc@30
|
366 string "=",
|
adamc@30
|
367 space,
|
adamc@30
|
368 p_con c]
|
adamc@156
|
369 | SgiDatatype x => p_datatype x
|
adamc@156
|
370 | SgiDatatypeImp (x, ms, x') =>
|
adamc@156
|
371 box [string "datatype",
|
adamc@156
|
372 space,
|
adamc@156
|
373 string x,
|
adamc@156
|
374 space,
|
adamc@156
|
375 string "=",
|
adamc@156
|
376 space,
|
adamc@156
|
377 string "datatype",
|
adamc@156
|
378 space,
|
adamc@156
|
379 p_list_sep (string ".") string (ms @ [x'])]
|
adamc@30
|
380 | SgiVal (x, c) => box [string "val",
|
adamc@30
|
381 space,
|
adamc@30
|
382 string x,
|
adamc@30
|
383 space,
|
adamc@30
|
384 string ":",
|
adamc@30
|
385 space,
|
adamc@30
|
386 p_con c]
|
adamc@30
|
387 | SgiStr (x, sgn) => box [string "structure",
|
adamc@30
|
388 space,
|
adamc@30
|
389 string x,
|
adamc@30
|
390 space,
|
adamc@30
|
391 string ":",
|
adamc@30
|
392 space,
|
adamc@30
|
393 p_sgn sgn]
|
adamc@59
|
394 | SgiSgn (x, sgn) => box [string "signature",
|
adamc@59
|
395 space,
|
adamc@59
|
396 string x,
|
adamc@59
|
397 space,
|
adamc@59
|
398 string "=",
|
adamc@59
|
399 space,
|
adamc@59
|
400 p_sgn sgn]
|
adamc@58
|
401 | SgiInclude sgn => box [string "include",
|
adamc@58
|
402 space,
|
adamc@58
|
403 p_sgn sgn]
|
adamc@88
|
404 | SgiConstraint (c1, c2) => box [string "constraint",
|
adamc@88
|
405 space,
|
adamc@88
|
406 p_con c1,
|
adamc@88
|
407 space,
|
adamc@88
|
408 string "~",
|
adamc@88
|
409 space,
|
adamc@88
|
410 p_con c2]
|
adamc@203
|
411 | SgiTable (x, c) => box [string "table",
|
adamc@203
|
412 space,
|
adamc@203
|
413 string x,
|
adamc@203
|
414 space,
|
adamc@203
|
415 string ":",
|
adamc@203
|
416 space,
|
adamc@203
|
417 p_con c]
|
adamc@338
|
418 | SgiSequence x => box [string "sequence",
|
adamc@338
|
419 space,
|
adamc@338
|
420 string x]
|
adamc@211
|
421 | SgiClassAbs x => box [string "class",
|
adamc@211
|
422 space,
|
adamc@211
|
423 string x]
|
adamc@211
|
424 | SgiClass (x, c) => box [string "class",
|
adamc@211
|
425 space,
|
adamc@211
|
426 string x,
|
adamc@211
|
427 space,
|
adamc@211
|
428 string "=",
|
adamc@211
|
429 space,
|
adamc@211
|
430 p_con c]
|
adamc@459
|
431 | SgiCookie (x, c) => box [string "cookie",
|
adamc@459
|
432 space,
|
adamc@459
|
433 string x,
|
adamc@459
|
434 space,
|
adamc@459
|
435 string ":",
|
adamc@459
|
436 space,
|
adamc@459
|
437 p_con c]
|
adamc@30
|
438
|
adamc@30
|
439 and p_sgn (sgn, _) =
|
adamc@30
|
440 case sgn of
|
adamc@30
|
441 SgnConst sgis => box [string "sig",
|
adamc@30
|
442 newline,
|
adamc@30
|
443 p_list_sep newline p_sgn_item sgis,
|
adamc@30
|
444 newline,
|
adamc@30
|
445 string "end"]
|
adamc@30
|
446 | SgnVar x => string x
|
adamc@40
|
447 | SgnFun (x, sgn, sgn') => box [string "functor",
|
adamc@40
|
448 space,
|
adamc@40
|
449 string "(",
|
adamc@40
|
450 string x,
|
adamc@40
|
451 space,
|
adamc@40
|
452 string ":",
|
adamc@40
|
453 p_sgn sgn,
|
adamc@40
|
454 string ")",
|
adamc@40
|
455 space,
|
adamc@40
|
456 string ":",
|
adamc@40
|
457 space,
|
adamc@40
|
458 p_sgn sgn']
|
adamc@42
|
459 | SgnWhere (sgn, x, c) => box [p_sgn sgn,
|
adamc@42
|
460 space,
|
adamc@42
|
461 string "where",
|
adamc@42
|
462 space,
|
adamc@42
|
463 string "con",
|
adamc@42
|
464 space,
|
adamc@42
|
465 string x,
|
adamc@42
|
466 space,
|
adamc@42
|
467 string "=",
|
adamc@42
|
468 space,
|
adamc@42
|
469 p_con c]
|
adamc@59
|
470 | SgnProj (m, ms, x) => p_list_sep (string ".") string (m :: ms @ [x])
|
adamc@59
|
471
|
adamc@42
|
472
|
adamc@123
|
473
|
adamc@1
|
474 fun p_decl ((d, _) : decl) =
|
adamc@1
|
475 case d of
|
adamc@1
|
476 DCon (x, NONE, c) => box [string "con",
|
adamc@1
|
477 space,
|
adamc@1
|
478 string x,
|
adamc@1
|
479 space,
|
adamc@1
|
480 string "=",
|
adamc@1
|
481 space,
|
adamc@1
|
482 p_con c]
|
adamc@1
|
483 | DCon (x, SOME k, c) => box [string "con",
|
adamc@1
|
484 space,
|
adamc@1
|
485 string x,
|
adamc@1
|
486 space,
|
adamc@1
|
487 string "::",
|
adamc@1
|
488 space,
|
adamc@1
|
489 p_kind k,
|
adamc@1
|
490 space,
|
adamc@1
|
491 string "=",
|
adamc@1
|
492 space,
|
adamc@1
|
493 p_con c]
|
adamc@156
|
494 | DDatatype x => p_datatype x
|
adamc@156
|
495 | DDatatypeImp (x, ms, x') =>
|
adamc@156
|
496 box [string "datatype",
|
adamc@156
|
497 space,
|
adamc@156
|
498 string x,
|
adamc@156
|
499 space,
|
adamc@156
|
500 string "=",
|
adamc@156
|
501 space,
|
adamc@156
|
502 string "datatype",
|
adamc@156
|
503 space,
|
adamc@156
|
504 p_list_sep (string ".") string (ms @ [x'])]
|
adamc@123
|
505 | DVal vi => box [string "val",
|
adamc@123
|
506 space,
|
adamc@123
|
507 p_vali vi]
|
adamc@123
|
508 | DValRec vis => box [string "val",
|
adamc@123
|
509 space,
|
adamc@123
|
510 string "rec",
|
adamc@123
|
511 space,
|
adamc@123
|
512 p_list_sep (box [newline, string "and", space]) p_vali vis]
|
adamc@1
|
513
|
adamc@30
|
514 | DSgn (x, sgn) => box [string "signature",
|
adamc@30
|
515 space,
|
adamc@30
|
516 string x,
|
adamc@30
|
517 space,
|
adamc@30
|
518 string "=",
|
adamc@30
|
519 space,
|
adamc@30
|
520 p_sgn sgn]
|
adamc@30
|
521 | DStr (x, NONE, str) => box [string "structure",
|
adamc@30
|
522 space,
|
adamc@30
|
523 string x,
|
adamc@30
|
524 space,
|
adamc@30
|
525 string "=",
|
adamc@30
|
526 space,
|
adamc@30
|
527 p_str str]
|
adamc@30
|
528 | DStr (x, SOME sgn, str) => box [string "structure",
|
adamc@30
|
529 space,
|
adamc@30
|
530 string x,
|
adamc@30
|
531 space,
|
adamc@30
|
532 string ":",
|
adamc@30
|
533 space,
|
adamc@30
|
534 p_sgn sgn,
|
adamc@30
|
535 space,
|
adamc@30
|
536 string "=",
|
adamc@30
|
537 space,
|
adamc@30
|
538 p_str str]
|
adamc@48
|
539 | DFfiStr (x, sgn) => box [string "extern",
|
adamc@48
|
540 space,
|
adamc@48
|
541 string "structure",
|
adamc@48
|
542 space,
|
adamc@48
|
543 string x,
|
adamc@48
|
544 space,
|
adamc@48
|
545 string ":",
|
adamc@48
|
546 space,
|
adamc@48
|
547 p_sgn sgn]
|
adamc@61
|
548 | DOpen (m, ms) => box [string "open",
|
adamc@61
|
549 space,
|
adamc@61
|
550 p_list_sep (string ".") string (m :: ms)]
|
adamc@88
|
551 | DConstraint (c1, c2) => box [string "constraint",
|
adamc@88
|
552 space,
|
adamc@88
|
553 p_con c1,
|
adamc@88
|
554 space,
|
adamc@88
|
555 string "~",
|
adamc@88
|
556 space,
|
adamc@88
|
557 p_con c2]
|
adamc@88
|
558 | DOpenConstraints (m, ms) => box [string "open",
|
adamc@88
|
559 space,
|
adamc@88
|
560 string "constraints",
|
adamc@88
|
561 space,
|
adamc@88
|
562 p_list_sep (string ".") string (m :: ms)]
|
adamc@30
|
563
|
adamc@109
|
564 | DExport str => box [string "export",
|
adamc@109
|
565 space,
|
adamc@109
|
566 p_str str]
|
adamc@203
|
567 | DTable (x, c) => box [string "table",
|
adamc@203
|
568 space,
|
adamc@203
|
569 string x,
|
adamc@203
|
570 space,
|
adamc@203
|
571 string ":",
|
adamc@203
|
572 space,
|
adamc@203
|
573 p_con c]
|
adamc@338
|
574 | DSequence x => box [string "sequence",
|
adamc@338
|
575 space,
|
adamc@338
|
576 string x]
|
adamc@211
|
577 | DClass (x, c) => box [string "class",
|
adamc@211
|
578 space,
|
adamc@211
|
579 string x,
|
adamc@211
|
580 space,
|
adamc@211
|
581 string "=",
|
adamc@211
|
582 space,
|
adamc@211
|
583 p_con c]
|
adamc@100
|
584
|
adamc@271
|
585 | DDatabase s => box [string "database",
|
adamc@271
|
586 space,
|
adamc@271
|
587 string s]
|
adamc@271
|
588
|
adamc@459
|
589 | DCookie (x, c) => box [string "cookie",
|
adamc@459
|
590 space,
|
adamc@459
|
591 string x,
|
adamc@459
|
592 space,
|
adamc@459
|
593 string ":",
|
adamc@459
|
594 space,
|
adamc@459
|
595 p_con c]
|
adamc@459
|
596
|
adamc@30
|
597 and p_str (str, _) =
|
adamc@30
|
598 case str of
|
adamc@30
|
599 StrConst ds => box [string "struct",
|
adamc@30
|
600 newline,
|
adamc@30
|
601 p_list_sep newline p_decl ds,
|
adamc@30
|
602 newline,
|
adamc@30
|
603 string "end"]
|
adamc@30
|
604 | StrVar x => string x
|
adamc@34
|
605 | StrProj (str, x) => box [p_str str,
|
adamc@34
|
606 string ".",
|
adamc@34
|
607 string x]
|
adamc@40
|
608 | StrFun (x, sgn, NONE, str) => box [string "functor",
|
adamc@40
|
609 space,
|
adamc@40
|
610 string "(",
|
adamc@40
|
611 string x,
|
adamc@40
|
612 space,
|
adamc@40
|
613 string ":",
|
adamc@40
|
614 p_sgn sgn,
|
adamc@40
|
615 string ")",
|
adamc@40
|
616 space,
|
adamc@40
|
617 string "=>",
|
adamc@40
|
618 space,
|
adamc@40
|
619 p_str str]
|
adamc@40
|
620 | StrFun (x, sgn, SOME sgn', str) => box [string "functor",
|
adamc@40
|
621 space,
|
adamc@40
|
622 string "(",
|
adamc@40
|
623 string x,
|
adamc@40
|
624 space,
|
adamc@40
|
625 string ":",
|
adamc@40
|
626 p_sgn sgn,
|
adamc@40
|
627 string ")",
|
adamc@40
|
628 space,
|
adamc@40
|
629 string ":",
|
adamc@40
|
630 space,
|
adamc@40
|
631 p_sgn sgn',
|
adamc@40
|
632 space,
|
adamc@40
|
633 string "=>",
|
adamc@40
|
634 space,
|
adamc@40
|
635 p_str str]
|
adamc@44
|
636 | StrApp (str1, str2) => box [p_str str1,
|
adamc@44
|
637 string "(",
|
adamc@44
|
638 p_str str2,
|
adamc@44
|
639 string ")"]
|
adamc@30
|
640
|
adamc@1
|
641 val p_file = p_list_sep newline p_decl
|
adamc@1
|
642
|
adamc@1
|
643 end
|