src/Pure/Isar/local_theory.ML
changeset 21273 3b01db9504a8
parent 21206 2af4c7b3f7ef
child 21292 11143b6ad87f
equal deleted inserted replaced
21272:a87b27cdd142 21273:3b01db9504a8
    32   val def: (bstring * mixfix) * ((bstring * Attrib.src list) * term) ->
    32   val def: (bstring * mixfix) * ((bstring * Attrib.src list) * term) ->
    33     local_theory -> (term * (bstring * thm)) * local_theory
    33     local_theory -> (term * (bstring * thm)) * local_theory
    34   val note: (bstring * Attrib.src list) * thm list ->
    34   val note: (bstring * Attrib.src list) * thm list ->
    35     local_theory -> (bstring * thm list) * Proof.context
    35     local_theory -> (bstring * thm list) * Proof.context
    36   val notation: Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory
    36   val notation: Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory
    37   val abbrevs: Syntax.mode -> ((bstring * mixfix) * term) list -> local_theory -> local_theory
    37   val abbrevs: Syntax.mode -> ((bstring * mixfix) * term) list -> local_theory ->
       
    38     (term * term) list * local_theory
    38   val init: string option -> operations -> Proof.context -> local_theory
    39   val init: string option -> operations -> Proof.context -> local_theory
    39   val reinit: local_theory -> local_theory
    40   val restore: local_theory -> local_theory
    40   val exit: bool -> local_theory -> Proof.context * theory
    41   val exit: bool -> local_theory -> Proof.context * theory
    41 end;
    42 end;
    42 
    43 
    43 structure LocalTheory: LOCAL_THEORY =
    44 structure LocalTheory: LOCAL_THEORY =
    44 struct
    45 struct
    57     (term * (bstring * thm)) list * local_theory,
    58     (term * (bstring * thm)) list * local_theory,
    58   notes: ((bstring * Attrib.src list) * (thm list * Attrib.src list) list) list -> local_theory ->
    59   notes: ((bstring * Attrib.src list) * (thm list * Attrib.src list) list) list -> local_theory ->
    59     (bstring * thm list) list * local_theory,
    60     (bstring * thm list) list * local_theory,
    60   term_syntax: (Context.generic -> Context.generic) -> local_theory -> local_theory,
    61   term_syntax: (Context.generic -> Context.generic) -> local_theory -> local_theory,
    61   declaration: (Context.generic -> Context.generic) -> local_theory -> local_theory,
    62   declaration: (Context.generic -> Context.generic) -> local_theory -> local_theory,
       
    63   reinit: Proof.context -> local_theory,
    62   exit: bool -> local_theory -> local_theory};
    64   exit: bool -> local_theory -> local_theory};
    63 
    65 
    64 datatype lthy = LThy of
    66 datatype lthy = LThy of
    65  {theory_prefix: string option,
    67  {theory_prefix: string option,
    66   operations: operations,
    68   operations: operations,
   143 val axioms = operation1 #axioms;
   145 val axioms = operation1 #axioms;
   144 val defs = operation1 #defs;
   146 val defs = operation1 #defs;
   145 val notes = operation1 #notes;
   147 val notes = operation1 #notes;
   146 val term_syntax = operation1 #term_syntax;
   148 val term_syntax = operation1 #term_syntax;
   147 val declaration = operation1 #declaration;
   149 val declaration = operation1 #declaration;
       
   150 val reinit = operation #reinit;
   148 
   151 
   149 
   152 
   150 (* derived operations *)
   153 (* derived operations *)
   151 
   154 
   152 fun def arg lthy = lthy |> defs [arg] |>> hd;
   155 fun def arg lthy = lthy |> defs [arg] |>> hd;
   155 
   158 
   156 fun notation mode args = term_syntax
   159 fun notation mode args = term_syntax
   157   (Context.mapping (Sign.add_notation mode args) (ProofContext.add_notation mode args));
   160   (Context.mapping (Sign.add_notation mode args) (ProofContext.add_notation mode args));
   158 
   161 
   159 fun abbrevs mode args = term_syntax
   162 fun abbrevs mode args = term_syntax
   160   (Context.mapping (Sign.add_abbrevs mode args) (ProofContext.add_abbrevs mode args));
   163   (Context.mapping (snd o Sign.add_abbrevs mode args) (snd o ProofContext.add_abbrevs mode args))
       
   164   #> ProofContext.add_abbrevs mode args;  (* FIXME *)
   161 
   165 
   162 
   166 
   163 (* init -- exit *)
   167 (* init -- exit *)
   164 
   168 
   165 fun init theory_prefix operations target = target |> Data.map
   169 fun init theory_prefix operations target = target |> Data.map
   166   (fn NONE => SOME (make_lthy (theory_prefix, operations, target))
   170   (fn NONE => SOME (make_lthy (theory_prefix, operations, target))
   167     | SOME _ => error "Local theory already initialized");
   171     | SOME _ => error "Local theory already initialized");
   168 
   172 
   169 fun reinit lthy =
   173 fun restore lthy =
   170   let val {theory_prefix, operations, target} = get_lthy lthy
   174   let val {theory_prefix, operations, target} = get_lthy lthy
   171   in init theory_prefix operations target end;
   175   in init theory_prefix operations target end;
   172 
   176 
   173 fun exit int lthy = lthy
   177 fun exit int lthy = lthy
   174   |> operation1 #exit int |> target_of
   178   |> operation1 #exit int |> target_of