src/Pure/Isar/isar_cmd.ML
author wenzelm
Tue Jul 27 21:56:32 1999 +0200 (1999-07-27 ago)
changeset 7101 ee79bf6feee2
parent 7023 5d1eafaff50c
child 7124 78c01842d3b5
permissions -rw-r--r--
removed restart;
added touch_all_thys, touch_thy, remove_thy, update_thy_only;
     1 (*  Title:      Pure/Isar/isar_cmd.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Non-logical toplevel commands.
     6 *)
     7 
     8 signature ISAR_CMD =
     9 sig
    10   val exit: Toplevel.transition -> Toplevel.transition
    11   val quit: Toplevel.transition -> Toplevel.transition
    12   val init_toplevel: Toplevel.transition -> Toplevel.transition
    13   val touch_all_thys: Toplevel.transition -> Toplevel.transition
    14   val touch_thy: string -> Toplevel.transition -> Toplevel.transition
    15   val remove_thy: string -> Toplevel.transition -> Toplevel.transition
    16   val kill_theory: Toplevel.transition -> Toplevel.transition
    17   val cannot_undo: string -> Toplevel.transition -> Toplevel.transition
    18   val clear_undo: Toplevel.transition -> Toplevel.transition
    19   val redo: Toplevel.transition -> Toplevel.transition
    20   val undos_proof: int -> Toplevel.transition -> Toplevel.transition
    21   val kill_proof: Toplevel.transition -> Toplevel.transition
    22   val undo_theory: Toplevel.transition -> Toplevel.transition
    23   val undo: Toplevel.transition -> Toplevel.transition
    24   val use: string -> Toplevel.transition -> Toplevel.transition
    25   val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
    26   val use_mltext: string -> Toplevel.transition -> Toplevel.transition
    27   val use_commit: Toplevel.transition -> Toplevel.transition
    28   val cd: string -> Toplevel.transition -> Toplevel.transition
    29   val pwd: Toplevel.transition -> Toplevel.transition
    30   val use_thy: string -> Toplevel.transition -> Toplevel.transition
    31   val use_thy_only: string -> Toplevel.transition -> Toplevel.transition
    32   val update_thy: string -> Toplevel.transition -> Toplevel.transition
    33   val update_thy_only: string -> Toplevel.transition -> Toplevel.transition
    34   val print_theory: Toplevel.transition -> Toplevel.transition
    35   val print_syntax: Toplevel.transition -> Toplevel.transition
    36   val print_theorems: Toplevel.transition -> Toplevel.transition
    37   val print_attributes: Toplevel.transition -> Toplevel.transition
    38   val print_methods: Toplevel.transition -> Toplevel.transition
    39   val print_binds: Toplevel.transition -> Toplevel.transition
    40   val print_lthms: Toplevel.transition -> Toplevel.transition
    41   val print_thms: (string * Args.src list) list -> Toplevel.transition -> Toplevel.transition
    42   val print_prop: string -> Toplevel.transition -> Toplevel.transition
    43   val print_term: string -> Toplevel.transition -> Toplevel.transition
    44   val print_type: string -> Toplevel.transition -> Toplevel.transition
    45 end;
    46 
    47 structure IsarCmd: ISAR_CMD =
    48 struct
    49 
    50 
    51 (* variations on exit *)
    52 
    53 val exit = Toplevel.keep (fn state =>
    54   (Context.set_context (try Toplevel.theory_of state);
    55     writeln "Leaving the Isar loop.  Invoke 'loop();' to restart.";
    56     raise Toplevel.TERMINATE));
    57 
    58 val quit = Toplevel.imperative quit;
    59 
    60 val init_toplevel = Toplevel.imperative (fn () => raise Toplevel.RESTART);
    61 
    62 
    63 (* touch theories *)
    64 
    65 val touch_all_thys = Toplevel.imperative ThyInfo.touch_all_thys;
    66 fun touch_thy name = Toplevel.imperative (fn () => ThyInfo.touch_thy name);
    67 fun remove_thy name = Toplevel.imperative (fn () => ThyInfo.remove_thy name);
    68 val kill_theory = Toplevel.imperative (fn () => warning "Nothing to kill.") o Toplevel.kill;
    69 
    70 
    71 (* history commands *)
    72 
    73 fun cannot_undo txt = Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt));
    74 val clear_undo = Toplevel.history History.clear o Toplevel.proof ProofHistory.clear;
    75 val redo = Toplevel.history History.redo o Toplevel.proof ProofHistory.redo;
    76 
    77 fun undos_proof n = Toplevel.proof (fn prf =>
    78   if ProofHistory.is_initial prf then raise Toplevel.UNDEF else funpow n ProofHistory.undo prf);
    79 
    80 val kill_proof = Toplevel.history (fn hist =>
    81   (case History.current hist of
    82     Toplevel.Theory _ => raise Toplevel.UNDEF
    83   | Toplevel.Proof _ => History.undo hist));
    84 
    85 val undo_theory = Toplevel.history (fn hist =>
    86   if History.is_initial hist then raise Toplevel.UNDEF else History.undo hist);
    87 
    88 val undo = kill_theory o undo_theory o undos_proof 1;
    89 
    90 
    91 (* use ML text *)
    92 
    93 fun use name = Toplevel.keep (fn state =>
    94   Context.setmp (try Toplevel.theory_of state) ThyInfo.use name);
    95 
    96 (*passes changes of theory context*)
    97 val use_mltext_theory = Toplevel.theory o IsarThy.use_mltext_theory;
    98 
    99 (*ignore result theory context*)
   100 fun use_mltext txt = Toplevel.keep (fn state =>
   101   (IsarThy.use_mltext txt (try Toplevel.theory_of state); ()));
   102 
   103 (*Note: commit is dynamically bound*)
   104 val use_commit = use_mltext "commit();";
   105 
   106 
   107 (* current working directory *)
   108 
   109 fun print_cd _ = writeln (Path.pack (File.pwd ()));
   110 
   111 fun cd dir = Toplevel.imperative (fn () => (File.cd (Path.unpack dir); print_cd ()));
   112 val pwd = Toplevel.imperative print_cd;
   113 
   114 
   115 (* load theory files *)
   116 
   117 fun use_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy name);
   118 fun use_thy_only name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy_only name);
   119 fun update_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.update_thy name);
   120 fun update_thy_only name = Toplevel.imperative (fn () => Context.save ThyInfo.update_thy_only name);
   121 
   122 
   123 (* print theory contents *)
   124 
   125 val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
   126 val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
   127 val print_theorems = Toplevel.keep (PureThy.print_theorems o Toplevel.theory_of);
   128 val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
   129 val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
   130 
   131 
   132 (* print proof context contents *)
   133 
   134 val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of);
   135 val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of);
   136 
   137 
   138 (* print theorems / types / terms / props *)
   139 
   140 fun print_thms args = Toplevel.keep (fn state =>
   141   let val st = Toplevel.node_case Proof.init_state Proof.enter_forward state
   142   in Display.print_thms (IsarThy.get_thmss args st) end);
   143 
   144 
   145 fun read_typ thy = Sign.read_typ (Theory.sign_of thy, K None);
   146 
   147 fun read_term T thy s =
   148   Thm.term_of (#1 (Thm.read_def_cterm (Theory.sign_of thy, K None, K None) [] true (s, T)));
   149 
   150 
   151 fun print_type s = Toplevel.keep (fn state =>
   152   let
   153     val sign = Toplevel.sign_of state;
   154     val T = Toplevel.node_case read_typ (ProofContext.read_typ o Proof.context_of) state s;
   155   in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
   156 
   157 fun print_term s = Toplevel.keep (fn state =>
   158   let
   159     val sign = Toplevel.sign_of state;
   160     val t = Toplevel.node_case (read_term (TVar (("'z", 0), logicS)))
   161       (ProofContext.read_term o Proof.context_of) state s;
   162     val T = Term.type_of t;
   163   in
   164     Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
   165       Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
   166   end);
   167 
   168 fun print_prop s = Toplevel.keep (fn state =>
   169   let
   170     val sign = Toplevel.sign_of state;
   171     val prop =
   172       Toplevel.node_case (read_term propT) (ProofContext.read_prop o Proof.context_of) state s;
   173   in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
   174 
   175 
   176 end;