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