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