annotate src/elab_print.sml @ 203:dd82457fda82

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