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