src/Pure/Isar/proof_display.ML
changeset 17369 dec2ddbb3edf
child 17756 d4a35f82fbb4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Isar/proof_display.ML	Tue Sep 13 22:19:54 2005 +0200
     1.3 @@ -0,0 +1,75 @@
     1.4 +(*  Title:      Pure/Isar/proof_display.ML
     1.5 +    ID:         $Id$
     1.6 +    Author:     Makarius
     1.7 +
     1.8 +Printing of Isar proof configurations etc.
     1.9 +*)
    1.10 +
    1.11 +signature PROOF_DISPLAY =
    1.12 +sig
    1.13 +  val string_of_rule: ProofContext.context -> string -> thm -> string
    1.14 +  val print_results: bool -> ProofContext.context ->
    1.15 +    ((string * string) * (string * thm list) list) -> unit
    1.16 +  val present_results: ProofContext.context ->
    1.17 +    ((string * string) * (string * thm list) list) -> unit
    1.18 +end
    1.19 +
    1.20 +structure ProofDisplay: PROOF_DISPLAY =
    1.21 +struct
    1.22 +
    1.23 +(* refinement rule *)
    1.24 +
    1.25 +fun pretty_rule ctxt s thm =
    1.26 +  Pretty.block [Pretty.str (s ^ " attempt to solve goal by exported rule:"),
    1.27 +    Pretty.fbrk, ProofContext.pretty_thm ctxt thm];
    1.28 +
    1.29 +val string_of_rule = Pretty.string_of ooo pretty_rule;
    1.30 +
    1.31 +
    1.32 +(* results *)
    1.33 +
    1.34 +local
    1.35 +
    1.36 +fun pretty_facts ctxt =
    1.37 +  List.concat o (separate [Pretty.fbrk, Pretty.str "and "]) o
    1.38 +    map (single o ProofContext.pretty_fact ctxt);
    1.39 +
    1.40 +fun pretty_results ctxt ((kind, ""), facts) =
    1.41 +      Pretty.block (Pretty.str kind :: Pretty.brk 1 :: pretty_facts ctxt facts)
    1.42 +  | pretty_results ctxt ((kind, name), [fact]) = Pretty.blk (1,
    1.43 +      [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, ProofContext.pretty_fact ctxt fact])
    1.44 +  | pretty_results ctxt ((kind, name), facts) = Pretty.blk (1,
    1.45 +      [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk,
    1.46 +        Pretty.blk (1, Pretty.str "(" :: pretty_facts ctxt facts @ [Pretty.str ")"])]);
    1.47 +
    1.48 +fun name_results "" res = res
    1.49 +  | name_results name res =
    1.50 +      let
    1.51 +        val n = length (List.concat (map #2 res));
    1.52 +        fun name_res (a, ths) i =
    1.53 +          let
    1.54 +            val m = length ths;
    1.55 +            val j = i + m;
    1.56 +          in
    1.57 +            if a <> "" then ((a, ths), j)
    1.58 +            else if m = n then ((name, ths), j)
    1.59 +            else if m = 1 then
    1.60 +              ((PureThy.string_of_thmref (NameSelection (name, [Single i])), ths), j)
    1.61 +            else ((PureThy.string_of_thmref (NameSelection (name, [FromTo (i, j - 1)])), ths), j)
    1.62 +          end;
    1.63 +      in #1 (fold_map name_res res 1) end;
    1.64 +
    1.65 +in
    1.66 +
    1.67 +fun print_results true = Pretty.writeln oo pretty_results
    1.68 +  | print_results false = K (K ());
    1.69 +
    1.70 +fun present_results ctxt ((kind, name), res) =
    1.71 +  if kind = "" orelse kind = Drule.internalK then ()
    1.72 +  else (print_results true ctxt ((kind, name), res);
    1.73 +    Context.setmp (SOME (ProofContext.theory_of ctxt))
    1.74 +      (Present.results kind) (name_results name res));
    1.75 +
    1.76 +end;
    1.77 +
    1.78 +end;