src/Pure/display.ML
changeset 6087 c8ec08fced15
parent 5902 c39b23d752b6
child 6279 eb4dc43023af
equal deleted inserted replaced
6086:8cd4190e633a 6087:c8ec08fced15
     7 *)
     7 *)
     8 
     8 
     9 signature DISPLAY =
     9 signature DISPLAY =
    10 sig
    10 sig
    11   val show_hyps		: bool ref
    11   val show_hyps		: bool ref
       
    12   val show_tags		: bool ref
    12   val pretty_thm	: thm -> Pretty.T
    13   val pretty_thm	: thm -> Pretty.T
       
    14   val pretty_thms	: thm list -> Pretty.T
    13   val string_of_thm	: thm -> string
    15   val string_of_thm	: thm -> string
    14   val pprint_thm	: thm -> pprint_args -> unit
    16   val pprint_thm	: thm -> pprint_args -> unit
    15   val print_thm		: thm -> unit
    17   val print_thm		: thm -> unit
       
    18   val print_thms	: thm list -> unit
    16   val prth		: thm -> thm
    19   val prth		: thm -> thm
    17   val prthq		: thm Seq.seq -> thm Seq.seq
    20   val prthq		: thm Seq.seq -> thm Seq.seq
    18   val prths		: thm list -> thm list
    21   val prths		: thm list -> thm list
    19   val pretty_ctyp	: ctyp -> Pretty.T
    22   val pretty_ctyp	: ctyp -> Pretty.T
    20   val pprint_ctyp	: ctyp -> pprint_args -> unit
    23   val pprint_ctyp	: ctyp -> pprint_args -> unit
    28   val pprint_theory	: theory -> pprint_args -> unit
    31   val pprint_theory	: theory -> pprint_args -> unit
    29   val print_syntax	: theory -> unit
    32   val print_syntax	: theory -> unit
    30   val print_theory	: theory -> unit
    33   val print_theory	: theory -> unit
    31   val pretty_name_space : string * NameSpace.T -> Pretty.T
    34   val pretty_name_space : string * NameSpace.T -> Pretty.T
    32   val show_consts	: bool ref
    35   val show_consts	: bool ref
    33 
       
    34 end;
    36 end;
    35 
    37 
    36 structure Display: DISPLAY =
    38 structure Display: DISPLAY =
    37 struct
    39 struct
    38 
    40 
    39 (*If false, hypotheses are printed as dots*)
    41 (** print thm **)
    40 val show_hyps = ref true;
    42 
       
    43 val show_hyps = ref true;	(*false: print meta-hypotheses as dots*)
       
    44 val show_tags = ref false;	(*false: suppress tags*)
       
    45 
       
    46 fun pretty_tag (name, args) = Pretty.strs (name :: args);
       
    47 val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
    41 
    48 
    42 fun pretty_thm th =
    49 fun pretty_thm th =
    43   let
    50   let
    44     val {sign, hyps, prop, ...} = rep_thm th;
    51     val {sign, hyps, prop, ...} = rep_thm th;
    45     val xshyps = extra_shyps th;
    52     val xshyps = Thm.extra_shyps th;
       
    53     val (_, tags) = Thm.get_name_tags th;
       
    54 
    46     val hlen = length xshyps + length hyps;
    55     val hlen = length xshyps + length hyps;
    47     val hsymbs =
    56     val hsymbs =
    48       if hlen = 0 then []
    57       if hlen = 0 then []
    49       else if ! show_hyps then
    58       else if ! show_hyps then
    50         [Pretty.brk 2, Pretty.list "[" "]"
    59         [Pretty.brk 2, Pretty.list "[" "]"
    51           (map (Sign.pretty_term sign) hyps @
    60           (map (Sign.pretty_term sign) hyps @
    52            map (Sign.pretty_sort sign) xshyps)]
    61            map (Sign.pretty_sort sign) xshyps)]
    53       else
    62       else
    54         [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^ "]")];
    63         [Pretty.brk 2, Pretty.str ("[" ^ implode (replicate hlen ".") ^ "]")];
    55   in
    64     val tsymbs =
    56     Pretty.block (Sign.pretty_term sign prop :: hsymbs)
    65       if null tags orelse not (! show_tags) then []
    57   end;
    66       else [Pretty.brk 1, pretty_tags tags];
       
    67   in Pretty.block (Sign.pretty_term sign prop :: (hsymbs @ tsymbs)) end;
    58 
    68 
    59 val string_of_thm = Pretty.string_of o pretty_thm;
    69 val string_of_thm = Pretty.string_of o pretty_thm;
    60 val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm;
    70 val pprint_thm = Pretty.pprint o Pretty.quote o pretty_thm;
    61 
    71 
    62 
    72 fun pretty_thms [th] = pretty_thm th
    63 (** Top-level commands for printing theorems **)
    73   | pretty_thms ths = Pretty.block (Pretty.fbreaks (map pretty_thm ths));
    64 val print_thm = writeln o string_of_thm;
    74 
       
    75 
       
    76 (* top-level commands for printing theorems *)
       
    77 
       
    78 val print_thm = Pretty.writeln o pretty_thm;
       
    79 val print_thms = Pretty.writeln o pretty_thms;
    65 
    80 
    66 fun prth th = (print_thm th; th);
    81 fun prth th = (print_thm th; th);
    67 
    82 
    68 (*Print and return a sequence of theorems, separated by blank lines. *)
    83 (*Print and return a sequence of theorems, separated by blank lines. *)
    69 fun prthq thseq =
    84 fun prthq thseq =