98 end; |
98 end; |
99 |
99 |
100 |
100 |
101 (* theory/locale substructures *) |
101 (* theory/locale substructures *) |
102 |
102 |
103 fun transfer thy = |
|
104 ProofContext.transfer thy #> map_locale (ProofContext.transfer thy); |
|
105 |
|
106 fun theory f ctxt = transfer (f (ProofContext.theory_of ctxt)) ctxt; |
|
107 |
|
108 fun theory_result f ctxt = |
103 fun theory_result f ctxt = |
109 let val (res, thy') = f (ProofContext.theory_of ctxt) |
104 let val (res, thy') = f (ProofContext.theory_of ctxt) |
110 in (res, transfer thy' ctxt) end; |
105 in (res, ctxt |> map_locale (ProofContext.transfer thy') |> ProofContext.transfer thy') end; |
|
106 |
|
107 fun theory f ctxt = #2 (theory_result (f #> pair ()) ctxt); |
111 |
108 |
112 fun locale_result f ctxt = |
109 fun locale_result f ctxt = |
113 (case locale_of ctxt of |
110 (case locale_of ctxt of |
114 NONE => error "Local theory: no locale context" |
111 NONE => error "Local theory: no locale context" |
115 | SOME (_, view_ctxt) => |
112 | SOME (_, view_ctxt) => |
116 let |
113 let |
117 val (res, loc_ctxt') = f view_ctxt; |
114 val (res, loc_ctxt') = f view_ctxt; |
118 val thy' = ProofContext.theory_of loc_ctxt'; |
115 val thy' = ProofContext.theory_of loc_ctxt'; |
119 in (res, ctxt |> map_locale (K loc_ctxt') |> transfer thy') end); |
116 in (res, ctxt |> map_locale (K loc_ctxt') |> ProofContext.transfer thy') end); |
120 |
117 |
121 fun locale f ctxt = |
118 fun locale f ctxt = |
122 if is_none (locale_of ctxt) then ctxt |
119 if is_none (locale_of ctxt) then ctxt |
123 else #2 (locale_result (f #> pair ()) ctxt); |
120 else #2 (locale_result (f #> pair ()) ctxt); |
124 |
121 |