1 (* Title: Pure/Isar/isar_syn.ML
2 Author: Markus Wenzel, TU Muenchen
4 Isar/Pure outer syntax.
7 structure IsarSyn: sig end =
10 structure P = OuterParse and K = OuterKeyword;
15 (*keep keywords consistent with the parsers, otherwise be prepared for
18 val _ = List.app OuterKeyword.keyword
19 ["!!", "!", "%", "(", ")", "+", ",", "--", ":", "::", ";", "<", "<=",
20 "=", "==", "=>", "?", "[", "\\<equiv>", "\\<leftharpoondown>",
21 "\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>", "]",
22 "advanced", "and", "assumes", "attach", "begin", "binder",
23 "constrains", "defines", "fixes", "for", "identifier", "if",
24 "imports", "in", "infix", "infixl", "infixr", "is",
25 "notes", "obtains", "open", "output", "overloaded", "pervasive",
26 "shows", "structure", "unchecked", "uses", "where", "|"];
33 OuterSyntax.command "theory" "begin theory" (K.tag_theory K.thy_begin)
34 (Thy_Header.args >> (Toplevel.print oo IsarCmd.init_theory));
37 OuterSyntax.command "end" "end (local) theory" (K.tag_theory K.thy_end)
38 (Scan.succeed (Toplevel.exit o Toplevel.end_local_theory));
42 (** markup commands **)
44 val _ = OuterSyntax.markup_command ThyOutput.Markup "header" "theory header" K.diag
45 (P.doc_source >> IsarCmd.header_markup);
47 val _ = OuterSyntax.markup_command ThyOutput.Markup "chapter" "chapter heading"
48 K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
50 val _ = OuterSyntax.markup_command ThyOutput.Markup "section" "section heading"
51 K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
53 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsection" "subsection heading"
54 K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
57 OuterSyntax.markup_command ThyOutput.Markup "subsubsection" "subsubsection heading"
58 K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
60 val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "text" "formal comment (theory)"
61 K.thy_decl (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
63 val _ = OuterSyntax.markup_command ThyOutput.Verbatim "text_raw" "raw document preparation text"
64 K.thy_decl (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
66 val _ = OuterSyntax.markup_command ThyOutput.Markup "sect" "formal comment (proof)"
67 (K.tag_proof K.prf_heading) (P.doc_source >> IsarCmd.proof_markup);
69 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsect" "formal comment (proof)"
70 (K.tag_proof K.prf_heading) (P.doc_source >> IsarCmd.proof_markup);
72 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsubsect" "formal comment (proof)"
73 (K.tag_proof K.prf_heading) (P.doc_source >> IsarCmd.proof_markup);
75 val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "txt" "formal comment (proof)"
76 (K.tag_proof K.prf_decl) (P.doc_source >> IsarCmd.proof_markup);
78 val _ = OuterSyntax.markup_command ThyOutput.Verbatim "txt_raw"
79 "raw document preparation text (proof)" (K.tag_proof K.prf_decl)
80 (P.doc_source >> IsarCmd.proof_markup);
84 (** theory commands **)
86 (* classes and sorts *)
89 OuterSyntax.command "classes" "declare type classes" K.thy_decl
90 (Scan.repeat1 (P.binding -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
91 P.!!! (P.list1 P.xname)) []) >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
94 OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
95 (P.and_list1 (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname))
96 >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
99 OuterSyntax.local_theory "default_sort" "declare default sort for explicit type variables"
101 (P.sort >> (fn s => fn lthy => Local_Theory.set_defsort (Syntax.read_sort lthy s) lthy));
107 OuterSyntax.local_theory "typedecl" "type declaration" K.thy_decl
108 (P.type_args -- P.binding -- P.opt_mixfix
109 >> (fn ((args, a), mx) => Typedecl.typedecl (a, map (rpair dummyS) args, mx) #> snd));
112 OuterSyntax.local_theory "types" "declare type abbreviations" K.thy_decl
114 (P.type_args -- P.binding -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_mixfix')))
115 >> (fold (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs)));
118 OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
119 K.thy_decl (Scan.repeat1 P.binding >> (Toplevel.theory o Sign.add_nonterminals));
122 OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
123 (Scan.repeat1 P.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
126 (* consts and syntax *)
129 OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
130 (P.const_binding >> (Toplevel.theory o Object_Logic.add_judgment_cmd));
133 OuterSyntax.command "consts" "declare constants" K.thy_decl
134 (Scan.repeat1 P.const_binding >> (Toplevel.theory o Sign.add_consts));
136 val opt_overloaded = P.opt_keyword "overloaded";
139 OuterSyntax.command "finalconsts" "declare constants as final" K.thy_decl
140 (opt_overloaded -- Scan.repeat1 P.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
143 (P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true;
146 Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) Syntax.mode_default;
149 OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
150 (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Sign.add_modesyntax));
153 OuterSyntax.command "no_syntax" "delete syntax declarations" K.thy_decl
154 (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Sign.del_modesyntax));
160 Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
162 fun trans_arrow toks =
163 ((P.$$$ "\\<rightharpoonup>" || P.$$$ "=>") >> K Syntax.ParseRule ||
164 (P.$$$ "\\<leftharpoondown>" || P.$$$ "<=") >> K Syntax.PrintRule ||
165 (P.$$$ "\\<rightleftharpoons>" || P.$$$ "==") >> K Syntax.ParsePrintRule) toks;
168 trans_pat -- P.!!! (trans_arrow -- trans_pat)
169 >> (fn (left, (arr, right)) => arr (left, right));
172 OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
173 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.add_trrules));
176 OuterSyntax.command "no_translations" "remove syntax translation rules" K.thy_decl
177 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.del_trrules));
180 (* axioms and definitions *)
183 OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
184 (Scan.repeat1 SpecParse.spec >> (Toplevel.theory o IsarCmd.add_axioms));
186 val opt_unchecked_overloaded =
187 Scan.optional (P.$$$ "(" |-- P.!!!
188 (((P.$$$ "unchecked" >> K true) -- Scan.optional (P.$$$ "overloaded" >> K true) false ||
189 P.$$$ "overloaded" >> K (false, true)) --| P.$$$ ")")) (false, false);
192 OuterSyntax.command "defs" "define constants" K.thy_decl
193 (opt_unchecked_overloaded --
194 Scan.repeat1 (SpecParse.thm_name ":" -- P.prop >> (fn ((x, y), z) => ((x, z), y)))
195 >> (Toplevel.theory o IsarCmd.add_defs));
201 P.binding --| P.where_ >> (fn x => (x, NONE, NoSyn)) ||
202 P.binding -- (P.$$$ "::" |-- P.!!! P.typ >> SOME) -- P.opt_mixfix'
203 --| Scan.option P.where_ >> P.triple1 ||
204 P.binding -- (P.mixfix >> pair NONE) --| Scan.option P.where_ >> P.triple2;
206 val old_constdef = Scan.option old_constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
209 Scan.optional ((P.$$$ "(" -- P.$$$ "structure") |-- P.!!! (P.simple_fixes --| P.$$$ ")")) [];
212 OuterSyntax.command "constdefs" "old-style constant definition" K.thy_decl
213 (structs -- Scan.repeat1 old_constdef >> (Toplevel.theory o Constdefs.add_constdefs));
216 (* constant definitions and abbreviations *)
219 OuterSyntax.local_theory "definition" "constant definition" K.thy_decl
220 (SpecParse.constdef >> (fn args => #2 o Specification.definition_cmd args));
223 OuterSyntax.local_theory "abbreviation" "constant abbreviation" K.thy_decl
224 (opt_mode -- (Scan.option SpecParse.constdecl -- P.prop)
225 >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
228 OuterSyntax.local_theory "type_notation" "add concrete syntax for type constructors" K.thy_decl
229 (opt_mode -- P.and_list1 (P.xname -- P.mixfix)
230 >> (fn (mode, args) => Specification.type_notation_cmd true mode args));
233 OuterSyntax.local_theory "no_type_notation" "delete concrete syntax for type constructors" K.thy_decl
234 (opt_mode -- P.and_list1 (P.xname -- P.mixfix)
235 >> (fn (mode, args) => Specification.type_notation_cmd false mode args));
238 OuterSyntax.local_theory "notation" "add concrete syntax for constants / fixed variables" K.thy_decl
239 (opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
240 >> (fn (mode, args) => Specification.notation_cmd true mode args));
243 OuterSyntax.local_theory "no_notation" "delete concrete syntax for constants / fixed variables" K.thy_decl
244 (opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
245 >> (fn (mode, args) => Specification.notation_cmd false mode args));
248 (* constant specifications *)
251 OuterSyntax.command "axiomatization" "axiomatic constant specification" K.thy_decl
252 (Scan.optional P.fixes [] --
253 Scan.optional (P.where_ |-- P.!!! (P.and_list1 SpecParse.specs)) []
254 >> (fn (x, y) => Toplevel.theory (#2 o Specification.axiomatization_cmd x y)));
260 SpecParse.name_facts >> (fn args => #2 o Specification.theorems_cmd kind args);
263 OuterSyntax.local_theory "theorems" "define theorems" K.thy_decl (theorems Thm.theoremK);
266 OuterSyntax.local_theory "lemmas" "define lemmas" K.thy_decl (theorems Thm.lemmaK);
269 OuterSyntax.local_theory "declare" "declare theorems" K.thy_decl
270 (P.and_list1 SpecParse.xthms1
271 >> (fn args => #2 o Specification.theorems_cmd "" [(Attrib.empty_binding, flat args)]));
274 (* name space entry path *)
277 OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
278 (Scan.succeed (Toplevel.theory Sign.root_path));
281 OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
282 (Scan.succeed (Toplevel.theory Sign.local_path));
284 fun hide_names name hide what =
285 OuterSyntax.command name ("hide " ^ what ^ " from name space") K.thy_decl
286 ((P.opt_keyword "open" >> not) -- Scan.repeat1 P.xname >>
287 (Toplevel.theory o uncurry hide));
289 val _ = hide_names "hide_class" IsarCmd.hide_class "classes";
290 val _ = hide_names "hide_type" IsarCmd.hide_type "types";
291 val _ = hide_names "hide_const" IsarCmd.hide_const "constants";
292 val _ = hide_names "hide_fact" IsarCmd.hide_fact "facts";
297 fun propagate_env (context as Context.Proof lthy) =
298 Context.Proof (Local_Theory.map_contexts (ML_Env.inherit context) lthy)
299 | propagate_env context = context;
301 fun propagate_env_prf prf = Proof.map_contexts
302 (Context.proof_map (ML_Env.inherit (Context.Proof (Proof.context_of prf)))) prf;
305 OuterSyntax.command "use" "ML text from file" (K.tag_ml K.thy_decl)
306 (P.path >> (fn path => Toplevel.generic_theory (ThyInfo.exec_file false path #> propagate_env)));
309 OuterSyntax.command "ML" "ML text within theory or local theory" (K.tag_ml K.thy_decl)
310 (P.ML_source >> (fn (txt, pos) =>
311 Toplevel.generic_theory
312 (ML_Context.exec (fn () => ML_Context.eval true pos txt) #> propagate_env)));
315 OuterSyntax.command "ML_prf" "ML text within proof" (K.tag_proof K.prf_decl)
316 (P.ML_source >> (fn (txt, pos) =>
317 Toplevel.proof (Proof.map_context (Context.proof_map
318 (ML_Context.exec (fn () => ML_Context.eval true pos txt))) #> propagate_env_prf)));
321 OuterSyntax.command "ML_val" "diagnostic ML text" (K.tag_ml K.diag)
322 (P.ML_source >> IsarCmd.ml_diag true);
325 OuterSyntax.command "ML_command" "diagnostic ML text (silent)" (K.tag_ml K.diag)
326 (P.ML_source >> (Toplevel.no_timing oo IsarCmd.ml_diag false));
329 OuterSyntax.command "setup" "ML theory setup" (K.tag_ml K.thy_decl)
330 (P.ML_source >> (Toplevel.theory o IsarCmd.global_setup));
333 OuterSyntax.local_theory "local_setup" "ML local theory setup" (K.tag_ml K.thy_decl)
334 (P.ML_source >> IsarCmd.local_setup);
337 OuterSyntax.command "attribute_setup" "define attribute in ML" (K.tag_ml K.thy_decl)
338 (P.position P.name -- P.!!! (P.$$$ "=" |-- P.ML_source -- P.text)
339 >> (fn (name, (txt, cmt)) => Toplevel.theory (Attrib.attribute_setup name txt cmt)));
342 OuterSyntax.command "method_setup" "define proof method in ML" (K.tag_ml K.thy_decl)
343 (P.position P.name -- P.!!! (P.$$$ "=" |-- P.ML_source -- P.text)
344 >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
347 OuterSyntax.local_theory "declaration" "generic ML declaration" (K.tag_ml K.thy_decl)
348 (P.opt_keyword "pervasive" -- P.ML_source >> uncurry IsarCmd.declaration);
351 OuterSyntax.local_theory "simproc_setup" "define simproc in ML" (K.tag_ml K.thy_decl)
352 (P.name -- (P.$$$ "(" |-- P.enum1 "|" P.term --| P.$$$ ")" --| P.$$$ "=") --
353 P.ML_source -- Scan.optional (P.$$$ "identifier" |-- Scan.repeat1 P.xname) []
354 >> (fn (((a, b), c), d) => IsarCmd.simproc_setup a b c d));
357 (* translation functions *)
359 val trfun = P.opt_keyword "advanced" -- P.ML_source;
362 OuterSyntax.command "parse_ast_translation" "install parse ast translation functions"
363 (K.tag_ml K.thy_decl)
364 (trfun >> (Toplevel.theory o IsarCmd.parse_ast_translation));
367 OuterSyntax.command "parse_translation" "install parse translation functions"
368 (K.tag_ml K.thy_decl)
369 (trfun >> (Toplevel.theory o IsarCmd.parse_translation));
372 OuterSyntax.command "print_translation" "install print translation functions"
373 (K.tag_ml K.thy_decl)
374 (trfun >> (Toplevel.theory o IsarCmd.print_translation));
377 OuterSyntax.command "typed_print_translation" "install typed print translation functions"
378 (K.tag_ml K.thy_decl)
379 (trfun >> (Toplevel.theory o IsarCmd.typed_print_translation));
382 OuterSyntax.command "print_ast_translation" "install print ast translation functions"
383 (K.tag_ml K.thy_decl)
384 (trfun >> (Toplevel.theory o IsarCmd.print_ast_translation));
390 OuterSyntax.command "oracle" "declare oracle" (K.tag_ml K.thy_decl)
391 (P.position P.name -- (P.$$$ "=" |-- P.ML_source) >>
392 (fn (x, y) => Toplevel.theory (IsarCmd.oracle x y)));
398 OuterSyntax.command "context" "enter local theory context" K.thy_decl
399 (P.name --| P.begin >> (fn name =>
400 Toplevel.print o Toplevel.begin_local_theory true (Theory_Target.context_cmd name)));
406 SpecParse.locale_expression false --
407 Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
408 Scan.repeat1 SpecParse.context_element >> pair ([], []);
411 OuterSyntax.command "locale" "define named proof context" K.thy_decl
412 (P.binding -- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (([], []), []) -- P.opt_begin
413 >> (fn ((name, (expr, elems)), begin) =>
414 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
415 (Expression.add_locale_cmd name Binding.empty expr elems #> snd)));
418 OuterSyntax.command "sublocale"
419 "prove sublocale relation between a locale and a locale expression" K.thy_goal
420 (P.xname --| (P.$$$ "\\<subseteq>" || P.$$$ "<") -- P.!!! (SpecParse.locale_expression false)
421 >> (fn (loc, expr) =>
422 Toplevel.print o Toplevel.theory_to_proof (Expression.sublocale_cmd loc expr)));
425 OuterSyntax.command "interpretation"
426 "prove interpretation of locale expression in theory" K.thy_goal
427 (P.!!! (SpecParse.locale_expression true) --
428 Scan.optional (P.where_ |-- P.and_list1 (SpecParse.opt_thm_name ":" -- P.prop)) []
429 >> (fn (expr, equations) => Toplevel.print o
430 Toplevel.theory_to_proof (Expression.interpretation_cmd expr equations)));
433 OuterSyntax.command "interpret"
434 "prove interpretation of locale expression in proof context"
435 (K.tag_proof K.prf_goal)
436 (P.!!! (SpecParse.locale_expression true)
437 >> (fn expr => Toplevel.print o Toplevel.proof' (Expression.interpret_cmd expr)));
443 SpecParse.class_expr --
444 Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
445 Scan.repeat1 SpecParse.context_element >> pair [];
448 OuterSyntax.command "class" "define type class" K.thy_decl
449 (P.binding -- Scan.optional (P.$$$ "=" |-- class_val) ([], []) -- P.opt_begin
450 >> (fn ((name, (supclasses, elems)), begin) =>
451 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
452 (Class.class_cmd name supclasses elems #> snd)));
455 OuterSyntax.local_theory_to_proof "subclass" "prove a subclass relation" K.thy_goal
456 (P.xname >> Class.subclass_cmd);
459 OuterSyntax.command "instantiation" "instantiate and prove type arity" K.thy_decl
460 (P.multi_arity --| P.begin
461 >> (fn arities => Toplevel.print o
462 Toplevel.begin_local_theory true (Theory_Target.instantiation_cmd arities)));
465 OuterSyntax.command "instance" "prove type arity or subclass relation" K.thy_goal
466 ((P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) >> Class.classrel_cmd ||
467 P.multi_arity >> Class.instance_arity_cmd)
468 >> (Toplevel.print oo Toplevel.theory_to_proof)
469 || Scan.succeed (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
472 (* arbitrary overloading *)
475 OuterSyntax.command "overloading" "overloaded definitions" K.thy_decl
476 (Scan.repeat1 (P.name --| (P.$$$ "\\<equiv>" || P.$$$ "==") -- P.term --
477 Scan.optional (P.$$$ "(" |-- (P.$$$ "unchecked" >> K false) --| P.$$$ ")") true
478 >> P.triple1) --| P.begin
479 >> (fn operations => Toplevel.print o
480 Toplevel.begin_local_theory true (Theory_Target.overloading_cmd operations)));
483 (* code generation *)
486 OuterSyntax.command "code_datatype" "define set of code datatype constructors" K.thy_decl
487 (Scan.repeat1 P.term >> (Toplevel.theory o Code.add_datatype_cmd));
491 (** proof commands **)
495 fun gen_theorem schematic kind =
496 OuterSyntax.local_theory_to_proof'
497 (if schematic then "schematic_" ^ kind else kind)
498 ("state " ^ (if schematic then "schematic " ^ kind else kind))
499 (if schematic then K.thy_schematic_goal else K.thy_goal)
500 (Scan.optional (SpecParse.opt_thm_name ":" --|
501 Scan.ahead (SpecParse.locale_keyword || SpecParse.statement_keyword)) Attrib.empty_binding --
502 SpecParse.general_statement >> (fn (a, (elems, concl)) =>
503 ((if schematic then Specification.schematic_theorem_cmd else Specification.theorem_cmd)
504 kind NONE (K I) a elems concl)));
506 val _ = gen_theorem false Thm.theoremK;
507 val _ = gen_theorem false Thm.lemmaK;
508 val _ = gen_theorem false Thm.corollaryK;
509 val _ = gen_theorem true Thm.theoremK;
510 val _ = gen_theorem true Thm.lemmaK;
511 val _ = gen_theorem true Thm.corollaryK;
514 OuterSyntax.local_theory_to_proof "example_proof"
515 "example proof body, without any result" K.thy_schematic_goal
517 (Specification.schematic_theorem_cmd "" NONE (K I)
518 Attrib.empty_binding [] (Element.Shows []) false #> Proof.enter_forward));
521 OuterSyntax.command "have" "state local goal"
522 (K.tag_proof K.prf_goal)
523 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.have));
526 OuterSyntax.command "hence" "abbreviates \"then have\""
527 (K.tag_proof K.prf_goal)
528 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.hence));
531 OuterSyntax.command "show" "state local goal, solving current obligation"
532 (K.tag_proof K.prf_asm_goal)
533 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.show));
536 OuterSyntax.command "thus" "abbreviates \"then show\""
537 (K.tag_proof K.prf_asm_goal)
538 (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.thus));
543 val facts = P.and_list1 SpecParse.xthms1;
546 OuterSyntax.command "then" "forward chaining"
547 (K.tag_proof K.prf_chain)
548 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
551 OuterSyntax.command "from" "forward chaining from given facts"
552 (K.tag_proof K.prf_chain)
553 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss_cmd)));
556 OuterSyntax.command "with" "forward chaining from given and current facts"
557 (K.tag_proof K.prf_chain)
558 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss_cmd)));
561 OuterSyntax.command "note" "define facts"
562 (K.tag_proof K.prf_decl)
563 (SpecParse.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss_cmd)));
566 OuterSyntax.command "using" "augment goal facts"
567 (K.tag_proof K.prf_decl)
568 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using_cmd)));
571 OuterSyntax.command "unfolding" "unfold definitions in goal and facts"
572 (K.tag_proof K.prf_decl)
573 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding_cmd)));
579 OuterSyntax.command "fix" "fix local variables (Skolem constants)"
580 (K.tag_proof K.prf_asm)
581 (P.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix_cmd)));
584 OuterSyntax.command "assume" "assume propositions"
585 (K.tag_proof K.prf_asm)
586 (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume_cmd)));
589 OuterSyntax.command "presume" "assume propositions, to be established later"
590 (K.tag_proof K.prf_asm)
591 (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume_cmd)));
594 OuterSyntax.command "def" "local definition"
595 (K.tag_proof K.prf_asm)
597 (SpecParse.opt_thm_name ":" --
598 ((P.binding -- P.opt_mixfix) -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp)))
599 >> (Toplevel.print oo (Toplevel.proof o Proof.def_cmd)));
602 OuterSyntax.command "obtain" "generalized existence"
603 (K.tag_proof K.prf_asm_goal)
604 (P.parname -- Scan.optional (P.fixes --| P.where_) [] -- SpecParse.statement
605 >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain_cmd x y z)));
608 OuterSyntax.command "guess" "wild guessing (unstructured)"
609 (K.tag_proof K.prf_asm_goal)
610 (Scan.optional P.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess_cmd)));
613 OuterSyntax.command "let" "bind text variables"
614 (K.tag_proof K.prf_decl)
615 (P.and_list1 (P.and_list1 P.term -- (P.$$$ "=" |-- P.term))
616 >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind_cmd)));
619 OuterSyntax.command "write" "add concrete syntax for constants / fixed variables"
620 (K.tag_proof K.prf_decl)
621 (opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
622 >> (fn (mode, args) => Toplevel.print o Toplevel.proof (Proof.write_cmd mode args)));
625 (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 (P.maybe P.name) --| P.$$$ ")") ||
626 P.xname >> rpair []) -- SpecParse.opt_attribs >> P.triple1;
629 OuterSyntax.command "case" "invoke local context"
630 (K.tag_proof K.prf_asm)
631 (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case_cmd)));
634 (* proof structure *)
637 OuterSyntax.command "{" "begin explicit proof block"
638 (K.tag_proof K.prf_open)
639 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
642 OuterSyntax.command "}" "end explicit proof block"
643 (K.tag_proof K.prf_close)
644 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
647 OuterSyntax.command "next" "enter next proof block"
648 (K.tag_proof K.prf_block)
649 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
655 OuterSyntax.command "qed" "conclude (sub-)proof"
656 (K.tag_proof K.qed_block)
657 (Scan.option Method.parse >> IsarCmd.qed);
660 OuterSyntax.command "by" "terminal backward proof"
662 (Method.parse -- Scan.option Method.parse >> IsarCmd.terminal_proof);
665 OuterSyntax.command ".." "default proof"
667 (Scan.succeed IsarCmd.default_proof);
670 OuterSyntax.command "." "immediate proof"
672 (Scan.succeed IsarCmd.immediate_proof);
675 OuterSyntax.command "done" "done proof"
677 (Scan.succeed IsarCmd.done_proof);
680 OuterSyntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
682 (Scan.succeed IsarCmd.skip_proof);
685 OuterSyntax.command "oops" "forget proof"
686 (K.tag_proof K.qed_global)
687 (Scan.succeed Toplevel.forget_proof);
693 OuterSyntax.command "defer" "shuffle internal proof state"
694 (K.tag_proof K.prf_script)
695 (Scan.option P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
698 OuterSyntax.command "prefer" "shuffle internal proof state"
699 (K.tag_proof K.prf_script)
700 (P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
703 OuterSyntax.command "apply" "initial refinement step (unstructured)"
704 (K.tag_proof K.prf_script)
705 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
708 OuterSyntax.command "apply_end" "terminal refinement (unstructured)"
709 (K.tag_proof K.prf_script)
710 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
713 OuterSyntax.command "proof" "backward proof"
714 (K.tag_proof K.prf_block)
715 (Scan.option Method.parse >> (fn m => Toplevel.print o
716 Toplevel.actual_proof (Proof_Node.applys (Proof.proof m)) o
717 Toplevel.skip_proof (fn i => i + 1)));
720 (* calculational proof commands *)
723 Scan.option (P.$$$ "(" |-- P.!!! ((SpecParse.xthms1 --| P.$$$ ")")));
726 OuterSyntax.command "also" "combine calculation and current facts"
727 (K.tag_proof K.prf_decl)
728 (calc_args >> (Toplevel.proofs' o Calculation.also_cmd));
731 OuterSyntax.command "finally" "combine calculation and current facts, exhibit result"
732 (K.tag_proof K.prf_chain)
733 (calc_args >> (Toplevel.proofs' o Calculation.finally_cmd));
736 OuterSyntax.command "moreover" "augment calculation by current facts"
737 (K.tag_proof K.prf_decl)
738 (Scan.succeed (Toplevel.proof' Calculation.moreover));
741 OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
742 (K.tag_proof K.prf_chain)
743 (Scan.succeed (Toplevel.proof' Calculation.ultimately));
746 (* proof navigation *)
749 OuterSyntax.command "back" "backtracking of proof command"
750 (K.tag_proof K.prf_script)
751 (Scan.succeed (Toplevel.print o Toplevel.actual_proof Proof_Node.back o Toplevel.skip_proof I));
754 (* nested commands *)
757 Scan.optional ValueParse.properties [] -- P.position P.string >> (fn (props, (str, pos)) =>
758 (Position.of_properties (Position.default_properties pos props), str));
761 OuterSyntax.improper_command "Isabelle.command" "nested Isabelle command" K.control
762 (props_text :|-- (fn (pos, str) =>
763 (case OuterSyntax.parse pos str of
764 [tr] => Scan.succeed (K tr)
765 | _ => Scan.fail_with (K "exactly one command expected"))
766 handle ERROR msg => Scan.fail_with (K msg)));
770 (** diagnostic commands (for interactive mode only) **)
772 val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
773 val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
776 OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
777 K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
780 OuterSyntax.improper_command "help" "print outer syntax commands" K.diag
781 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
784 OuterSyntax.improper_command "print_commands" "print outer syntax commands" K.diag
785 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
788 OuterSyntax.improper_command "print_configs" "print configuration options" K.diag
789 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_configs));
792 OuterSyntax.improper_command "print_context" "print theory context name" K.diag
793 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
796 OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
797 (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theory));
800 OuterSyntax.improper_command "print_syntax" "print inner syntax of context (verbose!)" K.diag
801 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
804 OuterSyntax.improper_command "print_abbrevs" "print constant abbreviation of context" K.diag
805 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_abbrevs));
808 OuterSyntax.improper_command "print_theorems"
809 "print theorems of local theory or proof context" K.diag
810 (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theorems));
813 OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
814 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales));
817 OuterSyntax.improper_command "print_classes" "print classes of this theory" K.diag
818 (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
819 o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
822 OuterSyntax.improper_command "print_locale" "print locale of this theory" K.diag
823 (opt_bang -- P.xname >> (Toplevel.no_timing oo IsarCmd.print_locale));
826 OuterSyntax.improper_command "print_interps"
827 "print interpretations of locale for this theory" K.diag
828 (P.xname >> (Toplevel.no_timing oo IsarCmd.print_registrations));
831 OuterSyntax.improper_command "print_attributes" "print attributes of this theory" K.diag
832 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
835 OuterSyntax.improper_command "print_simpset" "print context of Simplifier" K.diag
836 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_simpset));
839 OuterSyntax.improper_command "print_rules" "print intro/elim rules" K.diag
840 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules));
843 OuterSyntax.improper_command "print_trans_rules" "print transitivity rules" K.diag
844 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules));
847 OuterSyntax.improper_command "print_methods" "print methods of this theory" K.diag
848 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
851 OuterSyntax.improper_command "print_antiquotations" "print antiquotations (global)" K.diag
852 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations));
855 OuterSyntax.improper_command "thy_deps" "visualize theory dependencies"
856 K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.thy_deps));
859 OuterSyntax.improper_command "class_deps" "visualize class dependencies"
860 K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
863 OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
864 K.diag (SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
867 OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
868 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
871 OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag
872 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_facts));
875 OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
876 (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
879 OuterSyntax.improper_command "print_statement" "print theorems as long statements" K.diag
880 (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_stmts));
883 OuterSyntax.improper_command "thm" "print theorems" K.diag
884 (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
887 OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
888 (opt_modes -- Scan.option SpecParse.xthms1
889 >> (Toplevel.no_timing oo IsarCmd.print_prfs false));
892 OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
893 (opt_modes -- Scan.option SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true));
896 OuterSyntax.improper_command "prop" "read and print proposition" K.diag
897 (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
900 OuterSyntax.improper_command "term" "read and print term" K.diag
901 (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term));
904 OuterSyntax.improper_command "typ" "read and print type" K.diag
905 (opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
908 OuterSyntax.improper_command "print_codesetup" "print code generator setup" K.diag
910 (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
911 (Code.print_codesetup o Toplevel.theory_of)));
914 OuterSyntax.improper_command "unused_thms" "find unused theorems" K.diag
915 (Scan.option ((Scan.repeat1 (Scan.unless P.minus P.name) --| P.minus) --
916 Scan.option (Scan.repeat1 (Scan.unless P.minus P.name))) >>
917 (Toplevel.no_timing oo IsarCmd.unused_thms));
921 (** system commands (for interactive mode only) **)
924 OuterSyntax.improper_command "cd" "change current working directory" K.diag
925 (P.path >> (Toplevel.no_timing oo IsarCmd.cd));
928 OuterSyntax.improper_command "pwd" "print current working directory" K.diag
929 (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
932 OuterSyntax.improper_command "use_thy" "use theory file" K.diag
933 (P.name >> (fn name =>
934 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.use_thy name)));
937 OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
938 (P.name >> (fn name =>
939 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.touch_thy name)));
942 OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
943 (P.name >> (fn name =>
944 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.remove_thy name)));
947 OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
948 K.diag (P.name >> (fn name =>
949 Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.kill_thy name)));
952 OuterSyntax.improper_command "display_drafts" "display raw source files with symbols"
953 K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.display_drafts));
956 OuterSyntax.improper_command "print_drafts" "print raw source files with symbols"
957 K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.print_drafts));
960 Scan.option P.nat -- Scan.option (P.$$$ "," |-- P.!!! P.nat);
963 OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag
964 (opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr));
967 OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
968 (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
971 OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
972 (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
975 OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
976 (P.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
979 OuterSyntax.improper_command "quit" "quit Isabelle" K.control
980 (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
983 OuterSyntax.improper_command "exit" "exit Isar loop" K.control
984 (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));