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