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