| author | wenzelm | 
| Tue, 28 Oct 2014 09:57:12 +0100 | |
| changeset 58797 | 6d71f19a9fd6 | 
| parent 58011 | bc6bced136e5 | 
| child 59859 | f9d1442c70f3 | 
| permissions | -rw-r--r-- | 
| 18744 | 1 | (* Title: Pure/Isar/local_theory.ML | 
| 2 | Author: Makarius | |
| 3 | ||
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 4 | Local theory operations, with abstract target context. | 
| 18744 | 5 | *) | 
| 6 | ||
| 18951 | 7 | type local_theory = Proof.context; | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
36610diff
changeset | 8 | type generic_theory = Context.generic; | 
| 18951 | 9 | |
| 57926 
59b2572e8e93
load local_theory.ML before attrib.ML, with subtle change of semantics due to canonical Local_Theory.map_contexts instead of private Local_Theory.map_top;
 wenzelm parents: 
57925diff
changeset | 10 | structure Attrib = | 
| 
59b2572e8e93
load local_theory.ML before attrib.ML, with subtle change of semantics due to canonical Local_Theory.map_contexts instead of private Local_Theory.map_top;
 wenzelm parents: 
57925diff
changeset | 11 | struct | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57941diff
changeset | 12 | type binding = binding * Token.src list; | 
| 57926 
59b2572e8e93
load local_theory.ML before attrib.ML, with subtle change of semantics due to canonical Local_Theory.map_contexts instead of private Local_Theory.map_top;
 wenzelm parents: 
57925diff
changeset | 13 | end; | 
| 
59b2572e8e93
load local_theory.ML before attrib.ML, with subtle change of semantics due to canonical Local_Theory.map_contexts instead of private Local_Theory.map_top;
 wenzelm parents: 
57925diff
changeset | 14 | |
| 18744 | 15 | signature LOCAL_THEORY = | 
| 16 | sig | |
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 17 | type operations | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 18 | val assert: local_theory -> local_theory | 
| 47273 | 19 | val restore: local_theory -> local_theory | 
| 47064 | 20 | val level: Proof.context -> int | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 21 | val assert_bottom: bool -> local_theory -> local_theory | 
| 57926 
59b2572e8e93
load local_theory.ML before attrib.ML, with subtle change of semantics due to canonical Local_Theory.map_contexts instead of private Local_Theory.map_top;
 wenzelm parents: 
57925diff
changeset | 22 | val mark_brittle: local_theory -> local_theory | 
| 51735 | 23 | val assert_nonbrittle: local_theory -> local_theory | 
| 50739 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 24 | val open_target: Name_Space.naming -> operations -> (local_theory -> local_theory) -> | 
| 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 25 | local_theory -> local_theory | 
| 47064 | 26 | val close_target: local_theory -> local_theory | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 27 | val map_contexts: (int -> Proof.context -> Proof.context) -> local_theory -> local_theory | 
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 28 | val naming_of: local_theory -> Name_Space.naming | 
| 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 29 | val full_name: local_theory -> binding -> string | 
| 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 30 | val map_naming: (Name_Space.naming -> Name_Space.naming) -> local_theory -> local_theory | 
| 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 31 | val conceal: local_theory -> local_theory | 
| 33724 | 32 | val new_group: local_theory -> local_theory | 
| 33 | val reset_group: local_theory -> local_theory | |
| 33276 | 34 | val restore_naming: local_theory -> local_theory -> local_theory | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 35 | val standard_morphism: local_theory -> Proof.context -> morphism | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 36 | val standard_form: local_theory -> Proof.context -> (morphism -> 'a) -> 'a | 
| 20960 | 37 | val raw_theory_result: (theory -> 'a * theory) -> local_theory -> 'a * local_theory | 
| 38 | val raw_theory: (theory -> theory) -> local_theory -> local_theory | |
| 38757 
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
 wenzelm parents: 
38756diff
changeset | 39 | val background_theory_result: (theory -> 'a * theory) -> local_theory -> 'a * local_theory | 
| 
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
 wenzelm parents: 
38756diff
changeset | 40 | val background_theory: (theory -> theory) -> local_theory -> local_theory | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 41 | val target_of: local_theory -> Proof.context | 
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 42 | val target: (Proof.context -> Proof.context) -> local_theory -> local_theory | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 43 | val target_morphism: local_theory -> morphism | 
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
36610diff
changeset | 44 | val propagate_ml_env: generic_theory -> generic_theory | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 45 | val operations_of: local_theory -> operations | 
| 33764 
7bcefaab8d41
Local_Theory.define: eliminated slightly odd kind argument -- such low-level definitions should be hardly ever exposed to end-users anyway;
 wenzelm parents: 
33724diff
changeset | 46 | val define: (binding * mixfix) * (Attrib.binding * term) -> local_theory -> | 
| 28083 
103d9282a946
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
28017diff
changeset | 47 | (term * (string * thm)) * local_theory | 
| 46992 
eeea81b86b70
refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
 wenzelm parents: 
45298diff
changeset | 48 | val define_internal: (binding * mixfix) * (Attrib.binding * term) -> local_theory -> | 
| 
eeea81b86b70
refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
 wenzelm parents: 
45298diff
changeset | 49 | (term * (string * thm)) * local_theory | 
| 33670 
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
 wenzelm parents: 
33519diff
changeset | 50 | val note: Attrib.binding * thm list -> local_theory -> (string * thm list) * local_theory | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57941diff
changeset | 51 | val notes: (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 33670 
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
 wenzelm parents: 
33519diff
changeset | 52 | local_theory -> (string * thm list) list * local_theory | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57941diff
changeset | 53 | val notes_kind: string -> (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 28083 
103d9282a946
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
28017diff
changeset | 54 | local_theory -> (string * thm list) list * local_theory | 
| 38308 
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
 haftmann parents: 
37949diff
changeset | 55 | val abbrev: Syntax.mode -> (binding * mixfix) * term -> local_theory -> | 
| 
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
 haftmann parents: 
37949diff
changeset | 56 | (term * term) * local_theory | 
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 57 |   val declaration: {syntax: bool, pervasive: bool} -> declaration -> local_theory -> local_theory
 | 
| 56723 
a8f71445c265
subscription as target-specific implementation device
 haftmann parents: 
56141diff
changeset | 58 | val subscription: string * morphism -> (morphism * bool) option -> morphism -> | 
| 
a8f71445c265
subscription as target-specific implementation device
 haftmann parents: 
56141diff
changeset | 59 | local_theory -> local_theory | 
| 38308 
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
 haftmann parents: 
37949diff
changeset | 60 | val pretty: local_theory -> Pretty.T list | 
| 57929 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 61 | val add_thms_dynamic: binding * (Context.generic -> thm list) -> local_theory -> local_theory | 
| 36451 | 62 | val set_defsort: sort -> local_theory -> local_theory | 
| 35412 
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
 wenzelm parents: 
33764diff
changeset | 63 | val type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> local_theory -> local_theory | 
| 24949 | 64 | val notation: bool -> Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory | 
| 57938 | 65 | val generic_alias: | 
| 66 |     (('a Name_Space.table -> 'a Name_Space.table) -> Context.generic -> Context.generic) ->
 | |
| 67 | binding -> string -> local_theory -> local_theory | |
| 35738 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 68 | val class_alias: binding -> class -> local_theory -> local_theory | 
| 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 69 | val type_alias: binding -> string -> local_theory -> local_theory | 
| 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 70 | val const_alias: binding -> string -> local_theory -> local_theory | 
| 47061 
355317493f34
clarified Local_Theory.init: avoid hardwired naming policy, discontinued odd/unused group argument (cf. 5ee13e0428d2);
 wenzelm parents: 
46992diff
changeset | 71 | val init: Name_Space.naming -> operations -> Proof.context -> local_theory | 
| 21292 | 72 | val exit: local_theory -> Proof.context | 
| 28395 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 73 | val exit_global: local_theory -> theory | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 74 | val exit_result: (morphism -> 'a -> 'b) -> 'a * local_theory -> 'b * Proof.context | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 75 | val exit_result_global: (morphism -> 'a -> 'b) -> 'a * local_theory -> 'b * theory | 
| 18744 | 76 | end; | 
| 77 | ||
| 33671 | 78 | structure Local_Theory: LOCAL_THEORY = | 
| 18744 | 79 | struct | 
| 80 | ||
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 81 | (** local theory data **) | 
| 19059 
b4ca3100e818
init/exit no longer change the theory (no naming);
 wenzelm parents: 
19032diff
changeset | 82 | |
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 83 | (* type lthy *) | 
| 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 84 | |
| 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 85 | type operations = | 
| 46992 
eeea81b86b70
refined Local_Theory.define vs. Local_Theory.define_internal, which allows to pass alternative name to the foundational axiom -- expecially important for 'instantiation' or 'overloading', which loose name information due to Long_Name.base_name cooking etc.;
 wenzelm parents: 
45298diff
changeset | 86 |  {define: bool -> (binding * mixfix) * (Attrib.binding * term) -> local_theory ->
 | 
| 28083 
103d9282a946
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
28017diff
changeset | 87 | (term * (string * thm)) * local_theory, | 
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 88 | notes: string -> | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57941diff
changeset | 89 | (Attrib.binding * (thm list * Token.src list) list) list -> | 
| 28083 
103d9282a946
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
28017diff
changeset | 90 | local_theory -> (string * thm list) list * local_theory, | 
| 38308 
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
 haftmann parents: 
37949diff
changeset | 91 | abbrev: Syntax.mode -> (binding * mixfix) * term -> local_theory -> | 
| 
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
 haftmann parents: 
37949diff
changeset | 92 | (term * term) * local_theory, | 
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 93 |   declaration: {syntax: bool, pervasive: bool} -> declaration -> local_theory -> local_theory,
 | 
| 56723 
a8f71445c265
subscription as target-specific implementation device
 haftmann parents: 
56141diff
changeset | 94 | subscription: string * morphism -> (morphism * bool) option -> morphism -> | 
| 
a8f71445c265
subscription as target-specific implementation device
 haftmann parents: 
56141diff
changeset | 95 | local_theory -> local_theory, | 
| 38308 
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
 haftmann parents: 
37949diff
changeset | 96 | pretty: local_theory -> Pretty.T list, | 
| 21292 | 97 | exit: local_theory -> Proof.context}; | 
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 98 | |
| 47064 | 99 | type lthy = | 
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 100 |  {naming: Name_Space.naming,
 | 
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 101 | operations: operations, | 
| 50739 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 102 | after_close: local_theory -> local_theory, | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 103 | brittle: bool, | 
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 104 | target: Proof.context}; | 
| 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 105 | |
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 106 | fun make_lthy (naming, operations, after_close, brittle, target) : lthy = | 
| 57941 
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
 wenzelm parents: 
57938diff
changeset | 107 |   {naming = naming, operations = operations, after_close = after_close,
 | 
| 
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
 wenzelm parents: 
57938diff
changeset | 108 | brittle = brittle, target = target}; | 
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 109 | |
| 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 110 | |
| 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 111 | (* context data *) | 
| 18744 | 112 | |
| 33519 | 113 | structure Data = Proof_Data | 
| 18744 | 114 | ( | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 115 | type T = lthy list; | 
| 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 116 | fun init _ = []; | 
| 18744 | 117 | ); | 
| 118 | ||
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 119 | fun assert lthy = | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 120 | if null (Data.get lthy) then error "Missing local theory context" else lthy; | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 121 | |
| 57194 
d110b0d1bc12
tuned terminology: emphasize stack-like nature of nested local theories
 haftmann parents: 
56809diff
changeset | 122 | val bottom_of = List.last o Data.get o assert; | 
| 
d110b0d1bc12
tuned terminology: emphasize stack-like nature of nested local theories
 haftmann parents: 
56809diff
changeset | 123 | val top_of = hd o Data.get o assert; | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 124 | |
| 57925 
2bd92d3f92d7
clarified terminology: first is top (amending d110b0d1bc12);
 wenzelm parents: 
57924diff
changeset | 125 | fun map_top f = | 
| 50739 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 126 | assert #> | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 127 |   Data.map (fn {naming, operations, after_close, brittle, target} :: parents =>
 | 
| 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 128 | make_lthy (f (naming, operations, after_close, brittle, target)) :: parents); | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 129 | |
| 57194 
d110b0d1bc12
tuned terminology: emphasize stack-like nature of nested local theories
 haftmann parents: 
56809diff
changeset | 130 | fun restore lthy = #target (top_of lthy) |> Data.put (Data.get lthy); | 
| 47273 | 131 | |
| 47064 | 132 | |
| 133 | (* nested structure *) | |
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 134 | |
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 135 | val level = length o Data.get; (*1: main target at bottom, >= 2: nested context*) | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 136 | |
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 137 | fun assert_bottom b lthy = | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 138 | let | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 139 | val _ = assert lthy; | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 140 | val b' = level lthy <= 1; | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 141 | in | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 142 | if b andalso not b' then error "Not at bottom of local theory nesting" | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 143 | else if not b andalso b' then error "Already at bottom of local theory nesting" | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 144 | else lthy | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 145 | end; | 
| 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 146 | |
| 50739 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 147 | fun open_target naming operations after_close target = | 
| 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 148 | assert target | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 149 | |> Data.map (cons (make_lthy (naming, operations, after_close, true, target))); | 
| 47064 | 150 | |
| 151 | fun close_target lthy = | |
| 50739 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 152 | let | 
| 
5165d7e6d3b9
more precise Local_Theory.level: 1 really means main target and >= 2 nested context;
 wenzelm parents: 
49062diff
changeset | 153 | val _ = assert_bottom false lthy; | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 154 |     val ({after_close, ...} :: rest) = Data.get lthy;
 | 
| 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 155 | in lthy |> Data.put rest |> restore |> after_close end; | 
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 156 | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 157 | fun map_contexts f lthy = | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 158 | let val n = level lthy in | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 159 |     lthy |> (Data.map o map_index) (fn (i, {naming, operations, after_close, brittle, target}) =>
 | 
| 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 160 | make_lthy (naming, operations, after_close, brittle, | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 161 | target | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 162 | |> Context_Position.set_visible false | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 163 | |> f (n - i - 1) | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 164 | |> Context_Position.restore_visible target)) | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 165 | |> f n | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 166 | end; | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 167 | |
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 168 | |
| 51735 | 169 | (* brittle context -- implicit for nested structures *) | 
| 170 | ||
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 171 | fun mark_brittle lthy = | 
| 57924 | 172 | if level lthy = 1 then | 
| 57938 | 173 | map_top (fn (naming, operations, after_close, _, target) => | 
| 57924 | 174 | (naming, operations, after_close, true, target)) lthy | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 175 | else lthy; | 
| 51735 | 176 | |
| 177 | fun assert_nonbrittle lthy = | |
| 57924 | 178 | if #brittle (top_of lthy) then error "Brittle local theory context" | 
| 51735 | 179 | else lthy; | 
| 180 | ||
| 181 | ||
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 182 | (* naming *) | 
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 183 | |
| 57194 
d110b0d1bc12
tuned terminology: emphasize stack-like nature of nested local theories
 haftmann parents: 
56809diff
changeset | 184 | val naming_of = #naming o top_of; | 
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 185 | val full_name = Name_Space.full_name o naming_of; | 
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 186 | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 187 | fun map_naming f = | 
| 57925 
2bd92d3f92d7
clarified terminology: first is top (amending d110b0d1bc12);
 wenzelm parents: 
57924diff
changeset | 188 | map_top (fn (naming, operations, after_close, brittle, target) => | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 189 | (f naming, operations, after_close, brittle, target)); | 
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 190 | |
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 191 | val conceal = map_naming Name_Space.conceal; | 
| 33724 | 192 | val new_group = map_naming Name_Space.new_group; | 
| 193 | val reset_group = map_naming Name_Space.reset_group; | |
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 194 | |
| 33276 | 195 | val restore_naming = map_naming o K o naming_of; | 
| 196 | ||
| 26131 
91024979b9eb
maintain group in lthy data, implicit use in operations;
 wenzelm parents: 
25984diff
changeset | 197 | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 198 | (* standard morphisms *) | 
| 18767 | 199 | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 200 | fun standard_morphism lthy ctxt = | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 201 | Proof_Context.norm_export_morphism lthy ctxt $> | 
| 54740 | 202 | Morphism.binding_morphism "Local_Theory.standard_binding" | 
| 203 | (Name_Space.transform_binding (naming_of lthy)); | |
| 18767 | 204 | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 205 | fun standard_form lthy ctxt x = | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 206 | Morphism.form (Morphism.transform (standard_morphism lthy ctxt) x); | 
| 18767 | 207 | |
| 208 | ||
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 209 | (* background theory *) | 
| 19661 | 210 | |
| 20960 | 211 | fun raw_theory_result f lthy = | 
| 212 | let | |
| 42360 | 213 | val (res, thy') = f (Proof_Context.theory_of lthy); | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 214 | val lthy' = map_contexts (K (Proof_Context.transfer thy')) lthy; | 
| 20960 | 215 | in (res, lthy') end; | 
| 216 | ||
| 217 | fun raw_theory f = #2 o raw_theory_result (f #> pair ()); | |
| 218 | ||
| 38757 
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
 wenzelm parents: 
38756diff
changeset | 219 | fun background_theory_result f lthy = | 
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 220 | lthy |> raw_theory_result (fn thy => | 
| 33157 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 wenzelm parents: 
33095diff
changeset | 221 | thy | 
| 33166 
55f250ef9e31
maintain proper Name_Space.naming, with conceal and set_group;
 wenzelm parents: 
33157diff
changeset | 222 | |> Sign.map_naming (K (naming_of lthy)) | 
| 33157 
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
 wenzelm parents: 
33095diff
changeset | 223 | |> f | 
| 52788 | 224 | ||> Sign.restore_naming thy); | 
| 19661 | 225 | |
| 38757 
2b3e054ae6fc
renamed Local_Theory.theory(_result) to Local_Theory.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
 wenzelm parents: 
38756diff
changeset | 226 | fun background_theory f = #2 o background_theory_result (f #> pair ()); | 
| 19661 | 227 | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 228 | |
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 229 | (* target contexts *) | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 230 | |
| 57194 
d110b0d1bc12
tuned terminology: emphasize stack-like nature of nested local theories
 haftmann parents: 
56809diff
changeset | 231 | val target_of = #target o bottom_of; | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 232 | |
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 233 | fun target f lthy = | 
| 18744 | 234 | let | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 235 | val ctxt = target_of lthy; | 
| 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 236 | val ctxt' = ctxt | 
| 33383 | 237 | |> Context_Position.set_visible false | 
| 28406 
daeb21fec18f
target update: invisible context position avoids duplication of reports etc.;
 wenzelm parents: 
28395diff
changeset | 238 | |> f | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 239 | |> Context_Position.restore_visible ctxt; | 
| 42360 | 240 | val thy' = Proof_Context.theory_of ctxt'; | 
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 241 | in map_contexts (fn 0 => K ctxt' | _ => Proof_Context.transfer thy') lthy end; | 
| 18876 | 242 | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 243 | fun target_morphism lthy = standard_morphism lthy (target_of lthy); | 
| 18767 | 244 | |
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
36610diff
changeset | 245 | fun propagate_ml_env (context as Context.Proof lthy) = | 
| 47064 | 246 | let val inherit = ML_Env.inherit context in | 
| 247 | lthy | |
| 248 | |> background_theory (Context.theory_map inherit) | |
| 47245 
ff1770df59b8
Local_Theory.map_contexts with explicit level indication: 0 = main target at bottom;
 wenzelm parents: 
47081diff
changeset | 249 | |> map_contexts (K (Context.proof_map inherit)) | 
| 47064 | 250 | |> Context.Proof | 
| 251 | end | |
| 37949 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
36610diff
changeset | 252 | | propagate_ml_env context = context; | 
| 
48a874444164
moved management of auxiliary theory source files to Thy_Load -- as theory data instead of accidental loader state;
 wenzelm parents: 
36610diff
changeset | 253 | |
| 18767 | 254 | |
| 47064 | 255 | |
| 256 | (** operations **) | |
| 257 | ||
| 57194 
d110b0d1bc12
tuned terminology: emphasize stack-like nature of nested local theories
 haftmann parents: 
56809diff
changeset | 258 | val operations_of = #operations o top_of; | 
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 259 | |
| 57938 | 260 | fun operation f lthy = f (operations_of lthy) lthy; | 
| 261 | fun operation2 f x y = operation (fn ops => f ops x y); | |
| 262 | ||
| 47066 
8a6124d09ff5
basic support for nested contexts including bundles;
 wenzelm parents: 
47064diff
changeset | 263 | |
| 47064 | 264 | (* primitives *) | 
| 18781 | 265 | |
| 20888 
0ddd2f297ae7
turned into abstract wrapper module, cf. theory_target.ML;
 wenzelm parents: 
20784diff
changeset | 266 | val pretty = operation #pretty; | 
| 52788 | 267 | val abbrev = operation2 #abbrev; | 
| 268 | val define = operation2 #define false; | |
| 269 | val define_internal = operation2 #define true; | |
| 270 | val notes_kind = operation2 #notes; | |
| 271 | val declaration = operation2 #declaration; | |
| 56809 
b60009672a65
prevent subscription in nested contexts explicitly -- at foundational and user level
 haftmann parents: 
56723diff
changeset | 272 | fun subscription dep_morph mixin export = | 
| 
b60009672a65
prevent subscription in nested contexts explicitly -- at foundational and user level
 haftmann parents: 
56723diff
changeset | 273 | assert_bottom true #> operation (fn ops => #subscription ops dep_morph mixin export); | 
| 18781 | 274 | |
| 36451 | 275 | |
| 57938 | 276 | (* theorems *) | 
| 36451 | 277 | |
| 33670 
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
 wenzelm parents: 
33519diff
changeset | 278 | val notes = notes_kind ""; | 
| 
02b7738aef6a
eliminated slightly odd kind argument of LocalTheory.note(s);
 wenzelm parents: 
33519diff
changeset | 279 | fun note (a, ths) = notes [(a, [(ths, [])])] #>> the_single; | 
| 18781 | 280 | |
| 57929 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 281 | fun add_thms_dynamic (binding, f) lthy = | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 282 | lthy | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 283 | |> background_theory_result (fn thy => thy | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 284 | |> Global_Theory.add_thms_dynamic' (Sign.inherit_naming thy lthy) (binding, f)) | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 285 | |-> (fn name => | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 286 | map_contexts (fn _ => fn ctxt => | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 287 | Proof_Context.transfer_facts (Proof_Context.theory_of ctxt) ctxt) #> | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 288 |     declaration {syntax = false, pervasive = false} (fn phi =>
 | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 289 | let val binding' = Morphism.binding phi binding in | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 290 | Context.mapping | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 291 | (Global_Theory.alias_fact binding' name) | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 292 | (Proof_Context.fact_alias binding' name) | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 293 | end)); | 
| 
c5063c033a5a
tuned signature -- proper Local_Theory.add_thms_dynamic;
 wenzelm parents: 
57926diff
changeset | 294 | |
| 57938 | 295 | |
| 296 | (* default sort *) | |
| 297 | ||
| 36451 | 298 | fun set_defsort S = | 
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 299 |   declaration {syntax = true, pervasive = false}
 | 
| 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 300 | (K (Context.mapping (Sign.set_defsort S) (Proof_Context.set_defsort S))); | 
| 36451 | 301 | |
| 35738 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 302 | |
| 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 303 | (* notation *) | 
| 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 304 | |
| 35412 
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
 wenzelm parents: 
33764diff
changeset | 305 | fun type_notation add mode raw_args lthy = | 
| 50741 
20e6e1a92e54
less aggressive Assumption.export_term (similar to Generic_Target.abbrev): merely expand local defs and thus allow notation for local fixes;
 wenzelm parents: 
50739diff
changeset | 306 | let | 
| 
20e6e1a92e54
less aggressive Assumption.export_term (similar to Generic_Target.abbrev): merely expand local defs and thus allow notation for local fixes;
 wenzelm parents: 
50739diff
changeset | 307 | val args = map (apfst (Logic.type_map (Assumption.export_term lthy (target_of lthy)))) raw_args; | 
| 
20e6e1a92e54
less aggressive Assumption.export_term (similar to Generic_Target.abbrev): merely expand local defs and thus allow notation for local fixes;
 wenzelm parents: 
50739diff
changeset | 308 | in | 
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 309 |     declaration {syntax = true, pervasive = false}
 | 
| 47247 | 310 | (Proof_Context.generic_type_notation add mode args) lthy | 
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 311 | end; | 
| 35412 
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
 wenzelm parents: 
33764diff
changeset | 312 | |
| 24949 | 313 | fun notation add mode raw_args lthy = | 
| 50741 
20e6e1a92e54
less aggressive Assumption.export_term (similar to Generic_Target.abbrev): merely expand local defs and thus allow notation for local fixes;
 wenzelm parents: 
50739diff
changeset | 314 | let | 
| 
20e6e1a92e54
less aggressive Assumption.export_term (similar to Generic_Target.abbrev): merely expand local defs and thus allow notation for local fixes;
 wenzelm parents: 
50739diff
changeset | 315 | val args = map (apfst (Assumption.export_term lthy (target_of lthy))) raw_args | 
| 
20e6e1a92e54
less aggressive Assumption.export_term (similar to Generic_Target.abbrev): merely expand local defs and thus allow notation for local fixes;
 wenzelm parents: 
50739diff
changeset | 316 | in | 
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 317 |     declaration {syntax = true, pervasive = false}
 | 
| 47247 | 318 | (Proof_Context.generic_notation add mode args) lthy | 
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 319 | end; | 
| 21743 | 320 | |
| 21664 
dd4e89123359
notation/abbreviation: more serious handling of morphisms;
 wenzelm parents: 
21614diff
changeset | 321 | |
| 35738 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 322 | (* name space aliases *) | 
| 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 323 | |
| 57938 | 324 | fun generic_alias app b name = | 
| 325 |   declaration {syntax = false, pervasive = false} (fn phi => fn context =>
 | |
| 326 | let | |
| 327 | val naming = Name_Space.naming_of context; | |
| 328 | val b' = Morphism.binding phi b; | |
| 329 | in app (Name_Space.alias_table naming b' name) context end); | |
| 330 | ||
| 331 | fun syntax_alias global_alias local_alias b name = | |
| 45291 
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
 wenzelm parents: 
42360diff
changeset | 332 |   declaration {syntax = true, pervasive = false} (fn phi =>
 | 
| 35738 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 333 | let val b' = Morphism.binding phi b | 
| 45298 
aa35859c8741
uniform treatment of syntax declaration wrt. aux. context (NB: notation avoids duplicate mixfix internally);
 wenzelm parents: 
45291diff
changeset | 334 | in Context.mapping (global_alias b' name) (local_alias b' name) end); | 
| 35738 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 335 | |
| 57938 | 336 | val class_alias = syntax_alias Sign.class_alias Proof_Context.class_alias; | 
| 337 | val type_alias = syntax_alias Sign.type_alias Proof_Context.type_alias; | |
| 338 | val const_alias = syntax_alias Sign.const_alias Proof_Context.const_alias; | |
| 35738 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 339 | |
| 
98fd035c3fe3
added Local_Theory.alias operations (independent of target);
 wenzelm parents: 
35412diff
changeset | 340 | |
| 56055 
8fe7414f00b1
slightly more rubust (and opportunistic) exit for old-fashioned theory_to_proof, which is used by global 'sublocale' with Named_Target.init but without proper exit;
 wenzelm parents: 
54740diff
changeset | 341 | |
| 36451 | 342 | (** init and exit **) | 
| 343 | ||
| 28395 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 344 | (* init *) | 
| 20910 | 345 | |
| 47061 
355317493f34
clarified Local_Theory.init: avoid hardwired naming policy, discontinued odd/unused group argument (cf. 5ee13e0428d2);
 wenzelm parents: 
46992diff
changeset | 346 | fun init naming operations target = | 
| 52118 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 347 | target |> Data.map | 
| 
2a976115c7c3
mark local theory as brittle also after interpretation inside locales;
 haftmann parents: 
51735diff
changeset | 348 | (fn [] => [make_lthy (naming, operations, I, false, target)] | 
| 52788 | 349 | | _ => error "Local theory already initialized"); | 
| 20910 | 350 | |
| 28395 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 351 | |
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 352 | (* exit *) | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 353 | |
| 52788 | 354 | val exit = operation #exit; | 
| 42360 | 355 | val exit_global = Proof_Context.theory_of o exit; | 
| 28395 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 356 | |
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 357 | fun exit_result f (x, lthy) = | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 358 | let | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 359 | val ctxt = exit lthy; | 
| 33281 
223ef9bc399a
let naming transform binding beforehand -- covering only the "conceal" flag for now;
 wenzelm parents: 
33276diff
changeset | 360 | val phi = standard_morphism lthy ctxt; | 
| 28395 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 361 | in (f phi x, ctxt) end; | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 362 | |
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 363 | fun exit_result_global f (x, lthy) = | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 364 | let | 
| 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 365 | val thy = exit_global lthy; | 
| 42360 | 366 | val thy_ctxt = Proof_Context.init_global thy; | 
| 33281 
223ef9bc399a
let naming transform binding beforehand -- covering only the "conceal" flag for now;
 wenzelm parents: 
33276diff
changeset | 367 | val phi = standard_morphism lthy thy_ctxt; | 
| 28395 
984fcc8feb24
added exit_global, exit_result, exit_result_global;
 wenzelm parents: 
28379diff
changeset | 368 | in (f phi x, thy) end; | 
| 20910 | 369 | |
| 18781 | 370 | end; |