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