src/Pure/Isar/local_theory.ML
changeset 28379 0de8a35b866a
parent 28115 cd0d170d4dc6
child 28395 984fcc8feb24
equal deleted inserted replaced
28378:60cc0359363d 28379:0de8a35b866a
    15   val group_position_of: local_theory -> Properties.T
    15   val group_position_of: local_theory -> Properties.T
    16   val set_group: string -> local_theory -> local_theory
    16   val set_group: string -> local_theory -> local_theory
    17   val target_of: local_theory -> Proof.context
    17   val target_of: local_theory -> Proof.context
    18   val raw_theory_result: (theory -> 'a * theory) -> local_theory -> 'a * local_theory
    18   val raw_theory_result: (theory -> 'a * theory) -> local_theory -> 'a * local_theory
    19   val raw_theory: (theory -> theory) -> local_theory -> local_theory
    19   val raw_theory: (theory -> theory) -> local_theory -> local_theory
       
    20   val checkpoint: local_theory -> local_theory
    20   val full_naming: local_theory -> NameSpace.naming
    21   val full_naming: local_theory -> NameSpace.naming
    21   val full_name: local_theory -> bstring -> string
    22   val full_name: local_theory -> bstring -> string
    22   val theory_result: (theory -> 'a * theory) -> local_theory -> 'a * local_theory
    23   val theory_result: (theory -> 'a * theory) -> local_theory -> 'a * local_theory
    23   val theory: (theory -> theory) -> local_theory -> local_theory
    24   val theory: (theory -> theory) -> local_theory -> local_theory
    24   val target_result: (Proof.context -> 'a * Proof.context) -> local_theory -> 'a * local_theory
    25   val target_result: (Proof.context -> 'a * Proof.context) -> local_theory -> 'a * local_theory
   129       |> ProofContext.transfer thy';
   130       |> ProofContext.transfer thy';
   130   in (res, lthy') end;
   131   in (res, lthy') end;
   131 
   132 
   132 fun raw_theory f = #2 o raw_theory_result (f #> pair ());
   133 fun raw_theory f = #2 o raw_theory_result (f #> pair ());
   133 
   134 
       
   135 val checkpoint = raw_theory Theory.checkpoint;
       
   136 
   134 fun full_naming lthy =
   137 fun full_naming lthy =
   135   Sign.naming_of (ProofContext.theory_of lthy)
   138   Sign.naming_of (ProofContext.theory_of lthy)
   136   |> NameSpace.sticky_prefix (#theory_prefix (get_lthy lthy))
   139   |> NameSpace.sticky_prefix (#theory_prefix (get_lthy lthy))
   137   |> NameSpace.qualified_names;
   140   |> NameSpace.qualified_names;
   138 
   141 
   163 fun operation f lthy = f (#operations (get_lthy lthy)) lthy;
   166 fun operation f lthy = f (#operations (get_lthy lthy)) lthy;
   164 fun operation1 f x = operation (fn ops => f ops x);
   167 fun operation1 f x = operation (fn ops => f ops x);
   165 fun operation2 f x y lthy = operation (fn ops => f ops x y) lthy;
   168 fun operation2 f x y lthy = operation (fn ops => f ops x y) lthy;
   166 
   169 
   167 val pretty = operation #pretty;
   170 val pretty = operation #pretty;
   168 val abbrev = operation2 #abbrev;
   171 val abbrev = apsnd checkpoint ooo operation2 #abbrev;
   169 val define = operation2 #define;
   172 val define = apsnd checkpoint ooo operation2 #define;
   170 val notes = operation2 #notes;
   173 val notes = apsnd checkpoint ooo operation2 #notes;
   171 val type_syntax = operation1 #type_syntax;
   174 val type_syntax = checkpoint oo operation1 #type_syntax;
   172 val term_syntax = operation1 #term_syntax;
   175 val term_syntax = checkpoint oo operation1 #term_syntax;
   173 val declaration = operation1 #declaration;
   176 val declaration = checkpoint oo operation1 #declaration;
   174 
   177 
   175 fun note kind (a, ths) = notes kind [(a, [(ths, [])])] #>> the_single;
   178 fun note kind (a, ths) = notes kind [(a, [(ths, [])])] #>> the_single;
   176 
   179 
   177 fun target_morphism lthy =
   180 fun target_morphism lthy =
   178   ProofContext.export_morphism lthy (target_of lthy) $>
   181   ProofContext.export_morphism lthy (target_of lthy) $>
   185 
   188 
   186 (* init -- exit *)
   189 (* init -- exit *)
   187 
   190 
   188 fun init theory_prefix operations target = target |> Data.map
   191 fun init theory_prefix operations target = target |> Data.map
   189   (fn NONE => SOME (make_lthy ("", theory_prefix, operations, target))
   192   (fn NONE => SOME (make_lthy ("", theory_prefix, operations, target))
   190     | SOME _ => error "Local theory already initialized");
   193     | SOME _ => error "Local theory already initialized")
       
   194   |> checkpoint;
   191 
   195 
   192 fun restore lthy =
   196 fun restore lthy =
   193   let val {group = _, theory_prefix, operations, target} = get_lthy lthy
   197   let val {group = _, theory_prefix, operations, target} = get_lthy lthy
   194   in init theory_prefix operations target end;
   198   in init theory_prefix operations target end;
   195 
   199 
   196 val reinit = operation #reinit;
   200 val reinit = checkpoint o operation #reinit;
   197 val exit = operation #exit;
   201 val exit = ProofContext.theory Theory.checkpoint o operation #exit;
   198 
   202 
   199 end;
   203 end;