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