132 |
132 |
133 (* substructure mappings *) |
133 (* substructure mappings *) |
134 |
134 |
135 fun raw_theory_result f lthy = |
135 fun raw_theory_result f lthy = |
136 let |
136 let |
137 val (res, thy') = f (ProofContext.theory_of lthy); |
137 val (res, thy') = f (Proof_Context.theory_of lthy); |
138 val lthy' = lthy |
138 val lthy' = lthy |
139 |> map_target (ProofContext.transfer thy') |
139 |> map_target (Proof_Context.transfer thy') |
140 |> ProofContext.transfer thy'; |
140 |> Proof_Context.transfer thy'; |
141 in (res, lthy') end; |
141 in (res, lthy') end; |
142 |
142 |
143 fun raw_theory f = #2 o raw_theory_result (f #> pair ()); |
143 fun raw_theory f = #2 o raw_theory_result (f #> pair ()); |
144 |
144 |
145 val checkpoint = raw_theory Theory.checkpoint; |
145 val checkpoint = raw_theory Theory.checkpoint; |
158 let |
158 let |
159 val (res, ctxt') = target_of lthy |
159 val (res, ctxt') = target_of lthy |
160 |> Context_Position.set_visible false |
160 |> Context_Position.set_visible false |
161 |> f |
161 |> f |
162 ||> Context_Position.restore_visible lthy; |
162 ||> Context_Position.restore_visible lthy; |
163 val thy' = ProofContext.theory_of ctxt'; |
163 val thy' = Proof_Context.theory_of ctxt'; |
164 val lthy' = lthy |
164 val lthy' = lthy |
165 |> map_target (K ctxt') |
165 |> map_target (K ctxt') |
166 |> ProofContext.transfer thy'; |
166 |> Proof_Context.transfer thy'; |
167 in (res, lthy') end; |
167 in (res, lthy') end; |
168 |
168 |
169 fun target f = #2 o target_result (f #> pair ()); |
169 fun target f = #2 o target_result (f #> pair ()); |
170 |
170 |
171 fun map_contexts f = |
171 fun map_contexts f = |
179 |
179 |
180 |
180 |
181 (* morphisms *) |
181 (* morphisms *) |
182 |
182 |
183 fun standard_morphism lthy ctxt = |
183 fun standard_morphism lthy ctxt = |
184 ProofContext.norm_export_morphism lthy ctxt $> |
184 Proof_Context.norm_export_morphism lthy ctxt $> |
185 Morphism.binding_morphism (Name_Space.transform_binding (naming_of lthy)); |
185 Morphism.binding_morphism (Name_Space.transform_binding (naming_of lthy)); |
186 |
186 |
187 fun target_morphism lthy = standard_morphism lthy (target_of lthy); |
187 fun target_morphism lthy = standard_morphism lthy (target_of lthy); |
188 fun global_morphism lthy = |
188 fun global_morphism lthy = |
189 standard_morphism lthy (ProofContext.init_global (ProofContext.theory_of lthy)); |
189 standard_morphism lthy (Proof_Context.init_global (Proof_Context.theory_of lthy)); |
190 |
190 |
191 |
191 |
192 (* primitive operations *) |
192 (* primitive operations *) |
193 |
193 |
194 fun operation f lthy = f (#operations (get_lthy lthy)) lthy; |
194 fun operation f lthy = f (#operations (get_lthy lthy)) lthy; |
208 |
208 |
209 val notes = notes_kind ""; |
209 val notes = notes_kind ""; |
210 fun note (a, ths) = notes [(a, [(ths, [])])] #>> the_single; |
210 fun note (a, ths) = notes [(a, [(ths, [])])] #>> the_single; |
211 |
211 |
212 fun set_defsort S = |
212 fun set_defsort S = |
213 syntax_declaration false (K (Context.mapping (Sign.set_defsort S) (ProofContext.set_defsort S))); |
213 syntax_declaration false (K (Context.mapping (Sign.set_defsort S) (Proof_Context.set_defsort S))); |
214 |
214 |
215 |
215 |
216 (* notation *) |
216 (* notation *) |
217 |
217 |
218 fun type_notation add mode raw_args lthy = |
218 fun type_notation add mode raw_args lthy = |
219 let val args = map (apfst (Morphism.typ (target_morphism lthy))) raw_args |
219 let val args = map (apfst (Morphism.typ (target_morphism lthy))) raw_args |
220 in syntax_declaration false (ProofContext.target_type_notation add mode args) lthy end; |
220 in syntax_declaration false (Proof_Context.target_type_notation add mode args) lthy end; |
221 |
221 |
222 fun notation add mode raw_args lthy = |
222 fun notation add mode raw_args lthy = |
223 let val args = map (apfst (Morphism.term (target_morphism lthy))) raw_args |
223 let val args = map (apfst (Morphism.term (target_morphism lthy))) raw_args |
224 in syntax_declaration false (ProofContext.target_notation add mode args) lthy end; |
224 in syntax_declaration false (Proof_Context.target_notation add mode args) lthy end; |
225 |
225 |
226 |
226 |
227 (* name space aliases *) |
227 (* name space aliases *) |
228 |
228 |
229 fun alias global_alias local_alias b name = |
229 fun alias global_alias local_alias b name = |
230 syntax_declaration false (fn phi => |
230 syntax_declaration false (fn phi => |
231 let val b' = Morphism.binding phi b |
231 let val b' = Morphism.binding phi b |
232 in Context.mapping (global_alias b' name) (local_alias b' name) end) |
232 in Context.mapping (global_alias b' name) (local_alias b' name) end) |
233 #> local_alias b name; |
233 #> local_alias b name; |
234 |
234 |
235 val class_alias = alias Sign.class_alias ProofContext.class_alias; |
235 val class_alias = alias Sign.class_alias Proof_Context.class_alias; |
236 val type_alias = alias Sign.type_alias ProofContext.type_alias; |
236 val type_alias = alias Sign.type_alias Proof_Context.type_alias; |
237 val const_alias = alias Sign.const_alias ProofContext.const_alias; |
237 val const_alias = alias Sign.const_alias Proof_Context.const_alias; |
238 |
238 |
239 |
239 |
240 |
240 |
241 (** init and exit **) |
241 (** init and exit **) |
242 |
242 |
243 (* init *) |
243 (* init *) |
244 |
244 |
245 fun init group theory_prefix operations target = |
245 fun init group theory_prefix operations target = |
246 let val naming = |
246 let val naming = |
247 Sign.naming_of (ProofContext.theory_of target) |
247 Sign.naming_of (Proof_Context.theory_of target) |
248 |> Name_Space.set_group group |
248 |> Name_Space.set_group group |
249 |> Name_Space.mandatory_path theory_prefix; |
249 |> Name_Space.mandatory_path theory_prefix; |
250 in |
250 in |
251 target |> Data.map |
251 target |> Data.map |
252 (fn NONE => SOME (make_lthy (naming, theory_prefix, operations, target)) |
252 (fn NONE => SOME (make_lthy (naming, theory_prefix, operations, target)) |
259 in init (Name_Space.get_group naming) theory_prefix operations target end; |
259 in init (Name_Space.get_group naming) theory_prefix operations target end; |
260 |
260 |
261 |
261 |
262 (* exit *) |
262 (* exit *) |
263 |
263 |
264 val exit = ProofContext.background_theory Theory.checkpoint o operation #exit; |
264 val exit = Proof_Context.background_theory Theory.checkpoint o operation #exit; |
265 val exit_global = ProofContext.theory_of o exit; |
265 val exit_global = Proof_Context.theory_of o exit; |
266 |
266 |
267 fun exit_result f (x, lthy) = |
267 fun exit_result f (x, lthy) = |
268 let |
268 let |
269 val ctxt = exit lthy; |
269 val ctxt = exit lthy; |
270 val phi = standard_morphism lthy ctxt; |
270 val phi = standard_morphism lthy ctxt; |
271 in (f phi x, ctxt) end; |
271 in (f phi x, ctxt) end; |
272 |
272 |
273 fun exit_result_global f (x, lthy) = |
273 fun exit_result_global f (x, lthy) = |
274 let |
274 let |
275 val thy = exit_global lthy; |
275 val thy = exit_global lthy; |
276 val thy_ctxt = ProofContext.init_global thy; |
276 val thy_ctxt = Proof_Context.init_global thy; |
277 val phi = standard_morphism lthy thy_ctxt; |
277 val phi = standard_morphism lthy thy_ctxt; |
278 in (f phi x, thy) end; |
278 in (f phi x, thy) end; |
279 |
279 |
280 end; |
280 end; |