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