201 val mx3 = if is_locale then NoSyn else mx1; |
198 val mx3 = if is_locale then NoSyn else mx1; |
202 val (const, thy') = Sign.declare_const (ContextPosition.properties_of lthy) (c, U, mx3) thy; |
199 val (const, thy') = Sign.declare_const (ContextPosition.properties_of lthy) (c, U, mx3) thy; |
203 val t = Term.list_comb (const, map Free xs); |
200 val t = Term.list_comb (const, map Free xs); |
204 in (((c, mx2), t), thy') end; |
201 in (((c, mx2), t), thy') end; |
205 fun const_class ((c, _), mx) (_, t) = |
202 fun const_class ((c, _), mx) (_, t) = |
206 LocalTheory.raw_theory_result (Class.add_const_in_class target ((c, t), mx)) |
203 LocalTheory.raw_theory_result (Class.add_const_in_class target ((c, mx), t)) |
207 #-> Class.remove_constraint target; |
204 #-> Class.remove_constraint target; |
208 |
205 |
209 val (abbrs, lthy') = lthy |
206 val (abbrs, lthy') = lthy |
210 |> LocalTheory.theory_result (fold_map const decls) |
207 |> LocalTheory.theory_result (fold_map const decls) |
211 in |
208 in |
212 lthy' |
209 lthy' |
213 |> is_class ? fold2 const_class decls abbrs |
210 |> is_class ? fold2 const_class decls abbrs |
214 |> is_locale ? fold (internal_abbrev ta Syntax.mode_default) abbrs |
211 |> is_locale ? fold (internal_abbrev ta Syntax.mode_default) abbrs |
215 |> LocalDefs.add_defs (map (apsnd (pair ("", []))) abbrs) |>> map (apsnd snd) |
212 |> fold_map (apfst (apsnd snd) oo LocalDefs.add_def) abbrs |
216 end; |
213 end; |
217 |
214 |
218 |
215 |
219 (* abbrev *) |
216 (* abbrev *) |
220 |
217 |
242 |> LocalTheory.theory_result |
239 |> LocalTheory.theory_result |
243 (Sign.add_abbrev (#1 prmode) (ContextPosition.properties_of lthy) (c, u')) |
240 (Sign.add_abbrev (#1 prmode) (ContextPosition.properties_of lthy) (c, u')) |
244 |-> (fn (lhs, rhs) => |
241 |-> (fn (lhs, rhs) => |
245 LocalTheory.theory (Sign.notation true prmode [(lhs, mx3)]) |
242 LocalTheory.theory (Sign.notation true prmode [(lhs, mx3)]) |
246 #> is_locale ? internal_abbrev ta prmode ((c, mx2), Term.list_comb (lhs, xs)) |
243 #> is_locale ? internal_abbrev ta prmode ((c, mx2), Term.list_comb (lhs, xs)) |
247 #> is_class ? add_abbrev_in_class ((c, Term.list_comb (lhs, xs)), mx1)) |
244 #> is_class ? add_abbrev_in_class ((c, mx1), Term.list_comb (lhs, xs))) |
248 |> LocalDefs.add_defs [((c, NoSyn), (("", []), raw_t))] |>> the_single |
245 |> LocalDefs.add_def ((c, NoSyn), raw_t) |
249 end; |
246 end; |
250 |
247 |
251 |
248 |
252 (* define *) |
249 (* define *) |
253 |
250 |
313 |
310 |
314 fun begin target ctxt = |
311 fun begin target ctxt = |
315 let |
312 let |
316 val thy = ProofContext.theory_of ctxt; |
313 val thy = ProofContext.theory_of ctxt; |
317 val is_locale = target <> ""; |
314 val is_locale = target <> ""; |
318 val is_class = is_some (Class.class_of_locale thy target); |
315 val is_class = Class.is_class thy target; |
319 val ta = Target {target = target, is_locale = is_locale, is_class = is_class}; |
316 val ta = Target {target = target, is_locale = is_locale, is_class = is_class}; |
320 in |
317 in |
321 ctxt |
318 ctxt |
322 |> Data.put ta |
319 |> Data.put ta |
323 |> is_class ? Class.init target |
320 |> is_class ? Class.init target |
330 type_syntax = type_syntax ta, |
327 type_syntax = type_syntax ta, |
331 term_syntax = term_syntax ta, |
328 term_syntax = term_syntax ta, |
332 declaration = declaration ta, |
329 declaration = declaration ta, |
333 target_naming = target_naming ta, |
330 target_naming = target_naming ta, |
334 reinit = fn _ => |
331 reinit = fn _ => |
335 (if is_locale then Locale.init target else ProofContext.init) |
332 begin target o (if is_locale then Locale.init target else ProofContext.init), |
336 #> begin target, |
|
337 exit = LocalTheory.target_of} |
333 exit = LocalTheory.target_of} |
338 end; |
334 end; |
339 |
335 |
340 fun init NONE thy = begin "" (ProofContext.init thy) |
336 fun init NONE thy = begin "" (ProofContext.init thy) |
341 | init (SOME target) thy = begin target (Locale.init target thy); |
337 | init (SOME target) thy = begin target (Locale.init target thy); |