author | haftmann |
Thu, 22 May 2014 16:59:49 +0200 | |
changeset 57068 | 474403e50e05 |
parent 57067 | b3571d1a3e45 |
child 57071 | c97b8250c033 |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: Pure/Isar/named_target.ML |
20894 | 2 |
Author: Makarius |
30437 | 3 |
Author: Florian Haftmann, TU Muenchen |
20894 | 4 |
|
47066
8a6124d09ff5
basic support for nested contexts including bundles;
wenzelm
parents:
47061
diff
changeset
|
5 |
Targets for theory, locale, class -- at the bottom the nested structure. |
20894 | 6 |
*) |
7 |
||
38350
480b2de9927c
renamed Theory_Target to the more appropriate Named_Target
haftmann
parents:
38349
diff
changeset
|
8 |
signature NAMED_TARGET = |
20894 | 9 |
sig |
47066
8a6124d09ff5
basic support for nested contexts including bundles;
wenzelm
parents:
47061
diff
changeset
|
10 |
val peek: local_theory -> {target: string, is_locale: bool, is_class: bool} option |
52140 | 11 |
val is_theory: local_theory -> bool |
12 |
val the_name: local_theory -> string |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
13 |
val init: (local_theory -> local_theory) -> string -> theory -> local_theory |
38388 | 14 |
val theory_init: theory -> local_theory |
38391
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
15 |
val reinit: local_theory -> local_theory -> local_theory |
45488
6d71d9e52369
pass positions for named targets, for formal links in the document model;
wenzelm
parents:
45390
diff
changeset
|
16 |
val context_cmd: xstring * Position.T -> theory -> local_theory |
20894 | 17 |
end; |
18 |
||
38350
480b2de9927c
renamed Theory_Target to the more appropriate Named_Target
haftmann
parents:
38349
diff
changeset
|
19 |
structure Named_Target: NAMED_TARGET = |
20894 | 20 |
struct |
21 |
||
21006 | 22 |
(* context data *) |
23 |
||
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
24 |
datatype target = |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
25 |
Target of {target: string, is_locale: bool, is_class: bool, |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
26 |
before_exit: local_theory -> local_theory}; |
25012
448af76a1ba3
pass explicit target record -- more informative peek operation;
wenzelm
parents:
25002
diff
changeset
|
27 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
28 |
fun make_target target is_locale is_class before_exit = |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
29 |
Target {target = target, is_locale = is_locale, is_class = is_class, |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
30 |
before_exit = before_exit}; |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
31 |
|
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
32 |
fun named_target _ "" before_exit = make_target "" false false before_exit |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
33 |
| named_target thy locale before_exit = |
38378 | 34 |
if Locale.defined thy locale |
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
35 |
then make_target locale true (Class.is_class thy locale) before_exit |
38378 | 36 |
else error ("No such locale: " ^ quote locale); |
25012
448af76a1ba3
pass explicit target record -- more informative peek operation;
wenzelm
parents:
25002
diff
changeset
|
37 |
|
33519 | 38 |
structure Data = Proof_Data |
21006 | 39 |
( |
38391
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
40 |
type T = target option; |
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
41 |
fun init _ = NONE; |
21006 | 42 |
); |
43 |
||
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
44 |
val peek = |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
45 |
Data.get #> Option.map (fn Target {target, is_locale, is_class, ...} => |
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
46 |
{target = target, is_locale = is_locale, is_class = is_class}); |
21006 | 47 |
|
53088 | 48 |
fun is_theory lthy = |
49 |
Option.map #target (peek lthy) = SOME "" andalso Local_Theory.level lthy = 1; |
|
52140 | 50 |
|
51 |
fun the_name lthy = |
|
52 |
let |
|
53 |
val _ = Local_Theory.assert_bottom true lthy; |
|
53088 | 54 |
in |
55 |
(case Option.map #target (peek lthy) of |
|
52140 | 56 |
SOME target => target |
53088 | 57 |
| _ => error "Not in a named target") |
52140 | 58 |
end; |
59 |
||
21006 | 60 |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
61 |
(* consts *) |
24838 | 62 |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
63 |
fun locale_const locale prmode ((b, mx), rhs) = |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
64 |
Generic_Target.locale_declaration locale true (fn phi => |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
65 |
let |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
66 |
val b' = Morphism.binding phi b; |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
67 |
val rhs' = Morphism.term phi rhs; |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
68 |
val same_shape = Term.aconv_untyped (rhs, rhs'); |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
69 |
in |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
70 |
Generic_Target.generic_const same_shape prmode ((b', mx), rhs') |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
71 |
end) #> |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
72 |
Generic_Target.const_declaration |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
73 |
(fn (this, other) => other <> 0 andalso this <> other) prmode ((b, mx), rhs); |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
74 |
|
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
75 |
fun class_const class prmode (b, rhs) = |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
76 |
Generic_Target.locale_declaration class true (fn phi => |
45352 | 77 |
let |
78 |
val b' = Morphism.binding phi b; |
|
79 |
val rhs' = Morphism.term phi rhs; |
|
80 |
val same_shape = Term.aconv_untyped (rhs, rhs'); |
|
38297 | 81 |
|
45352 | 82 |
(* FIXME workaround based on educated guess *) |
83 |
val prefix' = Binding.prefix_of b'; |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
84 |
val is_canonical_class = |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
85 |
Binding.eq_name (b, b') |
45352 | 86 |
andalso not (null prefix') |
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
87 |
andalso List.last prefix' = (Class.class_prefix class, false) |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
88 |
orelse same_shape; |
47282 | 89 |
in |
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
90 |
not is_canonical_class ? Generic_Target.generic_const same_shape prmode ((b', NoSyn), rhs') |
47282 | 91 |
end) #> |
57057 | 92 |
Generic_Target.const_declaration |
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
93 |
(fn (this, other) => other <> 0 andalso this <> other) prmode ((b, NoSyn), rhs); |
38305 | 94 |
|
38297 | 95 |
|
38318
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
96 |
(* define *) |
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
97 |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
98 |
fun locale_foundation target (((b, U), mx), (b_def, rhs)) params = |
47289 | 99 |
Generic_Target.background_foundation (((b, U), NoSyn), (b_def, rhs)) params |
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
100 |
#-> (fn (lhs, def) => locale_const target Syntax.mode_default ((b, mx), lhs) |
47282 | 101 |
#> pair (lhs, def)); |
38318
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
102 |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
103 |
fun class_foundation target (((b, U), mx), (b_def, rhs)) params = |
47289 | 104 |
Generic_Target.background_foundation (((b, U), NoSyn), (b_def, rhs)) params |
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
105 |
#-> (fn (lhs, def) => class_const target Syntax.mode_default (b, lhs) |
57067 | 106 |
#> Class.const target ((b, mx), lhs) params |
47282 | 107 |
#> pair (lhs, def)); |
38318
1fade69519ab
different foundations for different targets; simplified syntax handling of abbreviations
haftmann
parents:
38314
diff
changeset
|
108 |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
109 |
fun target_foundation (ta as Target {target, is_locale, is_class, ...}) = |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
110 |
if is_class then class_foundation target |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
111 |
else if is_locale then locale_foundation target |
47284
0e65b6a016dc
clarified background_foundation vs. theory_foundation (with const_declaration);
wenzelm
parents:
47283
diff
changeset
|
112 |
else Generic_Target.theory_foundation; |
38303
ad4b59e9d0f9
factored out foundation of `define` into separate function
haftmann
parents:
38302
diff
changeset
|
113 |
|
24939 | 114 |
|
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
115 |
(* notes *) |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
116 |
|
39639 | 117 |
fun target_notes (Target {target, is_locale, ...}) = |
47250
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents:
47247
diff
changeset
|
118 |
if is_locale then Generic_Target.locale_notes target |
6523a21076a8
clarified Generic_Target.notes: always perform Attrib.partial_evaluation;
wenzelm
parents:
47247
diff
changeset
|
119 |
else Generic_Target.theory_notes; |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
120 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
121 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
122 |
(* abbrev *) |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
123 |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
124 |
fun locale_abbrev target prmode (b, mx) (t, _) xs = |
57068 | 125 |
Generic_Target.background_abbrev (b, t) |
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
126 |
#-> (fn (lhs, _) => |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
127 |
locale_const target prmode ((b, mx), Term.list_comb (Logic.unvarify_global lhs, xs))); |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
128 |
|
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
129 |
fun class_abbrev target prmode (b, mx) (t, t') xs = |
57068 | 130 |
Generic_Target.background_abbrev (b, t) |
57066
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
131 |
#-> (fn (lhs, _) => |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
132 |
class_const target prmode (b, Term.list_comb (Logic.unvarify_global lhs, xs))) |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
133 |
#> Class.abbrev target prmode ((b, mx), t'); |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
134 |
|
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
135 |
fun target_abbrev (ta as Target {target, is_locale, is_class, ...}) = |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
136 |
if is_class then class_abbrev target |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
137 |
else if is_locale then locale_abbrev target |
78651e94746f
tuned: prefer separate function trails for locales and classes rather than ad-hoc case distinction
haftmann
parents:
57065
diff
changeset
|
138 |
else Generic_Target.theory_abbrev; |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
139 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
140 |
|
47246
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
141 |
(* declaration *) |
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
142 |
|
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
143 |
fun target_declaration (Target {target, ...}) {syntax, pervasive} decl lthy = |
47279
4bab649dedf0
clarified standard_declaration vs. theory_declaration;
wenzelm
parents:
47278
diff
changeset
|
144 |
if target = "" then Generic_Target.theory_declaration decl lthy |
47246
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
145 |
else |
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
146 |
lthy |
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
147 |
|> pervasive ? Generic_Target.background_declaration decl |
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
148 |
|> Generic_Target.locale_declaration target syntax decl |
57065 | 149 |
|> Generic_Target.standard_declaration (fn (_, other) => other <> 0) decl; |
47246
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
150 |
|
2bbab021c0e6
clarified Named_Target.target_declaration: propagate through other levels as well;
wenzelm
parents:
47081
diff
changeset
|
151 |
|
56723
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
152 |
(* subscription *) |
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
153 |
|
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
154 |
fun target_subscription (Target {target, ...}) = |
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
155 |
if target = "" |
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
156 |
then Generic_Target.theory_registration |
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
157 |
else Generic_Target.locale_dependency target |
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
158 |
|
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
159 |
|
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
160 |
(* pretty *) |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
161 |
|
39639 | 162 |
fun pretty (Target {target, is_locale, is_class, ...}) ctxt = |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
163 |
let |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
164 |
val target_name = |
55763 | 165 |
[Pretty.keyword1 (if is_class then "class" else "locale"), Pretty.brk 1, |
52103 | 166 |
Locale.pretty_name ctxt target]; |
45353 | 167 |
val fixes = |
168 |
map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) |
|
169 |
(#1 (Proof_Context.inferred_fixes ctxt)); |
|
170 |
val assumes = |
|
171 |
map (fn A => (Attrib.empty_binding, [(Thm.term_of A, [])])) |
|
172 |
(Assumption.all_assms_of ctxt); |
|
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
173 |
val elems = |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
174 |
(if null fixes then [] else [Element.Fixes fixes]) @ |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
175 |
(if null assumes then [] else [Element.Assumes assumes]); |
40782 | 176 |
val body_elems = |
177 |
if not is_locale then [] |
|
39639 | 178 |
else if null elems then [Pretty.block target_name] |
179 |
else [Pretty.block (Pretty.fbreaks (Pretty.block (target_name @ [Pretty.str " ="]) :: |
|
40782 | 180 |
map (Pretty.chunks o Element.pretty_ctxt ctxt) elems))]; |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
181 |
in |
55763 | 182 |
Pretty.block [Pretty.keyword1 "theory", Pretty.brk 1, |
42360 | 183 |
Pretty.str (Context.theory_name (Proof_Context.theory_of ctxt))] :: body_elems |
38308
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
184 |
end; |
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
185 |
|
0e4649095739
try to uniformly follow define/note/abbrev/declaration order as close as possible
haftmann
parents:
38307
diff
changeset
|
186 |
|
38378 | 187 |
(* init *) |
25291 | 188 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
189 |
fun init_context (Target {target, is_locale, is_class, ...}) = |
42360 | 190 |
if not is_locale then Proof_Context.init_global |
29576 | 191 |
else if not is_class then Locale.init target |
38379
67d71449e85b
more convenient split of class modules: class and class_declaration
haftmann
parents:
38378
diff
changeset
|
192 |
else Class.init target; |
25269 | 193 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
194 |
fun init before_exit target thy = |
39639 | 195 |
let |
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
196 |
val ta = named_target thy target before_exit; |
47061
355317493f34
clarified Local_Theory.init: avoid hardwired naming policy, discontinued odd/unused group argument (cf. 5ee13e0428d2);
wenzelm
parents:
47000
diff
changeset
|
197 |
val naming = Sign.naming_of thy |
355317493f34
clarified Local_Theory.init: avoid hardwired naming policy, discontinued odd/unused group argument (cf. 5ee13e0428d2);
wenzelm
parents:
47000
diff
changeset
|
198 |
|> Name_Space.mandatory_path (Long_Name.base_name target); |
39639 | 199 |
in |
200 |
thy |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
55763
diff
changeset
|
201 |
|> Sign.change_begin |
39639 | 202 |
|> init_context ta |
203 |
|> Data.put (SOME ta) |
|
47061
355317493f34
clarified Local_Theory.init: avoid hardwired naming policy, discontinued odd/unused group argument (cf. 5ee13e0428d2);
wenzelm
parents:
47000
diff
changeset
|
204 |
|> Local_Theory.init naming |
39639 | 205 |
{define = Generic_Target.define (target_foundation ta), |
206 |
notes = Generic_Target.notes (target_notes ta), |
|
207 |
abbrev = Generic_Target.abbrev (target_abbrev ta), |
|
45291
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
wenzelm
parents:
45290
diff
changeset
|
208 |
declaration = target_declaration ta, |
56723
a8f71445c265
subscription as target-specific implementation device
haftmann
parents:
56056
diff
changeset
|
209 |
subscription = target_subscription ta, |
39639 | 210 |
pretty = pretty ta, |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
55763
diff
changeset
|
211 |
exit = before_exit #> Local_Theory.target_of #> Sign.change_end_local} |
39639 | 212 |
end; |
38247 | 213 |
|
41585
45d7da4e4ccf
added before_exit continuation for named targets (locale, class etc.), e.g. for final check/cleanup as in VC management;
wenzelm
parents:
40782
diff
changeset
|
214 |
val theory_init = init I ""; |
25269 | 215 |
|
47066
8a6124d09ff5
basic support for nested contexts including bundles;
wenzelm
parents:
47061
diff
changeset
|
216 |
val reinit = |
47069 | 217 |
Local_Theory.assert_bottom true #> Data.get #> the #> |
47066
8a6124d09ff5
basic support for nested contexts including bundles;
wenzelm
parents:
47061
diff
changeset
|
218 |
(fn Target {target, before_exit, ...} => Local_Theory.exit_global #> init before_exit target); |
38391
ba1cc1815ce1
named target is optional; explicit Name_Target.reinit
haftmann
parents:
38389
diff
changeset
|
219 |
|
47274 | 220 |
fun context_cmd ("-", _) thy = theory_init thy |
45488
6d71d9e52369
pass positions for named targets, for formal links in the document model;
wenzelm
parents:
45390
diff
changeset
|
221 |
| context_cmd target thy = init I (Locale.check thy target) thy; |
33282 | 222 |
|
20894 | 223 |
end; |