src/Pure/Isar/isar_syn.ML
author wenzelm
Wed Jun 25 17:38:32 2008 +0200 (2008-06-25 ago)
changeset 27353 71c4dd53d4cb
parent 27200 00b7b55b61bd
child 27378 0968c0d0b969
permissions -rw-r--r--
moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
     1 (*  Title:      Pure/Isar/isar_syn.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Isar/Pure outer syntax.
     6 *)
     7 
     8 structure IsarSyn: sig end =
     9 struct
    10 
    11 structure P = OuterParse and K = OuterKeyword;
    12 
    13 
    14 (** keywords **)
    15 
    16 (*keep keywords consistent with the parsers, otherwise be prepared for
    17   unexpected errors*)
    18 
    19 val _ = List.app OuterKeyword.keyword
    20  ["!!", "!", "%", "(", ")", "+", ",", "--", ":", "::", ";", "<", "<=",
    21   "=", "==", "=>", "?", "[", "\\<equiv>", "\\<leftharpoondown>",
    22   "\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>", "]",
    23   "advanced", "and", "assumes", "attach", "begin", "binder",
    24   "constrains", "defines", "fixes", "for", "identifier", "if",
    25   "imports", "in", "includes", "infix", "infixl", "infixr", "is",
    26   "notes", "obtains", "open", "output", "overloaded", "shows",
    27   "structure", "unchecked", "uses", "where", "|"];
    28 
    29 
    30 (** init and exit **)
    31 
    32 val _ =
    33   OuterSyntax.command "theory" "begin theory" (K.tag_theory K.thy_begin)
    34     (ThyHeader.args >> (Toplevel.print oo IsarCmd.theory));
    35 
    36 val _ =
    37   OuterSyntax.command "end" "end (local) theory" (K.tag_theory K.thy_end)
    38     (Scan.succeed (Toplevel.exit o Toplevel.end_local_theory));
    39 
    40 
    41 (** markup commands **)
    42 
    43 val _ = OuterSyntax.markup_command ThyOutput.Markup "header" "theory header" K.diag
    44   (P.position P.text >> IsarCmd.add_header);
    45 
    46 val _ = OuterSyntax.markup_command ThyOutput.Markup "chapter" "chapter heading"
    47   K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_chapter);
    48 
    49 val _ = OuterSyntax.markup_command ThyOutput.Markup "section" "section heading"
    50   K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_section);
    51 
    52 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsection" "subsection heading"
    53   K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_subsection);
    54 
    55 val _ =
    56   OuterSyntax.markup_command ThyOutput.Markup "subsubsection" "subsubsection heading"
    57   K.thy_heading (P.opt_target -- P.position P.text >> IsarCmd.add_subsubsection);
    58 
    59 val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "text" "formal comment (theory)"
    60   K.thy_decl (P.opt_target -- P.position P.text >> IsarCmd.add_text);
    61 
    62 val _ = OuterSyntax.markup_command ThyOutput.Verbatim "text_raw"
    63   "raw document preparation text"
    64   K.thy_decl (P.position P.text >> IsarCmd.add_text_raw);
    65 
    66 val _ = OuterSyntax.markup_command ThyOutput.Markup "sect" "formal comment (proof)"
    67   (K.tag_proof K.prf_heading) (P.position P.text >> IsarCmd.add_sect);
    68 
    69 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsect" "formal comment (proof)"
    70   (K.tag_proof K.prf_heading) (P.position P.text >> IsarCmd.add_subsect);
    71 
    72 val _ = OuterSyntax.markup_command ThyOutput.Markup "subsubsect"
    73   "formal comment (proof)" (K.tag_proof K.prf_heading)
    74   (P.position P.text >> IsarCmd.add_subsubsect);
    75 
    76 val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "txt" "formal comment (proof)"
    77   (K.tag_proof K.prf_decl) (P.position P.text >> IsarCmd.add_txt);
    78 
    79 val _ = OuterSyntax.markup_command ThyOutput.Verbatim "txt_raw"
    80   "raw document preparation text (proof)" (K.tag_proof K.prf_decl)
    81   (P.position P.text >> IsarCmd.add_txt_raw);
    82 
    83 
    84 
    85 (** theory sections **)
    86 
    87 (* classes and sorts *)
    88 
    89 val _ =
    90   OuterSyntax.command "classes" "declare type classes" K.thy_decl
    91     (Scan.repeat1 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
    92         P.!!! (P.list1 P.xname)) []) >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
    93 
    94 val _ =
    95   OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
    96     (P.and_list1 (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname))
    97     >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
    98 
    99 val _ =
   100   OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
   101     (P.sort >> (Toplevel.theory o Sign.add_defsort));
   102 
   103 val _ =
   104   OuterSyntax.command "axclass" "define axiomatic type class" K.thy_decl
   105     (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
   106         P.!!! (P.list1 P.xname)) []
   107         -- Scan.repeat (SpecParse.thm_name ":" -- (P.prop >> single))
   108       >> (fn (x, y) => Toplevel.theory (snd o Class.axclass_cmd x y)));
   109 
   110 
   111 (* types *)
   112 
   113 val _ =
   114   OuterSyntax.command "typedecl" "type declaration" K.thy_decl
   115     (P.type_args -- P.name -- P.opt_infix >> (fn ((args, a), mx) =>
   116       Toplevel.theory (ObjectLogic.typedecl (a, args, mx) #> snd)));
   117 
   118 val _ =
   119   OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
   120     (Scan.repeat1
   121       (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix')))
   122       >> (Toplevel.theory o Sign.add_tyabbrs o
   123         map (fn ((args, a), (T, mx)) => (a, args, T, mx))));
   124 
   125 val _ =
   126   OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
   127     K.thy_decl (Scan.repeat1 P.name >> (Toplevel.theory o Sign.add_nonterminals));
   128 
   129 val _ =
   130   OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
   131     (Scan.repeat1 P.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
   132 
   133 
   134 (* consts and syntax *)
   135 
   136 val _ =
   137   OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
   138     (P.const >> (Toplevel.theory o ObjectLogic.add_judgment));
   139 
   140 val _ =
   141   OuterSyntax.command "consts" "declare constants" K.thy_decl
   142     (Scan.repeat1 P.const >> (Toplevel.theory o Sign.add_consts));
   143 
   144 val opt_overloaded = P.opt_keyword "overloaded";
   145 
   146 val _ =
   147   OuterSyntax.command "finalconsts" "declare constants as final" K.thy_decl
   148     (opt_overloaded -- Scan.repeat1 P.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
   149 
   150 val mode_spec =
   151   (P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true;
   152 
   153 val opt_mode =
   154   Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) Syntax.mode_default;
   155 
   156 val _ =
   157   OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
   158     (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Sign.add_modesyntax));
   159 
   160 val _ =
   161   OuterSyntax.command "no_syntax" "delete syntax declarations" K.thy_decl
   162     (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Sign.del_modesyntax));
   163 
   164 
   165 (* translations *)
   166 
   167 val trans_pat =
   168   Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
   169 
   170 fun trans_arrow toks =
   171   ((P.$$$ "\\<rightharpoonup>" || P.$$$ "=>") >> K Syntax.ParseRule ||
   172     (P.$$$ "\\<leftharpoondown>" || P.$$$ "<=") >> K Syntax.PrintRule ||
   173     (P.$$$ "\\<rightleftharpoons>" || P.$$$ "==") >> K Syntax.ParsePrintRule) toks;
   174 
   175 val trans_line =
   176   trans_pat -- P.!!! (trans_arrow -- trans_pat)
   177     >> (fn (left, (arr, right)) => arr (left, right));
   178 
   179 val _ =
   180   OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
   181     (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.add_trrules));
   182 
   183 val _ =
   184   OuterSyntax.command "no_translations" "remove syntax translation rules" K.thy_decl
   185     (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.del_trrules));
   186 
   187 
   188 (* axioms and definitions *)
   189 
   190 val _ =
   191   OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
   192     (Scan.repeat1 SpecParse.spec_name >> (Toplevel.theory o IsarCmd.add_axioms));
   193 
   194 val opt_unchecked_overloaded =
   195   Scan.optional (P.$$$ "(" |-- P.!!!
   196     (((P.$$$ "unchecked" >> K true) -- Scan.optional (P.$$$ "overloaded" >> K true) false ||
   197       P.$$$ "overloaded" >> K (false, true)) --| P.$$$ ")")) (false, false);
   198 
   199 val _ =
   200   OuterSyntax.command "defs" "define constants" K.thy_decl
   201     (opt_unchecked_overloaded -- Scan.repeat1 SpecParse.spec_name
   202       >> (Toplevel.theory o IsarCmd.add_defs));
   203 
   204 
   205 (* old constdefs *)
   206 
   207 val old_constdecl =
   208   P.name --| P.where_ >> (fn x => (x, NONE, NoSyn)) ||
   209   P.name -- (P.$$$ "::" |-- P.!!! P.typ >> SOME) -- P.opt_mixfix'
   210     --| Scan.option P.where_ >> P.triple1 ||
   211   P.name -- (P.mixfix >> pair NONE) --| Scan.option P.where_ >> P.triple2;
   212 
   213 val old_constdef = Scan.option old_constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
   214 
   215 val structs =
   216   Scan.optional ((P.$$$ "(" -- P.$$$ "structure") |-- P.!!! (P.simple_fixes --| P.$$$ ")")) [];
   217 
   218 val _ =
   219   OuterSyntax.command "constdefs" "old-style constant definition" K.thy_decl
   220     (structs -- Scan.repeat1 old_constdef >> (Toplevel.theory o Constdefs.add_constdefs));
   221 
   222 
   223 (* constant definitions and abbreviations *)
   224 
   225 val constdecl =
   226   P.name --
   227     (P.where_ >> K (NONE, NoSyn) ||
   228       P.$$$ "::" |-- P.!!! ((P.typ >> SOME) -- P.opt_mixfix' --| P.where_) ||
   229       Scan.ahead (P.$$$ "(") |-- P.!!! (P.mixfix' --| P.where_ >> pair NONE))
   230   >> P.triple2;
   231 
   232 val constdef = Scan.option constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
   233 
   234 val _ =
   235   OuterSyntax.local_theory "definition" "constant definition" K.thy_decl
   236     (constdef >> (fn args => #2 o Specification.definition_cmd args));
   237 
   238 val _ =
   239   OuterSyntax.local_theory "abbreviation" "constant abbreviation" K.thy_decl
   240     (opt_mode -- (Scan.option constdecl -- P.prop)
   241     >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
   242 
   243 val _ =
   244   OuterSyntax.local_theory "notation" "add notation for constants / fixed variables" K.thy_decl
   245     (opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
   246     >> (fn (mode, args) => Specification.notation_cmd true mode args));
   247 
   248 val _ =
   249   OuterSyntax.local_theory "no_notation" "delete notation for constants / fixed variables" K.thy_decl
   250     (opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
   251     >> (fn (mode, args) => Specification.notation_cmd false mode args));
   252 
   253 
   254 (* constant specifications *)
   255 
   256 val _ =
   257   OuterSyntax.local_theory "axiomatization" "axiomatic constant specification" K.thy_decl
   258     (Scan.optional P.fixes [] --
   259       Scan.optional (P.where_ |-- P.!!! (P.and_list1 SpecParse.spec)) []
   260     >> (fn (x, y) => #2 o Specification.axiomatization_cmd x y));
   261 
   262 
   263 (* theorems *)
   264 
   265 fun theorems kind =
   266   SpecParse.name_facts >> (fn args => #2 o Specification.theorems_cmd kind args);
   267 
   268 val _ =
   269   OuterSyntax.local_theory "theorems" "define theorems" K.thy_decl (theorems Thm.theoremK);
   270 
   271 val _ =
   272   OuterSyntax.local_theory "lemmas" "define lemmas" K.thy_decl (theorems Thm.lemmaK);
   273 
   274 val _ =
   275   OuterSyntax.local_theory "declare" "declare theorems (improper)" K.thy_decl
   276     (P.and_list1 SpecParse.xthms1
   277       >> (fn args => #2 o Specification.theorems_cmd "" [(("", []), flat args)]));
   278 
   279 
   280 (* name space entry path *)
   281 
   282 val _ =
   283   OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
   284     (Scan.succeed (Toplevel.theory Sign.root_path));
   285 
   286 val _ =
   287   OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
   288     (Scan.succeed (Toplevel.theory Sign.local_path));
   289 
   290 val _ =
   291   OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
   292     ((P.opt_keyword "open" >> not) -- (P.name -- Scan.repeat1 P.xname) >>
   293       (Toplevel.theory o uncurry IsarCmd.hide_names));
   294 
   295 
   296 (* use ML text *)
   297 
   298 val _ =
   299   OuterSyntax.command "use" "eval ML text from file" (K.tag_ml K.thy_decl)
   300     (P.path >> (Toplevel.generic_theory o ThyInfo.exec_file false));
   301 
   302 val _ =
   303   OuterSyntax.command "ML" "eval ML text (diagnostic)" (K.tag_ml K.thy_decl)
   304     (P.position P.text >> (fn (txt, pos) =>
   305       Toplevel.generic_theory (ML_Context.exec (fn () => ML_Context.eval true pos txt))));
   306 
   307 val _ =
   308   OuterSyntax.command "ML_val" "eval ML text (diagnostic)" (K.tag_ml K.diag)
   309     (P.position P.text >> IsarCmd.ml_diag true);
   310 
   311 val _ =
   312   OuterSyntax.command "ML_command" "silently eval ML text (diagnostic)" (K.tag_ml K.diag)
   313     (P.position P.text >> (Toplevel.no_timing oo IsarCmd.ml_diag false));
   314 
   315 val _ =
   316   OuterSyntax.command "setup" "apply ML theory setup" (K.tag_ml K.thy_decl)
   317     (P.position P.text >> (Toplevel.theory o IsarCmd.generic_setup));
   318 
   319 val _ =
   320   OuterSyntax.command "method_setup" "define proof method in ML" (K.tag_ml K.thy_decl)
   321     (P.name -- P.!!! (P.$$$ "=" |-- P.position P.text -- P.text)
   322     >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
   323 
   324 val _ =
   325   OuterSyntax.local_theory "declaration" "generic ML declaration" (K.tag_ml K.thy_decl)
   326     (P.position P.text >> IsarCmd.declaration);
   327 
   328 val _ =
   329   OuterSyntax.local_theory "simproc_setup" "define simproc in ML" (K.tag_ml K.thy_decl)
   330     (P.name -- (P.$$$ "(" |-- P.enum1 "|" P.term --| P.$$$ ")" --| P.$$$ "=") --
   331       P.position P.text -- Scan.optional (P.$$$ "identifier" |-- Scan.repeat1 P.xname) []
   332     >> (fn (((a, b), c), d) => IsarCmd.simproc_setup a b c d));
   333 
   334 
   335 (* translation functions *)
   336 
   337 val trfun = P.opt_keyword "advanced" -- P.position P.text;
   338 
   339 val _ =
   340   OuterSyntax.command "parse_ast_translation" "install parse ast translation functions"
   341     (K.tag_ml K.thy_decl)
   342     (trfun >> (Toplevel.theory o IsarCmd.parse_ast_translation));
   343 
   344 val _ =
   345   OuterSyntax.command "parse_translation" "install parse translation functions"
   346     (K.tag_ml K.thy_decl)
   347     (trfun >> (Toplevel.theory o IsarCmd.parse_translation));
   348 
   349 val _ =
   350   OuterSyntax.command "print_translation" "install print translation functions"
   351     (K.tag_ml K.thy_decl)
   352     (trfun >> (Toplevel.theory o IsarCmd.print_translation));
   353 
   354 val _ =
   355   OuterSyntax.command "typed_print_translation" "install typed print translation functions"
   356     (K.tag_ml K.thy_decl)
   357     (trfun >> (Toplevel.theory o IsarCmd.typed_print_translation));
   358 
   359 val _ =
   360   OuterSyntax.command "print_ast_translation" "install print ast translation functions"
   361     (K.tag_ml K.thy_decl)
   362     (trfun >> (Toplevel.theory o IsarCmd.print_ast_translation));
   363 
   364 
   365 (* oracles *)
   366 
   367 val _ =
   368   OuterSyntax.command "oracle" "declare oracle" (K.tag_ml K.thy_decl)
   369     (P.name -- (P.$$$ "(" |-- P.text --| P.$$$ ")" --| P.$$$ "=")
   370       -- P.position P.text >> (fn ((x, y), z) => Toplevel.theory (IsarCmd.oracle x y z)));
   371 
   372 
   373 (* local theories *)
   374 
   375 val _ =
   376   OuterSyntax.command "context" "enter local theory context" K.thy_decl
   377     (P.name --| P.begin >> (fn name =>
   378       Toplevel.print o Toplevel.begin_local_theory true (TheoryTarget.context name)));
   379 
   380 
   381 (* locales *)
   382 
   383 val locale_val =
   384   SpecParse.locale_expr --
   385     Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
   386   Scan.repeat1 SpecParse.context_element >> pair Locale.empty;
   387 
   388 val _ =
   389   OuterSyntax.command "locale" "define named proof context" K.thy_decl
   390     ((P.opt_keyword "open" >> (fn true => NONE | false => SOME "")) --
   391       P.name -- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (Locale.empty, []) -- P.opt_begin
   392       >> (fn (((is_open, name), (expr, elems)), begin) =>
   393           (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
   394             (Locale.add_locale is_open name expr elems #-> TheoryTarget.begin)));
   395 
   396 val _ =
   397   OuterSyntax.command "interpretation"
   398     "prove and register interpretation of locale expression in theory or locale" K.thy_goal
   399     (P.xname --| (P.$$$ "\\<subseteq>" || P.$$$ "<") -- P.!!! SpecParse.locale_expr
   400       >> (Toplevel.print oo (Toplevel.theory_to_proof o Locale.interpretation_in_locale I)) ||
   401       SpecParse.opt_thm_name ":" -- SpecParse.locale_expr -- SpecParse.locale_insts
   402         >> (fn ((x, y), z) => Toplevel.print o
   403             Toplevel.theory_to_proof (Locale.interpretation I (apfst (pair true) x) y z)));
   404 
   405 val _ =
   406   OuterSyntax.command "interpret"
   407     "prove and register interpretation of locale expression in proof context"
   408     (K.tag_proof K.prf_goal)
   409     (SpecParse.opt_thm_name ":" -- SpecParse.locale_expr -- SpecParse.locale_insts
   410       >> (fn ((x, y), z) => Toplevel.print o
   411           Toplevel.proof' (Locale.interpret Seq.single (apfst (pair true) x) y z)));
   412 
   413 
   414 (* classes *)
   415 
   416 val class_val =
   417   SpecParse.class_expr --
   418     Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
   419   Scan.repeat1 SpecParse.context_element >> pair [];
   420 
   421 val _ =
   422   OuterSyntax.command "class" "define type class" K.thy_decl
   423    (P.name -- (P.$$$ "=" |-- class_val) -- P.opt_begin
   424     >> (fn ((name, (supclasses, elems)), begin) =>
   425         (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
   426           (Class.class_cmd name supclasses elems #-> TheoryTarget.begin)));
   427 
   428 val _ =
   429   OuterSyntax.local_theory_to_proof "subclass" "prove a subclass relation" K.thy_goal
   430     (P.xname >> Subclass.subclass_cmd);
   431 
   432 val _ =
   433   OuterSyntax.command "instantiation" "instantiate and prove type arity" K.thy_decl
   434    (P.multi_arity --| P.begin
   435      >> (fn arities => Toplevel.print o
   436          Toplevel.begin_local_theory true (Instance.instantiation_cmd arities)));
   437 
   438 val _ =
   439   OuterSyntax.command "instance" "prove type arity or subclass relation" K.thy_goal
   440   ((P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) >> Class.classrel_cmd ||
   441     P.arity >> Class.instance_arity_cmd)
   442     >> (Toplevel.print oo Toplevel.theory_to_proof)
   443   || Scan.succeed (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
   444 
   445 
   446 (* arbitrary overloading *)
   447 
   448 val _ =
   449   OuterSyntax.command "overloading" "overloaded definitions" K.thy_decl
   450    (Scan.repeat1 (P.name --| (P.$$$ "\\<equiv>" || P.$$$ "==") -- P.term --
   451       Scan.optional (P.$$$ "(" |-- (P.$$$ "unchecked" >> K false) --| P.$$$ ")") true
   452       >> P.triple1) --| P.begin
   453    >> (fn operations => Toplevel.print o
   454          Toplevel.begin_local_theory true (TheoryTarget.overloading_cmd operations)));
   455 
   456 
   457 (* code generation *)
   458 
   459 val _ =
   460   OuterSyntax.command "code_datatype" "define set of code datatype constructors" K.thy_decl
   461     (Scan.repeat1 P.term >> (Toplevel.theory o Code.add_datatype_cmd));
   462 
   463 
   464 
   465 (** proof commands **)
   466 
   467 (* statements *)
   468 
   469 fun gen_theorem kind =
   470   OuterSyntax.local_theory_to_proof' kind ("state " ^ kind) K.thy_goal
   471     (Scan.optional (SpecParse.opt_thm_name ":" --|
   472       Scan.ahead (SpecParse.locale_keyword || SpecParse.statement_keyword)) ("", []) --
   473       SpecParse.general_statement >> (fn (a, (elems, concl)) =>
   474         (Specification.theorem_cmd kind NONE (K I) a elems concl)));
   475 
   476 val _ = gen_theorem Thm.theoremK;
   477 val _ = gen_theorem Thm.lemmaK;
   478 val _ = gen_theorem Thm.corollaryK;
   479 
   480 val _ =
   481   OuterSyntax.command "have" "state local goal"
   482     (K.tag_proof K.prf_goal)
   483     (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.have));
   484 
   485 val _ =
   486   OuterSyntax.command "hence" "abbreviates \"then have\""
   487     (K.tag_proof K.prf_goal)
   488     (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.hence));
   489 
   490 val _ =
   491   OuterSyntax.command "show" "state local goal, solving current obligation"
   492     (K.tag_proof K.prf_asm_goal)
   493     (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.show));
   494 
   495 val _ =
   496   OuterSyntax.command "thus" "abbreviates \"then show\""
   497     (K.tag_proof K.prf_asm_goal)
   498     (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.thus));
   499 
   500 
   501 (* facts *)
   502 
   503 val facts = P.and_list1 SpecParse.xthms1;
   504 
   505 val _ =
   506   OuterSyntax.command "then" "forward chaining"
   507     (K.tag_proof K.prf_chain)
   508     (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
   509 
   510 val _ =
   511   OuterSyntax.command "from" "forward chaining from given facts"
   512     (K.tag_proof K.prf_chain)
   513     (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss)));
   514 
   515 val _ =
   516   OuterSyntax.command "with" "forward chaining from given and current facts"
   517     (K.tag_proof K.prf_chain)
   518     (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss)));
   519 
   520 val _ =
   521   OuterSyntax.command "note" "define facts"
   522     (K.tag_proof K.prf_decl)
   523     (SpecParse.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss)));
   524 
   525 val _ =
   526   OuterSyntax.command "using" "augment goal facts"
   527     (K.tag_proof K.prf_decl)
   528     (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using)));
   529 
   530 val _ =
   531   OuterSyntax.command "unfolding" "unfold definitions in goal and facts"
   532     (K.tag_proof K.prf_decl)
   533     (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding)));
   534 
   535 
   536 (* proof context *)
   537 
   538 val _ =
   539   OuterSyntax.command "fix" "fix local variables (Skolem constants)"
   540     (K.tag_proof K.prf_asm)
   541     (P.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix)));
   542 
   543 val _ =
   544   OuterSyntax.command "assume" "assume propositions"
   545     (K.tag_proof K.prf_asm)
   546     (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume)));
   547 
   548 val _ =
   549   OuterSyntax.command "presume" "assume propositions, to be established later"
   550     (K.tag_proof K.prf_asm)
   551     (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume)));
   552 
   553 val _ =
   554   OuterSyntax.command "def" "local definition"
   555     (K.tag_proof K.prf_asm)
   556     (P.and_list1
   557       (SpecParse.opt_thm_name ":" --
   558         ((P.name -- P.opt_mixfix) -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp)))
   559     >> (Toplevel.print oo (Toplevel.proof o Proof.def)));
   560 
   561 val _ =
   562   OuterSyntax.command "obtain" "generalized existence"
   563     (K.tag_proof K.prf_asm_goal)
   564     (P.parname -- Scan.optional (P.fixes --| P.where_) [] -- SpecParse.statement
   565       >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain x y z)));
   566 
   567 val _ =
   568   OuterSyntax.command "guess" "wild guessing (unstructured)"
   569     (K.tag_proof K.prf_asm_goal)
   570     (Scan.optional P.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess)));
   571 
   572 val _ =
   573   OuterSyntax.command "let" "bind text variables"
   574     (K.tag_proof K.prf_decl)
   575     (P.and_list1 (P.enum1 "and" P.term -- (P.$$$ "=" |-- P.term))
   576       >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind)));
   577 
   578 val case_spec =
   579   (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 (P.maybe P.name) --| P.$$$ ")") ||
   580     P.xname >> rpair []) -- SpecParse.opt_attribs >> P.triple1;
   581 
   582 val _ =
   583   OuterSyntax.command "case" "invoke local context"
   584     (K.tag_proof K.prf_asm)
   585     (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case)));
   586 
   587 
   588 (* proof structure *)
   589 
   590 val _ =
   591   OuterSyntax.command "{" "begin explicit proof block"
   592     (K.tag_proof K.prf_open)
   593     (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
   594 
   595 val _ =
   596   OuterSyntax.command "}" "end explicit proof block"
   597     (K.tag_proof K.prf_close)
   598     (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
   599 
   600 val _ =
   601   OuterSyntax.command "next" "enter next proof block"
   602     (K.tag_proof K.prf_block)
   603     (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
   604 
   605 
   606 (* end proof *)
   607 
   608 val _ =
   609   OuterSyntax.command "qed" "conclude (sub-)proof"
   610     (K.tag_proof K.qed_block)
   611     (Scan.option Method.parse >> IsarCmd.qed);
   612 
   613 val _ =
   614   OuterSyntax.command "by" "terminal backward proof"
   615     (K.tag_proof K.qed)
   616     (Method.parse -- Scan.option Method.parse >> IsarCmd.terminal_proof);
   617 
   618 val _ =
   619   OuterSyntax.command ".." "default proof"
   620     (K.tag_proof K.qed)
   621     (Scan.succeed IsarCmd.default_proof);
   622 
   623 val _ =
   624   OuterSyntax.command "." "immediate proof"
   625     (K.tag_proof K.qed)
   626     (Scan.succeed IsarCmd.immediate_proof);
   627 
   628 val _ =
   629   OuterSyntax.command "done" "done proof"
   630     (K.tag_proof K.qed)
   631     (Scan.succeed IsarCmd.done_proof);
   632 
   633 val _ =
   634   OuterSyntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
   635     (K.tag_proof K.qed)
   636     (Scan.succeed IsarCmd.skip_proof);
   637 
   638 val _ =
   639   OuterSyntax.command "oops" "forget proof"
   640     (K.tag_proof K.qed_global)
   641     (Scan.succeed Toplevel.forget_proof);
   642 
   643 
   644 (* proof steps *)
   645 
   646 val _ =
   647   OuterSyntax.command "defer" "shuffle internal proof state"
   648     (K.tag_proof K.prf_script)
   649     (Scan.option P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
   650 
   651 val _ =
   652   OuterSyntax.command "prefer" "shuffle internal proof state"
   653     (K.tag_proof K.prf_script)
   654     (P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
   655 
   656 val _ =
   657   OuterSyntax.command "apply" "initial refinement step (unstructured)"
   658     (K.tag_proof K.prf_script)
   659     (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
   660 
   661 val _ =
   662   OuterSyntax.command "apply_end" "terminal refinement (unstructured)"
   663     (K.tag_proof K.prf_script)
   664     (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
   665 
   666 val _ =
   667   OuterSyntax.command "proof" "backward proof"
   668     (K.tag_proof K.prf_block)
   669     (Scan.option Method.parse >> (fn m => Toplevel.print o
   670       Toplevel.actual_proof (ProofHistory.applys (Proof.proof m)) o
   671       Toplevel.skip_proof (History.apply (fn i => i + 1))));
   672 
   673 
   674 (* calculational proof commands *)
   675 
   676 val calc_args =
   677   Scan.option (P.$$$ "(" |-- P.!!! ((SpecParse.xthms1 --| P.$$$ ")")));
   678 
   679 val _ =
   680   OuterSyntax.command "also" "combine calculation and current facts"
   681     (K.tag_proof K.prf_decl)
   682     (calc_args >> (Toplevel.proofs' o Calculation.also));
   683 
   684 val _ =
   685   OuterSyntax.command "finally" "combine calculation and current facts, exhibit result"
   686     (K.tag_proof K.prf_chain)
   687     (calc_args >> (Toplevel.proofs' o Calculation.finally_));
   688 
   689 val _ =
   690   OuterSyntax.command "moreover" "augment calculation by current facts"
   691     (K.tag_proof K.prf_decl)
   692     (Scan.succeed (Toplevel.proof' Calculation.moreover));
   693 
   694 val _ =
   695   OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
   696     (K.tag_proof K.prf_chain)
   697     (Scan.succeed (Toplevel.proof' Calculation.ultimately));
   698 
   699 
   700 (* proof navigation *)
   701 
   702 val _ =
   703   OuterSyntax.command "back" "backtracking of proof command"
   704     (K.tag_proof K.prf_script)
   705     (Scan.succeed (Toplevel.print o IsarCmd.back));
   706 
   707 
   708 (* history *)
   709 
   710 val _ =
   711   OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control
   712     (P.name >> (Toplevel.no_timing oo IsarCmd.cannot_undo));
   713 
   714 val _ =
   715   OuterSyntax.improper_command "redo" "redo last command" K.control
   716     (Scan.succeed (Toplevel.no_timing o Toplevel.print o IsarCmd.redo));
   717 
   718 val _ =
   719   OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control
   720     (P.nat >> ((Toplevel.no_timing o Toplevel.print) oo IsarCmd.undos_proof));
   721 
   722 val _ =
   723   OuterSyntax.improper_command "undo" "undo last command" K.control
   724     (Scan.succeed (Toplevel.no_timing o IsarCmd.undo));
   725 
   726 val _ =
   727   OuterSyntax.improper_command "kill" "kill current history node" K.control
   728     (Scan.succeed (Toplevel.no_timing o Toplevel.print o IsarCmd.kill));
   729 
   730 
   731 (* nested command *)
   732 
   733 val _ =
   734   OuterSyntax.improper_command "Isabelle.command" "nested Isabelle command" K.control
   735     ((Scan.optional P.properties [] -- P.position P.string) :|-- (fn (props, arg) =>
   736       Scan.succeed (K (IsarCmd.nested_command props arg))
   737         handle ERROR msg => Scan.fail_with (K msg)));
   738 
   739 
   740 
   741 (** diagnostic commands (for interactive mode only) **)
   742 
   743 val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
   744 val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
   745 
   746 val _ =
   747   OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
   748     K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
   749 
   750 val _ =
   751   OuterSyntax.improper_command "help" "print outer syntax commands" K.diag
   752     (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
   753 
   754 val _ =
   755   OuterSyntax.improper_command "print_commands" "print outer syntax commands" K.diag
   756     (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
   757 
   758 val _ =
   759   OuterSyntax.improper_command "print_configs" "print configuration options" K.diag
   760     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_configs));
   761 
   762 val _ =
   763   OuterSyntax.improper_command "print_context" "print theory context name" K.diag
   764     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
   765 
   766 val _ =
   767   OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
   768     (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theory));
   769 
   770 val _ =
   771   OuterSyntax.improper_command "print_syntax" "print inner syntax of context (verbose!)" K.diag
   772     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
   773 
   774 val _ =
   775   OuterSyntax.improper_command "print_abbrevs" "print constant abbreviation of context" K.diag
   776     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_abbrevs));
   777 
   778 val _ =
   779   OuterSyntax.improper_command "print_theorems"
   780       "print theorems of local theory or proof context" K.diag
   781     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theorems));
   782 
   783 val _ =
   784   OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
   785     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales));
   786 
   787 val _ =
   788   OuterSyntax.improper_command "print_classes" "print classes of this theory" K.diag
   789     (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
   790       o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
   791 
   792 val _ =
   793   OuterSyntax.improper_command "print_locale" "print locale expression in this theory" K.diag
   794     (opt_bang -- locale_val >> (Toplevel.no_timing oo IsarCmd.print_locale));
   795 
   796 val _ =
   797   OuterSyntax.improper_command "print_interps"
   798     "print interpretations of named locale" K.diag
   799     (Scan.optional (P.$$$ "!" >> K true) false -- P.xname
   800       >> (Toplevel.no_timing oo uncurry IsarCmd.print_registrations));
   801 
   802 val _ =
   803   OuterSyntax.improper_command "print_attributes" "print attributes of this theory" K.diag
   804     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
   805 
   806 val _ =
   807   OuterSyntax.improper_command "print_simpset" "print context of Simplifier" K.diag
   808     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_simpset));
   809 
   810 val _ =
   811   OuterSyntax.improper_command "print_rules" "print intro/elim rules" K.diag
   812     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules));
   813 
   814 val _ =
   815   OuterSyntax.improper_command "print_trans_rules" "print transitivity rules" K.diag
   816     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules));
   817 
   818 val _ =
   819   OuterSyntax.improper_command "print_methods" "print methods of this theory" K.diag
   820     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
   821 
   822 val _ =
   823   OuterSyntax.improper_command "print_antiquotations" "print antiquotations (global)" K.diag
   824     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations));
   825 
   826 val _ =
   827   OuterSyntax.improper_command "thy_deps" "visualize theory dependencies"
   828     K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.thy_deps));
   829 
   830 val _ =
   831   OuterSyntax.improper_command "class_deps" "visualize class dependencies"
   832     K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
   833 
   834 val _ =
   835   OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
   836     K.diag (SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
   837 
   838 local
   839 
   840 val criterion =
   841   P.reserved "name" |-- P.!!! (P.$$$ ":" |-- P.xname) >> FindTheorems.Name ||
   842   P.reserved "intro" >> K FindTheorems.Intro ||
   843   P.reserved "elim" >> K FindTheorems.Elim ||
   844   P.reserved "dest" >> K FindTheorems.Dest ||
   845   P.reserved "simp" |-- P.!!! (P.$$$ ":" |-- P.term) >> FindTheorems.Simp ||
   846   P.term >> FindTheorems.Pattern;
   847 
   848 val options =
   849   Scan.optional
   850     (P.$$$ "(" |--
   851       P.!!! (Scan.option P.nat -- Scan.optional (P.reserved "with_dups" >> K false) true
   852         --| P.$$$ ")")) (NONE, true);
   853 in
   854 
   855 val _ =
   856   OuterSyntax.improper_command "find_theorems" "print theorems meeting specified criteria" K.diag
   857     (options -- Scan.repeat (((Scan.option P.minus >> is_none) -- criterion))
   858       >> (Toplevel.no_timing oo IsarCmd.find_theorems));
   859 
   860 end;
   861 
   862 val _ =
   863   OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
   864     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
   865 
   866 val _ =
   867   OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag
   868     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_facts));
   869 
   870 val _ =
   871   OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
   872     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
   873 
   874 val _ =
   875   OuterSyntax.improper_command "print_statement" "print theorems as long statements" K.diag
   876     (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_stmts));
   877 
   878 val _ =
   879   OuterSyntax.improper_command "thm" "print theorems" K.diag
   880     (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
   881 
   882 val _ =
   883   OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
   884     (opt_modes -- Scan.option SpecParse.xthms1
   885       >> (Toplevel.no_timing oo IsarCmd.print_prfs false));
   886 
   887 val _ =
   888   OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
   889     (opt_modes -- Scan.option SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true));
   890 
   891 val _ =
   892   OuterSyntax.improper_command "prop" "read and print proposition" K.diag
   893     (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
   894 
   895 val _ =
   896   OuterSyntax.improper_command "term" "read and print term" K.diag
   897     (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term));
   898 
   899 val _ =
   900   OuterSyntax.improper_command "typ" "read and print type" K.diag
   901     (opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
   902 
   903 val _ =
   904   OuterSyntax.improper_command "print_codesetup" "print code generator setup of this theory" K.diag
   905     (Scan.succeed
   906       (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
   907         (Code.print_codesetup o Toplevel.theory_of)));
   908 
   909 val _ =
   910   OuterSyntax.improper_command "unused_thms" "find unused theorems" K.diag
   911     (Scan.option ((Scan.repeat1 (Scan.unless P.minus P.name) --| P.minus) --
   912        Scan.option (Scan.repeat1 (Scan.unless P.minus P.name))) >>
   913          (Toplevel.no_timing oo IsarCmd.unused_thms));
   914 
   915 
   916 (** system commands (for interactive mode only) **)
   917 
   918 val _ =
   919   OuterSyntax.improper_command "cd" "change current working directory" K.diag
   920     (P.path >> (Toplevel.no_timing oo IsarCmd.cd));
   921 
   922 val _ =
   923   OuterSyntax.improper_command "pwd" "print current working directory" K.diag
   924     (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
   925 
   926 val _ =
   927   OuterSyntax.improper_command "use_thy" "use theory file" K.diag
   928     (P.name >> (fn name =>
   929       Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.use_thy name)));
   930 
   931 val _ =
   932   OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
   933     (P.name >> (Toplevel.no_timing oo IsarCmd.touch_thy));
   934 
   935 val _ =
   936   OuterSyntax.improper_command "touch_child_thys" "outdate child theories" K.diag
   937     (P.name >> (Toplevel.no_timing oo IsarCmd.touch_child_thys));
   938 
   939 val _ =
   940   OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
   941     (P.name >> (Toplevel.no_timing oo IsarCmd.remove_thy));
   942 
   943 val _ =
   944   OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
   945     K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.kill_thy));
   946 
   947 val _ =
   948   OuterSyntax.improper_command "display_drafts" "display raw source files with symbols"
   949     K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.display_drafts));
   950 
   951 val _ =
   952   OuterSyntax.improper_command "print_drafts" "print raw source files with symbols"
   953     K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.print_drafts));
   954 
   955 val opt_limits =
   956   Scan.option P.nat -- Scan.option (P.$$$ "," |-- P.!!! P.nat);
   957 
   958 val _ =
   959   OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag
   960     (opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr));
   961 
   962 val _ =
   963   OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
   964     (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
   965 
   966 val _ =
   967   OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
   968     (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
   969 
   970 val _ =
   971   OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
   972     (P.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
   973 
   974 val _ =
   975   OuterSyntax.improper_command "quit" "quit Isabelle" K.control
   976     (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
   977 
   978 val _ =
   979   OuterSyntax.improper_command "exit" "exit Isar loop" K.control
   980     (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
   981 
   982 val _ =
   983   OuterSyntax.improper_command "init_toplevel" "restart Isar toplevel loop" K.control
   984     (Scan.succeed (Toplevel.no_timing o IsarCmd.init_toplevel));
   985 
   986 val _ =
   987   OuterSyntax.improper_command "welcome" "print welcome message" K.diag
   988     (Scan.succeed (Toplevel.no_timing o IsarCmd.welcome));
   989 
   990 end;