src/Pure/Isar/isar_cmd.ML
author wenzelm
Tue, 17 Nov 1998 14:12:13 +0100
changeset 5913 c543568ccaca
parent 5895 457b42674b57
child 5991 832ec852fc4e
permissions -rw-r--r--
break: exhibit state; removed print_thm;
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 break: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    11
  val exit: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    12
  val quit: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    13
  val use: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    14
  val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    15
  val use_mltext: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    16
  val use_commit: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    17
  val cd: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    18
  val pwd: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    19
  val use_thy: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    20
  val load: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    21
  val print_theory: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    22
  val print_syntax: Toplevel.transition -> Toplevel.transition
5880
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
    23
  val print_theorems: Toplevel.transition -> Toplevel.transition
5831
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    24
  val print_attributes: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    25
  val print_methods: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    26
  val print_binds: Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    27
  val print_lthms: Toplevel.transition -> Toplevel.transition
5880
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
    28
  val print_thms: xstring * Args.src list -> Toplevel.transition -> Toplevel.transition
5831
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    29
  val print_prop: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    30
  val print_term: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    31
  val print_type: string -> Toplevel.transition -> Toplevel.transition
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    32
end;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    33
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    34
structure IsarCmd: ISAR_CMD =
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    35
struct
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    36
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    37
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    38
(* variations on exit *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    39
5913
c543568ccaca break: exhibit state;
wenzelm
parents: 5895
diff changeset
    40
val break = Toplevel.keep (fn state => raise Toplevel.BREAK state);
5831
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    41
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    42
val exit = Toplevel.keep (fn state =>
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    43
  (Context.set_context (try Toplevel.theory_of state);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    44
    writeln "Leaving the Isar loop.  Invoke 'main_loop();' to restart.";
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    45
    raise Toplevel.TERMINATE));
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    46
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    47
val quit = Toplevel.imperative quit;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    48
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    49
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    50
(* use ML text *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    51
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    52
fun use name = Toplevel.imperative (fn () => Use.use name);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    53
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    54
(*passes changes of theory context*)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    55
val use_mltext_theory = Toplevel.theory o IsarThy.use_mltext_theory;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    56
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    57
(*ignore result theory context*)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    58
fun use_mltext txt = Toplevel.keep (fn state =>
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    59
  (IsarThy.use_mltext txt (try Toplevel.theory_of state); ()));
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    60
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    61
(*Note: commit is dynamically bound*)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    62
val use_commit = use_mltext "commit();";
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    63
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    64
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    65
(* current working directory *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    66
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    67
fun print_cd _ = writeln (Library.pwd ());
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    68
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    69
fun cd dir = Toplevel.imperative (fn () => (Use.cd dir; print_cd ()));
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    70
val pwd = Toplevel.imperative print_cd;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    71
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    72
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    73
(* load theory files *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    74
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    75
fun use_thy name = Toplevel.imperative (fn () => ThyRead.use_thy name);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    76
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    77
fun load name =
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    78
  Toplevel.imperative (fn () => Toplevel.excursion (OuterSyntax.read_file (name ^ ".thy")));
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    79
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    80
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    81
(* print theory contents *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    82
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    83
val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    84
val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
5880
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
    85
val print_theorems = Toplevel.keep (PureThy.print_theorems o Toplevel.theory_of);
5831
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    86
val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    87
val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    88
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    89
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    90
(* print proof context contents *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    91
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    92
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
    93
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
    94
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    95
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    96
(* print theorems *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
    97
5880
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
    98
fun global_attribs thy ths srcs =
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
    99
  #2 (Attribute.applys ((Theory.copy thy, ths), map (Attrib.global_attribute thy) srcs));
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
   100
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
   101
fun local_attribs st ths srcs =
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
   102
  #2 (Attribute.applys ((Proof.context_of st, ths),
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
   103
    map (Attrib.local_attribute (Proof.theory_of st)) srcs));
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
   104
5913
c543568ccaca break: exhibit state;
wenzelm
parents: 5895
diff changeset
   105
fun print_thms (name, srcs) = Toplevel.keep (fn state =>
5831
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   106
  let
5880
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
   107
    val ths = map (apfst (Thm.transfer (Toplevel.theory_of state)))
5913
c543568ccaca break: exhibit state;
wenzelm
parents: 5895
diff changeset
   108
      (Toplevel.node_cases PureThy.get_tthms (ProofContext.get_tthms o Proof.context_of)
5831
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   109
        state name);
5880
feec44106a8e add print_theorems;
wenzelm
parents: 5831
diff changeset
   110
    val ths' = Toplevel.node_cases global_attribs local_attribs state ths srcs;
5913
c543568ccaca break: exhibit state;
wenzelm
parents: 5895
diff changeset
   111
  in Attribute.print_tthms ths' end);
5895
457b42674b57 added print_thm;
wenzelm
parents: 5880
diff changeset
   112
5831
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   113
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   114
(* print types, terms and props *)
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   115
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   116
fun read_typ thy = Sign.read_typ (Theory.sign_of thy, K None);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   117
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   118
fun read_term T thy s =
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   119
  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
   120
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   121
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   122
fun print_type s = Toplevel.keep (fn state =>
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   123
  let
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   124
    val sign = Toplevel.sign_of state;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   125
    val T = Toplevel.node_cases read_typ (ProofContext.read_typ o Proof.context_of) state s;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   126
  in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   127
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   128
fun print_term s = Toplevel.keep (fn state =>
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   129
  let
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   130
    val sign = Toplevel.sign_of state;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   131
    val t = Toplevel.node_cases (read_term (TVar (("'z", 0), logicS)))
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   132
      (ProofContext.read_term o Proof.context_of) state s;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   133
    val T = Term.type_of t;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   134
  in
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   135
    Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   136
      Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   137
  end);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   138
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   139
fun print_prop s = Toplevel.keep (fn state =>
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   140
  let
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   141
    val sign = Toplevel.sign_of state;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   142
    val prop =
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   143
      Toplevel.node_cases (read_term propT) (ProofContext.read_prop o Proof.context_of) state s;
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   144
  in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   145
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   146
996361157cfb Non-logical toplevel commands.
wenzelm
parents:
diff changeset
   147
end;