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@629
|
270 | EDisjointApp e => parenIf par (box [p_exp e,
|
adamc@629
|
271 space,
|
adamc@629
|
272 string "!"])
|
adamc@8
|
273
|
adamc@12
|
274 | ERecord xes => box [string "{",
|
adamc@12
|
275 p_list (fn (x, e) =>
|
adamc@21
|
276 box [p_name x,
|
adamc@12
|
277 space,
|
adamc@12
|
278 string "=",
|
adamc@12
|
279 space,
|
adamc@12
|
280 p_exp e]) xes,
|
adamc@12
|
281 string "}"]
|
adamc@12
|
282 | EField (e, c) => box [p_exp' true e,
|
adamc@12
|
283 string ".",
|
adamc@12
|
284 p_con' true c]
|
adamc@445
|
285 | EConcat (e1, e2) => parenIf par (box [p_exp' true e1,
|
adamc@445
|
286 space,
|
adamc@445
|
287 string "++",
|
adamc@445
|
288 space,
|
adamc@445
|
289 p_exp' true e2])
|
adamc@149
|
290 | ECut (e, c) => parenIf par (box [p_exp' true e,
|
adamc@149
|
291 space,
|
adamc@149
|
292 string "--",
|
adamc@149
|
293 space,
|
adamc@149
|
294 p_con' true c])
|
adamc@493
|
295 | ECutMulti (e, c) => parenIf par (box [p_exp' true e,
|
adamc@493
|
296 space,
|
adamc@493
|
297 string "---",
|
adamc@493
|
298 space,
|
adamc@493
|
299 p_con' true c])
|
adamc@170
|
300 | ECase (e, pes) => parenIf par (box [string "case",
|
adamc@170
|
301 space,
|
adamc@171
|
302 p_exp e,
|
adamc@170
|
303 space,
|
adamc@170
|
304 string "of",
|
adamc@170
|
305 space,
|
adamc@170
|
306 p_list_sep (box [space, string "|", space])
|
adamc@170
|
307 (fn (p, e) => box [p_pat p,
|
adamc@170
|
308 space,
|
adamc@170
|
309 string "=>",
|
adamc@170
|
310 space,
|
adamc@170
|
311 p_exp e]) pes])
|
adamc@170
|
312
|
adamc@219
|
313 | EWild => string "_"
|
adamc@210
|
314
|
adamc@446
|
315 | ELet (ds, e) => box [string "let",
|
adamc@446
|
316 newline,
|
adamc@446
|
317 box [p_list_sep newline p_edecl ds],
|
adamc@446
|
318 newline,
|
adamc@446
|
319 string "in",
|
adamc@446
|
320 newline,
|
adamc@446
|
321 box [p_exp e],
|
adamc@446
|
322 newline,
|
adamc@446
|
323 string "end"]
|
adamc@446
|
324
|
adamc@623
|
325 | EKAbs (x, e) => box [string x,
|
adamc@623
|
326 space,
|
adamc@623
|
327 string "-->",
|
adamc@623
|
328 space,
|
adamc@623
|
329 p_exp e]
|
adamc@623
|
330
|
adamc@8
|
331 and p_exp e = p_exp' false e
|
adamc@8
|
332
|
adamc@446
|
333 and p_edecl (d, _) =
|
adamc@446
|
334 case d of
|
adamc@446
|
335 EDVal vi => box [string "val",
|
adamc@446
|
336 space,
|
adamc@446
|
337 p_vali vi]
|
adamc@446
|
338 | EDValRec vis => box [string "val",
|
adamc@446
|
339 space,
|
adamc@446
|
340 string "rec",
|
adamc@446
|
341 space,
|
adamc@446
|
342 p_list_sep (box [newline, string "and", space]) p_vali vis]
|
adamc@446
|
343
|
adamc@446
|
344 and p_vali (x, co, e) =
|
adamc@446
|
345 case co of
|
adamc@446
|
346 NONE => box [string x,
|
adamc@446
|
347 space,
|
adamc@446
|
348 string "=",
|
adamc@446
|
349 space,
|
adamc@446
|
350 p_exp e]
|
adamc@446
|
351 | SOME t => box [string x,
|
adamc@446
|
352 space,
|
adamc@446
|
353 string ":",
|
adamc@446
|
354 space,
|
adamc@446
|
355 p_con t,
|
adamc@446
|
356 space,
|
adamc@446
|
357 string "=",
|
adamc@446
|
358 space,
|
adamc@446
|
359 p_exp e]
|
adamc@446
|
360
|
adamc@446
|
361
|
adamc@191
|
362 fun p_datatype (x, xs, cons) =
|
adamc@156
|
363 box [string "datatype",
|
adamc@156
|
364 space,
|
adamc@156
|
365 string x,
|
adamc@191
|
366 p_list_sep (box []) (fn x => box [space, string x]) xs,
|
adamc@156
|
367 space,
|
adamc@156
|
368 string "=",
|
adamc@156
|
369 space,
|
adamc@156
|
370 p_list_sep (box [space, string "|", space])
|
adamc@156
|
371 (fn (x, NONE) => string x
|
adamc@156
|
372 | (x, SOME t) => box [string x, space, string "of", space, p_con t])
|
adamc@156
|
373 cons]
|
adamc@156
|
374
|
adamc@30
|
375 fun p_sgn_item (sgi, _) =
|
adamc@30
|
376 case sgi of
|
adamc@30
|
377 SgiConAbs (x, k) => box [string "con",
|
adamc@30
|
378 space,
|
adamc@30
|
379 string x,
|
adamc@30
|
380 space,
|
adamc@30
|
381 string "::",
|
adamc@30
|
382 space,
|
adamc@30
|
383 p_kind k]
|
adamc@30
|
384 | SgiCon (x, NONE, c) => box [string "con",
|
adamc@30
|
385 space,
|
adamc@30
|
386 string x,
|
adamc@30
|
387 space,
|
adamc@30
|
388 string "=",
|
adamc@30
|
389 space,
|
adamc@30
|
390 p_con c]
|
adamc@30
|
391 | SgiCon (x, SOME k, c) => box [string "con",
|
adamc@30
|
392 space,
|
adamc@30
|
393 string x,
|
adamc@30
|
394 space,
|
adamc@30
|
395 string "::",
|
adamc@30
|
396 space,
|
adamc@30
|
397 p_kind k,
|
adamc@30
|
398 space,
|
adamc@30
|
399 string "=",
|
adamc@30
|
400 space,
|
adamc@30
|
401 p_con c]
|
adamc@156
|
402 | SgiDatatype x => p_datatype x
|
adamc@156
|
403 | SgiDatatypeImp (x, ms, x') =>
|
adamc@156
|
404 box [string "datatype",
|
adamc@156
|
405 space,
|
adamc@156
|
406 string x,
|
adamc@156
|
407 space,
|
adamc@156
|
408 string "=",
|
adamc@156
|
409 space,
|
adamc@156
|
410 string "datatype",
|
adamc@156
|
411 space,
|
adamc@156
|
412 p_list_sep (string ".") string (ms @ [x'])]
|
adamc@30
|
413 | SgiVal (x, c) => box [string "val",
|
adamc@30
|
414 space,
|
adamc@30
|
415 string x,
|
adamc@30
|
416 space,
|
adamc@30
|
417 string ":",
|
adamc@30
|
418 space,
|
adamc@30
|
419 p_con c]
|
adamc@706
|
420 | SgiTable (x, c, e) => box [string "table",
|
adamc@706
|
421 space,
|
adamc@706
|
422 string x,
|
adamc@706
|
423 space,
|
adamc@706
|
424 string ":",
|
adamc@706
|
425 space,
|
adamc@706
|
426 p_con c,
|
adamc@706
|
427 space,
|
adamc@706
|
428 string "constraints",
|
adamc@706
|
429 space,
|
adamc@706
|
430 p_exp e]
|
adamc@30
|
431 | SgiStr (x, sgn) => box [string "structure",
|
adamc@30
|
432 space,
|
adamc@30
|
433 string x,
|
adamc@30
|
434 space,
|
adamc@30
|
435 string ":",
|
adamc@30
|
436 space,
|
adamc@30
|
437 p_sgn sgn]
|
adamc@59
|
438 | SgiSgn (x, sgn) => box [string "signature",
|
adamc@59
|
439 space,
|
adamc@59
|
440 string x,
|
adamc@59
|
441 space,
|
adamc@59
|
442 string "=",
|
adamc@59
|
443 space,
|
adamc@59
|
444 p_sgn sgn]
|
adamc@58
|
445 | SgiInclude sgn => box [string "include",
|
adamc@58
|
446 space,
|
adamc@58
|
447 p_sgn sgn]
|
adamc@88
|
448 | SgiConstraint (c1, c2) => box [string "constraint",
|
adamc@88
|
449 space,
|
adamc@88
|
450 p_con c1,
|
adamc@88
|
451 space,
|
adamc@88
|
452 string "~",
|
adamc@88
|
453 space,
|
adamc@88
|
454 p_con c2]
|
adamc@563
|
455 | SgiClassAbs (x, k) => box [string "class",
|
adamc@563
|
456 space,
|
adamc@563
|
457 string x,
|
adamc@563
|
458 space,
|
adamc@563
|
459 string "::",
|
adamc@563
|
460 space,
|
adamc@563
|
461 p_kind k]
|
adamc@563
|
462 | SgiClass (x, k, c) => box [string "class",
|
adamc@563
|
463 space,
|
adamc@563
|
464 string x,
|
adamc@563
|
465 space,
|
adamc@563
|
466 string "::",
|
adamc@563
|
467 space,
|
adamc@563
|
468 p_kind k,
|
adamc@563
|
469 space,
|
adamc@563
|
470 string "=",
|
adamc@563
|
471 space,
|
adamc@563
|
472 p_con c]
|
adamc@563
|
473
|
adamc@30
|
474 and p_sgn (sgn, _) =
|
adamc@30
|
475 case sgn of
|
adamc@30
|
476 SgnConst sgis => box [string "sig",
|
adamc@30
|
477 newline,
|
adamc@30
|
478 p_list_sep newline p_sgn_item sgis,
|
adamc@30
|
479 newline,
|
adamc@30
|
480 string "end"]
|
adamc@30
|
481 | SgnVar x => string x
|
adamc@40
|
482 | SgnFun (x, sgn, sgn') => box [string "functor",
|
adamc@40
|
483 space,
|
adamc@40
|
484 string "(",
|
adamc@40
|
485 string x,
|
adamc@40
|
486 space,
|
adamc@40
|
487 string ":",
|
adamc@40
|
488 p_sgn sgn,
|
adamc@40
|
489 string ")",
|
adamc@40
|
490 space,
|
adamc@40
|
491 string ":",
|
adamc@40
|
492 space,
|
adamc@40
|
493 p_sgn sgn']
|
adamc@42
|
494 | SgnWhere (sgn, x, c) => box [p_sgn sgn,
|
adamc@42
|
495 space,
|
adamc@42
|
496 string "where",
|
adamc@42
|
497 space,
|
adamc@42
|
498 string "con",
|
adamc@42
|
499 space,
|
adamc@42
|
500 string x,
|
adamc@42
|
501 space,
|
adamc@42
|
502 string "=",
|
adamc@42
|
503 space,
|
adamc@42
|
504 p_con c]
|
adamc@59
|
505 | SgnProj (m, ms, x) => p_list_sep (string ".") string (m :: ms @ [x])
|
adamc@59
|
506
|
adamc@42
|
507
|
adamc@123
|
508
|
adamc@1
|
509 fun p_decl ((d, _) : decl) =
|
adamc@1
|
510 case d of
|
adamc@1
|
511 DCon (x, NONE, c) => box [string "con",
|
adamc@1
|
512 space,
|
adamc@1
|
513 string x,
|
adamc@1
|
514 space,
|
adamc@1
|
515 string "=",
|
adamc@1
|
516 space,
|
adamc@1
|
517 p_con c]
|
adamc@1
|
518 | DCon (x, SOME k, c) => box [string "con",
|
adamc@1
|
519 space,
|
adamc@1
|
520 string x,
|
adamc@1
|
521 space,
|
adamc@1
|
522 string "::",
|
adamc@1
|
523 space,
|
adamc@1
|
524 p_kind k,
|
adamc@1
|
525 space,
|
adamc@1
|
526 string "=",
|
adamc@1
|
527 space,
|
adamc@1
|
528 p_con c]
|
adamc@156
|
529 | DDatatype x => p_datatype x
|
adamc@156
|
530 | DDatatypeImp (x, ms, x') =>
|
adamc@156
|
531 box [string "datatype",
|
adamc@156
|
532 space,
|
adamc@156
|
533 string x,
|
adamc@156
|
534 space,
|
adamc@156
|
535 string "=",
|
adamc@156
|
536 space,
|
adamc@156
|
537 string "datatype",
|
adamc@156
|
538 space,
|
adamc@156
|
539 p_list_sep (string ".") string (ms @ [x'])]
|
adamc@123
|
540 | DVal vi => box [string "val",
|
adamc@123
|
541 space,
|
adamc@123
|
542 p_vali vi]
|
adamc@123
|
543 | DValRec vis => box [string "val",
|
adamc@123
|
544 space,
|
adamc@123
|
545 string "rec",
|
adamc@123
|
546 space,
|
adamc@123
|
547 p_list_sep (box [newline, string "and", space]) p_vali vis]
|
adamc@1
|
548
|
adamc@30
|
549 | DSgn (x, sgn) => box [string "signature",
|
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 | DStr (x, NONE, str) => box [string "structure",
|
adamc@30
|
557 space,
|
adamc@30
|
558 string x,
|
adamc@30
|
559 space,
|
adamc@30
|
560 string "=",
|
adamc@30
|
561 space,
|
adamc@30
|
562 p_str str]
|
adamc@30
|
563 | DStr (x, SOME sgn, str) => box [string "structure",
|
adamc@30
|
564 space,
|
adamc@30
|
565 string x,
|
adamc@30
|
566 space,
|
adamc@30
|
567 string ":",
|
adamc@30
|
568 space,
|
adamc@30
|
569 p_sgn sgn,
|
adamc@30
|
570 space,
|
adamc@30
|
571 string "=",
|
adamc@30
|
572 space,
|
adamc@30
|
573 p_str str]
|
adamc@48
|
574 | DFfiStr (x, sgn) => box [string "extern",
|
adamc@48
|
575 space,
|
adamc@48
|
576 string "structure",
|
adamc@48
|
577 space,
|
adamc@48
|
578 string x,
|
adamc@48
|
579 space,
|
adamc@48
|
580 string ":",
|
adamc@48
|
581 space,
|
adamc@48
|
582 p_sgn sgn]
|
adamc@61
|
583 | DOpen (m, ms) => box [string "open",
|
adamc@61
|
584 space,
|
adamc@61
|
585 p_list_sep (string ".") string (m :: ms)]
|
adamc@88
|
586 | DConstraint (c1, c2) => box [string "constraint",
|
adamc@88
|
587 space,
|
adamc@88
|
588 p_con c1,
|
adamc@88
|
589 space,
|
adamc@88
|
590 string "~",
|
adamc@88
|
591 space,
|
adamc@88
|
592 p_con c2]
|
adamc@88
|
593 | DOpenConstraints (m, ms) => box [string "open",
|
adamc@88
|
594 space,
|
adamc@88
|
595 string "constraints",
|
adamc@88
|
596 space,
|
adamc@88
|
597 p_list_sep (string ".") string (m :: ms)]
|
adamc@30
|
598
|
adamc@109
|
599 | DExport str => box [string "export",
|
adamc@109
|
600 space,
|
adamc@109
|
601 p_str str]
|
adamc@704
|
602 | DTable (x, c, e) => box [string "table",
|
adamc@704
|
603 space,
|
adamc@704
|
604 string x,
|
adamc@704
|
605 space,
|
adamc@704
|
606 string ":",
|
adamc@704
|
607 space,
|
adamc@704
|
608 p_con c,
|
adamc@704
|
609 space,
|
adamc@704
|
610 string "constraints",
|
adamc@704
|
611 space,
|
adamc@704
|
612 p_exp e]
|
adamc@338
|
613 | DSequence x => box [string "sequence",
|
adamc@338
|
614 space,
|
adamc@338
|
615 string x]
|
adamc@563
|
616 | DClass (x, k, c) => box [string "class",
|
adamc@563
|
617 space,
|
adamc@563
|
618 string x,
|
adamc@563
|
619 space,
|
adamc@563
|
620 string "=",
|
adamc@563
|
621 space,
|
adamc@563
|
622 p_con c]
|
adamc@100
|
623
|
adamc@271
|
624 | DDatabase s => box [string "database",
|
adamc@271
|
625 space,
|
adamc@271
|
626 string s]
|
adamc@271
|
627
|
adamc@459
|
628 | DCookie (x, c) => box [string "cookie",
|
adamc@459
|
629 space,
|
adamc@459
|
630 string x,
|
adamc@459
|
631 space,
|
adamc@459
|
632 string ":",
|
adamc@459
|
633 space,
|
adamc@459
|
634 p_con c]
|
adamc@459
|
635
|
adamc@30
|
636 and p_str (str, _) =
|
adamc@30
|
637 case str of
|
adamc@30
|
638 StrConst ds => box [string "struct",
|
adamc@30
|
639 newline,
|
adamc@30
|
640 p_list_sep newline p_decl ds,
|
adamc@30
|
641 newline,
|
adamc@30
|
642 string "end"]
|
adamc@30
|
643 | StrVar x => string x
|
adamc@34
|
644 | StrProj (str, x) => box [p_str str,
|
adamc@34
|
645 string ".",
|
adamc@34
|
646 string x]
|
adamc@40
|
647 | StrFun (x, sgn, NONE, str) => box [string "functor",
|
adamc@40
|
648 space,
|
adamc@40
|
649 string "(",
|
adamc@40
|
650 string x,
|
adamc@40
|
651 space,
|
adamc@40
|
652 string ":",
|
adamc@40
|
653 p_sgn sgn,
|
adamc@40
|
654 string ")",
|
adamc@40
|
655 space,
|
adamc@40
|
656 string "=>",
|
adamc@40
|
657 space,
|
adamc@40
|
658 p_str str]
|
adamc@40
|
659 | StrFun (x, sgn, SOME sgn', str) => box [string "functor",
|
adamc@40
|
660 space,
|
adamc@40
|
661 string "(",
|
adamc@40
|
662 string x,
|
adamc@40
|
663 space,
|
adamc@40
|
664 string ":",
|
adamc@40
|
665 p_sgn sgn,
|
adamc@40
|
666 string ")",
|
adamc@40
|
667 space,
|
adamc@40
|
668 string ":",
|
adamc@40
|
669 space,
|
adamc@40
|
670 p_sgn sgn',
|
adamc@40
|
671 space,
|
adamc@40
|
672 string "=>",
|
adamc@40
|
673 space,
|
adamc@40
|
674 p_str str]
|
adamc@44
|
675 | StrApp (str1, str2) => box [p_str str1,
|
adamc@44
|
676 string "(",
|
adamc@44
|
677 p_str str2,
|
adamc@44
|
678 string ")"]
|
adamc@30
|
679
|
adamc@1
|
680 val p_file = p_list_sep newline p_decl
|
adamc@1
|
681
|
adamc@1
|
682 end
|