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