src/Pure/ML-Systems/ml_pretty.ML
author blanchet
Thu, 16 Dec 2010 22:45:02 +0100
changeset 41220 4d11b0de7dd8
parent 38635 f76ad0771f67
child 61862 e2a9e46ac0fb
permissions -rw-r--r--
discriminate SMT errors a bit better

(*  Title:      Pure/ML-Systems/ml_pretty.ML
    Author:     Makarius

Minimal support for raw ML pretty printing -- for boot-strapping only.
*)

structure ML_Pretty =
struct

datatype pretty =
  Block of (string * string) * pretty list * int |
  String of string * int |
  Break of bool * int;

fun block prts = Block (("", ""), prts, 2);
fun str s = String (s, size s);
fun brk wd = Break (false, wd);

fun pair pretty1 pretty2 ((x, y), depth: int) =
  block [str "(", pretty1 (x, depth), str ",", brk 1, pretty2 (y, depth - 1), str ")"];

fun enum sep lpar rpar pretty (args, depth) =
  let
    fun elems _ [] = []
      | elems 0 _ = [str "..."]
      | elems d [x] = [pretty (x, d)]
      | elems d (x :: xs) = pretty (x, d) :: str sep :: brk 1 :: elems (d - 1) xs;
  in block (str lpar :: (elems (Int.max (depth, 0)) args @ [str rpar])) end;

end;