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