comparison src/source_print.sml @ 446:86c063fedc4d

Parsing 'let'
author Adam Chlipala <adamc@hcoop.net>
date Sat, 01 Nov 2008 10:47:10 -0400
parents dfc8c991abd0
children f542bc3133dc
comparison
equal deleted inserted replaced
445:dfc8c991abd0 446:86c063fedc4d
283 space, 283 space,
284 p_exp e]) pes]) 284 p_exp e]) pes])
285 285
286 | EWild => string "_" 286 | EWild => string "_"
287 287
288 | ELet (ds, e) => box [string "let",
289 newline,
290 box [p_list_sep newline p_edecl ds],
291 newline,
292 string "in",
293 newline,
294 box [p_exp e],
295 newline,
296 string "end"]
297
288 and p_exp e = p_exp' false e 298 and p_exp e = p_exp' false e
289 299
290 fun p_datatype (x, xs, cons) = 300 and p_edecl (d, _) =
291 box [string "datatype", 301 case d of
292 space, 302 EDVal vi => box [string "val",
293 string x, 303 space,
294 p_list_sep (box []) (fn x => box [space, string x]) xs, 304 p_vali vi]
295 space, 305 | EDValRec vis => box [string "val",
296 string "=", 306 space,
297 space, 307 string "rec",
298 p_list_sep (box [space, string "|", space]) 308 space,
299 (fn (x, NONE) => string x 309 p_list_sep (box [newline, string "and", space]) p_vali vis]
300 | (x, SOME t) => box [string x, space, string "of", space, p_con t]) 310
301 cons] 311 and p_vali (x, co, e) =
302
303 fun p_sgn_item (sgi, _) =
304 case sgi of
305 SgiConAbs (x, k) => box [string "con",
306 space,
307 string x,
308 space,
309 string "::",
310 space,
311 p_kind k]
312 | SgiCon (x, NONE, c) => box [string "con",
313 space,
314 string x,
315 space,
316 string "=",
317 space,
318 p_con c]
319 | SgiCon (x, SOME k, c) => box [string "con",
320 space,
321 string x,
322 space,
323 string "::",
324 space,
325 p_kind k,
326 space,
327 string "=",
328 space,
329 p_con c]
330 | SgiDatatype x => p_datatype x
331 | SgiDatatypeImp (x, ms, x') =>
332 box [string "datatype",
333 space,
334 string x,
335 space,
336 string "=",
337 space,
338 string "datatype",
339 space,
340 p_list_sep (string ".") string (ms @ [x'])]
341 | SgiVal (x, c) => box [string "val",
342 space,
343 string x,
344 space,
345 string ":",
346 space,
347 p_con c]
348 | SgiStr (x, sgn) => box [string "structure",
349 space,
350 string x,
351 space,
352 string ":",
353 space,
354 p_sgn sgn]
355 | SgiSgn (x, sgn) => box [string "signature",
356 space,
357 string x,
358 space,
359 string "=",
360 space,
361 p_sgn sgn]
362 | SgiInclude sgn => box [string "include",
363 space,
364 p_sgn sgn]
365 | SgiConstraint (c1, c2) => box [string "constraint",
366 space,
367 p_con c1,
368 space,
369 string "~",
370 space,
371 p_con c2]
372 | SgiTable (x, c) => box [string "table",
373 space,
374 string x,
375 space,
376 string ":",
377 space,
378 p_con c]
379 | SgiSequence x => box [string "sequence",
380 space,
381 string x]
382 | SgiClassAbs x => box [string "class",
383 space,
384 string x]
385 | SgiClass (x, c) => box [string "class",
386 space,
387 string x,
388 space,
389 string "=",
390 space,
391 p_con c]
392
393 and p_sgn (sgn, _) =
394 case sgn of
395 SgnConst sgis => box [string "sig",
396 newline,
397 p_list_sep newline p_sgn_item sgis,
398 newline,
399 string "end"]
400 | SgnVar x => string x
401 | SgnFun (x, sgn, sgn') => box [string "functor",
402 space,
403 string "(",
404 string x,
405 space,
406 string ":",
407 p_sgn sgn,
408 string ")",
409 space,
410 string ":",
411 space,
412 p_sgn sgn']
413 | SgnWhere (sgn, x, c) => box [p_sgn sgn,
414 space,
415 string "where",
416 space,
417 string "con",
418 space,
419 string x,
420 space,
421 string "=",
422 space,
423 p_con c]
424 | SgnProj (m, ms, x) => p_list_sep (string ".") string (m :: ms @ [x])
425
426
427 fun p_vali (x, co, e) =
428 case co of 312 case co of
429 NONE => box [string x, 313 NONE => box [string x,
430 space, 314 space,
431 string "=", 315 string "=",
432 space, 316 space,
438 p_con t, 322 p_con t,
439 space, 323 space,
440 string "=", 324 string "=",
441 space, 325 space,
442 p_exp e] 326 p_exp e]
327
328
329 fun p_datatype (x, xs, cons) =
330 box [string "datatype",
331 space,
332 string x,
333 p_list_sep (box []) (fn x => box [space, string x]) xs,
334 space,
335 string "=",
336 space,
337 p_list_sep (box [space, string "|", space])
338 (fn (x, NONE) => string x
339 | (x, SOME t) => box [string x, space, string "of", space, p_con t])
340 cons]
341
342 fun p_sgn_item (sgi, _) =
343 case sgi of
344 SgiConAbs (x, k) => box [string "con",
345 space,
346 string x,
347 space,
348 string "::",
349 space,
350 p_kind k]
351 | SgiCon (x, NONE, c) => box [string "con",
352 space,
353 string x,
354 space,
355 string "=",
356 space,
357 p_con c]
358 | SgiCon (x, SOME k, c) => box [string "con",
359 space,
360 string x,
361 space,
362 string "::",
363 space,
364 p_kind k,
365 space,
366 string "=",
367 space,
368 p_con c]
369 | SgiDatatype x => p_datatype x
370 | SgiDatatypeImp (x, ms, x') =>
371 box [string "datatype",
372 space,
373 string x,
374 space,
375 string "=",
376 space,
377 string "datatype",
378 space,
379 p_list_sep (string ".") string (ms @ [x'])]
380 | SgiVal (x, c) => box [string "val",
381 space,
382 string x,
383 space,
384 string ":",
385 space,
386 p_con c]
387 | SgiStr (x, sgn) => box [string "structure",
388 space,
389 string x,
390 space,
391 string ":",
392 space,
393 p_sgn sgn]
394 | SgiSgn (x, sgn) => box [string "signature",
395 space,
396 string x,
397 space,
398 string "=",
399 space,
400 p_sgn sgn]
401 | SgiInclude sgn => box [string "include",
402 space,
403 p_sgn sgn]
404 | SgiConstraint (c1, c2) => box [string "constraint",
405 space,
406 p_con c1,
407 space,
408 string "~",
409 space,
410 p_con c2]
411 | SgiTable (x, c) => box [string "table",
412 space,
413 string x,
414 space,
415 string ":",
416 space,
417 p_con c]
418 | SgiSequence x => box [string "sequence",
419 space,
420 string x]
421 | SgiClassAbs x => box [string "class",
422 space,
423 string x]
424 | SgiClass (x, c) => box [string "class",
425 space,
426 string x,
427 space,
428 string "=",
429 space,
430 p_con c]
431
432 and p_sgn (sgn, _) =
433 case sgn of
434 SgnConst sgis => box [string "sig",
435 newline,
436 p_list_sep newline p_sgn_item sgis,
437 newline,
438 string "end"]
439 | SgnVar x => string x
440 | SgnFun (x, sgn, sgn') => box [string "functor",
441 space,
442 string "(",
443 string x,
444 space,
445 string ":",
446 p_sgn sgn,
447 string ")",
448 space,
449 string ":",
450 space,
451 p_sgn sgn']
452 | SgnWhere (sgn, x, c) => box [p_sgn sgn,
453 space,
454 string "where",
455 space,
456 string "con",
457 space,
458 string x,
459 space,
460 string "=",
461 space,
462 p_con c]
463 | SgnProj (m, ms, x) => p_list_sep (string ".") string (m :: ms @ [x])
464
465
443 466
444 fun p_decl ((d, _) : decl) = 467 fun p_decl ((d, _) : decl) =
445 case d of 468 case d of
446 DCon (x, NONE, c) => box [string "con", 469 DCon (x, NONE, c) => box [string "con",
447 space, 470 space,