aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Aspinall1998-08-21 14:38:23 +0000
committerDavid Aspinall1998-08-21 14:38:23 +0000
commit438d3b99713a940f1814f749b38235fb64a6a5d7 (patch)
tree638ffff3003e56828f5e78e41dc6dcf778f5c62d
parent4c39fd9067655d73e2045f2eb7a607c9a39f7ddb (diff)
First attempt, proof state works.
-rw-r--r--isa-print-functions.ML172
-rw-r--r--isa.el58
2 files changed, 211 insertions, 19 deletions
diff --git a/isa-print-functions.ML b/isa-print-functions.ML
new file mode 100644
index 00000000..3af539a5
--- /dev/null
+++ b/isa-print-functions.ML
@@ -0,0 +1,172 @@
+(*
+ isa-print-functions.ML
+
+ Customized version of Isabelle printing for script management
+ mode.
+
+ $Id$
+
+*)
+
+
+
+val proof_state_special_prefix="\248";
+val proof_state_special_suffix="\249";
+val goal_start_special="\253";
+
+
+
+(* val orig_prs_fn = !prs_fn; *)
+(* val orig_warning_fn = !warning_fn; *)
+(* val orig_error_fn = !error_fn; *)
+
+(* copied from Pure/library.ML: *)
+local
+ fun out s =
+ (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut);
+
+ fun prefix_lines prfx txt =
+ txt |> split_lines |> map (fn s => prfx ^ s ^ "\n") |> implode;
+in
+
+(*hooks for output channels: normal, warning, error*)
+
+(* da: NO CHANGES NEEDED YET *)
+val () =
+ (prs_fn := (fn s => out s);
+ warning_fn := (fn s => out (prefix_lines "### " s));
+ error_fn := (fn s => out (prefix_lines "*** " s)))
+
+end;
+
+
+
+local
+
+ (* utils *)
+
+ fun ins_entry (x, y) [] = [(x, [y])]
+ | ins_entry (x, y) ((pair as (x', ys')) :: pairs) =
+ if x = x' then (x', y ins ys') :: pairs
+ else pair :: ins_entry (x, y) pairs;
+
+ fun add_consts (Const (c, T), env) = ins_entry (T, (c, T)) env
+ | add_consts (t $ u, env) = add_consts (u, add_consts (t, env))
+ | add_consts (Abs (_, _, t), env) = add_consts (t, env)
+ | add_consts (_, env) = env;
+
+ fun add_vars (Free (x, T), env) = ins_entry (T, (x, ~1)) env
+ | add_vars (Var (xi, T), env) = ins_entry (T, xi) env
+ | add_vars (Abs (_, _, t), env) = add_vars (t, env)
+ | add_vars (t $ u, env) = add_vars (u, add_vars (t, env))
+ | add_vars (_, env) = env;
+
+ fun add_varsT (Type (_, Ts), env) = foldr add_varsT (Ts, env)
+ | add_varsT (TFree (x, S), env) = ins_entry (S, (x, ~1)) env
+ | add_varsT (TVar (xi, S), env) = ins_entry (S, xi) env;
+
+ fun sort_idxs vs = map (apsnd (sort (prod_ord string_ord int_ord))) vs;
+ fun sort_cnsts cs = map (apsnd (sort_wrt fst)) cs;
+
+
+ (* prepare atoms *)
+
+ fun consts_of t = sort_cnsts (add_consts (t, []));
+ fun vars_of t = sort_idxs (add_vars (t, []));
+ fun varsT_of t = rev (sort_idxs (it_term_types add_varsT (t, [])));
+
+in
+
+ fun script_print_goals maxgoals state =
+ let
+ val {sign, ...} = rep_thm state;
+
+ val prt_term = Sign.pretty_term sign;
+ val prt_typ = Sign.pretty_typ sign;
+ val prt_sort = Sign.pretty_sort sign;
+
+ fun prt_atoms prt prtT (X, xs) = Pretty.block
+ [Pretty.block (Pretty.commas (map prt xs)), Pretty.str " ::",
+ Pretty.brk 1, prtT X];
+
+ fun prt_var (x, ~1) = prt_term (Syntax.free x)
+ | prt_var xi = prt_term (Syntax.var xi);
+
+ fun prt_varT (x, ~1) = prt_typ (TFree (x, []))
+ | prt_varT xi = prt_typ (TVar (xi, []));
+
+ val prt_consts = prt_atoms (prt_term o Const) prt_typ;
+ val prt_vars = prt_atoms prt_var prt_typ;
+ val prt_varsT = prt_atoms prt_varT prt_sort;
+
+
+ fun print_list _ _ [] = ()
+ | print_list name prt lst = (writeln "";
+ Pretty.writeln (Pretty.big_list name (map prt lst)));
+
+ fun print_subgoals (_, []) = ()
+ | print_subgoals (n, A :: As) = (Pretty.writeln (Pretty.blk (0,
+ [Pretty.str (goal_start_special ^
+ " " ^ string_of_int n ^ ". "), prt_term A]));
+ print_subgoals (n + 1, As));
+
+ val print_ffpairs =
+ print_list "Flex-flex pairs:" (prt_term o Logic.mk_flexpair);
+
+ val print_consts = print_list "Constants:" prt_consts o consts_of;
+ val print_vars = print_list "Variables:" prt_vars o vars_of;
+ val print_varsT = print_list "Type variables:" prt_varsT o varsT_of;
+
+
+ val {prop, ...} = rep_thm state;
+ val (tpairs, As, B) = Logic.strip_horn prop;
+ val ngoals = length As;
+
+ fun print_gs (types, sorts) =
+ (Pretty.writeln (prt_term B);
+ if ngoals = 0 then writeln "No subgoals!"
+ else if ngoals > maxgoals then
+ (print_subgoals (1, take (maxgoals, As));
+ writeln ("A total of " ^ string_of_int ngoals ^ " subgoals..."))
+ else print_subgoals (1, As);
+
+ print_ffpairs tpairs;
+
+ if types andalso ! show_consts then print_consts prop else ();
+ if types then print_vars prop else ();
+ if sorts then print_varsT prop else ());
+ in
+ setmp show_no_free_types true
+ (setmp show_types (! show_types orelse ! show_sorts)
+ (setmp show_sorts false print_gs))
+ (! show_types orelse ! show_sorts, ! show_sorts)
+ end;
+
+end;
+
+
+
+
+(* Pure/goals.ML declares print_current_goals_fn. *)
+
+val orig_print_current_goals_fn = !print_current_goals_fn;
+
+fun script_mode_print_current_goals_fn n max th =
+ (writeln ("Level " ^ string_of_int n); script_print_goals max th);
+
+local
+ fun out s =
+ (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut);
+ fun cgf i j t =
+ (out proof_state_special_prefix;
+ script_mode_print_current_goals_fn i j t;
+ out proof_state_special_suffix)
+in
+ val () = (print_current_goals_fn := cgf)
+end
+
+
+
+
+
+ \ No newline at end of file
diff --git a/isa.el b/isa.el
index ee80e89b..c750d5b4 100644
--- a/isa.el
+++ b/isa.el
@@ -1,8 +1,11 @@
;; isa.el Major mode for Isabelle proof assistant
;; Copyright (C) 1994-1998 LFCS Edinburgh.
-;; Authors: Healfdene Goguen, Thomas Kleymann, David Aspinall
+;; Author: David Aspinall
;; $Log$
+;; Revision 2.1 1998/08/21 14:37:18 da
+;; First attempt, proof state works.
+;;
;; Revision 2.0 1998/08/11 14:59:57 da
;; New branch
;;
@@ -10,6 +13,10 @@
;; Isabelle proof.el support.
;;
+;; STATUS:
+;; - Basic proof state extraction works, using prompt regexp
+;; - Undo needs attention
+
(require 'isa-syntax)
(require 'outline)
@@ -51,7 +58,9 @@
"The working directory of the isabelle shell")
(defvar isa-shell-prompt-pattern
- "^2?[---=#>]>? *\\|^\\*\\* .*"
+ ;; borrowed from somewhere?
+ ;; "^2?[---=#>]>? *\\|^\\*\\* .*"
+ "^> "
"*The prompt pattern for the inferior shell running isabelle.")
(defvar isa-shell-cd "cd \"%s\";"
@@ -123,7 +132,7 @@
(not (eq (span-property (prev-span span 'type) 'type) 'comment))
(isa-goal-command-p
(span-property (prev-span span 'type) 'cmd)))
- (concat "Restart" proof-terminal-string)
+ (concat "choplev 0" proof-terminal-string)
(while span
(setq str (span-property span 'cmd))
(cond ((eq (span-property span 'type) 'vanilla)
@@ -138,7 +147,7 @@
(setq i (+ 1 i))))
(t nil))))
(setq span (next-span span 'type)))
- (concat "Undo " (int-to-string ct) proof-terminal-string))))
+ (concat "choplev " (int-to-string ct) proof-terminal-string))))
(defconst isa-keywords-decl-defn-regexp
(ids-to-regexp (append isa-keywords-decl isa-keywords-defn))
@@ -316,12 +325,13 @@
(setq proof-assistant isa-assistant
proof-www-home-page isa-www-home-page)
- (setq proof-prf-string "Show"
- proof-ctxt-string "Print All"
- proof-help-string "Help")
+ (setq proof-prf-string "pr()"
+ proof-ctxt-string "print \"No context for Isabelle.\""
+ proof-help-string "print \"No in-built help for Isabelle.\"")
(setq proof-goal-command-p 'isa-goal-command-p
proof-count-undos-fn 'isa-count-undos
+ ;; this one won't be relevant.
proof-find-and-forget-fn 'isa-find-and-forget
proof-goal-hyp-fn 'isa-goal-hyp
proof-state-preserving-p 'isa-state-preserving-p
@@ -369,6 +379,8 @@
(add-hook 'proof-shell-exit-hook 'isa-zap-line-width nil t)
(add-hook 'proof-pre-shell-start-hook 'isa-pre-shell-start nil t))
+
+
(defun isa-shell-mode-config ()
(setq proof-shell-prompt-pattern isa-shell-prompt-pattern
proof-shell-cd isa-shell-cd
@@ -381,23 +393,31 @@
proof-shell-assumption-regexp isa-id
proof-shell-goal-regexp isa-goal-regexp
proof-shell-first-special-char ?\360
- proof-shell-wakeup-char ?> ; ?\371 ; done: prompt
; The next three represent path annotation information
- proof-shell-start-char nil ; ?\372 ; not done
- proof-shell-end-char nil ; ?\373 ; not done
- proof-shell-field-char nil ; ?\374 ; not done
- proof-shell-goal-char nil ; ?\375 ; done
- proof-shell-eager-annotation-start "\376" ; done
- proof-shell-eager-annotation-end "\377" ; done
+
+ proof-shell-eager-annotation-start "\376"
+ proof-shell-eager-annotation-end "\377"
proof-shell-annotated-prompt-regexp proof-shell-prompt-pattern
;(concat proof-shell-prompt-pattern
- ; (char-to-string proof-shell-wakeup-char)) ; done
+ ; (char-to-string proof-shell-wakeup-char))
proof-shell-result-start "\372 Pbp result \373"
proof-shell-result-end "\372 End Pbp result \373"
- proof-shell-start-goals-regexp "^Level" ; isa-goal-regexp ; -9]+ subgoals?"
- proof-shell-end-goals-regexp proof-shell-annotated-prompt-regexp
- proof-shell-init-cmd nil
- proof-analyse-using-stack t)
+ proof-analyse-using-stack t
+ proof-shell-start-char ?\372 ; not done
+ proof-shell-end-char ?\373 ; not done
+ proof-shell-field-char ?\374 ; not done
+ ;; da: settings below here WORK
+ ;; ============================
+ proof-shell-goal-char ?\375
+ ;; We can't hack the SML prompt, so set wakeup-char to nil.
+ proof-shell-wakeup-char nil
+ proof-shell-start-goals-regexp "\370"
+ proof-shell-end-goals-regexp "\371"
+ ;; initial command configures Isabelle by hacking print functions.
+ ;; may need directory for this: /home/da/devel/lego/elisp/
+ proof-shell-init-cmd
+ "use \"isa-print-functions.ML\";")
+
;; The following hook is removed once it's called.
;; FIXME: maybe add this back later.