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