1 (* Title: Pure/Isar/isar_syn.ML
2 Author: Markus Wenzel, TU Muenchen
4 Isar/Pure outer syntax.
7 structure Isar_Syn: 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 >> (fn (name, imports, uses) =>
33 Toplevel.init_theory name
34 (fn () => Thy_Info.toplevel_begin_theory name imports (map (apfst Path.explode) uses))));
37 Outer_Syntax.command "end" "end (local) theory" (Keyword.tag_theory Keyword.thy_end)
39 (Toplevel.exit o Toplevel.end_local_theory o Toplevel.end_proof (K Proof.end_notepad)));
43 (** markup commands **)
45 val _ = Outer_Syntax.markup_command Thy_Output.Markup "header" "theory header" Keyword.diag
46 (Parse.doc_source >> Isar_Cmd.header_markup);
48 val _ = Outer_Syntax.markup_command Thy_Output.Markup "chapter" "chapter heading"
49 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
51 val _ = Outer_Syntax.markup_command Thy_Output.Markup "section" "section heading"
52 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
54 val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsection" "subsection heading"
55 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
58 Outer_Syntax.markup_command Thy_Output.Markup "subsubsection" "subsubsection heading"
59 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
61 val _ = Outer_Syntax.markup_command Thy_Output.MarkupEnv "text" "formal comment (theory)"
62 Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
64 val _ = Outer_Syntax.markup_command Thy_Output.Verbatim "text_raw" "raw document preparation text"
65 Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
67 val _ = Outer_Syntax.markup_command Thy_Output.Markup "sect" "formal comment (proof)"
68 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
70 val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsect" "formal comment (proof)"
71 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
73 val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsubsect" "formal comment (proof)"
74 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
76 val _ = Outer_Syntax.markup_command Thy_Output.MarkupEnv "txt" "formal comment (proof)"
77 (Keyword.tag_proof Keyword.prf_decl) (Parse.doc_source >> Isar_Cmd.proof_markup);
79 val _ = Outer_Syntax.markup_command Thy_Output.Verbatim "txt_raw"
80 "raw document preparation text (proof)" (Keyword.tag_proof Keyword.prf_decl)
81 (Parse.doc_source >> Isar_Cmd.proof_markup);
85 (** theory commands **)
87 (* classes and sorts *)
90 Outer_Syntax.command "classes" "declare type classes" Keyword.thy_decl
91 (Scan.repeat1 (Parse.binding -- Scan.optional ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |--
92 Parse.!!! (Parse.list1 Parse.xname)) [])
93 >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
96 Outer_Syntax.command "classrel" "state inclusion of type classes (axiomatic!)" Keyword.thy_decl
97 (Parse.and_list1 (Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<")
98 |-- Parse.!!! Parse.xname))
99 >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
102 Outer_Syntax.local_theory "default_sort" "declare default sort for explicit type variables"
104 (Parse.sort >> (fn s => fn lthy => Local_Theory.set_defsort (Syntax.read_sort lthy s) lthy));
110 Outer_Syntax.local_theory "typedecl" "type declaration" Keyword.thy_decl
111 (Parse.type_args -- Parse.binding -- Parse.opt_mixfix
112 >> (fn ((args, a), mx) => Typedecl.typedecl (a, map (rpair dummyS) args, mx) #> snd));
115 Outer_Syntax.local_theory "types" "declare type abbreviations" Keyword.thy_decl
117 (Parse.type_args -- Parse.binding --
118 (Parse.$$$ "=" |-- Parse.!!! (Parse.typ -- Parse.opt_mixfix')))
119 >> (fold (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs)));
122 Outer_Syntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
123 Keyword.thy_decl (Scan.repeat1 Parse.binding >> (Toplevel.theory o Sign.add_nonterminals));
126 Outer_Syntax.command "arities" "state type arities (axiomatic!)" Keyword.thy_decl
127 (Scan.repeat1 Parse.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
130 (* consts and syntax *)
133 Outer_Syntax.command "judgment" "declare object-logic judgment" Keyword.thy_decl
134 (Parse.const_binding >> (Toplevel.theory o Object_Logic.add_judgment_cmd));
137 Outer_Syntax.command "consts" "declare constants" Keyword.thy_decl
138 (Scan.repeat1 Parse.const_binding >> (Toplevel.theory o Sign.add_consts));
140 val opt_overloaded = Parse.opt_keyword "overloaded";
143 Outer_Syntax.command "finalconsts" "declare constants as final" Keyword.thy_decl
144 (opt_overloaded -- Scan.repeat1 Parse.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
147 (Parse.$$$ "output" >> K ("", false)) ||
148 Parse.name -- Scan.optional (Parse.$$$ "output" >> K false) true;
151 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (mode_spec --| Parse.$$$ ")")) Syntax.mode_default;
154 Outer_Syntax.command "syntax" "declare syntactic constants" Keyword.thy_decl
155 (opt_mode -- Scan.repeat1 Parse.const >> (Toplevel.theory o uncurry Sign.add_modesyntax));
158 Outer_Syntax.command "no_syntax" "delete syntax declarations" Keyword.thy_decl
159 (opt_mode -- Scan.repeat1 Parse.const >> (Toplevel.theory o uncurry Sign.del_modesyntax));
165 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Parse.xname --| Parse.$$$ ")")) "logic"
168 fun trans_arrow toks =
169 ((Parse.$$$ "\\<rightharpoonup>" || Parse.$$$ "=>") >> K Syntax.ParseRule ||
170 (Parse.$$$ "\\<leftharpoondown>" || Parse.$$$ "<=") >> K Syntax.PrintRule ||
171 (Parse.$$$ "\\<rightleftharpoons>" || Parse.$$$ "==") >> K Syntax.ParsePrintRule) toks;
174 trans_pat -- Parse.!!! (trans_arrow -- trans_pat)
175 >> (fn (left, (arr, right)) => arr (left, right));
178 Outer_Syntax.command "translations" "declare syntax translation rules" Keyword.thy_decl
179 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.add_trrules));
182 Outer_Syntax.command "no_translations" "remove syntax translation rules" Keyword.thy_decl
183 (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.del_trrules));
186 (* axioms and definitions *)
189 Outer_Syntax.command "axioms" "state arbitrary propositions (axiomatic!)" Keyword.thy_decl
190 (Scan.repeat1 Parse_Spec.spec >>
191 (fn spec => Toplevel.theory (fn thy =>
192 (legacy_feature "Old 'axioms' command -- use 'axiomatization' instead";
193 Isar_Cmd.add_axioms spec thy))));
195 val opt_unchecked_overloaded =
196 Scan.optional (Parse.$$$ "(" |-- Parse.!!!
197 (((Parse.$$$ "unchecked" >> K true) -- Scan.optional (Parse.$$$ "overloaded" >> K true) false ||
198 Parse.$$$ "overloaded" >> K (false, true)) --| Parse.$$$ ")")) (false, false);
201 Outer_Syntax.command "defs" "define constants" Keyword.thy_decl
202 (opt_unchecked_overloaded --
203 Scan.repeat1 (Parse_Spec.thm_name ":" -- Parse.prop >> (fn ((x, y), z) => ((x, z), y)))
204 >> (Toplevel.theory o Isar_Cmd.add_defs));
207 (* constant definitions and abbreviations *)
210 Outer_Syntax.local_theory "definition" "constant definition" Keyword.thy_decl
211 (Parse_Spec.constdef >> (fn args => #2 o Specification.definition_cmd args));
214 Outer_Syntax.local_theory "abbreviation" "constant abbreviation" Keyword.thy_decl
215 (opt_mode -- (Scan.option Parse_Spec.constdecl -- Parse.prop)
216 >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
219 Outer_Syntax.local_theory "type_notation" "add concrete syntax for type constructors"
221 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse.mixfix)
222 >> (fn (mode, args) => Specification.type_notation_cmd true mode args));
225 Outer_Syntax.local_theory "no_type_notation" "delete concrete syntax for type constructors"
227 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse.mixfix)
228 >> (fn (mode, args) => Specification.type_notation_cmd false mode args));
231 Outer_Syntax.local_theory "notation" "add concrete syntax for constants / fixed variables"
233 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
234 >> (fn (mode, args) => Specification.notation_cmd true mode args));
237 Outer_Syntax.local_theory "no_notation" "delete concrete syntax for constants / fixed variables"
239 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
240 >> (fn (mode, args) => Specification.notation_cmd false mode args));
243 (* constant specifications *)
246 Outer_Syntax.command "axiomatization" "axiomatic constant specification" Keyword.thy_decl
247 (Scan.optional Parse.fixes [] --
248 Scan.optional (Parse.where_ |-- Parse.!!! (Parse.and_list1 Parse_Spec.specs)) []
249 >> (fn (x, y) => Toplevel.theory (#2 o Specification.axiomatization_cmd x y)));
255 Parse_Spec.name_facts >> (fn args => #2 o Specification.theorems_cmd kind args);
258 Outer_Syntax.local_theory "theorems" "define theorems" Keyword.thy_decl (theorems Thm.theoremK);
261 Outer_Syntax.local_theory "lemmas" "define lemmas" Keyword.thy_decl (theorems Thm.lemmaK);
264 Outer_Syntax.local_theory "declare" "declare theorems" Keyword.thy_decl
265 (Parse.and_list1 Parse_Spec.xthms1
266 >> (fn args => #2 o Specification.theorems_cmd "" [(Attrib.empty_binding, flat args)]));
269 (* name space entry path *)
271 fun hide_names name hide what =
272 Outer_Syntax.command name ("hide " ^ what ^ " from name space") Keyword.thy_decl
273 ((Parse.opt_keyword "open" >> not) -- Scan.repeat1 Parse.xname >>
274 (Toplevel.theory o uncurry hide));
276 val _ = hide_names "hide_class" Isar_Cmd.hide_class "classes";
277 val _ = hide_names "hide_type" Isar_Cmd.hide_type "types";
278 val _ = hide_names "hide_const" Isar_Cmd.hide_const "constants";
279 val _ = hide_names "hide_fact" Isar_Cmd.hide_fact "facts";
285 Outer_Syntax.command "use" "ML text from file" (Keyword.tag_ml Keyword.thy_decl)
286 (Parse.path >> (fn path => Toplevel.generic_theory (Thy_Load.exec_ml path)));
289 Outer_Syntax.command "ML" "ML text within theory or local theory"
290 (Keyword.tag_ml Keyword.thy_decl)
291 (Parse.ML_source >> (fn (txt, pos) =>
292 Toplevel.generic_theory
293 (ML_Context.exec (fn () => ML_Context.eval_text true pos txt) #>
294 Local_Theory.propagate_ml_env)));
297 Outer_Syntax.command "ML_prf" "ML text within proof" (Keyword.tag_proof Keyword.prf_decl)
298 (Parse.ML_source >> (fn (txt, pos) =>
299 Toplevel.proof (Proof.map_context (Context.proof_map
300 (ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> Proof.propagate_ml_env)));
303 Outer_Syntax.command "ML_val" "diagnostic ML text" (Keyword.tag_ml Keyword.diag)
304 (Parse.ML_source >> Isar_Cmd.ml_diag true);
307 Outer_Syntax.command "ML_command" "diagnostic ML text (silent)" (Keyword.tag_ml Keyword.diag)
308 (Parse.ML_source >> (Toplevel.no_timing oo Isar_Cmd.ml_diag false));
311 Outer_Syntax.command "setup" "ML theory setup" (Keyword.tag_ml Keyword.thy_decl)
312 (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.global_setup));
315 Outer_Syntax.local_theory "local_setup" "ML local theory setup" (Keyword.tag_ml Keyword.thy_decl)
316 (Parse.ML_source >> Isar_Cmd.local_setup);
319 Outer_Syntax.command "attribute_setup" "define attribute in ML" (Keyword.tag_ml Keyword.thy_decl)
320 (Parse.position Parse.name -- Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Parse.text)
321 >> (fn (name, (txt, cmt)) => Toplevel.theory (Attrib.attribute_setup name txt cmt)));
324 Outer_Syntax.command "method_setup" "define proof method in ML" (Keyword.tag_ml Keyword.thy_decl)
325 (Parse.position Parse.name -- Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Parse.text)
326 >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
329 Outer_Syntax.local_theory "declaration" "generic ML declaration"
330 (Keyword.tag_ml Keyword.thy_decl)
331 (Parse.opt_keyword "pervasive" -- Parse.ML_source
332 >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = false, pervasive = pervasive} txt));
335 Outer_Syntax.local_theory "syntax_declaration" "generic ML declaration"
336 (Keyword.tag_ml Keyword.thy_decl)
337 (Parse.opt_keyword "pervasive" -- Parse.ML_source
338 >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = true, pervasive = pervasive} txt));
341 Outer_Syntax.local_theory "simproc_setup" "define simproc in ML" (Keyword.tag_ml Keyword.thy_decl)
343 (Parse.$$$ "(" |-- Parse.enum1 "|" Parse.term --| Parse.$$$ ")" --| Parse.$$$ "=") --
344 Parse.ML_source -- Scan.optional (Parse.$$$ "identifier" |-- Scan.repeat1 Parse.xname) []
345 >> (fn (((a, b), c), d) => Isar_Cmd.simproc_setup a b c d));
348 (* translation functions *)
350 val trfun = Parse.opt_keyword "advanced" -- Parse.ML_source;
353 Outer_Syntax.command "parse_ast_translation" "install parse ast translation functions"
354 (Keyword.tag_ml Keyword.thy_decl)
355 (trfun >> (Toplevel.theory o Isar_Cmd.parse_ast_translation));
358 Outer_Syntax.command "parse_translation" "install parse translation functions"
359 (Keyword.tag_ml Keyword.thy_decl)
360 (trfun >> (Toplevel.theory o Isar_Cmd.parse_translation));
363 Outer_Syntax.command "print_translation" "install print translation functions"
364 (Keyword.tag_ml Keyword.thy_decl)
365 (trfun >> (Toplevel.theory o Isar_Cmd.print_translation));
368 Outer_Syntax.command "typed_print_translation" "install typed print translation functions"
369 (Keyword.tag_ml Keyword.thy_decl)
370 (trfun >> (Toplevel.theory o Isar_Cmd.typed_print_translation));
373 Outer_Syntax.command "print_ast_translation" "install print ast translation functions"
374 (Keyword.tag_ml Keyword.thy_decl)
375 (trfun >> (Toplevel.theory o Isar_Cmd.print_ast_translation));
381 Outer_Syntax.command "oracle" "declare oracle" (Keyword.tag_ml Keyword.thy_decl)
382 (Parse.position Parse.name -- (Parse.$$$ "=" |-- Parse.ML_source) >>
383 (fn (x, y) => Toplevel.theory (Isar_Cmd.oracle x y)));
389 Outer_Syntax.command "context" "enter local theory context" Keyword.thy_decl
390 (Parse.name --| Parse.begin >> (fn name =>
391 Toplevel.print o Toplevel.begin_local_theory true (Named_Target.context_cmd name)));
397 Parse_Spec.locale_expression false --
398 Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
399 Scan.repeat1 Parse_Spec.context_element >> pair ([], []);
402 Outer_Syntax.command "locale" "define named proof context" Keyword.thy_decl
404 Scan.optional (Parse.$$$ "=" |-- Parse.!!! locale_val) (([], []), []) -- Parse.opt_begin
405 >> (fn ((name, (expr, elems)), begin) =>
406 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
407 (Expression.add_locale_cmd name Binding.empty expr elems #> snd)));
410 Outer_Syntax.command "sublocale"
411 "prove sublocale relation between a locale and a locale expression" Keyword.thy_goal
412 (Parse.xname --| (Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") --
413 Parse.!!! (Parse_Spec.locale_expression false)
414 >> (fn (loc, expr) =>
415 Toplevel.print o Toplevel.theory_to_proof (Expression.sublocale_cmd loc expr)));
418 Outer_Syntax.command "interpretation"
419 "prove interpretation of locale expression in theory" Keyword.thy_goal
420 (Parse.!!! (Parse_Spec.locale_expression true) --
421 Scan.optional (Parse.where_ |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []
422 >> (fn (expr, equations) => Toplevel.print o
423 Toplevel.theory_to_proof (Expression.interpretation_cmd expr equations)));
426 Outer_Syntax.command "interpret"
427 "prove interpretation of locale expression in proof context"
428 (Keyword.tag_proof Keyword.prf_goal)
429 (Parse.!!! (Parse_Spec.locale_expression true) --
430 Scan.optional (Parse.where_ |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []
431 >> (fn (expr, equations) => Toplevel.print o
432 Toplevel.proof' (Expression.interpret_cmd expr equations)));
438 Parse_Spec.class_expr --
439 Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
440 Scan.repeat1 Parse_Spec.context_element >> pair [];
443 Outer_Syntax.command "class" "define type class" Keyword.thy_decl
444 (Parse.binding -- Scan.optional (Parse.$$$ "=" |-- class_val) ([], []) -- Parse.opt_begin
445 >> (fn ((name, (supclasses, elems)), begin) =>
446 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
447 (Class_Declaration.class_cmd name supclasses elems #> snd)));
450 Outer_Syntax.local_theory_to_proof "subclass" "prove a subclass relation" Keyword.thy_goal
451 (Parse.xname >> Class_Declaration.subclass_cmd);
454 Outer_Syntax.command "instantiation" "instantiate and prove type arity" Keyword.thy_decl
455 (Parse.multi_arity --| Parse.begin
456 >> (fn arities => Toplevel.print o
457 Toplevel.begin_local_theory true (Class.instantiation_cmd arities)));
460 Outer_Syntax.command "instance" "prove type arity or subclass relation" Keyword.thy_goal
461 ((Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |-- Parse.!!! Parse.xname)
462 >> Class.classrel_cmd ||
463 Parse.multi_arity >> Class.instance_arity_cmd)
464 >> (Toplevel.print oo Toplevel.theory_to_proof) ||
466 (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
469 (* arbitrary overloading *)
472 Outer_Syntax.command "overloading" "overloaded definitions" Keyword.thy_decl
473 (Scan.repeat1 (Parse.name --| (Parse.$$$ "\\<equiv>" || Parse.$$$ "==") -- Parse.term --
474 Scan.optional (Parse.$$$ "(" |-- (Parse.$$$ "unchecked" >> K false) --| Parse.$$$ ")") true
475 >> Parse.triple1) --| Parse.begin
476 >> (fn operations => Toplevel.print o
477 Toplevel.begin_local_theory true (Overloading.overloading_cmd operations)));
480 (* code generation *)
483 Outer_Syntax.command "code_datatype" "define set of code datatype constructors" Keyword.thy_decl
484 (Scan.repeat1 Parse.term >> (Toplevel.theory o Code.add_datatype_cmd));
488 (** proof commands **)
492 fun gen_theorem schematic kind =
493 Outer_Syntax.local_theory_to_proof'
494 (if schematic then "schematic_" ^ kind else kind)
495 ("state " ^ (if schematic then "schematic " ^ kind else kind))
496 (if schematic then Keyword.thy_schematic_goal else Keyword.thy_goal)
497 (Scan.optional (Parse_Spec.opt_thm_name ":" --|
498 Scan.ahead (Parse_Spec.locale_keyword || Parse_Spec.statement_keyword)) Attrib.empty_binding --
499 Parse_Spec.general_statement >> (fn (a, (elems, concl)) =>
500 ((if schematic then Specification.schematic_theorem_cmd else Specification.theorem_cmd)
501 kind NONE (K I) a elems concl)));
503 val _ = gen_theorem false Thm.theoremK;
504 val _ = gen_theorem false Thm.lemmaK;
505 val _ = gen_theorem false Thm.corollaryK;
506 val _ = gen_theorem true Thm.theoremK;
507 val _ = gen_theorem true Thm.lemmaK;
508 val _ = gen_theorem true Thm.corollaryK;
511 Outer_Syntax.local_theory_to_proof "notepad"
512 "Isar proof state as formal notepad, without any result" Keyword.thy_decl
513 (Parse.begin >> K Proof.begin_notepad);
516 Outer_Syntax.local_theory_to_proof "example_proof"
517 "example proof body, without any result" Keyword.thy_schematic_goal
519 (Specification.theorem_cmd "" NONE (K I)
520 Attrib.empty_binding [] (Element.Shows []) false #> Proof.enter_forward));
523 Outer_Syntax.command "have" "state local goal"
524 (Keyword.tag_proof Keyword.prf_goal)
525 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.have));
528 Outer_Syntax.command "hence" "abbreviates \"then have\""
529 (Keyword.tag_proof Keyword.prf_goal)
530 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.hence));
533 Outer_Syntax.command "show" "state local goal, solving current obligation"
534 (Keyword.tag_proof Keyword.prf_asm_goal)
535 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.show));
538 Outer_Syntax.command "thus" "abbreviates \"then show\""
539 (Keyword.tag_proof Keyword.prf_asm_goal)
540 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.thus));
545 val facts = Parse.and_list1 Parse_Spec.xthms1;
548 Outer_Syntax.command "then" "forward chaining"
549 (Keyword.tag_proof Keyword.prf_chain)
550 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
553 Outer_Syntax.command "from" "forward chaining from given facts"
554 (Keyword.tag_proof Keyword.prf_chain)
555 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss_cmd)));
558 Outer_Syntax.command "with" "forward chaining from given and current facts"
559 (Keyword.tag_proof Keyword.prf_chain)
560 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss_cmd)));
563 Outer_Syntax.command "note" "define facts"
564 (Keyword.tag_proof Keyword.prf_decl)
565 (Parse_Spec.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss_cmd)));
568 Outer_Syntax.command "using" "augment goal facts"
569 (Keyword.tag_proof Keyword.prf_decl)
570 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using_cmd)));
573 Outer_Syntax.command "unfolding" "unfold definitions in goal and facts"
574 (Keyword.tag_proof Keyword.prf_decl)
575 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding_cmd)));
581 Outer_Syntax.command "fix" "fix local variables (Skolem constants)"
582 (Keyword.tag_proof Keyword.prf_asm)
583 (Parse.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix_cmd)));
586 Outer_Syntax.command "assume" "assume propositions"
587 (Keyword.tag_proof Keyword.prf_asm)
588 (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume_cmd)));
591 Outer_Syntax.command "presume" "assume propositions, to be established later"
592 (Keyword.tag_proof Keyword.prf_asm)
593 (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume_cmd)));
596 Outer_Syntax.command "def" "local definition"
597 (Keyword.tag_proof Keyword.prf_asm)
599 (Parse_Spec.opt_thm_name ":" --
600 ((Parse.binding -- Parse.opt_mixfix) --
601 ((Parse.$$$ "\\<equiv>" || Parse.$$$ "==") |-- Parse.!!! Parse.termp)))
602 >> (Toplevel.print oo (Toplevel.proof o Proof.def_cmd)));
605 Outer_Syntax.command "obtain" "generalized existence"
606 (Keyword.tag_proof Keyword.prf_asm_goal)
607 (Parse.parname -- Scan.optional (Parse.fixes --| Parse.where_) [] -- Parse_Spec.statement
608 >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain_cmd x y z)));
611 Outer_Syntax.command "guess" "wild guessing (unstructured)"
612 (Keyword.tag_proof Keyword.prf_asm_goal)
613 (Scan.optional Parse.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess_cmd)));
616 Outer_Syntax.command "let" "bind text variables"
617 (Keyword.tag_proof Keyword.prf_decl)
618 (Parse.and_list1 (Parse.and_list1 Parse.term -- (Parse.$$$ "=" |-- Parse.term))
619 >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind_cmd)));
622 Outer_Syntax.command "write" "add concrete syntax for constants / fixed variables"
623 (Keyword.tag_proof Keyword.prf_decl)
624 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
625 >> (fn (mode, args) => Toplevel.print o Toplevel.proof (Proof.write_cmd mode args)));
629 Parse.!!! (Parse.xname -- Scan.repeat1 (Parse.maybe Parse.name) --| Parse.$$$ ")") ||
630 Parse.xname >> rpair []) -- Parse_Spec.opt_attribs >> Parse.triple1;
633 Outer_Syntax.command "case" "invoke local context"
634 (Keyword.tag_proof Keyword.prf_asm)
635 (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case_cmd)));
638 (* proof structure *)
641 Outer_Syntax.command "{" "begin explicit proof block"
642 (Keyword.tag_proof Keyword.prf_open)
643 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
646 Outer_Syntax.command "}" "end explicit proof block"
647 (Keyword.tag_proof Keyword.prf_close)
648 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
651 Outer_Syntax.command "next" "enter next proof block"
652 (Keyword.tag_proof Keyword.prf_block)
653 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
659 Outer_Syntax.command "qed" "conclude (sub-)proof"
660 (Keyword.tag_proof Keyword.qed_block)
661 (Scan.option Method.parse >> Isar_Cmd.qed);
664 Outer_Syntax.command "by" "terminal backward proof"
665 (Keyword.tag_proof Keyword.qed)
666 (Method.parse -- Scan.option Method.parse >> Isar_Cmd.terminal_proof);
669 Outer_Syntax.command ".." "default proof"
670 (Keyword.tag_proof Keyword.qed)
671 (Scan.succeed Isar_Cmd.default_proof);
674 Outer_Syntax.command "." "immediate proof"
675 (Keyword.tag_proof Keyword.qed)
676 (Scan.succeed Isar_Cmd.immediate_proof);
679 Outer_Syntax.command "done" "done proof"
680 (Keyword.tag_proof Keyword.qed)
681 (Scan.succeed Isar_Cmd.done_proof);
684 Outer_Syntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
685 (Keyword.tag_proof Keyword.qed)
686 (Scan.succeed Isar_Cmd.skip_proof);
689 Outer_Syntax.command "oops" "forget proof"
690 (Keyword.tag_proof Keyword.qed_global)
691 (Scan.succeed Toplevel.forget_proof);
697 Outer_Syntax.command "defer" "shuffle internal proof state"
698 (Keyword.tag_proof Keyword.prf_script)
699 (Scan.option Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
702 Outer_Syntax.command "prefer" "shuffle internal proof state"
703 (Keyword.tag_proof Keyword.prf_script)
704 (Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
707 Outer_Syntax.command "apply" "initial refinement step (unstructured)"
708 (Keyword.tag_proof Keyword.prf_script)
709 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
712 Outer_Syntax.command "apply_end" "terminal refinement (unstructured)"
713 (Keyword.tag_proof Keyword.prf_script)
714 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
717 Outer_Syntax.command "proof" "backward proof"
718 (Keyword.tag_proof Keyword.prf_block)
719 (Scan.option Method.parse >> (fn m => Toplevel.print o
720 Toplevel.actual_proof (Proof_Node.applys (Proof.proof m)) o
721 Toplevel.skip_proof (fn i => i + 1)));
724 (* calculational proof commands *)
727 Scan.option (Parse.$$$ "(" |-- Parse.!!! ((Parse_Spec.xthms1 --| Parse.$$$ ")")));
730 Outer_Syntax.command "also" "combine calculation and current facts"
731 (Keyword.tag_proof Keyword.prf_decl)
732 (calc_args >> (Toplevel.proofs' o Calculation.also_cmd));
735 Outer_Syntax.command "finally" "combine calculation and current facts, exhibit result"
736 (Keyword.tag_proof Keyword.prf_chain)
737 (calc_args >> (Toplevel.proofs' o Calculation.finally_cmd));
740 Outer_Syntax.command "moreover" "augment calculation by current facts"
741 (Keyword.tag_proof Keyword.prf_decl)
742 (Scan.succeed (Toplevel.proof' Calculation.moreover));
745 Outer_Syntax.command "ultimately" "augment calculation by current facts, exhibit result"
746 (Keyword.tag_proof Keyword.prf_chain)
747 (Scan.succeed (Toplevel.proof' Calculation.ultimately));
750 (* proof navigation *)
753 Outer_Syntax.command "back" "backtracking of proof command"
754 (Keyword.tag_proof Keyword.prf_script)
755 (Scan.succeed (Toplevel.print o Toplevel.actual_proof Proof_Node.back o Toplevel.skip_proof I));
758 (* nested commands *)
761 Scan.optional Parse_Value.properties [] -- Parse.position Parse.string
762 >> (fn (props, (str, pos)) =>
763 (Position.of_properties (Position.default_properties pos props), str));
766 Outer_Syntax.improper_command "Isabelle.command" "nested Isabelle command" Keyword.control
767 (props_text :|-- (fn (pos, str) =>
768 (case Outer_Syntax.parse pos str of
769 [tr] => Scan.succeed (K tr)
770 | _ => Scan.fail_with (K "exactly one command expected"))
771 handle ERROR msg => Scan.fail_with (K msg)));
775 (** diagnostic commands (for interactive mode only) **)
778 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.xname --| Parse.$$$ ")")) [];
780 val opt_bang = Scan.optional (Parse.$$$ "!" >> K true) false;
783 Outer_Syntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
784 Keyword.diag (Parse.nat >>
785 (fn n => Toplevel.no_timing o Toplevel.imperative (fn () => Pretty.margin_default := n)));
788 Outer_Syntax.improper_command "help" "print outer syntax commands" Keyword.diag
789 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
792 Outer_Syntax.improper_command "print_commands" "print outer syntax commands" Keyword.diag
793 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
796 Outer_Syntax.improper_command "print_configs" "print configuration options" Keyword.diag
797 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_configs));
800 Outer_Syntax.improper_command "print_context" "print theory context name" Keyword.diag
801 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_context));
804 Outer_Syntax.improper_command "print_theory" "print logical theory contents (verbose!)"
805 Keyword.diag (opt_bang >> (Toplevel.no_timing oo Isar_Cmd.print_theory));
808 Outer_Syntax.improper_command "print_syntax" "print inner syntax of context (verbose!)"
809 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_syntax));
812 Outer_Syntax.improper_command "print_abbrevs" "print constant abbreviation of context"
813 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_abbrevs));
816 Outer_Syntax.improper_command "print_theorems"
817 "print theorems of local theory or proof context" Keyword.diag
818 (opt_bang >> (Toplevel.no_timing oo Isar_Cmd.print_theorems));
821 Outer_Syntax.improper_command "print_locales" "print locales of this theory" Keyword.diag
822 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_locales));
825 Outer_Syntax.improper_command "print_classes" "print classes of this theory" Keyword.diag
826 (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
827 o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
830 Outer_Syntax.improper_command "print_locale" "print locale of this theory" Keyword.diag
831 (opt_bang -- Parse.xname >> (Toplevel.no_timing oo Isar_Cmd.print_locale));
834 Outer_Syntax.improper_command "print_interps"
835 "print interpretations of locale for this theory" Keyword.diag
836 (Parse.xname >> (Toplevel.no_timing oo Isar_Cmd.print_registrations));
839 Outer_Syntax.improper_command "print_attributes" "print attributes of this theory" Keyword.diag
840 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_attributes));
843 Outer_Syntax.improper_command "print_simpset" "print context of Simplifier" Keyword.diag
844 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_simpset));
847 Outer_Syntax.improper_command "print_rules" "print intro/elim rules" Keyword.diag
848 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_rules));
851 Outer_Syntax.improper_command "print_trans_rules" "print transitivity rules" Keyword.diag
852 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_trans_rules));
855 Outer_Syntax.improper_command "print_methods" "print methods of this theory" Keyword.diag
856 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_methods));
859 Outer_Syntax.improper_command "print_antiquotations" "print antiquotations (global)" Keyword.diag
860 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_antiquotations));
863 Outer_Syntax.improper_command "thy_deps" "visualize theory dependencies"
864 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.thy_deps));
867 Outer_Syntax.improper_command "class_deps" "visualize class dependencies"
868 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.class_deps));
871 Outer_Syntax.improper_command "thm_deps" "visualize theorem dependencies"
872 Keyword.diag (Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.thm_deps));
875 Outer_Syntax.improper_command "print_binds" "print term bindings of proof context" Keyword.diag
876 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_binds));
879 Outer_Syntax.improper_command "print_facts" "print facts of proof context" Keyword.diag
880 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_facts));
883 Outer_Syntax.improper_command "print_cases" "print cases of proof context" Keyword.diag
884 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_cases));
887 Outer_Syntax.improper_command "print_statement" "print theorems as long statements" Keyword.diag
888 (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_stmts));
891 Outer_Syntax.improper_command "thm" "print theorems" Keyword.diag
892 (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_thms));
895 Outer_Syntax.improper_command "prf" "print proof terms of theorems" Keyword.diag
896 (opt_modes -- Scan.option Parse_Spec.xthms1
897 >> (Toplevel.no_timing oo Isar_Cmd.print_prfs false));
900 Outer_Syntax.improper_command "full_prf" "print full proof terms of theorems" Keyword.diag
901 (opt_modes -- Scan.option Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_prfs true));
904 Outer_Syntax.improper_command "prop" "read and print proposition" Keyword.diag
905 (opt_modes -- Parse.term >> (Toplevel.no_timing oo Isar_Cmd.print_prop));
908 Outer_Syntax.improper_command "term" "read and print term" Keyword.diag
909 (opt_modes -- Parse.term >> (Toplevel.no_timing oo Isar_Cmd.print_term));
912 Outer_Syntax.improper_command "typ" "read and print type" Keyword.diag
913 (opt_modes -- Parse.typ >> (Toplevel.no_timing oo Isar_Cmd.print_type));
916 Outer_Syntax.improper_command "print_codesetup" "print code generator setup" Keyword.diag
918 (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
919 (Code.print_codesetup o Toplevel.theory_of)));
922 Outer_Syntax.improper_command "unused_thms" "find unused theorems" Keyword.diag
923 (Scan.option ((Scan.repeat1 (Scan.unless Parse.minus Parse.name) --| Parse.minus) --
924 Scan.option (Scan.repeat1 (Scan.unless Parse.minus Parse.name))) >>
925 (Toplevel.no_timing oo Isar_Cmd.unused_thms));
929 (** system commands (for interactive mode only) **)
932 Outer_Syntax.improper_command "cd" "change current working directory" Keyword.control
933 (Parse.path >> (fn path => Toplevel.no_timing o Toplevel.imperative (fn () => File.cd path)));
936 Outer_Syntax.improper_command "pwd" "print current working directory" Keyword.diag
937 (Scan.succeed (Toplevel.no_timing o
938 Toplevel.imperative (fn () => writeln (Path.implode (File.pwd ())))));
941 Outer_Syntax.improper_command "use_thy" "use theory file" Keyword.control
942 (Parse.name >> (fn name =>
943 Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.use_thy name)));
946 Outer_Syntax.improper_command "remove_thy" "remove theory from loader database" Keyword.control
947 (Parse.name >> (fn name =>
948 Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.remove_thy name)));
951 Outer_Syntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
952 Keyword.control (Parse.name >> (fn name =>
953 Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.kill_thy name)));
956 Outer_Syntax.improper_command "display_drafts" "display raw source files with symbols"
957 Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo Isar_Cmd.display_drafts));
960 Outer_Syntax.improper_command "print_drafts" "print raw source files with symbols"
961 Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo Isar_Cmd.print_drafts));
963 val _ = (* FIXME tty only *)
964 Outer_Syntax.improper_command "pr" "print current proof state (if present)" Keyword.diag
965 (opt_modes -- Scan.option Parse.nat >> (fn (modes, limit) =>
966 Toplevel.no_timing o Toplevel.keep (fn state =>
967 (case limit of NONE => () | SOME n => Goal_Display.goals_limit_default := n;
968 Toplevel.quiet := false;
969 Print_Mode.with_modes modes (Toplevel.print_state true) state))));
972 Outer_Syntax.improper_command "disable_pr" "disable printing of toplevel state" Keyword.control
973 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (fn () => Toplevel.quiet := true)));
976 Outer_Syntax.improper_command "enable_pr" "enable printing of toplevel state" Keyword.control
977 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (fn () => Toplevel.quiet := false)));
980 Outer_Syntax.improper_command "commit" "commit current session to ML database" Keyword.control
981 (Parse.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
984 Outer_Syntax.improper_command "quit" "quit Isabelle" Keyword.control
985 (Parse.opt_unit >> (Toplevel.no_timing oo K (Toplevel.imperative quit)));
988 Outer_Syntax.improper_command "exit" "exit Isar loop" Keyword.control
990 (Toplevel.no_timing o Toplevel.keep (fn state =>
991 (Context.set_thread_data (try Toplevel.generic_theory_of state);
992 raise Runtime.TERMINATE))));