src/Pure/Isar/isar_thy.ML
author wenzelm
Thu, 11 Mar 1999 21:53:50 +0100
changeset 6354 a4c75cbd2fbf
parent 6331 fb7b8d6c2bd1
child 6371 8469852acbc0
permissions -rw-r--r--
add_title;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/isar_thy.ML
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     4
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     5
Derived theory operations.
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     6
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     7
TODO:
5925
669d0bc621e1 tuned comments;
wenzelm
parents: 5915
diff changeset
     8
  - pure_thy.ML: add_constdefs (atomic!);
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     9
  - 'methods' section (proof macros, ML method defs) (!?);
5882
c8096461f5c8 renamed tac / etac to refine / then_refine;
wenzelm
parents: 5830
diff changeset
    10
  - next_block: ProofHistory open / close (!?);
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    11
*)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    12
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    13
signature ISAR_THY =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    14
sig
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    15
  val add_text: string -> theory -> theory
6354
a4c75cbd2fbf add_title;
wenzelm
parents: 6331
diff changeset
    16
  val add_title: string -> string -> string -> theory -> theory
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    17
  val add_chapter: string -> theory -> theory
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    18
  val add_section: string -> theory -> theory
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    19
  val add_subsection: string -> theory -> theory
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    20
  val add_subsubsection: string -> theory -> theory
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    21
  val add_axioms: ((bstring * string) * Args.src list) list -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    22
  val add_defs: ((bstring * string) * Args.src list) list -> theory -> theory
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    23
  val have_theorems: (bstring * Args.src list) * (xstring * Args.src list) list
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    24
    -> theory -> theory
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    25
  val have_lemmas: (bstring * Args.src list) * (xstring * Args.src list) list
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    26
    -> theory -> theory
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    27
  val have_facts: (string * Args.src list) * (string * Args.src list) list
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    28
    -> ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    29
  val fix: (string * string option) list -> ProofHistory.T -> ProofHistory.T
5938
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    30
  val match_bind: (string list * string) list -> ProofHistory.T -> ProofHistory.T
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    31
  val theorem: string -> Args.src list -> string * string list -> theory -> ProofHistory.T
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    32
  val lemma: string -> Args.src list -> string * string list -> theory -> ProofHistory.T
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    33
  val assume: string -> Args.src list -> (string * string list) list
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    34
    -> ProofHistory.T -> ProofHistory.T
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    35
  val show: string -> Args.src list -> string * string list -> ProofHistory.T -> ProofHistory.T
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    36
  val have: string -> Args.src list -> string * string list -> ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    37
  val chain: ProofHistory.T -> ProofHistory.T
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    38
  val from_facts: (string * Args.src list) list -> ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    39
  val begin_block: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    40
  val next_block: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    41
  val end_block: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    42
  val qed_with: bstring option * Args.src list option -> ProofHistory.T -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    43
  val qed: ProofHistory.T -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    44
  val kill_proof: ProofHistory.T -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    45
  val tac: Method.text -> ProofHistory.T -> ProofHistory.T
5882
c8096461f5c8 renamed tac / etac to refine / then_refine;
wenzelm
parents: 5830
diff changeset
    46
  val then_tac: Method.text -> ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    47
  val proof: Method.text option -> ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    48
  val terminal_proof: Method.text -> ProofHistory.T -> ProofHistory.T
6108
2c9ed58c30ba 'same' method, 'immediate' proof;
wenzelm
parents: 6091
diff changeset
    49
  val immediate_proof: ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    50
  val default_proof: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    51
  val use_mltext: string -> theory option -> theory option
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    52
  val use_mltext_theory: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    53
  val use_setup: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    54
  val parse_ast_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    55
  val parse_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    56
  val print_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    57
  val typed_print_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    58
  val print_ast_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    59
  val token_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    60
  val add_oracle: bstring * string -> theory -> theory
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
    61
  val begin_theory: string -> string list -> (string * bool) list -> theory
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
    62
  val end_theory: theory -> theory
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    63
  val theory: string * string list * (string * bool) list
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    64
    -> Toplevel.transition -> Toplevel.transition
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    65
  val context: string -> Toplevel.transition -> Toplevel.transition
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    66
  val update_context: string -> Toplevel.transition -> Toplevel.transition
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    67
end;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    68
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    69
structure IsarThy: ISAR_THY =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    70
struct
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    71
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    72
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    73
(** derived theory and proof operations **)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    74
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    75
(* formal comments *)	(* FIXME dummy *)
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    76
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    77
fun add_text (txt:string) (thy:theory) = thy;
6354
a4c75cbd2fbf add_title;
wenzelm
parents: 6331
diff changeset
    78
fun add_title title author date thy = thy;
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    79
val add_chapter = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    80
val add_section = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    81
val add_subsection = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    82
val add_subsubsection = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    83
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    84
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    85
(* axioms and defs *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    86
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    87
fun add_axms f args thy =
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    88
  f (map (fn (x, srcs) => (x, map (Attrib.global_attribute thy) srcs)) args) thy;
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    89
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    90
val add_axioms = add_axms PureThy.add_axioms;
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    91
val add_defs = add_axms PureThy.add_defs;
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    92
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    93
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    94
(* theorems *)
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    95
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    96
fun gen_have_thmss get attrib f ((name, more_srcs), th_srcs) x =
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    97
  f name (map (attrib x) more_srcs)
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    98
    (map (fn (s, srcs) => (get x s, map (attrib x) srcs)) th_srcs) x;
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    99
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   100
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   101
val have_theorems =
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   102
  #1 oo gen_have_thmss PureThy.get_thms Attrib.global_attribute PureThy.have_thmss;
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   103
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   104
val have_lemmas =
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   105
  #1 oo gen_have_thmss PureThy.get_thms Attrib.global_attribute
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   106
    (fn name => fn more_atts => PureThy.have_thmss name (more_atts @ [Drule.tag_lemma]));
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   107
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   108
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   109
val have_thmss =
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   110
  gen_have_thmss (ProofContext.get_thms o Proof.context_of)
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   111
    (Attrib.local_attribute o Proof.theory_of) Proof.have_thmss;
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   112
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   113
val have_facts = ProofHistory.apply o have_thmss;
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   114
val from_facts = ProofHistory.apply o (Proof.chain oo curry have_thmss ("", []));
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   115
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   116
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   117
(* context *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   118
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   119
val fix = ProofHistory.apply o Proof.fix;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   120
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   121
val match_bind = ProofHistory.apply o Proof.match_bind;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   122
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   123
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   124
(* statements *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   125
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   126
fun global_statement f name tags s thy =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   127
  ProofHistory.init (f name (map (Attrib.global_attribute thy) tags) s thy);
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   128
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   129
fun local_statement f name tags s = ProofHistory.apply_open (fn state =>
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   130
  f name (map (Attrib.local_attribute (Proof.theory_of state)) tags) s state);
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   131
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   132
val theorem = global_statement Proof.theorem;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   133
val lemma = global_statement Proof.lemma;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   134
val assume = local_statement Proof.assume;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   135
val show = local_statement Proof.show;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   136
val have = local_statement Proof.have;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   137
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   138
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   139
(* forward chaining *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   140
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   141
val chain = ProofHistory.apply Proof.chain;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   142
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   143
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   144
(* end proof *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   145
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   146
fun qed_with (alt_name, alt_tags) prf =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   147
  let
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   148
    val state = ProofHistory.current prf;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   149
    val thy = Proof.theory_of state;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   150
    val alt_atts = apsome (map (Attrib.global_attribute thy)) alt_tags;
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   151
    val (thy', (kind, name, thm)) = Method.qed alt_name alt_atts state;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   152
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   153
    val prt_result = Pretty.block
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   154
      [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, Display.pretty_thm thm];
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   155
  in Pretty.writeln prt_result; thy end;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   156
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   157
val qed = qed_with (None, None);
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   158
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   159
val kill_proof = Proof.theory_of o ProofHistory.current;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   160
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   161
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   162
(* blocks *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   163
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   164
val begin_block = ProofHistory.apply_open Proof.begin_block;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   165
val next_block = ProofHistory.apply Proof.next_block;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   166
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   167
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   168
(* backward steps *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   169
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   170
val tac = ProofHistory.applys o Method.tac;
5882
c8096461f5c8 renamed tac / etac to refine / then_refine;
wenzelm
parents: 5830
diff changeset
   171
val then_tac = ProofHistory.applys o Method.then_tac;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   172
val proof = ProofHistory.applys o Method.proof;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   173
val end_block = ProofHistory.applys_close Method.end_block;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   174
val terminal_proof = ProofHistory.applys_close o Method.terminal_proof;
6108
2c9ed58c30ba 'same' method, 'immediate' proof;
wenzelm
parents: 6091
diff changeset
   175
val immediate_proof = ProofHistory.applys_close Method.immediate_proof;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   176
val default_proof = ProofHistory.applys_close Method.default_proof;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   177
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   178
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   179
(* use ML text *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   180
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   181
fun use_mltext txt opt_thy = #2 (Context.pass opt_thy (use_text false) txt);
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   182
fun use_mltext_theory txt thy = #2 (Context.pass_theory thy (use_text false) txt);
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   183
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   184
fun use_context txt = use_mltext_theory ("Context.>> (" ^ txt ^ ");");
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   185
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   186
fun use_let name body txt =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   187
  use_context ("let val " ^ name ^ " = " ^ txt ^ " in\n" ^ body ^ " end");
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   188
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   189
val use_setup =
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   190
  use_let "setup: (theory -> theory) list" "Library.apply setup";
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   191
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   192
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   193
(* translation functions *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   194
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   195
val parse_ast_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   196
  use_let "parse_ast_translation: (string * (Syntax.ast list -> Syntax.ast)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   197
    "Theory.add_trfuns (parse_ast_translation, [], [], [])";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   198
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   199
val parse_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   200
  use_let "parse_translation: (string * (term list -> term)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   201
    "Theory.add_trfuns ([], parse_translation, [], [])";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   202
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   203
val print_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   204
  use_let "print_translation: (string * (term list -> term)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   205
    "Theory.add_trfuns ([], [], print_translation, [])";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   206
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   207
val print_ast_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   208
  use_let "print_ast_translation: (string * (Syntax.ast list -> Syntax.ast)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   209
    "Theory.add_trfuns ([], [], [], print_ast_translation)";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   210
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   211
val typed_print_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   212
  use_let "typed_print_translation: (string * (bool -> typ -> term list -> term)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   213
    "Theory.add_trfunsT typed_print_translation";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   214
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   215
val token_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   216
  use_let "token_translation: (string * string * (string -> string * int)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   217
    "Theory.add_tokentrfuns token_translation";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   218
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   219
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   220
(* add_oracle *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   221
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   222
fun add_oracle (name, txt) =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   223
  use_let
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   224
    "oracle: bstring * (Sign.sg * Object.T -> term)"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   225
    "Theory.add_oracle oracle"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   226
    ("(" ^ quote name ^ ", " ^ txt ^ ")");
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   227
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   228
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   229
(* theory init and exit *)	(* FIXME move? rearrange? *)
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   230
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   231
fun begin_theory name parents files =
6266
a5f9fa6b6d7c Context.fetch, Context.setmp;
wenzelm
parents: 6253
diff changeset
   232
  let
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   233
    val paths = map (apfst Path.unpack) files;
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   234
    val thy = ThyInfo.begin_theory name parents paths;
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   235
  in Present.begin_theory name parents paths; thy end;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   236
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   237
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   238
(* FIXME
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   239
fun end_theory thy =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   240
  let val thy' = PureThy.end_theory thy in
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   241
    Present.end_theory (PureThy.get_name thy');
6198
7fa2deb92b39 ThyInfo.begin_theory;
wenzelm
parents: 6108
diff changeset
   242
    transform_error ThyInfo.put_theory thy'
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   243
      handle exn => raise PureThy.ROLLBACK (thy', Some exn)     (* FIXME !!?? *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   244
  end;
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   245
*)
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   246
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   247
fun end_theory thy =
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   248
  (Present.end_theory (PureThy.get_name thy); ThyInfo.end_theory thy);
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   249
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   250
fun bg_theory (name, parents, files) () = begin_theory name parents files;
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   251
fun en_theory thy = (end_theory thy; ());
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   252
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   253
fun theory spec = Toplevel.init_theory (bg_theory spec) en_theory;
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   254
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   255
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   256
(* context switch *)
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   257
6253
dbaf79ac2ff9 made MLWorks happy;
wenzelm
parents: 6246
diff changeset
   258
fun switch_theory load name =
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   259
  Toplevel.init_theory
6253
dbaf79ac2ff9 made MLWorks happy;
wenzelm
parents: 6246
diff changeset
   260
    (fn () => (Context.save load name; ThyInfo.get_theory name)) (K ());
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   261
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   262
val context = switch_theory ThyInfo.use_thy;
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   263
val update_context = switch_theory ThyInfo.update_thy;
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   264
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   265
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   266
end;