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 NONE name
35 Thy_Info.toplevel_begin_theory master name imports (map (apfst Path.explode) uses))));
38 Outer_Syntax.command "end" "end (local) theory" (Keyword.tag_theory Keyword.thy_end)
40 (Toplevel.exit o Toplevel.end_local_theory o Toplevel.end_proof (K Proof.end_notepad)));
44 (** markup commands **)
46 val _ = Outer_Syntax.markup_command Thy_Output.Markup "header" "theory header" Keyword.diag
47 (Parse.doc_source >> Isar_Cmd.header_markup);
49 val _ = Outer_Syntax.markup_command Thy_Output.Markup "chapter" "chapter heading"
50 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
52 val _ = Outer_Syntax.markup_command Thy_Output.Markup "section" "section heading"
53 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
55 val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsection" "subsection heading"
56 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
59 Outer_Syntax.markup_command Thy_Output.Markup "subsubsection" "subsubsection heading"
60 Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
62 val _ = Outer_Syntax.markup_command Thy_Output.MarkupEnv "text" "formal comment (theory)"
63 Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
65 val _ = Outer_Syntax.markup_command Thy_Output.Verbatim "text_raw" "raw document preparation text"
66 Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
68 val _ = Outer_Syntax.markup_command Thy_Output.Markup "sect" "formal comment (proof)"
69 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
71 val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsect" "formal comment (proof)"
72 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
74 val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsubsect" "formal comment (proof)"
75 (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
77 val _ = Outer_Syntax.markup_command Thy_Output.MarkupEnv "txt" "formal comment (proof)"
78 (Keyword.tag_proof Keyword.prf_decl) (Parse.doc_source >> Isar_Cmd.proof_markup);
80 val _ = Outer_Syntax.markup_command Thy_Output.Verbatim "txt_raw"
81 "raw document preparation text (proof)" (Keyword.tag_proof Keyword.prf_decl)
82 (Parse.doc_source >> Isar_Cmd.proof_markup);
86 (** theory commands **)
88 (* classes and sorts *)
91 Outer_Syntax.command "classes" "declare type classes" Keyword.thy_decl
92 (Scan.repeat1 (Parse.binding -- Scan.optional ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |--
93 Parse.!!! (Parse.list1 Parse.xname)) [])
94 >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
97 Outer_Syntax.command "classrel" "state inclusion of type classes (axiomatic!)" Keyword.thy_decl
98 (Parse.and_list1 (Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<")
99 |-- Parse.!!! Parse.xname))
100 >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
103 Outer_Syntax.local_theory "default_sort" "declare default sort for explicit type variables"
105 (Parse.sort >> (fn s => fn lthy => Local_Theory.set_defsort (Syntax.read_sort lthy s) lthy));
111 Outer_Syntax.local_theory "typedecl" "type declaration" Keyword.thy_decl
112 (Parse.type_args -- Parse.binding -- Parse.opt_mixfix
113 >> (fn ((args, a), mx) => Typedecl.typedecl (a, map (rpair dummyS) args, mx) #> snd));
116 Parse.type_args -- Parse.binding --
117 (Parse.$$$ "=" |-- Parse.!!! (Parse.typ -- Parse.opt_mixfix'));
120 Outer_Syntax.local_theory "types" "declare type abbreviations" Keyword.thy_decl
121 (Scan.repeat1 type_abbrev >> (fn specs => fn lthy =>
122 (legacy_feature "Old 'types' commands -- use 'type_synonym' instead";
123 fold (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs) specs lthy)));
126 Outer_Syntax.local_theory "type_synonym" "declare type abbreviation" Keyword.thy_decl
127 (type_abbrev >> (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs));
130 Outer_Syntax.command "nonterminal"
131 "declare syntactic type constructors (grammar nonterminal symbols)" Keyword.thy_decl
132 (Parse.and_list1 Parse.binding >> (Toplevel.theory o Sign.add_nonterminals));
135 Outer_Syntax.command "arities" "state type arities (axiomatic!)" Keyword.thy_decl
136 (Scan.repeat1 Parse.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
139 (* consts and syntax *)
142 Outer_Syntax.command "judgment" "declare object-logic judgment" Keyword.thy_decl
143 (Parse.const_binding >> (Toplevel.theory o Object_Logic.add_judgment_cmd));
146 Outer_Syntax.command "consts" "declare constants" Keyword.thy_decl
147 (Scan.repeat1 Parse.const_binding >> (Toplevel.theory o Sign.add_consts));
149 val opt_overloaded = Parse.opt_keyword "overloaded";
152 Outer_Syntax.command "finalconsts" "declare constants as final" Keyword.thy_decl
153 (opt_overloaded -- Scan.repeat1 Parse.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
156 (Parse.$$$ "output" >> K ("", false)) ||
157 Parse.name -- Scan.optional (Parse.$$$ "output" >> K false) true;
160 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (mode_spec --| Parse.$$$ ")")) Syntax.mode_default;
163 Outer_Syntax.command "syntax" "declare syntactic constants" Keyword.thy_decl
164 (opt_mode -- Scan.repeat1 Parse.const >> (Toplevel.theory o uncurry Sign.add_modesyntax));
167 Outer_Syntax.command "no_syntax" "delete syntax declarations" Keyword.thy_decl
168 (opt_mode -- Scan.repeat1 Parse.const >> (Toplevel.theory o uncurry Sign.del_modesyntax));
174 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Parse.xname --| Parse.$$$ ")")) "logic"
177 fun trans_arrow toks =
178 ((Parse.$$$ "\\<rightharpoonup>" || Parse.$$$ "=>") >> K Syntax.Parse_Rule ||
179 (Parse.$$$ "\\<leftharpoondown>" || Parse.$$$ "<=") >> K Syntax.Print_Rule ||
180 (Parse.$$$ "\\<rightleftharpoons>" || Parse.$$$ "==") >> K Syntax.Parse_Print_Rule) toks;
183 trans_pat -- Parse.!!! (trans_arrow -- trans_pat)
184 >> (fn (left, (arr, right)) => arr (left, right));
187 Outer_Syntax.command "translations" "declare syntax translation rules" Keyword.thy_decl
188 (Scan.repeat1 trans_line >> (Toplevel.theory o Isar_Cmd.translations));
191 Outer_Syntax.command "no_translations" "remove syntax translation rules" Keyword.thy_decl
192 (Scan.repeat1 trans_line >> (Toplevel.theory o Isar_Cmd.no_translations));
195 (* axioms and definitions *)
198 Outer_Syntax.command "axioms" "state arbitrary propositions (axiomatic!)" Keyword.thy_decl
199 (Scan.repeat1 Parse_Spec.spec >>
200 (fn spec => Toplevel.theory (fn thy =>
201 (legacy_feature "Old 'axioms' command -- use 'axiomatization' instead";
202 Isar_Cmd.add_axioms spec thy))));
204 val opt_unchecked_overloaded =
205 Scan.optional (Parse.$$$ "(" |-- Parse.!!!
206 (((Parse.$$$ "unchecked" >> K true) -- Scan.optional (Parse.$$$ "overloaded" >> K true) false ||
207 Parse.$$$ "overloaded" >> K (false, true)) --| Parse.$$$ ")")) (false, false);
210 Outer_Syntax.command "defs" "define constants" Keyword.thy_decl
211 (opt_unchecked_overloaded --
212 Scan.repeat1 (Parse_Spec.thm_name ":" -- Parse.prop >> (fn ((x, y), z) => ((x, z), y)))
213 >> (Toplevel.theory o Isar_Cmd.add_defs));
216 (* constant definitions and abbreviations *)
219 Outer_Syntax.local_theory "definition" "constant definition" Keyword.thy_decl
220 (Parse_Spec.constdef >> (fn args => #2 o Specification.definition_cmd args));
223 Outer_Syntax.local_theory "abbreviation" "constant abbreviation" Keyword.thy_decl
224 (opt_mode -- (Scan.option Parse_Spec.constdecl -- Parse.prop)
225 >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
228 Outer_Syntax.local_theory "type_notation" "add concrete syntax for type constructors"
230 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse.mixfix)
231 >> (fn (mode, args) => Specification.type_notation_cmd true mode args));
234 Outer_Syntax.local_theory "no_type_notation" "delete concrete syntax for type constructors"
236 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse.mixfix)
237 >> (fn (mode, args) => Specification.type_notation_cmd false mode args));
240 Outer_Syntax.local_theory "notation" "add concrete syntax for constants / fixed variables"
242 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
243 >> (fn (mode, args) => Specification.notation_cmd true mode args));
246 Outer_Syntax.local_theory "no_notation" "delete concrete syntax for constants / fixed variables"
248 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
249 >> (fn (mode, args) => Specification.notation_cmd false mode args));
252 (* constant specifications *)
255 Outer_Syntax.command "axiomatization" "axiomatic constant specification" Keyword.thy_decl
256 (Scan.optional Parse.fixes [] --
257 Scan.optional (Parse.where_ |-- Parse.!!! (Parse.and_list1 Parse_Spec.specs)) []
258 >> (fn (x, y) => Toplevel.theory (#2 o Specification.axiomatization_cmd x y)));
264 Parse_Spec.name_facts >> (fn args => #2 o Specification.theorems_cmd kind args);
267 Outer_Syntax.local_theory "theorems" "define theorems" Keyword.thy_decl (theorems Thm.theoremK);
270 Outer_Syntax.local_theory "lemmas" "define lemmas" Keyword.thy_decl (theorems Thm.lemmaK);
273 Outer_Syntax.local_theory "declare" "declare theorems" Keyword.thy_decl
274 (Parse.and_list1 Parse_Spec.xthms1
275 >> (fn args => #2 o Specification.theorems_cmd "" [(Attrib.empty_binding, flat args)]));
278 (* name space entry path *)
280 fun hide_names name hide what =
281 Outer_Syntax.command name ("hide " ^ what ^ " from name space") Keyword.thy_decl
282 ((Parse.opt_keyword "open" >> not) -- Scan.repeat1 Parse.xname >>
283 (Toplevel.theory o uncurry hide));
285 val _ = hide_names "hide_class" Isar_Cmd.hide_class "classes";
286 val _ = hide_names "hide_type" Isar_Cmd.hide_type "types";
287 val _ = hide_names "hide_const" Isar_Cmd.hide_const "constants";
288 val _ = hide_names "hide_fact" Isar_Cmd.hide_fact "facts";
294 Outer_Syntax.command "use" "ML text from file" (Keyword.tag_ml Keyword.thy_decl)
295 (Parse.path >> (fn path => Toplevel.generic_theory (Thy_Load.exec_ml path)));
298 Outer_Syntax.command "ML" "ML text within theory or local theory"
299 (Keyword.tag_ml Keyword.thy_decl)
300 (Parse.ML_source >> (fn (txt, pos) =>
301 Toplevel.generic_theory
302 (ML_Context.exec (fn () => ML_Context.eval_text true pos txt) #>
303 Local_Theory.propagate_ml_env)));
306 Outer_Syntax.command "ML_prf" "ML text within proof" (Keyword.tag_proof Keyword.prf_decl)
307 (Parse.ML_source >> (fn (txt, pos) =>
308 Toplevel.proof (Proof.map_context (Context.proof_map
309 (ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> Proof.propagate_ml_env)));
312 Outer_Syntax.command "ML_val" "diagnostic ML text" (Keyword.tag_ml Keyword.diag)
313 (Parse.ML_source >> Isar_Cmd.ml_diag true);
316 Outer_Syntax.command "ML_command" "diagnostic ML text (silent)" (Keyword.tag_ml Keyword.diag)
317 (Parse.ML_source >> (Toplevel.no_timing oo Isar_Cmd.ml_diag false));
320 Outer_Syntax.command "setup" "ML theory setup" (Keyword.tag_ml Keyword.thy_decl)
321 (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.global_setup));
324 Outer_Syntax.local_theory "local_setup" "ML local theory setup" (Keyword.tag_ml Keyword.thy_decl)
325 (Parse.ML_source >> Isar_Cmd.local_setup);
328 Outer_Syntax.command "attribute_setup" "define attribute in ML" (Keyword.tag_ml Keyword.thy_decl)
329 (Parse.position Parse.name -- Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Parse.text)
330 >> (fn (name, (txt, cmt)) => Toplevel.theory (Attrib.attribute_setup name txt cmt)));
333 Outer_Syntax.command "method_setup" "define proof method in ML" (Keyword.tag_ml Keyword.thy_decl)
334 (Parse.position Parse.name -- Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Parse.text)
335 >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
338 Outer_Syntax.local_theory "declaration" "generic ML declaration"
339 (Keyword.tag_ml Keyword.thy_decl)
340 (Parse.opt_keyword "pervasive" -- Parse.ML_source
341 >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = false, pervasive = pervasive} txt));
344 Outer_Syntax.local_theory "syntax_declaration" "generic ML declaration"
345 (Keyword.tag_ml Keyword.thy_decl)
346 (Parse.opt_keyword "pervasive" -- Parse.ML_source
347 >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = true, pervasive = pervasive} txt));
350 Outer_Syntax.local_theory "simproc_setup" "define simproc in ML" (Keyword.tag_ml Keyword.thy_decl)
352 (Parse.$$$ "(" |-- Parse.enum1 "|" Parse.term --| Parse.$$$ ")" --| Parse.$$$ "=") --
353 Parse.ML_source -- Scan.optional (Parse.$$$ "identifier" |-- Scan.repeat1 Parse.xname) []
354 >> (fn (((a, b), c), d) => Isar_Cmd.simproc_setup a b c d));
357 (* translation functions *)
359 val trfun = Parse.opt_keyword "advanced" -- Parse.ML_source;
362 Outer_Syntax.command "parse_ast_translation" "install parse ast translation functions"
363 (Keyword.tag_ml Keyword.thy_decl)
364 (trfun >> (Toplevel.theory o Isar_Cmd.parse_ast_translation));
367 Outer_Syntax.command "parse_translation" "install parse translation functions"
368 (Keyword.tag_ml Keyword.thy_decl)
369 (trfun >> (Toplevel.theory o Isar_Cmd.parse_translation));
372 Outer_Syntax.command "print_translation" "install print translation functions"
373 (Keyword.tag_ml Keyword.thy_decl)
374 (trfun >> (Toplevel.theory o Isar_Cmd.print_translation));
377 Outer_Syntax.command "typed_print_translation" "install typed print translation functions"
378 (Keyword.tag_ml Keyword.thy_decl)
379 (trfun >> (Toplevel.theory o Isar_Cmd.typed_print_translation));
382 Outer_Syntax.command "print_ast_translation" "install print ast translation functions"
383 (Keyword.tag_ml Keyword.thy_decl)
384 (trfun >> (Toplevel.theory o Isar_Cmd.print_ast_translation));
390 Outer_Syntax.command "oracle" "declare oracle" (Keyword.tag_ml Keyword.thy_decl)
391 (Parse.position Parse.name -- (Parse.$$$ "=" |-- Parse.ML_source) >>
392 (fn (x, y) => Toplevel.theory (Isar_Cmd.oracle x y)));
398 Outer_Syntax.command "context" "enter local theory context" Keyword.thy_decl
399 (Parse.name --| Parse.begin >> (fn name =>
400 Toplevel.print o Toplevel.begin_local_theory true (Named_Target.context_cmd name)));
406 Parse_Spec.locale_expression false --
407 Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
408 Scan.repeat1 Parse_Spec.context_element >> pair ([], []);
411 Outer_Syntax.command "locale" "define named proof context" Keyword.thy_decl
413 Scan.optional (Parse.$$$ "=" |-- Parse.!!! locale_val) (([], []), []) -- Parse.opt_begin
414 >> (fn ((name, (expr, elems)), begin) =>
415 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
416 (Expression.add_locale_cmd I name Binding.empty expr elems #> snd)));
418 fun parse_interpretation_arguments mandatory =
419 Parse.!!! (Parse_Spec.locale_expression mandatory) --
421 (Parse.where_ |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) [];
424 Outer_Syntax.command "sublocale"
425 "prove sublocale relation between a locale and a locale expression" Keyword.thy_goal
426 (Parse.xname --| (Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") --
427 parse_interpretation_arguments false
428 >> (fn (loc, (expr, equations)) =>
429 Toplevel.print o Toplevel.theory_to_proof (Expression.sublocale_cmd I loc expr equations)));
432 Outer_Syntax.command "interpretation"
433 "prove interpretation of locale expression in theory" Keyword.thy_goal
434 (parse_interpretation_arguments true
435 >> (fn (expr, equations) => Toplevel.print o
436 Toplevel.theory_to_proof (Expression.interpretation_cmd expr equations)));
439 Outer_Syntax.command "interpret"
440 "prove interpretation of locale expression in proof context"
441 (Keyword.tag_proof Keyword.prf_goal)
442 (parse_interpretation_arguments true
443 >> (fn (expr, equations) => Toplevel.print o
444 Toplevel.proof' (Expression.interpret_cmd expr equations)));
450 Parse_Spec.class_expr --
451 Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
452 Scan.repeat1 Parse_Spec.context_element >> pair [];
455 Outer_Syntax.command "class" "define type class" Keyword.thy_decl
456 (Parse.binding -- Scan.optional (Parse.$$$ "=" |-- class_val) ([], []) -- Parse.opt_begin
457 >> (fn ((name, (supclasses, elems)), begin) =>
458 (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
459 (Class_Declaration.class_cmd I name supclasses elems #> snd)));
462 Outer_Syntax.local_theory_to_proof "subclass" "prove a subclass relation" Keyword.thy_goal
463 (Parse.xname >> Class_Declaration.subclass_cmd I);
466 Outer_Syntax.command "instantiation" "instantiate and prove type arity" Keyword.thy_decl
467 (Parse.multi_arity --| Parse.begin
468 >> (fn arities => Toplevel.print o
469 Toplevel.begin_local_theory true (Class.instantiation_cmd arities)));
472 Outer_Syntax.command "instance" "prove type arity or subclass relation" Keyword.thy_goal
473 ((Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |-- Parse.!!! Parse.xname)
474 >> Class.classrel_cmd ||
475 Parse.multi_arity >> Class.instance_arity_cmd)
476 >> (Toplevel.print oo Toplevel.theory_to_proof) ||
478 (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
481 (* arbitrary overloading *)
484 Outer_Syntax.command "overloading" "overloaded definitions" Keyword.thy_decl
485 (Scan.repeat1 (Parse.name --| (Parse.$$$ "\\<equiv>" || Parse.$$$ "==") -- Parse.term --
486 Scan.optional (Parse.$$$ "(" |-- (Parse.$$$ "unchecked" >> K false) --| Parse.$$$ ")") true
487 >> Parse.triple1) --| Parse.begin
488 >> (fn operations => Toplevel.print o
489 Toplevel.begin_local_theory true (Overloading.overloading_cmd operations)));
492 (* code generation *)
495 Outer_Syntax.command "code_datatype" "define set of code datatype constructors" Keyword.thy_decl
496 (Scan.repeat1 Parse.term >> (Toplevel.theory o Code.add_datatype_cmd));
500 (** proof commands **)
504 fun gen_theorem schematic kind =
505 Outer_Syntax.local_theory_to_proof'
506 (if schematic then "schematic_" ^ kind else kind)
507 ("state " ^ (if schematic then "schematic " ^ kind else kind))
508 (if schematic then Keyword.thy_schematic_goal else Keyword.thy_goal)
509 (Scan.optional (Parse_Spec.opt_thm_name ":" --|
510 Scan.ahead (Parse_Spec.locale_keyword || Parse_Spec.statement_keyword)) Attrib.empty_binding --
511 Parse_Spec.general_statement >> (fn (a, (elems, concl)) =>
512 ((if schematic then Specification.schematic_theorem_cmd else Specification.theorem_cmd)
513 kind NONE (K I) a elems concl)));
515 val _ = gen_theorem false Thm.theoremK;
516 val _ = gen_theorem false Thm.lemmaK;
517 val _ = gen_theorem false Thm.corollaryK;
518 val _ = gen_theorem true Thm.theoremK;
519 val _ = gen_theorem true Thm.lemmaK;
520 val _ = gen_theorem true Thm.corollaryK;
523 Outer_Syntax.local_theory_to_proof "notepad"
524 "Isar proof state as formal notepad, without any result" Keyword.thy_decl
525 (Parse.begin >> K Proof.begin_notepad);
528 Outer_Syntax.command "have" "state local goal"
529 (Keyword.tag_proof Keyword.prf_goal)
530 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.have));
533 Outer_Syntax.command "hence" "abbreviates \"then have\""
534 (Keyword.tag_proof Keyword.prf_goal)
535 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.hence));
538 Outer_Syntax.command "show" "state local goal, solving current obligation"
539 (Keyword.tag_proof Keyword.prf_asm_goal)
540 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.show));
543 Outer_Syntax.command "thus" "abbreviates \"then show\""
544 (Keyword.tag_proof Keyword.prf_asm_goal)
545 (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.thus));
550 val facts = Parse.and_list1 Parse_Spec.xthms1;
553 Outer_Syntax.command "then" "forward chaining"
554 (Keyword.tag_proof Keyword.prf_chain)
555 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
558 Outer_Syntax.command "from" "forward chaining from given facts"
559 (Keyword.tag_proof Keyword.prf_chain)
560 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss_cmd)));
563 Outer_Syntax.command "with" "forward chaining from given and current facts"
564 (Keyword.tag_proof Keyword.prf_chain)
565 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss_cmd)));
568 Outer_Syntax.command "note" "define facts"
569 (Keyword.tag_proof Keyword.prf_decl)
570 (Parse_Spec.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss_cmd)));
573 Outer_Syntax.command "using" "augment goal facts"
574 (Keyword.tag_proof Keyword.prf_decl)
575 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using_cmd)));
578 Outer_Syntax.command "unfolding" "unfold definitions in goal and facts"
579 (Keyword.tag_proof Keyword.prf_decl)
580 (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding_cmd)));
586 Outer_Syntax.command "fix" "fix local variables (Skolem constants)"
587 (Keyword.tag_proof Keyword.prf_asm)
588 (Parse.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix_cmd)));
591 Outer_Syntax.command "assume" "assume propositions"
592 (Keyword.tag_proof Keyword.prf_asm)
593 (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume_cmd)));
596 Outer_Syntax.command "presume" "assume propositions, to be established later"
597 (Keyword.tag_proof Keyword.prf_asm)
598 (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume_cmd)));
601 Outer_Syntax.command "def" "local definition"
602 (Keyword.tag_proof Keyword.prf_asm)
604 (Parse_Spec.opt_thm_name ":" --
605 ((Parse.binding -- Parse.opt_mixfix) --
606 ((Parse.$$$ "\\<equiv>" || Parse.$$$ "==") |-- Parse.!!! Parse.termp)))
607 >> (Toplevel.print oo (Toplevel.proof o Proof.def_cmd)));
610 Outer_Syntax.command "obtain" "generalized existence"
611 (Keyword.tag_proof Keyword.prf_asm_goal)
612 (Parse.parname -- Scan.optional (Parse.fixes --| Parse.where_) [] -- Parse_Spec.statement
613 >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain_cmd x y z)));
616 Outer_Syntax.command "guess" "wild guessing (unstructured)"
617 (Keyword.tag_proof Keyword.prf_asm_goal)
618 (Scan.optional Parse.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess_cmd)));
621 Outer_Syntax.command "let" "bind text variables"
622 (Keyword.tag_proof Keyword.prf_decl)
623 (Parse.and_list1 (Parse.and_list1 Parse.term -- (Parse.$$$ "=" |-- Parse.term))
624 >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind_cmd)));
627 Outer_Syntax.command "write" "add concrete syntax for constants / fixed variables"
628 (Keyword.tag_proof Keyword.prf_decl)
629 (opt_mode -- Parse.and_list1 (Parse.xname -- Parse_Spec.locale_mixfix)
630 >> (fn (mode, args) => Toplevel.print o Toplevel.proof (Proof.write_cmd mode args)));
634 Parse.!!! (Parse.xname -- Scan.repeat1 (Parse.maybe Parse.name) --| Parse.$$$ ")") ||
635 Parse.xname >> rpair []) -- Parse_Spec.opt_attribs >> Parse.triple1;
638 Outer_Syntax.command "case" "invoke local context"
639 (Keyword.tag_proof Keyword.prf_asm)
640 (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case_cmd)));
643 (* proof structure *)
646 Outer_Syntax.command "{" "begin explicit proof block"
647 (Keyword.tag_proof Keyword.prf_open)
648 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
651 Outer_Syntax.command "}" "end explicit proof block"
652 (Keyword.tag_proof Keyword.prf_close)
653 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
656 Outer_Syntax.command "next" "enter next proof block"
657 (Keyword.tag_proof Keyword.prf_block)
658 (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
664 Outer_Syntax.command "qed" "conclude (sub-)proof"
665 (Keyword.tag_proof Keyword.qed_block)
666 (Scan.option Method.parse >> Isar_Cmd.qed);
669 Outer_Syntax.command "by" "terminal backward proof"
670 (Keyword.tag_proof Keyword.qed)
671 (Method.parse -- Scan.option Method.parse >> Isar_Cmd.terminal_proof);
674 Outer_Syntax.command ".." "default proof"
675 (Keyword.tag_proof Keyword.qed)
676 (Scan.succeed Isar_Cmd.default_proof);
679 Outer_Syntax.command "." "immediate proof"
680 (Keyword.tag_proof Keyword.qed)
681 (Scan.succeed Isar_Cmd.immediate_proof);
684 Outer_Syntax.command "done" "done proof"
685 (Keyword.tag_proof Keyword.qed)
686 (Scan.succeed Isar_Cmd.done_proof);
689 Outer_Syntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
690 (Keyword.tag_proof Keyword.qed)
691 (Scan.succeed Isar_Cmd.skip_proof);
694 Outer_Syntax.command "oops" "forget proof"
695 (Keyword.tag_proof Keyword.qed_global)
696 (Scan.succeed Toplevel.forget_proof);
702 Outer_Syntax.command "defer" "shuffle internal proof state"
703 (Keyword.tag_proof Keyword.prf_script)
704 (Scan.option Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
707 Outer_Syntax.command "prefer" "shuffle internal proof state"
708 (Keyword.tag_proof Keyword.prf_script)
709 (Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
712 Outer_Syntax.command "apply" "initial refinement step (unstructured)"
713 (Keyword.tag_proof Keyword.prf_script)
714 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
717 Outer_Syntax.command "apply_end" "terminal refinement (unstructured)"
718 (Keyword.tag_proof Keyword.prf_script)
719 (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
722 Outer_Syntax.command "proof" "backward proof"
723 (Keyword.tag_proof Keyword.prf_block)
724 (Scan.option Method.parse >> (fn m => Toplevel.print o
725 Toplevel.actual_proof (Proof_Node.applys (Proof.proof m)) o
726 Toplevel.skip_proof (fn i => i + 1)));
729 (* calculational proof commands *)
732 Scan.option (Parse.$$$ "(" |-- Parse.!!! ((Parse_Spec.xthms1 --| Parse.$$$ ")")));
735 Outer_Syntax.command "also" "combine calculation and current facts"
736 (Keyword.tag_proof Keyword.prf_decl)
737 (calc_args >> (Toplevel.proofs' o Calculation.also_cmd));
740 Outer_Syntax.command "finally" "combine calculation and current facts, exhibit result"
741 (Keyword.tag_proof Keyword.prf_chain)
742 (calc_args >> (Toplevel.proofs' o Calculation.finally_cmd));
745 Outer_Syntax.command "moreover" "augment calculation by current facts"
746 (Keyword.tag_proof Keyword.prf_decl)
747 (Scan.succeed (Toplevel.proof' Calculation.moreover));
750 Outer_Syntax.command "ultimately" "augment calculation by current facts, exhibit result"
751 (Keyword.tag_proof Keyword.prf_chain)
752 (Scan.succeed (Toplevel.proof' Calculation.ultimately));
755 (* proof navigation *)
758 Outer_Syntax.command "back" "backtracking of proof command"
759 (Keyword.tag_proof Keyword.prf_script)
760 (Scan.succeed (Toplevel.print o Toplevel.actual_proof Proof_Node.back o Toplevel.skip_proof I));
763 (* nested commands *)
766 Scan.optional Parse_Value.properties [] -- Parse.position Parse.string
767 >> (fn (props, (str, pos)) =>
768 (Position.of_properties (Position.default_properties pos props), str));
771 Outer_Syntax.improper_command "Isabelle.command" "nested Isabelle command" Keyword.control
772 (props_text :|-- (fn (pos, str) =>
773 (case Outer_Syntax.parse pos str of
774 [tr] => Scan.succeed (K tr)
775 | _ => Scan.fail_with (K "exactly one command expected"))
776 handle ERROR msg => Scan.fail_with (K msg)));
780 (** diagnostic commands (for interactive mode only) **)
783 Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.xname --| Parse.$$$ ")")) [];
785 val opt_bang = Scan.optional (Parse.$$$ "!" >> K true) false;
788 Outer_Syntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
789 Keyword.diag (Parse.nat >>
790 (fn n => Toplevel.no_timing o Toplevel.imperative (fn () => Pretty.margin_default := n)));
793 Outer_Syntax.improper_command "help" "print outer syntax commands" Keyword.diag
794 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
797 Outer_Syntax.improper_command "print_commands" "print outer syntax commands" Keyword.diag
798 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
801 Outer_Syntax.improper_command "print_configs" "print configuration options" Keyword.diag
802 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_configs));
805 Outer_Syntax.improper_command "print_context" "print theory context name" Keyword.diag
806 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_context));
809 Outer_Syntax.improper_command "print_theory" "print logical theory contents (verbose!)"
810 Keyword.diag (opt_bang >> (Toplevel.no_timing oo Isar_Cmd.print_theory));
813 Outer_Syntax.improper_command "print_syntax" "print inner syntax of context (verbose!)"
814 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_syntax));
817 Outer_Syntax.improper_command "print_abbrevs" "print constant abbreviation of context"
818 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_abbrevs));
821 Outer_Syntax.improper_command "print_theorems"
822 "print theorems of local theory or proof context" Keyword.diag
823 (opt_bang >> (Toplevel.no_timing oo Isar_Cmd.print_theorems));
826 Outer_Syntax.improper_command "print_locales" "print locales of this theory" Keyword.diag
827 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_locales));
830 Outer_Syntax.improper_command "print_classes" "print classes of this theory" Keyword.diag
831 (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
832 o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
835 Outer_Syntax.improper_command "print_locale" "print locale of this theory" Keyword.diag
836 (opt_bang -- Parse.xname >> (Toplevel.no_timing oo Isar_Cmd.print_locale));
839 Outer_Syntax.improper_command "print_interps"
840 "print interpretations of locale for this theory or proof context" Keyword.diag
841 (Parse.xname >> (Toplevel.no_timing oo Isar_Cmd.print_registrations));
844 Outer_Syntax.improper_command "print_dependencies"
845 "print dependencies of locale expression" Keyword.diag
846 (opt_bang -- Parse_Spec.locale_expression true >>
847 (Toplevel.no_timing oo Isar_Cmd.print_dependencies));
850 Outer_Syntax.improper_command "print_attributes" "print attributes of this theory" Keyword.diag
851 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_attributes));
854 Outer_Syntax.improper_command "print_simpset" "print context of Simplifier" Keyword.diag
855 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_simpset));
858 Outer_Syntax.improper_command "print_rules" "print intro/elim rules" Keyword.diag
859 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_rules));
862 Outer_Syntax.improper_command "print_trans_rules" "print transitivity rules" Keyword.diag
863 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_trans_rules));
866 Outer_Syntax.improper_command "print_methods" "print methods of this theory" Keyword.diag
867 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_methods));
870 Outer_Syntax.improper_command "print_antiquotations" "print antiquotations (global)" Keyword.diag
871 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_antiquotations));
874 Outer_Syntax.improper_command "thy_deps" "visualize theory dependencies"
875 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.thy_deps));
878 Outer_Syntax.improper_command "class_deps" "visualize class dependencies"
879 Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.class_deps));
882 Outer_Syntax.improper_command "thm_deps" "visualize theorem dependencies"
883 Keyword.diag (Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.thm_deps));
886 Outer_Syntax.improper_command "print_binds" "print term bindings of proof context" Keyword.diag
887 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_binds));
890 Outer_Syntax.improper_command "print_facts" "print facts of proof context" Keyword.diag
891 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_facts));
894 Outer_Syntax.improper_command "print_cases" "print cases of proof context" Keyword.diag
895 (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_cases));
898 Outer_Syntax.improper_command "print_statement" "print theorems as long statements" Keyword.diag
899 (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_stmts));
902 Outer_Syntax.improper_command "thm" "print theorems" Keyword.diag
903 (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_thms));
906 Outer_Syntax.improper_command "prf" "print proof terms of theorems" Keyword.diag
907 (opt_modes -- Scan.option Parse_Spec.xthms1
908 >> (Toplevel.no_timing oo Isar_Cmd.print_prfs false));
911 Outer_Syntax.improper_command "full_prf" "print full proof terms of theorems" Keyword.diag
912 (opt_modes -- Scan.option Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_prfs true));
915 Outer_Syntax.improper_command "prop" "read and print proposition" Keyword.diag
916 (opt_modes -- Parse.term >> (Toplevel.no_timing oo Isar_Cmd.print_prop));
919 Outer_Syntax.improper_command "term" "read and print term" Keyword.diag
920 (opt_modes -- Parse.term >> (Toplevel.no_timing oo Isar_Cmd.print_term));
923 Outer_Syntax.improper_command "typ" "read and print type" Keyword.diag
924 (opt_modes -- Parse.typ >> (Toplevel.no_timing oo Isar_Cmd.print_type));
927 Outer_Syntax.improper_command "print_codesetup" "print code generator setup" Keyword.diag
929 (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
930 (Code.print_codesetup o Toplevel.theory_of)));
933 Outer_Syntax.improper_command "unused_thms" "find unused theorems" Keyword.diag
934 (Scan.option ((Scan.repeat1 (Scan.unless Parse.minus Parse.name) --| Parse.minus) --
935 Scan.option (Scan.repeat1 (Scan.unless Parse.minus Parse.name))) >>
936 (Toplevel.no_timing oo Isar_Cmd.unused_thms));
940 (** system commands (for interactive mode only) **)
943 Outer_Syntax.improper_command "cd" "change current working directory" Keyword.control
944 (Parse.path >> (fn path => Toplevel.no_timing o Toplevel.imperative (fn () => File.cd path)));
947 Outer_Syntax.improper_command "pwd" "print current working directory" Keyword.diag
948 (Scan.succeed (Toplevel.no_timing o
949 Toplevel.imperative (fn () => writeln (Path.print (File.pwd ())))));
952 Outer_Syntax.improper_command "use_thy" "use theory file" Keyword.control
953 (Parse.name >> (fn name =>
954 Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.use_thy name)));
957 Outer_Syntax.improper_command "remove_thy" "remove theory from loader database" Keyword.control
958 (Parse.name >> (fn name =>
959 Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.remove_thy name)));
962 Outer_Syntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
963 Keyword.control (Parse.name >> (fn name =>
964 Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.kill_thy name)));
967 Outer_Syntax.improper_command "display_drafts" "display raw source files with symbols"
968 Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo Isar_Cmd.display_drafts));
971 Outer_Syntax.improper_command "print_drafts" "print raw source files with symbols"
972 Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo Isar_Cmd.print_drafts));
974 val _ = (* FIXME tty only *)
975 Outer_Syntax.improper_command "pr" "print current proof state (if present)" Keyword.diag
976 (opt_modes -- Scan.option Parse.nat >> (fn (modes, limit) =>
977 Toplevel.no_timing o Toplevel.keep (fn state =>
978 (case limit of NONE => () | SOME n => Goal_Display.goals_limit_default := n;
979 Toplevel.quiet := false;
980 Print_Mode.with_modes modes (Toplevel.print_state true) state))));
983 Outer_Syntax.improper_command "disable_pr" "disable printing of toplevel state" Keyword.control
984 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (fn () => Toplevel.quiet := true)));
987 Outer_Syntax.improper_command "enable_pr" "enable printing of toplevel state" Keyword.control
988 (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (fn () => Toplevel.quiet := false)));
991 Outer_Syntax.improper_command "commit" "commit current session to ML database" Keyword.control
992 (Parse.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
995 Outer_Syntax.improper_command "quit" "quit Isabelle" Keyword.control
996 (Parse.opt_unit >> (Toplevel.no_timing oo K (Toplevel.imperative quit)));
999 Outer_Syntax.improper_command "exit" "exit Isar loop" Keyword.control
1001 (Toplevel.no_timing o Toplevel.keep (fn state =>
1002 (Context.set_thread_data (try Toplevel.generic_theory_of state);
1003 raise Runtime.TERMINATE))));