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