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