replaced ML_Lex.read_antiq by more concise ML_Lex.read, which includes full read/report with explicit position information;
ML_Context.eval/expression expect explicit ML_Lex source, which allows surrounding further text without loosing position information;
fall back on ML_Context.eval_text if there is no position or no surrounding text;
proper Args.name_source_position for method "tactic" and "raw_tactic";
tuned;
1 (* Title: Pure/Isar/isar_syn.ML
2 Author: Markus Wenzel, TU Muenchen
4 Isar/Pure outer syntax.
7 structure IsarSyn: sig end =
12 (*keep keywords consistent with the parsers, otherwise be prepared for
15 val _ = List.app Keyword.keyword
16 ["!!", "!", "%", "(", ")", "+", ",", "--", ":", "::", ";", "<", "<=",
17 "=", "==", "=>", "?", "[", "\\<equiv>", "\\<leftharpoondown>",
18 "\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>", "]",
19 "advanced", "and", "assumes", "attach", "begin", "binder",
20 "constrains", "defines", "fixes", "for", "identifier", "if",
21 "imports", "in", "infix", "infixl", "infixr", "is",
22 "notes", "obtains", "open", "output", "overloaded", "pervasive",
23 "shows", "structure", "unchecked", "uses", "where", "|"];
30 Outer_Syntax.command "theory" "begin theory" (Keyword.tag_theory Keyword.thy_begin)
31 (Thy_Header.args >> (Toplevel.print oo IsarCmd.init_theory));
34 Outer_Syntax.command "end" "end (local) theory" (Keyword.tag_theory Keyword.thy_end)
35 (Scan.succeed (Toplevel.exit o Toplevel.end_local_theory));
39 (** markup commands **)
41 val _ = Outer_Syntax.markup_command ThyOutput.Markup "header" "theory header" Keyword.diag
42 (Parse.doc_source >> IsarCmd.header_markup);
44 val _ = Outer_Syntax.markup_command ThyOutput.Markup "chapter" "chapter heading"
45 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> IsarCmd.local_theory_markup);
47 val _ = Outer_Syntax.markup_command ThyOutput.Markup "section" "section heading"
48 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> IsarCmd.local_theory_markup);
50 val _ = Outer_Syntax.markup_command ThyOutput.Markup "subsection" "subsection heading"
51 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> IsarCmd.local_theory_markup);
54 Outer_Syntax.markup_command ThyOutput.Markup "subsubsection" "subsubsection heading"
55 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> IsarCmd.local_theory_markup);
57 val _ = Outer_Syntax.markup_command ThyOutput.MarkupEnv "text" "formal comment (theory)"
58 Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> IsarCmd.local_theory_markup);
60 val _ = Outer_Syntax.markup_command ThyOutput.Verbatim "text_raw" "raw document preparation text"
61 Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> IsarCmd.local_theory_markup);
63 val _ = Outer_Syntax.markup_command ThyOutput.Markup "sect" "formal comment (proof)"
64 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> IsarCmd.proof_markup);
66 val _ = Outer_Syntax.markup_command ThyOutput.Markup "subsect" "formal comment (proof)"
67 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> IsarCmd.proof_markup);
69 val _ = Outer_Syntax.markup_command ThyOutput.Markup "subsubsect" "formal comment (proof)"
70 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> IsarCmd.proof_markup);
72 val _ = Outer_Syntax.markup_command ThyOutput.MarkupEnv "txt" "formal comment (proof)"
73 (Keyword.tag_proof Keyword.prf_decl) (Parse.doc_source >> IsarCmd.proof_markup);
75 val _ = Outer_Syntax.markup_command ThyOutput.Verbatim "txt_raw"
76 "raw document preparation text (proof)" (Keyword.tag_proof Keyword.prf_decl)
77 (Parse.doc_source >> IsarCmd.proof_markup);
81 (** theory commands **)
83 (* classes and sorts *)
86 Outer_Syntax.command "classes" "declare type classes" Keyword.thy_decl
87 (Scan.repeat1 (Parse.binding -- Scan.optional ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |--
88 Parse.!!! (Parse.list1 Parse.xname)) [])
89 >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
92 Outer_Syntax.command "classrel" "state inclusion of type classes (axiomatic!)" Keyword.thy_decl
93 (Parse.and_list1 (Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<")
94 |-- Parse.!!! Parse.xname))
95 >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
98 Outer_Syntax.local_theory "default_sort" "declare default sort for explicit type variables"
100 (Parse.sort >> (fn s => fn lthy => Local_Theory.set_defsort (Syntax.read_sort lthy s) lthy));
106 Outer_Syntax.local_theory "typedecl" "type declaration" Keyword.thy_decl
107 (Parse.type_args -- Parse.binding -- Parse.opt_mixfix
108 >> (fn ((args, a), mx) => Typedecl.typedecl (a, map (rpair dummyS) args, mx) #> snd));
111 Outer_Syntax.local_theory "types" "declare type abbreviations" Keyword.thy_decl
113 (Parse.type_args -- Parse.binding --
114 (Parse.$$$ "=" |-- Parse.!!! (Parse.typ -- Parse.opt_mixfix')))
115 >> (fold (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs)));
118 Outer_Syntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
119 Keyword.thy_decl (Scan.repeat1 Parse.binding >> (Toplevel.theory o Sign.add_nonterminals));
122 Outer_Syntax.command "arities" "state type arities (axiomatic!)" Keyword.thy_decl
123 (Scan.repeat1 Parse.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
126 (* consts and syntax *)
129 Outer_Syntax.command "judgment" "declare object-logic judgment" Keyword.thy_decl
130 (Parse.const_binding >> (Toplevel.theory o Object_Logic.add_judgment_cmd));
133 Outer_Syntax.command "consts" "declare constants" Keyword.thy_decl
134 (Scan.repeat1 Parse.const_binding >> (Toplevel.theory o Sign.add_consts));
136 val opt_overloaded = Parse.opt_keyword "overloaded";
139 Outer_Syntax.command "finalconsts" "declare constants as final" Keyword.thy_decl
140 (opt_overloaded -- Scan.repeat1 Parse.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
143 (Parse.$$$ "output" >> K ("", false)) ||
144 Parse.name -- Scan.optional (Parse.$$$ "output" >> K false) true;
147 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (mode_spec --| Parse.$$$ ")")) Syntax.mode_default;
150 Outer_Syntax.command "syntax" "declare syntactic constants" Keyword.thy_decl
151 (opt_mode -- Scan.repeat1 Parse.const >> (Toplevel.theory o uncurry Sign.add_modesyntax));
154 Outer_Syntax.command "no_syntax" "delete syntax declarations" Keyword.thy_decl
155 (opt_mode -- Scan.repeat1 Parse.const >> (Toplevel.theory o uncurry Sign.del_modesyntax));
161 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Parse.xname --| Parse.$$$ ")")) "logic"
164 fun trans_arrow toks =
165 ((Parse.$$$ "\\<rightharpoonup>" || Parse.$$$ "=>") >> K Syntax.ParseRule ||
166 (Parse.$$$ "\\<leftharpoondown>" || Parse.$$$ "<=") >> K Syntax.PrintRule ||
167 (Parse.$$$ "\\<rightleftharpoons>" || Parse.$$$ "==") >> K Syntax.ParsePrintRule) toks;
170 trans_pat -- Parse.!!! (trans_arrow -- trans_pat)
171 >> (fn (left, (arr, right)) => arr (left, right));
174 Outer_Syntax.command "translations" "declare syntax translation rules" Keyword.thy_decl
175 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.add_trrules));
178 Outer_Syntax.command "no_translations" "remove syntax translation rules" Keyword.thy_decl
179 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.del_trrules));
182 (* axioms and definitions *)
185 Outer_Syntax.command "axioms" "state arbitrary propositions (axiomatic!)" Keyword.thy_decl
186 (Scan.repeat1 Parse_Spec.spec >>
188 (IsarCmd.add_axioms o
189 tap (fn _ => legacy_feature "Old 'axioms' command -- use 'axiomatization' instead"))));
191 val opt_unchecked_overloaded =
192 Scan.optional (Parse.$$$ "(" |-- Parse.!!!
193 (((Parse.$$$ "unchecked" >> K true) -- Scan.optional (Parse.$$$ "overloaded" >> K true) false ||
194 Parse.$$$ "overloaded" >> K (false, true)) --| Parse.$$$ ")")) (false, false);
197 Outer_Syntax.command "defs" "define constants" Keyword.thy_decl
198 (opt_unchecked_overloaded --
199 Scan.repeat1 (Parse_Spec.thm_name ":" -- Parse.prop >> (fn ((x, y), z) => ((x, z), y)))
200 >> (Toplevel.theory o IsarCmd.add_defs));
206 Parse.binding --| Parse.where_ >> (fn x => (x, NONE, NoSyn)) ||
207 Parse.binding -- (Parse.$$$ "::" |-- Parse.!!! Parse.typ >> SOME) -- Parse.opt_mixfix'
208 --| Scan.option Parse.where_ >> Parse.triple1 ||
209 Parse.binding -- (Parse.mixfix >> pair NONE) --| Scan.option Parse.where_ >> Parse.triple2;
211 val old_constdef = Scan.option old_constdecl -- (Parse_Spec.opt_thm_name ":" -- Parse.prop);
214 Scan.optional ((Parse.$$$ "(" -- Parse.$$$ "structure")
215 |-- Parse.!!! (Parse.simple_fixes --| Parse.$$$ ")")) [];
218 Outer_Syntax.command "constdefs" "old-style constant definition" Keyword.thy_decl
219 (structs -- Scan.repeat1 old_constdef >> (Toplevel.theory o Constdefs.add_constdefs));
222 (* constant definitions and abbreviations *)
225 Outer_Syntax.local_theory "definition" "constant definition" Keyword.thy_decl
226 (Parse_Spec.constdef >> (fn args => #2 o Specification.definition_cmd args));
229 Outer_Syntax.local_theory "abbreviation" "constant abbreviation" Keyword.thy_decl
230 (opt_mode -- (Scan.option Parse_Spec.constdecl -- Parse.prop)
231 >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
234 Outer_Syntax.local_theory "type_notation" "add concrete syntax for type constructors"
236 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse.mixfix)
237 >> (fn (mode, args) => Specification.type_notation_cmd true mode args));
240 Outer_Syntax.local_theory "no_type_notation" "delete concrete syntax for type constructors"
242 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse.mixfix)
243 >> (fn (mode, args) => Specification.type_notation_cmd false mode args));
246 Outer_Syntax.local_theory "notation" "add concrete syntax for constants / fixed variables"
248 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
249 >> (fn (mode, args) => Specification.notation_cmd true mode args));
252 Outer_Syntax.local_theory "no_notation" "delete concrete syntax for constants / fixed variables"
254 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
255 >> (fn (mode, args) => Specification.notation_cmd false mode args));
258 (* constant specifications *)
261 Outer_Syntax.command "axiomatization" "axiomatic constant specification" Keyword.thy_decl
262 (Scan.optional Parse.fixes [] --
263 Scan.optional (Parse.where_ |-- Parse.!!! (Parse.and_list1 Parse_Spec.specs)) []
264 >> (fn (x, y) => Toplevel.theory (#2 o Specification.axiomatization_cmd x y)));
270 Parse_Spec.name_facts >> (fn args => #2 o Specification.theorems_cmd kind args);
273 Outer_Syntax.local_theory "theorems" "define theorems" Keyword.thy_decl (theorems Thm.theoremK);
276 Outer_Syntax.local_theory "lemmas" "define lemmas" Keyword.thy_decl (theorems Thm.lemmaK);
279 Outer_Syntax.local_theory "declare" "declare theorems" Keyword.thy_decl
280 (Parse.and_list1 Parse_Spec.xthms1
281 >> (fn args => #2 o Specification.theorems_cmd "" [(Attrib.empty_binding, flat args)]));
284 (* name space entry path *)
287 Outer_Syntax.command "global" "disable prefixing of theory name" Keyword.thy_decl
288 (Scan.succeed (Toplevel.theory Sign.root_path));
291 Outer_Syntax.command "local" "enable prefixing of theory name" Keyword.thy_decl
292 (Scan.succeed (Toplevel.theory Sign.local_path));
294 fun hide_names name hide what =
295 Outer_Syntax.command name ("hide " ^ what ^ " from name space") Keyword.thy_decl
296 ((Parse.opt_keyword "open" >> not) -- Scan.repeat1 Parse.xname >>
297 (Toplevel.theory o uncurry hide));
299 val _ = hide_names "hide_class" IsarCmd.hide_class "classes";
300 val _ = hide_names "hide_type" IsarCmd.hide_type "types";
301 val _ = hide_names "hide_const" IsarCmd.hide_const "constants";
302 val _ = hide_names "hide_fact" IsarCmd.hide_fact "facts";
307 fun propagate_env (context as Context.Proof lthy) =
308 Context.Proof (Local_Theory.map_contexts (ML_Env.inherit context) lthy)
309 | propagate_env context = context;
311 fun propagate_env_prf prf = Proof.map_contexts
312 (Context.proof_map (ML_Env.inherit (Context.Proof (Proof.context_of prf)))) prf;
315 Outer_Syntax.command "use" "ML text from file" (Keyword.tag_ml Keyword.thy_decl)
317 (fn path => Toplevel.generic_theory (ThyInfo.exec_file false path #> propagate_env)));
320 Outer_Syntax.command "ML" "ML text within theory or local theory"
321 (Keyword.tag_ml Keyword.thy_decl)
322 (Parse.ML_source >> (fn (txt, pos) =>
323 Toplevel.generic_theory
324 (ML_Context.exec (fn () => ML_Context.eval_text true pos txt) #> propagate_env)));
327 Outer_Syntax.command "ML_prf" "ML text within proof" (Keyword.tag_proof Keyword.prf_decl)
328 (Parse.ML_source >> (fn (txt, pos) =>
329 Toplevel.proof (Proof.map_context (Context.proof_map
330 (ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> propagate_env_prf)));
333 Outer_Syntax.command "ML_val" "diagnostic ML text" (Keyword.tag_ml Keyword.diag)
334 (Parse.ML_source >> IsarCmd.ml_diag true);
337 Outer_Syntax.command "ML_command" "diagnostic ML text (silent)" (Keyword.tag_ml Keyword.diag)
338 (Parse.ML_source >> (Toplevel.no_timing oo IsarCmd.ml_diag false));
341 Outer_Syntax.command "setup" "ML theory setup" (Keyword.tag_ml Keyword.thy_decl)
342 (Parse.ML_source >> (Toplevel.theory o IsarCmd.global_setup));
345 Outer_Syntax.local_theory "local_setup" "ML local theory setup" (Keyword.tag_ml Keyword.thy_decl)
346 (Parse.ML_source >> IsarCmd.local_setup);
349 Outer_Syntax.command "attribute_setup" "define attribute in ML" (Keyword.tag_ml Keyword.thy_decl)
350 (Parse.position Parse.name -- Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Parse.text)
351 >> (fn (name, (txt, cmt)) => Toplevel.theory (Attrib.attribute_setup name txt cmt)));
354 Outer_Syntax.command "method_setup" "define proof method in ML" (Keyword.tag_ml Keyword.thy_decl)
355 (Parse.position Parse.name -- Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Parse.text)
356 >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
359 Outer_Syntax.local_theory "declaration" "generic ML declaration" (Keyword.tag_ml Keyword.thy_decl)
360 (Parse.opt_keyword "pervasive" -- Parse.ML_source >> uncurry IsarCmd.declaration);
363 Outer_Syntax.local_theory "simproc_setup" "define simproc in ML" (Keyword.tag_ml Keyword.thy_decl)
365 (Parse.$$$ "(" |-- Parse.enum1 "|" Parse.term --| Parse.$$$ ")" --| Parse.$$$ "=") --
366 Parse.ML_source -- Scan.optional (Parse.$$$ "identifier" |-- Scan.repeat1 Parse.xname) []
367 >> (fn (((a, b), c), d) => IsarCmd.simproc_setup a b c d));
370 (* translation functions *)
372 val trfun = Parse.opt_keyword "advanced" -- Parse.ML_source;
375 Outer_Syntax.command "parse_ast_translation" "install parse ast translation functions"
376 (Keyword.tag_ml Keyword.thy_decl)
377 (trfun >> (Toplevel.theory o IsarCmd.parse_ast_translation));
380 Outer_Syntax.command "parse_translation" "install parse translation functions"
381 (Keyword.tag_ml Keyword.thy_decl)
382 (trfun >> (Toplevel.theory o IsarCmd.parse_translation));
385 Outer_Syntax.command "print_translation" "install print translation functions"
386 (Keyword.tag_ml Keyword.thy_decl)
387 (trfun >> (Toplevel.theory o IsarCmd.print_translation));
390 Outer_Syntax.command "typed_print_translation" "install typed print translation functions"
391 (Keyword.tag_ml Keyword.thy_decl)
392 (trfun >> (Toplevel.theory o IsarCmd.typed_print_translation));
395 Outer_Syntax.command "print_ast_translation" "install print ast translation functions"
396 (Keyword.tag_ml Keyword.thy_decl)
397 (trfun >> (Toplevel.theory o IsarCmd.print_ast_translation));
403 Outer_Syntax.command "oracle" "declare oracle" (Keyword.tag_ml Keyword.thy_decl)
404 (Parse.position Parse.name -- (Parse.$$$ "=" |-- Parse.ML_source) >>
405 (fn (x, y) => Toplevel.theory (IsarCmd.oracle x y)));
411 Outer_Syntax.command "context" "enter local theory context" Keyword.thy_decl
412 (Parse.name --| Parse.begin >> (fn name =>
413 Toplevel.print o Toplevel.begin_local_theory true (Theory_Target.context_cmd name)));
419 Parse_Spec.locale_expression false --
420 Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
421 Scan.repeat1 Parse_Spec.context_element >> pair ([], []);
424 Outer_Syntax.command "locale" "define named proof context" Keyword.thy_decl
426 Scan.optional (Parse.$$$ "=" |-- Parse.!!! locale_val) (([], []), []) -- Parse.opt_begin
427 >> (fn ((name, (expr, elems)), begin) =>
428 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
429 (Expression.add_locale_cmd name Binding.empty expr elems #> snd)));
432 Outer_Syntax.command "sublocale"
433 "prove sublocale relation between a locale and a locale expression" Keyword.thy_goal
434 (Parse.xname --| (Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") --
435 Parse.!!! (Parse_Spec.locale_expression false)
436 >> (fn (loc, expr) =>
437 Toplevel.print o Toplevel.theory_to_proof (Expression.sublocale_cmd loc expr)));
440 Outer_Syntax.command "interpretation"
441 "prove interpretation of locale expression in theory" Keyword.thy_goal
442 (Parse.!!! (Parse_Spec.locale_expression true) --
443 Scan.optional (Parse.where_ |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []
444 >> (fn (expr, equations) => Toplevel.print o
445 Toplevel.theory_to_proof (Expression.interpretation_cmd expr equations)));
448 Outer_Syntax.command "interpret"
449 "prove interpretation of locale expression in proof context"
450 (Keyword.tag_proof Keyword.prf_goal)
451 (Parse.!!! (Parse_Spec.locale_expression true)
452 >> (fn expr => Toplevel.print o Toplevel.proof' (Expression.interpret_cmd expr)));
458 Parse_Spec.class_expr --
459 Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
460 Scan.repeat1 Parse_Spec.context_element >> pair [];
463 Outer_Syntax.command "class" "define type class" Keyword.thy_decl
464 (Parse.binding -- Scan.optional (Parse.$$$ "=" |-- class_val) ([], []) -- Parse.opt_begin
465 >> (fn ((name, (supclasses, elems)), begin) =>
466 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
467 (Class.class_cmd name supclasses elems #> snd)));
470 Outer_Syntax.local_theory_to_proof "subclass" "prove a subclass relation" Keyword.thy_goal
471 (Parse.xname >> Class.subclass_cmd);
474 Outer_Syntax.command "instantiation" "instantiate and prove type arity" Keyword.thy_decl
475 (Parse.multi_arity --| Parse.begin
476 >> (fn arities => Toplevel.print o
477 Toplevel.begin_local_theory true (Theory_Target.instantiation_cmd arities)));
480 Outer_Syntax.command "instance" "prove type arity or subclass relation" Keyword.thy_goal
481 ((Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |-- Parse.!!! Parse.xname)
482 >> Class.classrel_cmd ||
483 Parse.multi_arity >> Class.instance_arity_cmd)
484 >> (Toplevel.print oo Toplevel.theory_to_proof) ||
486 (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
489 (* arbitrary overloading *)
492 Outer_Syntax.command "overloading" "overloaded definitions" Keyword.thy_decl
493 (Scan.repeat1 (Parse.name --| (Parse.$$$ "\\<equiv>" || Parse.$$$ "==") -- Parse.term --
494 Scan.optional (Parse.$$$ "(" |-- (Parse.$$$ "unchecked" >> K false) --| Parse.$$$ ")") true
495 >> Parse.triple1) --| Parse.begin
496 >> (fn operations => Toplevel.print o
497 Toplevel.begin_local_theory true (Theory_Target.overloading_cmd operations)));
500 (* code generation *)
503 Outer_Syntax.command "code_datatype" "define set of code datatype constructors" Keyword.thy_decl
504 (Scan.repeat1 Parse.term >> (Toplevel.theory o Code.add_datatype_cmd));
508 (** proof commands **)
512 fun gen_theorem schematic kind =
513 Outer_Syntax.local_theory_to_proof'
514 (if schematic then "schematic_" ^ kind else kind)
515 ("state " ^ (if schematic then "schematic " ^ kind else kind))
516 (if schematic then Keyword.thy_schematic_goal else Keyword.thy_goal)
517 (Scan.optional (Parse_Spec.opt_thm_name ":" --|
518 Scan.ahead (Parse_Spec.locale_keyword || Parse_Spec.statement_keyword)) Attrib.empty_binding --
519 Parse_Spec.general_statement >> (fn (a, (elems, concl)) =>
520 ((if schematic then Specification.schematic_theorem_cmd else Specification.theorem_cmd)
521 kind NONE (K I) a elems concl)));
523 val _ = gen_theorem false Thm.theoremK;
524 val _ = gen_theorem false Thm.lemmaK;
525 val _ = gen_theorem false Thm.corollaryK;
526 val _ = gen_theorem true Thm.theoremK;
527 val _ = gen_theorem true Thm.lemmaK;
528 val _ = gen_theorem true Thm.corollaryK;
531 Outer_Syntax.local_theory_to_proof "example_proof"
532 "example proof body, without any result" Keyword.thy_schematic_goal
534 (Specification.schematic_theorem_cmd "" NONE (K I)
535 Attrib.empty_binding [] (Element.Shows []) false #> Proof.enter_forward));
538 Outer_Syntax.command "have" "state local goal"
539 (Keyword.tag_proof Keyword.prf_goal)
540 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.have));
543 Outer_Syntax.command "hence" "abbreviates \"then have\""
544 (Keyword.tag_proof Keyword.prf_goal)
545 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.hence));
548 Outer_Syntax.command "show" "state local goal, solving current obligation"
549 (Keyword.tag_proof Keyword.prf_asm_goal)
550 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.show));
553 Outer_Syntax.command "thus" "abbreviates \"then show\""
554 (Keyword.tag_proof Keyword.prf_asm_goal)
555 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.thus));
560 val facts = Parse.and_list1 Parse_Spec.xthms1;
563 Outer_Syntax.command "then" "forward chaining"
564 (Keyword.tag_proof Keyword.prf_chain)
565 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
568 Outer_Syntax.command "from" "forward chaining from given facts"
569 (Keyword.tag_proof Keyword.prf_chain)
570 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss_cmd)));
573 Outer_Syntax.command "with" "forward chaining from given and current facts"
574 (Keyword.tag_proof Keyword.prf_chain)
575 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss_cmd)));
578 Outer_Syntax.command "note" "define facts"
579 (Keyword.tag_proof Keyword.prf_decl)
580 (Parse_Spec.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss_cmd)));
583 Outer_Syntax.command "using" "augment goal facts"
584 (Keyword.tag_proof Keyword.prf_decl)
585 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using_cmd)));
588 Outer_Syntax.command "unfolding" "unfold definitions in goal and facts"
589 (Keyword.tag_proof Keyword.prf_decl)
590 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding_cmd)));
596 Outer_Syntax.command "fix" "fix local variables (Skolem constants)"
597 (Keyword.tag_proof Keyword.prf_asm)
598 (Parse.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix_cmd)));
601 Outer_Syntax.command "assume" "assume propositions"
602 (Keyword.tag_proof Keyword.prf_asm)
603 (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume_cmd)));
606 Outer_Syntax.command "presume" "assume propositions, to be established later"
607 (Keyword.tag_proof Keyword.prf_asm)
608 (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume_cmd)));
611 Outer_Syntax.command "def" "local definition"
612 (Keyword.tag_proof Keyword.prf_asm)
614 (Parse_Spec.opt_thm_name ":" --
615 ((Parse.binding -- Parse.opt_mixfix) --
616 ((Parse.$$$ "\\<equiv>" || Parse.$$$ "==") |-- Parse.!!! Parse.termp)))
617 >> (Toplevel.print oo (Toplevel.proof o Proof.def_cmd)));
620 Outer_Syntax.command "obtain" "generalized existence"
621 (Keyword.tag_proof Keyword.prf_asm_goal)
622 (Parse.parname -- Scan.optional (Parse.fixes --| Parse.where_) [] -- Parse_Spec.statement
623 >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain_cmd x y z)));
626 Outer_Syntax.command "guess" "wild guessing (unstructured)"
627 (Keyword.tag_proof Keyword.prf_asm_goal)
628 (Scan.optional Parse.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess_cmd)));
631 Outer_Syntax.command "let" "bind text variables"
632 (Keyword.tag_proof Keyword.prf_decl)
633 (Parse.and_list1 (Parse.and_list1 Parse.term -- (Parse.$$$ "=" |-- Parse.term))
634 >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind_cmd)));
637 Outer_Syntax.command "write" "add concrete syntax for constants / fixed variables"
638 (Keyword.tag_proof Keyword.prf_decl)
639 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
640 >> (fn (mode, args) => Toplevel.print o Toplevel.proof (Proof.write_cmd mode args)));
644 Parse.!!! (Parse.xname -- Scan.repeat1 (Parse.maybe Parse.name) --| Parse.$$$ ")") ||
645 Parse.xname >> rpair []) -- Parse_Spec.opt_attribs >> Parse.triple1;
648 Outer_Syntax.command "case" "invoke local context"
649 (Keyword.tag_proof Keyword.prf_asm)
650 (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case_cmd)));
653 (* proof structure *)
656 Outer_Syntax.command "{" "begin explicit proof block"
657 (Keyword.tag_proof Keyword.prf_open)
658 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
661 Outer_Syntax.command "}" "end explicit proof block"
662 (Keyword.tag_proof Keyword.prf_close)
663 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
666 Outer_Syntax.command "next" "enter next proof block"
667 (Keyword.tag_proof Keyword.prf_block)
668 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
674 Outer_Syntax.command "qed" "conclude (sub-)proof"
675 (Keyword.tag_proof Keyword.qed_block)
676 (Scan.option Method.parse >> IsarCmd.qed);
679 Outer_Syntax.command "by" "terminal backward proof"
680 (Keyword.tag_proof Keyword.qed)
681 (Method.parse -- Scan.option Method.parse >> IsarCmd.terminal_proof);
684 Outer_Syntax.command ".." "default proof"
685 (Keyword.tag_proof Keyword.qed)
686 (Scan.succeed IsarCmd.default_proof);
689 Outer_Syntax.command "." "immediate proof"
690 (Keyword.tag_proof Keyword.qed)
691 (Scan.succeed IsarCmd.immediate_proof);
694 Outer_Syntax.command "done" "done proof"
695 (Keyword.tag_proof Keyword.qed)
696 (Scan.succeed IsarCmd.done_proof);
699 Outer_Syntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
700 (Keyword.tag_proof Keyword.qed)
701 (Scan.succeed IsarCmd.skip_proof);
704 Outer_Syntax.command "oops" "forget proof"
705 (Keyword.tag_proof Keyword.qed_global)
706 (Scan.succeed Toplevel.forget_proof);
712 Outer_Syntax.command "defer" "shuffle internal proof state"
713 (Keyword.tag_proof Keyword.prf_script)
714 (Scan.option Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
717 Outer_Syntax.command "prefer" "shuffle internal proof state"
718 (Keyword.tag_proof Keyword.prf_script)
719 (Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
722 Outer_Syntax.command "apply" "initial refinement step (unstructured)"
723 (Keyword.tag_proof Keyword.prf_script)
724 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
727 Outer_Syntax.command "apply_end" "terminal refinement (unstructured)"
728 (Keyword.tag_proof Keyword.prf_script)
729 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
732 Outer_Syntax.command "proof" "backward proof"
733 (Keyword.tag_proof Keyword.prf_block)
734 (Scan.option Method.parse >> (fn m => Toplevel.print o
735 Toplevel.actual_proof (Proof_Node.applys (Proof.proof m)) o
736 Toplevel.skip_proof (fn i => i + 1)));
739 (* calculational proof commands *)
742 Scan.option (Parse.$$$ "(" |-- Parse.!!! ((Parse_Spec.xthms1 --| Parse.$$$ ")")));
745 Outer_Syntax.command "also" "combine calculation and current facts"
746 (Keyword.tag_proof Keyword.prf_decl)
747 (calc_args >> (Toplevel.proofs' o Calculation.also_cmd));
750 Outer_Syntax.command "finally" "combine calculation and current facts, exhibit result"
751 (Keyword.tag_proof Keyword.prf_chain)
752 (calc_args >> (Toplevel.proofs' o Calculation.finally_cmd));
755 Outer_Syntax.command "moreover" "augment calculation by current facts"
756 (Keyword.tag_proof Keyword.prf_decl)
757 (Scan.succeed (Toplevel.proof' Calculation.moreover));
760 Outer_Syntax.command "ultimately" "augment calculation by current facts, exhibit result"
761 (Keyword.tag_proof Keyword.prf_chain)
762 (Scan.succeed (Toplevel.proof' Calculation.ultimately));
765 (* proof navigation *)
768 Outer_Syntax.command "back" "backtracking of proof command"
769 (Keyword.tag_proof Keyword.prf_script)
770 (Scan.succeed (Toplevel.print o Toplevel.actual_proof Proof_Node.back o Toplevel.skip_proof I));
773 (* nested commands *)
776 Scan.optional Parse_Value.properties [] -- Parse.position Parse.string
777 >> (fn (props, (str, pos)) =>
778 (Position.of_properties (Position.default_properties pos props), str));
781 Outer_Syntax.improper_command "Isabelle.command" "nested Isabelle command" Keyword.control
782 (props_text :|-- (fn (pos, str) =>
783 (case Outer_Syntax.parse pos str of
784 [tr] => Scan.succeed (K tr)
785 | _ => Scan.fail_with (K "exactly one command expected"))
786 handle ERROR msg => Scan.fail_with (K msg)));
790 (** diagnostic commands (for interactive mode only) **)
793 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.xname --| Parse.$$$ ")")) [];
795 val opt_bang = Scan.optional (Parse.$$$ "!" >> K true) false;
798 Outer_Syntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
799 Keyword.diag (Parse.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
802 Outer_Syntax.improper_command "help" "print outer syntax commands" Keyword.diag
803 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
806 Outer_Syntax.improper_command "print_commands" "print outer syntax commands" Keyword.diag
807 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
810 Outer_Syntax.improper_command "print_configs" "print configuration options" Keyword.diag
811 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_configs));
814 Outer_Syntax.improper_command "print_context" "print theory context name" Keyword.diag
815 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
818 Outer_Syntax.improper_command "print_theory" "print logical theory contents (verbose!)"
819 Keyword.diag (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theory));
822 Outer_Syntax.improper_command "print_syntax" "print inner syntax of context (verbose!)"
823 Keyword.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
826 Outer_Syntax.improper_command "print_abbrevs" "print constant abbreviation of context"
827 Keyword.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.print_abbrevs));
830 Outer_Syntax.improper_command "print_theorems"
831 "print theorems of local theory or proof context" Keyword.diag
832 (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theorems));
835 Outer_Syntax.improper_command "print_locales" "print locales of this theory" Keyword.diag
836 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales));
839 Outer_Syntax.improper_command "print_classes" "print classes of this theory" Keyword.diag
840 (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
841 o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
844 Outer_Syntax.improper_command "print_locale" "print locale of this theory" Keyword.diag
845 (opt_bang -- Parse.xname >> (Toplevel.no_timing oo IsarCmd.print_locale));
848 Outer_Syntax.improper_command "print_interps"
849 "print interpretations of locale for this theory" Keyword.diag
850 (Parse.xname >> (Toplevel.no_timing oo IsarCmd.print_registrations));
853 Outer_Syntax.improper_command "print_attributes" "print attributes of this theory" Keyword.diag
854 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
857 Outer_Syntax.improper_command "print_simpset" "print context of Simplifier" Keyword.diag
858 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_simpset));
861 Outer_Syntax.improper_command "print_rules" "print intro/elim rules" Keyword.diag
862 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules));
865 Outer_Syntax.improper_command "print_trans_rules" "print transitivity rules" Keyword.diag
866 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules));
869 Outer_Syntax.improper_command "print_methods" "print methods of this theory" Keyword.diag
870 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
873 Outer_Syntax.improper_command "print_antiquotations" "print antiquotations (global)" Keyword.diag
874 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations));
877 Outer_Syntax.improper_command "thy_deps" "visualize theory dependencies"
878 Keyword.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.thy_deps));
881 Outer_Syntax.improper_command "class_deps" "visualize class dependencies"
882 Keyword.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
885 Outer_Syntax.improper_command "thm_deps" "visualize theorem dependencies"
886 Keyword.diag (Parse_Spec.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
889 Outer_Syntax.improper_command "print_binds" "print term bindings of proof context" Keyword.diag
890 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
893 Outer_Syntax.improper_command "print_facts" "print facts of proof context" Keyword.diag
894 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_facts));
897 Outer_Syntax.improper_command "print_cases" "print cases of proof context" Keyword.diag
898 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
901 Outer_Syntax.improper_command "print_statement" "print theorems as long statements" Keyword.diag
902 (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_stmts));
905 Outer_Syntax.improper_command "thm" "print theorems" Keyword.diag
906 (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
909 Outer_Syntax.improper_command "prf" "print proof terms of theorems" Keyword.diag
910 (opt_modes -- Scan.option Parse_Spec.xthms1
911 >> (Toplevel.no_timing oo IsarCmd.print_prfs false));
914 Outer_Syntax.improper_command "full_prf" "print full proof terms of theorems" Keyword.diag
915 (opt_modes -- Scan.option Parse_Spec.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true));
918 Outer_Syntax.improper_command "prop" "read and print proposition" Keyword.diag
919 (opt_modes -- Parse.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
922 Outer_Syntax.improper_command "term" "read and print term" Keyword.diag
923 (opt_modes -- Parse.term >> (Toplevel.no_timing oo IsarCmd.print_term));
926 Outer_Syntax.improper_command "typ" "read and print type" Keyword.diag
927 (opt_modes -- Parse.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
930 Outer_Syntax.improper_command "print_codesetup" "print code generator setup" Keyword.diag
932 (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
933 (Code.print_codesetup o Toplevel.theory_of)));
936 Outer_Syntax.improper_command "unused_thms" "find unused theorems" Keyword.diag
937 (Scan.option ((Scan.repeat1 (Scan.unless Parse.minus Parse.name) --| Parse.minus) --
938 Scan.option (Scan.repeat1 (Scan.unless Parse.minus Parse.name))) >>
939 (Toplevel.no_timing oo IsarCmd.unused_thms));
943 (** system commands (for interactive mode only) **)
946 Outer_Syntax.improper_command "cd" "change current working directory" Keyword.diag
947 (Parse.path >> (Toplevel.no_timing oo IsarCmd.cd));
950 Outer_Syntax.improper_command "pwd" "print current working directory" Keyword.diag
951 (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
954 Outer_Syntax.improper_command "use_thy" "use theory file" Keyword.diag
955 (Parse.name >> (fn name =>
956 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.use_thy name)));
959 Outer_Syntax.improper_command "touch_thy" "outdate theory, including descendants" Keyword.diag
960 (Parse.name >> (fn name =>
961 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.touch_thy name)));
964 Outer_Syntax.improper_command "remove_thy" "remove theory from loader database" Keyword.diag
965 (Parse.name >> (fn name =>
966 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.remove_thy name)));
969 Outer_Syntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
970 Keyword.diag (Parse.name >> (fn name =>
971 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.kill_thy name)));
974 Outer_Syntax.improper_command "display_drafts" "display raw source files with symbols"
975 Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo IsarCmd.display_drafts));
978 Outer_Syntax.improper_command "print_drafts" "print raw source files with symbols"
979 Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo IsarCmd.print_drafts));
982 Scan.option Parse.nat -- Scan.option (Parse.$$$ "," |-- Parse.!!! Parse.nat);
985 Outer_Syntax.improper_command "pr" "print current proof state (if present)" Keyword.diag
986 (opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr));
989 Outer_Syntax.improper_command "disable_pr" "disable printing of toplevel state" Keyword.diag
990 (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
993 Outer_Syntax.improper_command "enable_pr" "enable printing of toplevel state" Keyword.diag
994 (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
997 Outer_Syntax.improper_command "commit" "commit current session to ML database" Keyword.diag
998 (Parse.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
1001 Outer_Syntax.improper_command "quit" "quit Isabelle" Keyword.control
1002 (Parse.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
1005 Outer_Syntax.improper_command "exit" "exit Isar loop" Keyword.control
1006 (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));