6 *) |
6 *) |
7 |
7 |
8 signature THEORY_TARGET = |
8 signature THEORY_TARGET = |
9 sig |
9 sig |
10 val peek: local_theory -> {target: string, is_locale: bool, is_class: bool} |
10 val peek: local_theory -> {target: string, is_locale: bool, is_class: bool} |
|
11 val init: string option -> theory -> local_theory |
|
12 val init_cmd: xstring -> theory -> local_theory |
11 val begin: string -> Proof.context -> local_theory |
13 val begin: string -> Proof.context -> local_theory |
12 val init: string option -> theory -> local_theory |
|
13 val init_cmd: xstring option -> theory -> local_theory |
|
14 end; |
14 end; |
15 |
15 |
16 structure TheoryTarget: THEORY_TARGET = |
16 structure TheoryTarget: THEORY_TARGET = |
17 struct |
17 struct |
18 |
18 |
19 (* context data *) |
19 (* context data *) |
20 |
20 |
21 datatype target = Target of {target: string, is_locale: bool, is_class: bool}; |
21 datatype target = Target of {target: string, is_locale: bool, is_class: bool}; |
22 |
22 |
23 fun make_target target is_locale is_class = |
23 fun make_target thy NONE = |
24 Target {target = target, is_locale = is_locale, is_class = is_class}; |
24 Target {target = "", is_locale = false, is_class = false} |
|
25 | make_target thy (SOME target) = |
|
26 Target {target = target, is_locale = true, is_class = Class.is_class thy target}; |
25 |
27 |
26 structure Data = ProofDataFun |
28 structure Data = ProofDataFun |
27 ( |
29 ( |
28 type T = target; |
30 type T = target; |
29 fun init _ = make_target "" false false; |
31 fun init thy = make_target thy NONE; |
30 ); |
32 ); |
31 |
33 |
32 val peek = (fn Target args => args) o Data.get; |
34 val peek = (fn Target args => args) o Data.get; |
33 |
35 |
34 |
36 |
295 end; |
297 end; |
296 |
298 |
297 |
299 |
298 (* init and exit *) |
300 (* init and exit *) |
299 |
301 |
300 fun begin target ctxt = |
302 fun init_ctxt ta thy = |
301 let |
303 let |
302 val thy = ProofContext.theory_of ctxt; |
304 val Target {target = target, is_locale = is_locale, is_class = is_class} = ta |
303 val is_locale = target <> ""; |
305 in |
304 val is_class = Class.is_class thy target; |
306 thy |
305 val ta = Target {target = target, is_locale = is_locale, is_class = is_class}; |
307 |> (if is_locale then Locale.init target else ProofContext.init) |
306 in |
|
307 ctxt |
|
308 |> Data.put ta |
|
309 |> is_class ? Class.init target |
308 |> is_class ? Class.init target |
310 |> LocalTheory.init (NameSpace.base target) |
309 end; |
|
310 |
|
311 fun init_ops ta init_ctxt = |
|
312 let |
|
313 val Target {target = target, ...} = ta; |
|
314 in |
|
315 Data.put ta |
|
316 #> LocalTheory.init (NameSpace.base target) |
311 {pretty = pretty ta, |
317 {pretty = pretty ta, |
312 axioms = axioms ta, |
318 axioms = axioms ta, |
313 abbrev = abbrev ta, |
319 abbrev = abbrev ta, |
314 define = define ta, |
320 define = define ta, |
315 notes = notes ta, |
321 notes = notes ta, |
316 type_syntax = type_syntax ta, |
322 type_syntax = type_syntax ta, |
317 term_syntax = term_syntax ta, |
323 term_syntax = term_syntax ta, |
318 declaration = declaration ta, |
324 declaration = declaration ta, |
319 target_naming = target_naming ta, |
325 target_naming = target_naming ta, |
320 reinit = fn _ => |
326 reinit = fn _ => init_ops ta init_ctxt o init_ctxt, |
321 begin target o (if is_locale then Locale.init target else ProofContext.init), |
|
322 exit = LocalTheory.target_of} |
327 exit = LocalTheory.target_of} |
323 end; |
328 end; |
324 |
329 |
325 fun init NONE thy = begin "" (ProofContext.init thy) |
330 fun init target thy = |
326 | init (SOME target) thy = begin target (Locale.init target thy); |
331 let |
327 |
332 val ta = make_target thy target; |
328 fun init_cmd (SOME "-") thy = init NONE thy |
333 val init_ctxt = init_ctxt ta; |
329 | init_cmd target thy = init (Option.map (Locale.intern thy) target) thy; |
334 in |
|
335 thy |
|
336 |> init_ctxt |
|
337 |> init_ops ta init_ctxt |
|
338 end; |
|
339 |
|
340 fun begin target ctxt = |
|
341 let |
|
342 val thy = ProofContext.theory_of ctxt; |
|
343 val ta = make_target thy (SOME target); |
|
344 in |
|
345 ctxt |
|
346 |> init_ops ta (init_ctxt ta) |
|
347 end; |
|
348 |
|
349 fun init_cmd "-" thy = init NONE thy |
|
350 | init_cmd target thy = init (SOME (Locale.intern thy target)) thy; |
330 |
351 |
331 end; |
352 end; |