20 datatype target = Target of {target: string, is_locale: bool, is_class: bool}; |
20 datatype target = Target of {target: string, is_locale: bool, is_class: bool}; |
21 |
21 |
22 fun make_target target is_locale is_class = |
22 fun make_target target is_locale is_class = |
23 Target {target = target, is_locale = is_locale, is_class = is_class}; |
23 Target {target = target, is_locale = is_locale, is_class = is_class}; |
24 |
24 |
25 val global_target = make_target "" false false; |
25 val global_target = Target {target = "", is_locale = false, is_class = false}; |
|
26 |
|
27 fun named_target _ NONE = global_target |
|
28 | named_target thy (SOME locale) = |
|
29 if Locale.defined thy locale |
|
30 then Target {target = locale, is_locale = true, is_class = Class_Target.is_class thy locale} |
|
31 else error ("No such locale: " ^ quote locale); |
26 |
32 |
27 structure Data = Proof_Data |
33 structure Data = Proof_Data |
28 ( |
34 ( |
29 type T = target; |
35 type T = target; |
30 fun init _ = global_target; |
36 fun init _ = global_target; |
166 Pretty.block [Pretty.command "theory", Pretty.brk 1, |
172 Pretty.block [Pretty.command "theory", Pretty.brk 1, |
167 Pretty.str (Context.theory_name (ProofContext.theory_of ctxt))] :: |
173 Pretty.str (Context.theory_name (ProofContext.theory_of ctxt))] :: |
168 pretty_thy ctxt target is_class; |
174 pretty_thy ctxt target is_class; |
169 |
175 |
170 |
176 |
171 (* init various targets *) |
177 (* init *) |
172 |
178 |
173 local |
179 local |
174 |
180 |
175 fun init_data (Target {target, is_locale, is_class}) = |
181 fun init_context (Target {target, is_locale, is_class}) = |
176 if not is_locale then ProofContext.init_global |
182 if not is_locale then ProofContext.init_global |
177 else if not is_class then Locale.init target |
183 else if not is_class then Locale.init target |
178 else Class_Target.init target; |
184 else Class_Target.init target; |
179 |
185 |
180 fun init_target (ta as Target {target, ...}) thy = |
186 fun init_target (ta as Target {target, ...}) thy = |
181 thy |
187 thy |
182 |> init_data ta |
188 |> init_context ta |
183 |> Data.put ta |
189 |> Data.put ta |
184 |> Local_Theory.init NONE (Long_Name.base_name target) |
190 |> Local_Theory.init NONE (Long_Name.base_name target) |
185 {define = Generic_Target.define (target_foundation ta), |
191 {define = Generic_Target.define (target_foundation ta), |
186 notes = Generic_Target.notes (target_notes ta), |
192 notes = Generic_Target.notes (target_notes ta), |
187 abbrev = Generic_Target.abbrev (target_abbrev ta), |
193 abbrev = Generic_Target.abbrev (target_abbrev ta), |
191 { syntax = true, pervasive = pervasive }, |
197 { syntax = true, pervasive = pervasive }, |
192 pretty = pretty ta, |
198 pretty = pretty ta, |
193 reinit = init_target ta o ProofContext.theory_of, |
199 reinit = init_target ta o ProofContext.theory_of, |
194 exit = Local_Theory.target_of}; |
200 exit = Local_Theory.target_of}; |
195 |
201 |
196 fun named_target _ NONE = global_target |
|
197 | named_target thy (SOME target) = |
|
198 if Locale.defined thy target |
|
199 then make_target target true (Class_Target.is_class thy target) |
|
200 else error ("No such locale: " ^ quote target); |
|
201 |
|
202 in |
202 in |
203 |
203 |
204 fun init target thy = init_target (named_target thy target) thy; |
204 fun init target thy = init_target (named_target thy target) thy; |
205 |
205 |
206 fun context_cmd "-" thy = init NONE thy |
206 fun context_cmd "-" thy = init NONE thy |