fun map_contexts f lthy = letval n = level lthy in
lthy |> (Data.map o map_index)
(fn (i, {background_naming, operations, conclude, target}) =>
make_lthy (background_naming, operations, conclude,
target
|> Context_Position.set_visible false
|> f (n - i - 1)
|> Context_Position.restore_visible target))
|> f n end;
(* naming for background theory *)
val background_naming_of = #background_naming o top_of;
fun map_background_naming f =
map_top (fn (background_naming, operations, conclude, target) =>
(f background_naming, operations, conclude, target));
val restore_background_naming = map_background_naming o K o background_naming_of;
val full_name = Name_Space.full_name o background_naming_of; fun full_name_pos lthy b = (full_name lthy b, Binding.default_pos_of b);
val new_group = map_background_naming Name_Space.new_group; val reset_group = map_background_naming Name_Space.reset_group;
fun standard_morphism_theory lthy =
standard_morphism lthy (Proof_Context.init_global (Proof_Context.theory_of lthy));
fun standard_form lthy ctxt x =
Morphism.form (Morphism.transform (standard_morphism lthy ctxt) x);
(* background theory *)
fun raw_theory_result f lthy = let val (res, thy') = f (Proof_Context.theory_of lthy); val lthy' = map_contexts (K (Proof_Context.transfer thy')) lthy; in (res, lthy') end;
fun raw_theory f = #2 o raw_theory_result (f #> pair ());
fun background_theory_result f lthy = let val naming =
background_naming_of lthy
|> Name_Space.transform_naming (Proof_Context.naming_of lthy); in
lthy |> raw_theory_result (fn thy =>
thy
|> Sign.map_naming (K naming)
|> f
||> Sign.restore_naming thy) end;
fun background_theory f = #2 o background_theory_result (f #> pair ());
(* target contexts *)
val target_of = #target o bottom_of;
fun target f lthy = let val ctxt = target_of lthy; val ctxt' = ctxt
|> Context_Position.set_visible false
|> f
|> Context_Position.restore_visible ctxt; val thy' = Proof_Context.theory_of ctxt'; in map_contexts (fn 0 => K ctxt' | _ => Proof_Context.transfer thy') lthy end;
fun target_morphism lthy = standard_morphism lthy (target_of lthy);
fun propagate_ml_env (context as Context.Proof lthy) = letval inherit = ML_Env.inherit [context] in
lthy
|> background_theory (Context.theory_map inherit)
|> map_contexts (K (Context.proof_map inherit))
|> Context.Proof end
| propagate_ml_env context = context;
fun touch_ml_env context = if Context.enabled_tracing () then
(case context of
Context.Theory _ => ML_Env.touch context
| Context.Proof _ => context) else context;
(** operations **)
val operations_of = #operations o top_of;
fun operation f lthy = f (operations_of lthy) lthy; fun operation1 f x = operation (fn ops => f ops x); fun operation2 f x y = operation (fn ops => f ops x y);
(* primitives *)
val pretty = operation #pretty; val abbrev = operation2 #abbrev; val define = operation2 #define false; val define_internal = operation2 #define true; val notes_kind = operation2 #notes; fun declaration args = operation2 #declaration args o Morphism.entity; val theory_registration = operation1 #theory_registration; fun locale_dependency registration =
assert_bottom #> operation1 #locale_dependency registration;
(* theorems *)
val notes = notes_kind ""; fun note (a, ths) = notes [(a, [(ths, [])])] #>> the_single;
fun gen_translations prep_trrule add raw_args lthy = let val args = map (prep_trrule lthy) raw_args; val _ = Sign.check_translations lthy args; in
declaration {syntax = true, pervasive = false, pos = Position.thread_data ()}
(fn _ => Proof_Context.generic_translations add args) lthy end;
val translations = gen_translations (K I); val translations_cmd = gen_translations Syntax.parse_trrule;
(* notation *)
local
fun gen_type_notation prep_type add mode raw_args lthy = let val prepare = prep_type lthy #> Logic.type_map (Assumption.export_term lthy (target_of lthy)); val args = map (apfst prepare) raw_args; val args' = map (apsnd Mixfix.reset_pos) args; val _ = lthy |> Context_Position.is_visible lthy ? Proof_Context.type_notation add mode args; in
declaration {syntax = true, pervasive = false, pos = Position.thread_data ()}
(Proof_Context.generic_type_notation add mode args') lthy end;
fun gen_notation prep_const add mode raw_args lthy = let val prepare = prep_const lthy #> Assumption.export_term lthy (target_of lthy); val args = map (apfst prepare) raw_args; val args' = map (apsnd Mixfix.reset_pos) args; val _ = lthy |> Context_Position.is_visible lthy ? Proof_Context.notation add mode args; in
declaration {syntax = true, pervasive = false, pos = Position.thread_data ()}
(Proof_Context.generic_notation add mode args') lthy end;
in
val type_notation = gen_type_notation (K I); val type_notation_cmd =
gen_type_notation (Proof_Context.read_type_name {proper = true, strict = false});
val notation = gen_notation (K I); val notation_cmd = gen_notation (Proof_Context.read_const {proper = false, strict = false});
end;
(* name space aliases *)
fun syntax_alias global_alias local_alias b name =
declaration {syntax = true, pervasive = false, pos = Position.thread_data ()} (fn phi => letval b' = Morphism.binding phi b in Context.mapping (global_alias b' name) (local_alias b' name) end);
val type_alias = syntax_alias Sign.type_alias Proof_Context.type_alias; val const_alias = syntax_alias Sign.const_alias Proof_Context.const_alias;
fun exit lthy = exit_of lthy (assert_bottom lthy); val exit_global = Proof_Context.theory_of o exit;
fun exit_result decl (x, lthy) = let val ctxt = exit lthy; val phi = standard_morphism lthy ctxt; in (decl phi x, ctxt) end;
fun exit_result_global decl (x, lthy) = let val thy = exit_global lthy; val thy_ctxt = Proof_Context.init_global thy; val phi = standard_morphism lthy thy_ctxt; in (decl phi x, thy) end;
(* nested targets *)
fun begin_nested lthy = let val _ = assert lthy; val (scope, target) = Proof_Context.new_scope lthy; val entry = make_lthy (background_naming_of lthy, operations_of lthy,
Proof_Context.restore_naming lthy, target); val lthy' = Data.map (cons entry) target; in (scope, lthy') end;
fun end_nested lthy = let val _ = assert_not_bottom lthy; val ({conclude, ...} :: rest) = Data.get lthy; in lthy |> Data.put rest |> reset |> conclude end;
fun end_nested_result decl (x, lthy) = let val outer_lthy = end_nested lthy; val phi = Proof_Context.export_morphism lthy outer_lthy; in (decl phi x, outer_lthy) end;
end;
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.