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