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