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