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