1 (* Title: Pure/Isar/isar_syn.ML
3 Author: Markus Wenzel, TU Muenchen
5 Isar/Pure outer syntax.
8 structure IsarSyn: sig end =
11 structure P = OuterParse and K = OuterKeyword;
16 (*keep keywords consistent with the parsers, otherwise be prepared for
19 val _ = OuterSyntax.keywords
20 ["!!", "!", "%", "(", ")", "+", ",", "--", ":", "::", ";", "<", "<=",
21 "=", "==", "=>", "?", "[", "\\<equiv>", "\\<leftharpoondown>",
22 "\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>", "]",
23 "advanced", "and", "assumes", "attach", "begin", "binder", "concl",
24 "constrains", "defines", "fixes", "for", "identifier", "if",
25 "imports", "in", "includes", "infix", "infixl", "infixr", "is",
26 "notes", "obtains", "open", "output", "overloaded", "shows",
27 "structure", "unchecked", "uses", "where", "|"];
33 OuterSyntax.command "theory" "begin theory" (K.tag_theory K.thy_begin)
34 (ThyHeader.args >> (Toplevel.print oo IsarCmd.theory));
37 OuterSyntax.command "end" "end (local) theory" (K.tag_theory K.thy_end)
38 (Scan.succeed (Toplevel.exit o Toplevel.end_local_theory));
41 (** markup commands **)
43 val _ = OuterSyntax.markup_command ThyOutput.Markup "header" "theory header" K.diag
44 (P.position P.text >> IsarCmd.add_header);
46 val _ = OuterSyntax.markup_command ThyOutput.Markup "chapter" "chapter heading"
47 K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_chapter);
49 val _ = OuterSyntax.markup_command ThyOutput.Markup "section" "section heading"
50 K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_section);
52 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsection" "subsection heading"
53 K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_subsection);
56 OuterSyntax.markup_command ThyOutput.Markup "subsubsection" "subsubsection heading"
57 K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_subsubsection);
59 val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "text" "formal comment (theory)"
60 K.thy_decl (P.opt_target -- P.position P.text >> IsarCmd.add_text);
62 val _ = OuterSyntax.markup_command ThyOutput.Verbatim "text_raw"
63 "raw document preparation text"
64 K.thy_decl (P.position P.text >> IsarCmd.add_text_raw);
66 val _ = OuterSyntax.markup_command ThyOutput.Markup "sect" "formal comment (proof)"
67 (K.tag_proof K.prf_heading) (P.position P.text >> IsarCmd.add_sect);
69 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsect" "formal comment (proof)"
70 (K.tag_proof K.prf_heading) (P.position P.text >> IsarCmd.add_subsect);
72 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsubsect"
73 "formal comment (proof)" (K.tag_proof K.prf_heading)
74 (P.position P.text >> IsarCmd.add_subsubsect);
76 val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "txt" "formal comment (proof)"
77 (K.tag_proof K.prf_decl) (P.position P.text >> IsarCmd.add_txt);
79 val _ = OuterSyntax.markup_command ThyOutput.Verbatim "txt_raw"
80 "raw document preparation text (proof)" (K.tag_proof K.prf_decl)
81 (P.position P.text >> IsarCmd.add_txt_raw);
85 (** theory sections **)
87 (* classes and sorts *)
90 OuterSyntax.command "classes" "declare type classes" K.thy_decl
91 (Scan.repeat1 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
92 P.!!! (P.list1 P.xname)) []) >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
95 OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
96 (P.and_list1 (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname))
97 >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
100 OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
101 (P.sort >> (Toplevel.theory o Sign.add_defsort));
104 OuterSyntax.command "axclass" "define axiomatic type class" K.thy_decl
105 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
106 P.!!! (P.list1 P.xname)) []
107 -- Scan.repeat (SpecParse.thm_name ":" -- (P.prop >> single))
108 >> (fn (x, y) => Toplevel.theory (snd o Class.axclass_cmd x y)));
114 OuterSyntax.command "typedecl" "type declaration" K.thy_decl
115 (P.type_args -- P.name -- P.opt_infix >> (fn ((args, a), mx) =>
116 Toplevel.theory (ObjectLogic.typedecl (a, args, mx) #> snd)));
119 OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
121 (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix')))
122 >> (Toplevel.theory o Sign.add_tyabbrs o
123 map (fn ((args, a), (T, mx)) => (a, args, T, mx))));
126 OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
127 K.thy_decl (Scan.repeat1 P.name >> (Toplevel.theory o Sign.add_nonterminals));
130 OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
131 (Scan.repeat1 P.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
134 (* consts and syntax *)
137 OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
138 (P.const >> (Toplevel.theory o ObjectLogic.add_judgment));
141 OuterSyntax.command "consts" "declare constants" K.thy_decl
142 (Scan.repeat1 P.const >> (Toplevel.theory o Sign.add_consts));
144 val opt_overloaded = P.opt_keyword "overloaded";
147 OuterSyntax.command "finalconsts" "declare constants as final" K.thy_decl
148 (opt_overloaded -- Scan.repeat1 P.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
151 (P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true;
154 Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) Syntax.mode_default;
157 OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
158 (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Sign.add_modesyntax));
161 OuterSyntax.command "no_syntax" "delete syntax declarations" K.thy_decl
162 (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Sign.del_modesyntax));
168 Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
170 fun trans_arrow toks =
171 ((P.$$$ "\\<rightharpoonup>" || P.$$$ "=>") >> K Syntax.ParseRule ||
172 (P.$$$ "\\<leftharpoondown>" || P.$$$ "<=") >> K Syntax.PrintRule ||
173 (P.$$$ "\\<rightleftharpoons>" || P.$$$ "==") >> K Syntax.ParsePrintRule) toks;
176 trans_pat -- P.!!! (trans_arrow -- trans_pat)
177 >> (fn (left, (arr, right)) => arr (left, right));
180 OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
181 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.add_trrules));
184 OuterSyntax.command "no_translations" "remove syntax translation rules" K.thy_decl
185 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.del_trrules));
188 (* axioms and definitions *)
191 OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
192 (Scan.repeat1 SpecParse.spec_name >> (Toplevel.theory o IsarCmd.add_axioms));
194 val opt_unchecked_overloaded =
195 Scan.optional (P.$$$ "(" |-- P.!!!
196 (((P.$$$ "unchecked" >> K true) -- Scan.optional (P.$$$ "overloaded" >> K true) false ||
197 P.$$$ "overloaded" >> K (false, true)) --| P.$$$ ")")) (false, false);
200 OuterSyntax.command "defs" "define constants" K.thy_decl
201 (opt_unchecked_overloaded -- Scan.repeat1 SpecParse.spec_name
202 >> (Toplevel.theory o IsarCmd.add_defs));
208 P.name --| P.where_ >> (fn x => (x, NONE, NoSyn)) ||
209 P.name -- (P.$$$ "::" |-- P.!!! P.typ >> SOME) -- P.opt_mixfix'
210 --| Scan.option P.where_ >> P.triple1 ||
211 P.name -- (P.mixfix >> pair NONE) --| Scan.option P.where_ >> P.triple2;
213 val old_constdef = Scan.option old_constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
216 Scan.optional ((P.$$$ "(" -- P.$$$ "structure") |-- P.!!! (P.simple_fixes --| P.$$$ ")")) [];
219 OuterSyntax.command "constdefs" "old-style constant definition" K.thy_decl
220 (structs -- Scan.repeat1 old_constdef >> (Toplevel.theory o Constdefs.add_constdefs));
223 (* constant definitions and abbreviations *)
227 (P.where_ >> K (NONE, NoSyn) ||
228 P.$$$ "::" |-- P.!!! ((P.typ >> SOME) -- P.opt_mixfix' --| P.where_) ||
229 Scan.ahead (P.$$$ "(") |-- P.!!! (P.mixfix' --| P.where_ >> pair NONE))
232 val constdef = Scan.option constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
235 OuterSyntax.command "definition" "constant definition" K.thy_decl
236 (P.opt_target -- constdef
237 >> (fn (loc, args) => Toplevel.local_theory loc (#2 o Specification.definition_cmd args)));
240 OuterSyntax.command "abbreviation" "constant abbreviation" K.thy_decl
241 (P.opt_target -- opt_mode -- (Scan.option constdecl -- P.prop)
242 >> (fn ((loc, mode), args) =>
243 Toplevel.local_theory loc (Specification.abbreviation_cmd mode args)));
246 OuterSyntax.command "notation" "add notation for constants / fixed variables" K.thy_decl
247 (P.opt_target -- opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
248 >> (fn ((loc, mode), args) =>
249 Toplevel.local_theory loc (Specification.notation_cmd true mode args)));
252 OuterSyntax.command "no_notation" "delete notation for constants / fixed variables" K.thy_decl
253 (P.opt_target -- opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
254 >> (fn ((loc, mode), args) =>
255 Toplevel.local_theory loc (Specification.notation_cmd false mode args)));
258 (* constant specifications *)
261 OuterSyntax.command "axiomatization" "axiomatic constant specification" K.thy_decl
263 (Scan.optional P.fixes [] --
264 Scan.optional (P.where_ |-- P.!!! (P.and_list1 SpecParse.spec)) [])
265 >> (fn (loc, (x, y)) => Toplevel.local_theory loc (#2 o Specification.axiomatization_cmd x y)));
270 fun theorems kind = P.opt_target -- SpecParse.name_facts
271 >> (fn (loc, args) => Toplevel.local_theory loc (#2 o Specification.theorems_cmd kind args));
274 OuterSyntax.command "theorems" "define theorems" K.thy_decl (theorems Thm.theoremK);
277 OuterSyntax.command "lemmas" "define lemmas" K.thy_decl (theorems Thm.lemmaK);
280 OuterSyntax.command "declare" "declare theorems (improper)" K.thy_decl
281 (P.opt_target -- (P.and_list1 SpecParse.xthms1 >> flat)
282 >> (fn (loc, args) => Toplevel.local_theory loc
283 (#2 o Specification.theorems_cmd "" [(("", []), args)])));
286 (* name space entry path *)
289 OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
290 (Scan.succeed (Toplevel.theory Sign.root_path));
293 OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
294 (Scan.succeed (Toplevel.theory Sign.local_path));
297 OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
298 ((P.opt_keyword "open" >> not) -- (P.name -- Scan.repeat1 P.xname) >>
299 (Toplevel.theory o uncurry Sign.hide_names));
305 OuterSyntax.command "use" "eval ML text from file" (K.tag_ml K.thy_decl)
306 (P.path >> (Toplevel.generic_theory o ThyInfo.exec_file false));
309 OuterSyntax.command "ML" "eval ML text (diagnostic)" (K.tag_ml K.thy_decl)
310 (P.position P.text >> (fn (txt, pos) =>
311 Toplevel.generic_theory (ML_Context.exec (fn () => ML_Context.eval true pos txt))));
314 OuterSyntax.command "ML_val" "eval ML text (diagnostic)" (K.tag_ml K.diag)
315 (P.position P.text >> IsarCmd.ml_diag true);
318 OuterSyntax.command "ML_command" "silently eval ML text (diagnostic)" (K.tag_ml K.diag)
319 (P.position P.text >> (Toplevel.no_timing oo IsarCmd.ml_diag false));
322 OuterSyntax.command "setup" "apply ML theory setup" (K.tag_ml K.thy_decl)
323 (P.position P.text >> (Toplevel.theory o IsarCmd.generic_setup));
326 OuterSyntax.command "method_setup" "define proof method in ML" (K.tag_ml K.thy_decl)
327 (P.name -- P.!!! (P.$$$ "=" |-- P.position P.text -- P.text)
328 >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
331 OuterSyntax.command "declaration" "generic ML declaration" (K.tag_ml K.thy_decl)
332 (P.opt_target -- P.position P.text
333 >> (fn (loc, txt) => Toplevel.local_theory loc (IsarCmd.declaration txt)));
336 OuterSyntax.command "simproc_setup" "define simproc in ML" (K.tag_ml K.thy_decl)
338 P.name -- (P.$$$ "(" |-- P.enum1 "|" P.term --| P.$$$ ")" --| P.$$$ "=") --
339 P.position P.text -- Scan.optional (P.$$$ "identifier" |-- Scan.repeat1 P.xname) []
340 >> (fn ((((loc, a), b), c), d) => Toplevel.local_theory loc (IsarCmd.simproc_setup a b c d)));
343 (* translation functions *)
345 val trfun = P.opt_keyword "advanced" -- P.position P.text;
348 OuterSyntax.command "parse_ast_translation" "install parse ast translation functions"
349 (K.tag_ml K.thy_decl)
350 (trfun >> (Toplevel.theory o IsarCmd.parse_ast_translation));
353 OuterSyntax.command "parse_translation" "install parse translation functions"
354 (K.tag_ml K.thy_decl)
355 (trfun >> (Toplevel.theory o IsarCmd.parse_translation));
358 OuterSyntax.command "print_translation" "install print translation functions"
359 (K.tag_ml K.thy_decl)
360 (trfun >> (Toplevel.theory o IsarCmd.print_translation));
363 OuterSyntax.command "typed_print_translation" "install typed print translation functions"
364 (K.tag_ml K.thy_decl)
365 (trfun >> (Toplevel.theory o IsarCmd.typed_print_translation));
368 OuterSyntax.command "print_ast_translation" "install print ast translation functions"
369 (K.tag_ml K.thy_decl)
370 (trfun >> (Toplevel.theory o IsarCmd.print_ast_translation));
373 OuterSyntax.command "token_translation" "install token translation functions"
374 (K.tag_ml K.thy_decl)
375 (P.position P.text >> (Toplevel.theory o IsarCmd.token_translation));
381 OuterSyntax.command "oracle" "declare oracle" (K.tag_ml K.thy_decl)
382 (P.name -- (P.$$$ "(" |-- P.text --| P.$$$ ")" --| P.$$$ "=")
383 -- P.position P.text >> (fn ((x, y), z) => Toplevel.theory (IsarCmd.oracle x y z)));
389 OuterSyntax.command "context" "enter local theory context" K.thy_decl
390 (P.name --| P.begin >> (fn name =>
391 Toplevel.print o Toplevel.begin_local_theory true (TheoryTarget.context name)));
397 SpecParse.locale_expr --
398 Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
399 Scan.repeat1 SpecParse.context_element >> pair Locale.empty;
402 OuterSyntax.command "locale" "define named proof context" K.thy_decl
403 ((P.opt_keyword "open" >> (fn true => NONE | false => SOME "")) --
404 P.name -- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (Locale.empty, []) -- P.opt_begin
405 >> (fn (((is_open, name), (expr, elems)), begin) =>
406 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
407 (Locale.add_locale is_open name expr elems #-> TheoryTarget.begin)));
410 OuterSyntax.command "interpretation"
411 "prove and register interpretation of locale expression in theory or locale" K.thy_goal
412 (P.xname --| (P.$$$ "\\<subseteq>" || P.$$$ "<") -- P.!!! SpecParse.locale_expr
413 >> (Toplevel.print oo (Toplevel.theory_to_proof o Locale.interpretation_in_locale I)) ||
414 SpecParse.opt_thm_name ":" -- SpecParse.locale_expr -- SpecParse.locale_insts
415 >> (fn ((x, y), z) => Toplevel.print o
416 Toplevel.theory_to_proof (Locale.interpretation I (apfst (pair true) x) y z)));
419 OuterSyntax.command "interpret"
420 "prove and register interpretation of locale expression in proof context"
421 (K.tag_proof K.prf_goal)
422 (SpecParse.opt_thm_name ":" -- SpecParse.locale_expr -- SpecParse.locale_insts
423 >> (fn ((x, y), z) => Toplevel.print o
424 Toplevel.proof' (Locale.interpret Seq.single (apfst (pair true) x) y z)));
430 SpecParse.class_expr --
431 Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
432 Scan.repeat1 SpecParse.context_element >> pair [];
435 OuterSyntax.command "class" "define type class" K.thy_decl
436 (P.name -- (P.$$$ "=" |-- class_val) -- P.opt_begin
437 >> (fn ((name, (supclasses, elems)), begin) =>
438 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
439 (Class.class_cmd name supclasses elems #-> TheoryTarget.begin)));
442 OuterSyntax.command "subclass" "prove a subclass relation" K.thy_goal
443 (P.opt_target -- P.xname >> (fn (loc, class) =>
444 Toplevel.print o Toplevel.local_theory_to_proof loc (Subclass.subclass_cmd class)));
447 OuterSyntax.command "instantiation" "instantiate and prove type arity" K.thy_decl
448 (P.multi_arity --| P.begin
449 >> (fn arities => Toplevel.print o
450 Toplevel.begin_local_theory true (Instance.instantiation_cmd arities)));
453 OuterSyntax.command "instance" "prove type arity or subclass relation" K.thy_goal
454 ((P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) >> Class.classrel_cmd ||
455 P.arity -- Scan.repeat (SpecParse.opt_thm_name ":" -- P.prop)
456 >> (fn (arity, defs) => Instance.instance_cmd arity defs))
457 >> (Toplevel.print oo Toplevel.theory_to_proof)
458 || Scan.succeed (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
461 (* arbitrary overloading *)
464 OuterSyntax.command "overloading" "overloaded definitions" K.thy_decl
465 (Scan.repeat1 (P.name --| (P.$$$ "\\<equiv>" || P.$$$ "==") -- P.term --
466 Scan.optional (P.$$$ "(" |-- (P.$$$ "unchecked" >> K false) --| P.$$$ ")") true
467 >> P.triple1) --| P.begin
468 >> (fn operations => Toplevel.print o
469 Toplevel.begin_local_theory true (TheoryTarget.overloading_cmd operations)));
472 (* code generation *)
475 OuterSyntax.command "code_datatype" "define set of code datatype constructors" K.thy_decl
476 (Scan.repeat1 P.term >> (Toplevel.theory o Code.add_datatype_cmd));
480 (** proof commands **)
484 fun gen_theorem kind =
485 OuterSyntax.command kind ("state " ^ kind) K.thy_goal
486 (P.opt_target -- Scan.optional (SpecParse.opt_thm_name ":" --|
487 Scan.ahead (SpecParse.locale_keyword || SpecParse.statement_keyword)) ("", []) --
488 SpecParse.general_statement >> (fn ((loc, a), (elems, concl)) =>
490 Toplevel.local_theory_to_proof' loc
491 (Specification.theorem_cmd kind NONE (K I) a elems concl))));
493 val _ = gen_theorem Thm.theoremK;
494 val _ = gen_theorem Thm.lemmaK;
495 val _ = gen_theorem Thm.corollaryK;
498 OuterSyntax.command "have" "state local goal"
499 (K.tag_proof K.prf_goal)
500 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.have));
503 OuterSyntax.command "hence" "abbreviates \"then have\""
504 (K.tag_proof K.prf_goal)
505 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.hence));
508 OuterSyntax.command "show" "state local goal, solving current obligation"
509 (K.tag_proof K.prf_asm_goal)
510 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.show));
513 OuterSyntax.command "thus" "abbreviates \"then show\""
514 (K.tag_proof K.prf_asm_goal)
515 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.thus));
520 val facts = P.and_list1 SpecParse.xthms1;
523 OuterSyntax.command "then" "forward chaining"
524 (K.tag_proof K.prf_chain)
525 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
528 OuterSyntax.command "from" "forward chaining from given facts"
529 (K.tag_proof K.prf_chain)
530 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss)));
533 OuterSyntax.command "with" "forward chaining from given and current facts"
534 (K.tag_proof K.prf_chain)
535 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss)));
538 OuterSyntax.command "note" "define facts"
539 (K.tag_proof K.prf_decl)
540 (SpecParse.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss)));
543 OuterSyntax.command "using" "augment goal facts"
544 (K.tag_proof K.prf_decl)
545 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using)));
548 OuterSyntax.command "unfolding" "unfold definitions in goal and facts"
549 (K.tag_proof K.prf_decl)
550 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding)));
556 OuterSyntax.command "fix" "fix local variables (Skolem constants)"
557 (K.tag_proof K.prf_asm)
558 (P.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix)));
561 OuterSyntax.command "assume" "assume propositions"
562 (K.tag_proof K.prf_asm)
563 (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume)));
566 OuterSyntax.command "presume" "assume propositions, to be established later"
567 (K.tag_proof K.prf_asm)
568 (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume)));
571 OuterSyntax.command "def" "local definition"
572 (K.tag_proof K.prf_asm)
574 (SpecParse.opt_thm_name ":" --
575 ((P.name -- P.opt_mixfix) -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp)))
576 >> (Toplevel.print oo (Toplevel.proof o Proof.def)));
579 OuterSyntax.command "obtain" "generalized existence"
580 (K.tag_proof K.prf_asm_goal)
581 (P.parname -- Scan.optional (P.fixes --| P.where_) [] -- SpecParse.statement
582 >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain x y z)));
585 OuterSyntax.command "guess" "wild guessing (unstructured)"
586 (K.tag_proof K.prf_asm_goal)
587 (Scan.optional P.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess)));
590 OuterSyntax.command "let" "bind text variables"
591 (K.tag_proof K.prf_decl)
592 (P.and_list1 (P.enum1 "and" P.term -- (P.$$$ "=" |-- P.term))
593 >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind)));
596 (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 (P.maybe P.name) --| P.$$$ ")") ||
597 P.xname >> rpair []) -- SpecParse.opt_attribs >> P.triple1;
600 OuterSyntax.command "case" "invoke local context"
601 (K.tag_proof K.prf_asm)
602 (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case)));
605 (* proof structure *)
608 OuterSyntax.command "{" "begin explicit proof block"
609 (K.tag_proof K.prf_open)
610 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
613 OuterSyntax.command "}" "end explicit proof block"
614 (K.tag_proof K.prf_close)
615 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
618 OuterSyntax.command "next" "enter next proof block"
619 (K.tag_proof K.prf_block)
620 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
626 OuterSyntax.command "qed" "conclude (sub-)proof"
627 (K.tag_proof K.qed_block)
628 (Scan.option Method.parse >> (Toplevel.print oo IsarCmd.qed));
631 OuterSyntax.command "by" "terminal backward proof"
633 (Method.parse -- Scan.option Method.parse >> (Toplevel.print oo IsarCmd.terminal_proof));
636 OuterSyntax.command ".." "default proof"
638 (Scan.succeed (Toplevel.print o IsarCmd.default_proof));
641 OuterSyntax.command "." "immediate proof"
643 (Scan.succeed (Toplevel.print o IsarCmd.immediate_proof));
646 OuterSyntax.command "done" "done proof"
648 (Scan.succeed (Toplevel.print o IsarCmd.done_proof));
651 OuterSyntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
653 (Scan.succeed (Toplevel.print o IsarCmd.skip_proof));
656 OuterSyntax.command "oops" "forget proof"
657 (K.tag_proof K.qed_global)
658 (Scan.succeed Toplevel.forget_proof);
664 OuterSyntax.command "defer" "shuffle internal proof state"
665 (K.tag_proof K.prf_script)
666 (Scan.option P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
669 OuterSyntax.command "prefer" "shuffle internal proof state"
670 (K.tag_proof K.prf_script)
671 (P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
674 OuterSyntax.command "apply" "initial refinement step (unstructured)"
675 (K.tag_proof K.prf_script)
676 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
679 OuterSyntax.command "apply_end" "terminal refinement (unstructured)"
680 (K.tag_proof K.prf_script)
681 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
684 OuterSyntax.command "proof" "backward proof"
685 (K.tag_proof K.prf_block)
686 (Scan.option Method.parse >> (fn m => Toplevel.print o
687 Toplevel.actual_proof (ProofHistory.applys (Proof.proof m)) o
688 Toplevel.skip_proof (History.apply (fn i => i + 1))));
691 (* calculational proof commands *)
694 Scan.option (P.$$$ "(" |-- P.!!! ((SpecParse.xthms1 --| P.$$$ ")")));
697 OuterSyntax.command "also" "combine calculation and current facts"
698 (K.tag_proof K.prf_decl)
699 (calc_args >> (Toplevel.proofs' o Calculation.also));
702 OuterSyntax.command "finally" "combine calculation and current facts, exhibit result"
703 (K.tag_proof K.prf_chain)
704 (calc_args >> (Toplevel.proofs' o Calculation.finally_));
707 OuterSyntax.command "moreover" "augment calculation by current facts"
708 (K.tag_proof K.prf_decl)
709 (Scan.succeed (Toplevel.proof' Calculation.moreover));
712 OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
713 (K.tag_proof K.prf_chain)
714 (Scan.succeed (Toplevel.proof' Calculation.ultimately));
717 (* proof navigation *)
720 OuterSyntax.command "back" "backtracking of proof command"
721 (K.tag_proof K.prf_script)
722 (Scan.succeed (Toplevel.print o IsarCmd.back));
728 OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control
729 (P.name >> (Toplevel.no_timing oo IsarCmd.cannot_undo));
732 OuterSyntax.improper_command "redo" "redo last command" K.control
733 (Scan.succeed (Toplevel.no_timing o Toplevel.print o IsarCmd.redo));
736 OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control
737 (P.nat >> ((Toplevel.no_timing o Toplevel.print) oo IsarCmd.undos_proof));
740 OuterSyntax.improper_command "undo" "undo last command" K.control
741 (Scan.succeed (Toplevel.no_timing o IsarCmd.undo));
744 OuterSyntax.improper_command "kill" "kill current history node" K.control
745 (Scan.succeed (Toplevel.no_timing o Toplevel.print o IsarCmd.kill));
751 OuterSyntax.improper_command "Isabelle.command" "nested Isabelle command" K.control
752 ((Scan.optional P.properties [] -- P.position P.string) :|-- (fn (props, arg) =>
753 Scan.succeed (K (IsarCmd.nested_command props arg))
754 handle ERROR msg => Scan.fail_with (K msg)));
758 (** diagnostic commands (for interactive mode only) **)
760 val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
761 val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
764 OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
765 K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
768 OuterSyntax.improper_command "help" "print outer syntax commands" K.diag
769 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
772 OuterSyntax.improper_command "print_commands" "print outer syntax commands" K.diag
773 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
776 OuterSyntax.improper_command "print_configs" "print configuration options" K.diag
777 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_configs));
780 OuterSyntax.improper_command "print_context" "print theory context name" K.diag
781 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
784 OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
785 (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theory));
788 OuterSyntax.improper_command "print_syntax" "print inner syntax of context (verbose!)" K.diag
789 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
792 OuterSyntax.improper_command "print_abbrevs" "print constant abbreviation of context" K.diag
793 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_abbrevs));
796 OuterSyntax.improper_command "print_theorems"
797 "print theorems of local theory or proof context" K.diag
798 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theorems));
801 OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
802 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales));
805 OuterSyntax.improper_command "print_classes" "print classes of this theory" K.diag
806 (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
807 o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
810 OuterSyntax.improper_command "print_locale" "print locale expression in this theory" K.diag
811 (opt_bang -- locale_val >> (Toplevel.no_timing oo IsarCmd.print_locale));
814 OuterSyntax.improper_command "print_interps"
815 "print interpretations of named locale" K.diag
816 (Scan.optional (P.$$$ "!" >> K true) false -- P.xname
817 >> (Toplevel.no_timing oo uncurry IsarCmd.print_registrations));
820 OuterSyntax.improper_command "print_attributes" "print attributes of this theory" K.diag
821 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
824 OuterSyntax.improper_command "print_simpset" "print context of Simplifier" K.diag
825 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_simpset));
828 OuterSyntax.improper_command "print_rules" "print intro/elim rules" K.diag
829 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules));
832 OuterSyntax.improper_command "print_trans_rules" "print transitivity rules" K.diag
833 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules));
836 OuterSyntax.improper_command "print_methods" "print methods of this theory" K.diag
837 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
840 OuterSyntax.improper_command "print_antiquotations" "print antiquotations (global)" K.diag
841 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations));
844 OuterSyntax.improper_command "thy_deps" "visualize theory dependencies"
845 K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.thy_deps));
848 OuterSyntax.improper_command "class_deps" "visualize class dependencies"
849 K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
852 OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
853 K.diag (SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
858 P.reserved "name" |-- P.!!! (P.$$$ ":" |-- P.xname) >> FindTheorems.Name ||
859 P.reserved "intro" >> K FindTheorems.Intro ||
860 P.reserved "elim" >> K FindTheorems.Elim ||
861 P.reserved "dest" >> K FindTheorems.Dest ||
862 P.reserved "simp" |-- P.!!! (P.$$$ ":" |-- P.term) >> FindTheorems.Simp ||
863 P.term >> FindTheorems.Pattern;
868 P.!!! (Scan.option P.nat -- Scan.optional (P.reserved "with_dups" >> K false) true
869 --| P.$$$ ")")) (NONE, true);
873 OuterSyntax.improper_command "find_theorems" "print theorems meeting specified criteria" K.diag
874 (options -- Scan.repeat (((Scan.option P.minus >> is_none) -- criterion))
875 >> (Toplevel.no_timing oo IsarCmd.find_theorems));
880 OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
881 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
884 OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag
885 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_facts));
888 OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
889 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
892 OuterSyntax.improper_command "print_statement" "print theorems as long statements" K.diag
893 (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_stmts));
896 OuterSyntax.improper_command "thm" "print theorems" K.diag
897 (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
900 OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
901 (opt_modes -- Scan.option SpecParse.xthms1
902 >> (Toplevel.no_timing oo IsarCmd.print_prfs false));
905 OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
906 (opt_modes -- Scan.option SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true));
909 OuterSyntax.improper_command "prop" "read and print proposition" K.diag
910 (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
913 OuterSyntax.improper_command "term" "read and print term" K.diag
914 (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term));
917 OuterSyntax.improper_command "typ" "read and print type" K.diag
918 (opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
921 OuterSyntax.improper_command "print_codesetup" "print code generator setup of this theory" K.diag
923 (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
924 (Code.print_codesetup o Toplevel.theory_of)));
927 OuterSyntax.improper_command "unused_thms" "find unused theorems" K.diag
928 (Scan.option ((Scan.repeat1 (Scan.unless P.minus P.name) --| P.minus) --
929 Scan.option (Scan.repeat1 (Scan.unless P.minus P.name))) >>
930 (Toplevel.no_timing oo IsarCmd.unused_thms));
933 (** system commands (for interactive mode only) **)
936 OuterSyntax.improper_command "cd" "change current working directory" K.diag
937 (P.path >> (Toplevel.no_timing oo IsarCmd.cd));
940 OuterSyntax.improper_command "pwd" "print current working directory" K.diag
941 (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
944 OuterSyntax.improper_command "use_thy" "use theory file" K.diag
945 (P.name >> (fn name =>
946 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.use_thy name)));
949 OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
950 (P.name >> (Toplevel.no_timing oo IsarCmd.touch_thy));
953 OuterSyntax.improper_command "touch_child_thys" "outdate child theories" K.diag
954 (P.name >> (Toplevel.no_timing oo IsarCmd.touch_child_thys));
957 OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
958 (P.name >> (Toplevel.no_timing oo IsarCmd.remove_thy));
961 OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
962 K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.kill_thy));
965 OuterSyntax.improper_command "display_drafts" "display raw source files with symbols"
966 K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.display_drafts));
969 OuterSyntax.improper_command "print_drafts" "print raw source files with symbols"
970 K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.print_drafts));
973 Scan.option P.nat -- Scan.option (P.$$$ "," |-- P.!!! P.nat);
976 OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag
977 (opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr));
980 OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
981 (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
984 OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
985 (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
988 OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
989 (P.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
992 OuterSyntax.improper_command "quit" "quit Isabelle" K.control
993 (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
996 OuterSyntax.improper_command "exit" "exit Isar loop" K.control
997 (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
1000 OuterSyntax.improper_command "init_toplevel" "restart Isar toplevel loop" K.control
1001 (Scan.succeed (Toplevel.no_timing o IsarCmd.init_toplevel));
1004 OuterSyntax.improper_command "welcome" "print welcome message" K.diag
1005 (Scan.succeed (Toplevel.no_timing o IsarCmd.welcome));