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