src/Pure/Isar/proof_display.ML
author wenzelm
Sat Mar 21 20:00:23 2009 +0100 (2009-03-21)
changeset 30628 4078276bcace
parent 30364 577edc39b501
child 30724 2e54e89bcce7
permissions -rw-r--r--
removed obsolete pprint operations;
some explicit pp operations for toplevel pretty printing;
     1 (*  Title:      Pure/Isar/proof_display.ML
     2     Author:     Makarius
     3 
     4 Printing of theorems, goals, results etc.
     5 *)
     6 
     7 signature PROOF_DISPLAY =
     8 sig
     9   val pp_context: Proof.context -> Pretty.T
    10   val pp_thm: thm -> Pretty.T
    11   val pp_typ: theory -> typ -> Pretty.T
    12   val pp_term: theory -> term -> Pretty.T
    13   val pp_ctyp: ctyp -> Pretty.T
    14   val pp_cterm: cterm -> Pretty.T
    15   val print_theorems_diff: theory -> theory -> unit
    16   val print_theorems: theory -> unit
    17   val pretty_full_theory: bool -> theory -> Pretty.T
    18   val print_theory: theory -> unit
    19   val string_of_rule: Proof.context -> string -> thm -> string
    20   val print_results: bool -> Proof.context -> ((string * string) * (string * thm list) list) -> unit
    21   val pretty_consts: Proof.context -> (string * typ -> bool) -> (string * typ) list -> Pretty.T
    22 end
    23 
    24 structure ProofDisplay: PROOF_DISPLAY =
    25 struct
    26 
    27 (* toplevel pretty printing *)
    28 
    29 fun pp_context ctxt =
    30  (if ! ProofContext.debug then
    31     Pretty.quote (Pretty.big_list "proof context:" (ProofContext.pretty_context ctxt))
    32   else Pretty.str "<context>");
    33 
    34 fun pp_thm th =
    35   let val thy = Thm.theory_of_thm th
    36   in Display.pretty_thm_aux (Syntax.pp_global thy) true false [] th end;
    37 
    38 val pp_typ = Pretty.quote oo Syntax.pretty_typ_global;
    39 val pp_term = Pretty.quote oo Syntax.pretty_term_global;
    40 
    41 fun pp_ctyp cT = pp_typ (Thm.theory_of_ctyp cT) (Thm.typ_of cT);
    42 fun pp_cterm ct = pp_term (Thm.theory_of_cterm ct) (Thm.term_of ct);
    43 
    44 
    45 (* theorems and theory *)
    46 
    47 fun pretty_theorems_diff prev_thys thy =
    48   let
    49     val pretty_fact = ProofContext.pretty_fact (ProofContext.init thy);
    50     val thmss = Facts.dest_static (map PureThy.facts_of prev_thys) (PureThy.facts_of thy);
    51   in Pretty.big_list "theorems:" (map #1 (sort_wrt (#1 o #2) (map (`pretty_fact) thmss))) end;
    52 
    53 fun print_theorems_diff prev_thy thy =
    54   Pretty.writeln (pretty_theorems_diff [prev_thy] thy);
    55 
    56 fun pretty_theorems thy = pretty_theorems_diff (Theory.parents_of thy) thy;
    57 val print_theorems = Pretty.writeln o pretty_theorems;
    58 
    59 fun pretty_full_theory verbose thy =
    60   Pretty.chunks (Display.pretty_full_theory verbose thy @ [pretty_theorems thy]);
    61 
    62 val print_theory = Pretty.writeln o pretty_full_theory false;
    63 
    64 
    65 (* refinement rule *)
    66 
    67 fun pretty_rule ctxt s thm =
    68   Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"),
    69     Pretty.fbrk, ProofContext.pretty_thm ctxt thm];
    70 
    71 val string_of_rule = Pretty.string_of ooo pretty_rule;
    72 
    73 
    74 (* results *)
    75 
    76 local
    77 
    78 fun pretty_fact_name (kind, "") = Pretty.str kind
    79   | pretty_fact_name (kind, name) = Pretty.block [Pretty.str kind, Pretty.brk 1,
    80       Pretty.str (Long_Name.base_name name), Pretty.str ":"];
    81 
    82 fun pretty_facts ctxt =
    83   flat o (separate [Pretty.fbrk, Pretty.str "and "]) o
    84     map (single o ProofContext.pretty_fact ctxt);
    85 
    86 in
    87 
    88 fun print_results do_print ctxt ((kind, name), facts) =
    89   if not do_print orelse kind = "" orelse kind = Thm.internalK then ()
    90   else if name = "" then
    91     Pretty.writeln (Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts))
    92   else Pretty.writeln
    93     (case facts of
    94       [fact] => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
    95         ProofContext.pretty_fact ctxt fact])
    96     | _ => Pretty.blk (1, [pretty_fact_name (kind, name), Pretty.fbrk,
    97         Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]));
    98 
    99 end;
   100 
   101 
   102 (* consts *)
   103 
   104 local
   105 
   106 fun pretty_var ctxt (x, T) =
   107   Pretty.block [Pretty.str x, Pretty.str " ::", Pretty.brk 1,
   108     Pretty.quote (Syntax.pretty_typ ctxt T)];
   109 
   110 fun pretty_vars ctxt kind vs = Pretty.big_list kind (map (pretty_var ctxt) vs);
   111 
   112 in
   113 
   114 fun pretty_consts ctxt pred cs =
   115   (case filter pred (#1 (ProofContext.inferred_fixes ctxt)) of
   116     [] => pretty_vars ctxt "constants" cs
   117   | ps => Pretty.chunks [pretty_vars ctxt "parameters" ps, pretty_vars ctxt "constants" cs]);
   118 
   119 end;
   120 
   121 end;