equal
deleted
inserted
replaced
1 (* Title: Pure/Isar/named_target.ML |
1 (* Title: Pure/Isar/named_target.ML |
2 Author: Makarius |
2 Author: Makarius |
3 Author: Florian Haftmann, TU Muenchen |
3 Author: Florian Haftmann, TU Muenchen |
4 |
4 |
5 Targets for theory, locale and class. |
5 Targets for theory, locale, class -- at the bottom the nested structure. |
6 *) |
6 *) |
7 |
7 |
8 signature NAMED_TARGET = |
8 signature NAMED_TARGET = |
9 sig |
9 sig |
|
10 val peek: local_theory -> {target: string, is_locale: bool, is_class: bool} option |
|
11 val assert: local_theory -> local_theory |
10 val init: (local_theory -> local_theory) -> string -> theory -> local_theory |
12 val init: (local_theory -> local_theory) -> string -> theory -> local_theory |
11 val theory_init: theory -> local_theory |
13 val theory_init: theory -> local_theory |
12 val reinit: local_theory -> local_theory -> local_theory |
14 val reinit: local_theory -> local_theory -> local_theory |
13 val context_cmd: xstring * Position.T -> theory -> local_theory |
15 val context_cmd: xstring * Position.T -> theory -> local_theory |
14 val peek: local_theory -> {target: string, is_locale: bool, is_class: bool} option |
|
15 end; |
16 end; |
16 |
17 |
17 structure Named_Target: NAMED_TARGET = |
18 structure Named_Target: NAMED_TARGET = |
18 struct |
19 struct |
19 |
20 |
40 ); |
41 ); |
41 |
42 |
42 val peek = |
43 val peek = |
43 Data.get #> Option.map (fn Target {target, is_locale, is_class, ...} => |
44 Data.get #> Option.map (fn Target {target, is_locale, is_class, ...} => |
44 {target = target, is_locale = is_locale, is_class = is_class}); |
45 {target = target, is_locale = is_locale, is_class = is_class}); |
|
46 |
|
47 fun assert lthy = |
|
48 if is_some (peek lthy) then lthy |
|
49 else error "Not in a named target (global theory, locale, class)"; |
45 |
50 |
46 |
51 |
47 (* generic declarations *) |
52 (* generic declarations *) |
48 |
53 |
49 fun locale_declaration locale syntax decl lthy = |
54 fun locale_declaration locale syntax decl lthy = |
207 exit = Local_Theory.target_of o before_exit} |
212 exit = Local_Theory.target_of o before_exit} |
208 end; |
213 end; |
209 |
214 |
210 val theory_init = init I ""; |
215 val theory_init = init I ""; |
211 |
216 |
212 fun reinit lthy = |
217 val reinit = |
213 (case Data.get lthy of |
218 assert #> Data.get #> the #> |
214 SOME (Target {target, before_exit, ...}) => |
219 (fn Target {target, before_exit, ...} => Local_Theory.exit_global #> init before_exit target); |
215 init before_exit target o Local_Theory.exit_global |
|
216 | NONE => error "Not in a named target"); |
|
217 |
220 |
218 fun context_cmd ("-", _) thy = init I "" thy |
221 fun context_cmd ("-", _) thy = init I "" thy |
219 | context_cmd target thy = init I (Locale.check thy target) thy; |
222 | context_cmd target thy = init I (Locale.check thy target) thy; |
220 |
223 |
221 end; |
224 end; |