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