src/Pure/Isar/isar_cmd.ML
changeset 26455 1757a6e049f4
parent 26435 bdce320cd426
child 26463 9283b4185fdf
equal deleted inserted replaced
26454:57923fdab83b 26455:1757a6e049f4
   133 (** theory declarations **)
   133 (** theory declarations **)
   134 
   134 
   135 (* generic_setup *)
   135 (* generic_setup *)
   136 
   136 
   137 fun generic_setup (txt, pos) =
   137 fun generic_setup (txt, pos) =
   138   ML_Context.use_let pos "val setup: theory -> theory" "Context.map_theory setup" txt
   138   ML_Context.expression pos "val setup: theory -> theory" "Context.map_theory setup" txt
   139   |> Context.theory_map;
   139   |> Context.theory_map;
   140 
   140 
   141 
   141 
   142 (* translation functions *)
   142 (* translation functions *)
   143 
   143 
   150   | advancedN true = "advanced_";
   150   | advancedN true = "advanced_";
   151 
   151 
   152 in
   152 in
   153 
   153 
   154 fun parse_ast_translation (a, (txt, pos)) =
   154 fun parse_ast_translation (a, (txt, pos)) =
   155   txt |> ML_Context.use_let pos ("val parse_ast_translation: (string * (" ^ advancedT a ^
   155   txt |> ML_Context.expression pos
       
   156     ("val parse_ast_translation: (string * (" ^ advancedT a ^
   156       "Syntax.ast list -> Syntax.ast)) list")
   157       "Syntax.ast list -> Syntax.ast)) list")
   157     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns (parse_ast_translation, [], [], []))")
   158     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns (parse_ast_translation, [], [], []))")
   158   |> Context.theory_map;
   159   |> Context.theory_map;
   159 
   160 
   160 fun parse_translation (a, (txt, pos)) =
   161 fun parse_translation (a, (txt, pos)) =
   161   txt |> ML_Context.use_let pos ("val parse_translation: (string * (" ^ advancedT a ^
   162   txt |> ML_Context.expression pos
       
   163     ("val parse_translation: (string * (" ^ advancedT a ^
   162       "term list -> term)) list")
   164       "term list -> term)) list")
   163     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], parse_translation, [], []))")
   165     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], parse_translation, [], []))")
   164   |> Context.theory_map;
   166   |> Context.theory_map;
   165 
   167 
   166 fun print_translation (a, (txt, pos)) =
   168 fun print_translation (a, (txt, pos)) =
   167   txt |> ML_Context.use_let pos ("val print_translation: (string * (" ^ advancedT a ^
   169   txt |> ML_Context.expression pos
       
   170     ("val print_translation: (string * (" ^ advancedT a ^
   168       "term list -> term)) list")
   171       "term list -> term)) list")
   169     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], [], print_translation, []))")
   172     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], [], print_translation, []))")
   170   |> Context.theory_map;
   173   |> Context.theory_map;
   171 
   174 
   172 fun print_ast_translation (a, (txt, pos)) =
   175 fun print_ast_translation (a, (txt, pos)) =
   173   txt |> ML_Context.use_let pos ("val print_ast_translation: (string * (" ^ advancedT a ^
   176   txt |> ML_Context.expression pos
       
   177     ("val print_ast_translation: (string * (" ^ advancedT a ^
   174       "Syntax.ast list -> Syntax.ast)) list")
   178       "Syntax.ast list -> Syntax.ast)) list")
   175     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], [], [], print_ast_translation))")
   179     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfuns ([], [], [], print_ast_translation))")
   176   |> Context.theory_map;
   180   |> Context.theory_map;
   177 
   181 
   178 fun typed_print_translation (a, (txt, pos)) =
   182 fun typed_print_translation (a, (txt, pos)) =
   179   txt |> ML_Context.use_let pos ("val typed_print_translation: (string * (" ^ advancedT a ^
   183   txt |> ML_Context.expression pos
       
   184     ("val typed_print_translation: (string * (" ^ advancedT a ^
   180       "bool -> typ -> term list -> term)) list")
   185       "bool -> typ -> term list -> term)) list")
   181     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfunsT typed_print_translation)")
   186     ("Context.map_theory (Sign.add_" ^ advancedN a ^ "trfunsT typed_print_translation)")
   182   |> Context.theory_map;
   187   |> Context.theory_map;
   183 
   188 
   184 fun token_translation (txt, pos) =
   189 fun token_translation (txt, pos) =
   185   txt |> ML_Context.use_let pos
   190   txt |> ML_Context.expression pos
   186     "val token_translation: (string * string * (string -> output * int)) list"
   191     "val token_translation: (string * string * (string -> output * int)) list"
   187       "Context.map_theory (Sign.add_tokentrfuns token_translation)"
   192       "Context.map_theory (Sign.add_tokentrfuns token_translation)"
   188   |> Context.theory_map;
   193   |> Context.theory_map;
   189 
   194 
   190 end;
   195 end;
   203     \  val thy = ML_Context.the_global_context ();\n\
   208     \  val thy = ML_Context.the_global_context ();\n\
   204     \  val invoke_" ^ name ^ " = Thm.invoke_oracle_i thy (Sign.full_name thy name);\n\
   209     \  val invoke_" ^ name ^ " = Thm.invoke_oracle_i thy (Sign.full_name thy name);\n\
   205     \in\n\
   210     \in\n\
   206     \  fun " ^ name ^ " thy x = invoke_" ^ name ^ " (thy, Arg x);\n\
   211     \  fun " ^ name ^ " thy x = invoke_" ^ name ^ " (thy, Arg x);\n\
   207     \end;\n";
   212     \end;\n";
   208   in ML_Context.use_mltext_update false pos txt end
   213   in Context.theory_map (ML_Context.exec (fn () => ML_Context.eval false pos txt)) end;
   209   |> Context.theory_map;
       
   210 
   214 
   211 
   215 
   212 (* axioms *)
   216 (* axioms *)
   213 
   217 
   214 fun add_axms f args thy =
   218 fun add_axms f args thy =
   231 
   235 
   232 
   236 
   233 (* declarations *)
   237 (* declarations *)
   234 
   238 
   235 fun declaration (txt, pos) =
   239 fun declaration (txt, pos) =
   236   txt |> ML_Context.use_let pos "val declaration: Morphism.declaration"
   240   txt |> ML_Context.expression pos
       
   241     "val declaration: Morphism.declaration"
   237     "Context.map_proof (LocalTheory.declaration declaration)"
   242     "Context.map_proof (LocalTheory.declaration declaration)"
   238   |> Context.proof_map;
   243   |> Context.proof_map;
   239 
   244 
   240 
   245 
   241 (* simprocs *)
   246 (* simprocs *)
   242 
   247 
   243 fun simproc_setup name lhss (proc, pos) identifier =
   248 fun simproc_setup name lhss (proc, pos) identifier =
   244   ML_Context.use_let pos
   249   ML_Context.expression pos
   245     "val proc: Morphism.morphism -> Simplifier.simpset -> cterm -> thm option"
   250     "val proc: Morphism.morphism -> Simplifier.simpset -> cterm -> thm option"
   246   ("Context.map_proof (Simplifier.def_simproc {name = " ^ ML_Syntax.print_string name ^ ", \
   251   ("Context.map_proof (Simplifier.def_simproc {name = " ^ ML_Syntax.print_string name ^ ", \
   247     \lhss = " ^ ML_Syntax.print_strings lhss ^ ", proc = proc, \
   252     \lhss = " ^ ML_Syntax.print_strings lhss ^ ", proc = proc, \
   248     \identifier = Library.maps ML_Context.thms " ^ ML_Syntax.print_strings identifier ^ "})") proc
   253     \identifier = Library.maps ML_Context.thms " ^ ML_Syntax.print_strings identifier ^ "})") proc
   249   |> Context.proof_map;
   254   |> Context.proof_map;
   380 
   385 
   381 fun use path = Toplevel.keep (fn state =>
   386 fun use path = Toplevel.keep (fn state =>
   382   Context.setmp_thread_data (try Toplevel.generic_theory_of state) (ThyInfo.load_file false) path);
   387   Context.setmp_thread_data (try Toplevel.generic_theory_of state) (ThyInfo.load_file false) path);
   383 
   388 
   384 (*passes changes of theory context*)
   389 (*passes changes of theory context*)
   385 fun use_mltext_theory (txt, pos) =
   390 fun use_mltext_theory (txt, pos) = Toplevel.theory' (fn int =>
   386   Toplevel.theory' (fn int => Context.theory_map (ML_Context.use_mltext_update int pos txt));
   391   Context.theory_map (ML_Context.exec (fn () => ML_Context.eval int pos txt)));
   387 
   392 
   388 (*ignore result theory context*)
   393 (*ignore result theory context*)
   389 fun use_mltext verbose (txt, pos) = Toplevel.keep' (fn int => fn state =>
   394 fun use_mltext verbose (txt, pos) = Toplevel.keep' (fn int => fn state =>
   390   (ML_Context.use_mltext (verbose andalso int) pos txt (try Toplevel.generic_theory_of state)));
   395   (ML_Context.eval_in (try Toplevel.generic_theory_of state) (verbose andalso int) pos txt));
   391 
   396 
   392 val use_commit = Toplevel.imperative Secure.commit;
   397 val use_commit = Toplevel.imperative Secure.commit;
   393 
   398 
   394 
   399 
   395 (* nested commands *)
   400 (* nested commands *)