src/Pure/ML-Systems/ml_pretty.ML
author nipkow
Mon, 12 Sep 2011 07:55:43 +0200
changeset 44890 22f665a2e91c
parent 38635 f76ad0771f67
child 61862 e2a9e46ac0fb
permissions -rw-r--r--
new fastforce replacing fastsimp - less confusing name

(*  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;