src/Pure/Isar/isar_syn.ML
author haftmann
Wed Jan 07 08:03:25 2009 +0100 (2009-01-07 ago)
changeset 29378 2821c2c5270d
parent 29363 c1f024b4d76d
child 29390 5c26e3a63b8e
permissions -rw-r--r--
proper local_theory after Class.class
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@17353
     7
structure IsarSyn: sig end =
wenzelm@5832
     8
struct
wenzelm@5832
     9
wenzelm@17068
    10
structure P = OuterParse and K = OuterKeyword;
wenzelm@5832
    11
wenzelm@5832
    12
wenzelm@24868
    13
(** keywords **)
wenzelm@24868
    14
wenzelm@24868
    15
(*keep keywords consistent with the parsers, otherwise be prepared for
wenzelm@24868
    16
  unexpected errors*)
wenzelm@24868
    17
wenzelm@27353
    18
val _ = List.app OuterKeyword.keyword
wenzelm@24868
    19
 ["!!", "!", "%", "(", ")", "+", ",", "--", ":", "::", ";", "<", "<=",
wenzelm@24868
    20
  "=", "==", "=>", "?", "[", "\\<equiv>", "\\<leftharpoondown>",
wenzelm@24868
    21
  "\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>", "]",
wenzelm@26888
    22
  "advanced", "and", "assumes", "attach", "begin", "binder",
wenzelm@24868
    23
  "constrains", "defines", "fixes", "for", "identifier", "if",
ballarin@28721
    24
  "imports", "in", "infix", "infixl", "infixr", "is",
haftmann@25003
    25
  "notes", "obtains", "open", "output", "overloaded", "shows",
wenzelm@24868
    26
  "structure", "unchecked", "uses", "where", "|"];
wenzelm@24868
    27
wenzelm@24868
    28
wenzelm@5832
    29
(** init and exit **)
wenzelm@5832
    30
wenzelm@24868
    31
val _ =
wenzelm@17068
    32
  OuterSyntax.command "theory" "begin theory" (K.tag_theory K.thy_begin)
wenzelm@27575
    33
    (ThyHeader.args >> (Toplevel.print oo IsarCmd.init_theory));
wenzelm@5832
    34
wenzelm@24868
    35
val _ =
wenzelm@20958
    36
  OuterSyntax.command "end" "end (local) theory" (K.tag_theory K.thy_end)
wenzelm@21004
    37
    (Scan.succeed (Toplevel.exit o Toplevel.end_local_theory));
wenzelm@6687
    38
wenzelm@5832
    39
wenzelm@7749
    40
(** markup commands **)
wenzelm@5832
    41
wenzelm@24868
    42
val _ = OuterSyntax.markup_command ThyOutput.Markup "header" "theory header" K.diag
wenzelm@27872
    43
  (P.doc_source >> IsarCmd.header_markup);
wenzelm@6353
    44
wenzelm@24868
    45
val _ = OuterSyntax.markup_command ThyOutput.Markup "chapter" "chapter heading"
wenzelm@27872
    46
  K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
wenzelm@5958
    47
wenzelm@24868
    48
val _ = OuterSyntax.markup_command ThyOutput.Markup "section" "section heading"
wenzelm@27872
    49
  K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
wenzelm@5958
    50
wenzelm@24868
    51
val _ = OuterSyntax.markup_command ThyOutput.Markup "subsection" "subsection heading"
wenzelm@27872
    52
  K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
wenzelm@5958
    53
wenzelm@24868
    54
val _ =
wenzelm@22117
    55
  OuterSyntax.markup_command ThyOutput.Markup "subsubsection" "subsubsection heading"
wenzelm@27872
    56
  K.thy_heading (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
wenzelm@5832
    57
wenzelm@24868
    58
val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "text" "formal comment (theory)"
wenzelm@27872
    59
  K.thy_decl (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
wenzelm@7172
    60
wenzelm@27872
    61
val _ = OuterSyntax.markup_command ThyOutput.Verbatim "text_raw" "raw document preparation text"
wenzelm@27872
    62
  K.thy_decl (P.opt_target -- P.doc_source >> IsarCmd.local_theory_markup);
wenzelm@7172
    63
wenzelm@24868
    64
val _ = OuterSyntax.markup_command ThyOutput.Markup "sect" "formal comment (proof)"
wenzelm@27872
    65
  (K.tag_proof K.prf_heading) (P.doc_source >> IsarCmd.proof_markup);
wenzelm@7172
    66
wenzelm@24868
    67
val _ = OuterSyntax.markup_command ThyOutput.Markup "subsect" "formal comment (proof)"
wenzelm@27872
    68
  (K.tag_proof K.prf_heading) (P.doc_source >> IsarCmd.proof_markup);
wenzelm@7172
    69
wenzelm@27872
    70
val _ = OuterSyntax.markup_command ThyOutput.Markup "subsubsect" "formal comment (proof)"
wenzelm@27872
    71
  (K.tag_proof K.prf_heading) (P.doc_source >> IsarCmd.proof_markup);
wenzelm@7172
    72
wenzelm@24868
    73
val _ = OuterSyntax.markup_command ThyOutput.MarkupEnv "txt" "formal comment (proof)"
wenzelm@27872
    74
  (K.tag_proof K.prf_decl) (P.doc_source >> IsarCmd.proof_markup);
wenzelm@7172
    75
wenzelm@24868
    76
val _ = OuterSyntax.markup_command ThyOutput.Verbatim "txt_raw"
wenzelm@17068
    77
  "raw document preparation text (proof)" (K.tag_proof K.prf_decl)
wenzelm@27872
    78
  (P.doc_source >> IsarCmd.proof_markup);
wenzelm@7775
    79
wenzelm@5832
    80
wenzelm@6886
    81
wenzelm@6886
    82
(** theory sections **)
wenzelm@6886
    83
wenzelm@5832
    84
(* classes and sorts *)
wenzelm@5832
    85
wenzelm@24868
    86
val _ =
wenzelm@6723
    87
  OuterSyntax.command "classes" "declare type classes" K.thy_decl
wenzelm@11101
    88
    (Scan.repeat1 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
wenzelm@24932
    89
        P.!!! (P.list1 P.xname)) []) >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
wenzelm@5832
    90
wenzelm@24868
    91
val _ =
wenzelm@6723
    92
  OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
wenzelm@14779
    93
    (P.and_list1 (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname))
wenzelm@24932
    94
    >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
wenzelm@5832
    95
wenzelm@24868
    96
val _ =
wenzelm@6723
    97
  OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
wenzelm@22796
    98
    (P.sort >> (Toplevel.theory o Sign.add_defsort));
wenzelm@5832
    99
wenzelm@24868
   100
val _ =
wenzelm@19245
   101
  OuterSyntax.command "axclass" "define axiomatic type class" K.thy_decl
haftmann@21462
   102
    (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
haftmann@21462
   103
        P.!!! (P.list1 P.xname)) []
wenzelm@22117
   104
        -- Scan.repeat (SpecParse.thm_name ":" -- (P.prop >> single))
haftmann@24219
   105
      >> (fn (x, y) => Toplevel.theory (snd o Class.axclass_cmd x y)));
wenzelm@19245
   106
wenzelm@5832
   107
wenzelm@5832
   108
(* types *)
wenzelm@5832
   109
wenzelm@24868
   110
val _ =
wenzelm@12624
   111
  OuterSyntax.command "typedecl" "type declaration" K.thy_decl
wenzelm@12876
   112
    (P.type_args -- P.name -- P.opt_infix >> (fn ((args, a), mx) =>
wenzelm@25495
   113
      Toplevel.theory (ObjectLogic.typedecl (a, args, mx) #> snd)));
wenzelm@5832
   114
wenzelm@24868
   115
val _ =
wenzelm@6723
   116
  OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
wenzelm@6727
   117
    (Scan.repeat1
wenzelm@12876
   118
      (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix')))
wenzelm@22796
   119
      >> (Toplevel.theory o Sign.add_tyabbrs o
wenzelm@12876
   120
        map (fn ((args, a), (T, mx)) => (a, args, T, mx))));
wenzelm@5832
   121
wenzelm@24868
   122
val _ =
wenzelm@6370
   123
  OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
wenzelm@22796
   124
    K.thy_decl (Scan.repeat1 P.name >> (Toplevel.theory o Sign.add_nonterminals));
wenzelm@5832
   125
wenzelm@24868
   126
val _ =
wenzelm@6723
   127
  OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
wenzelm@24932
   128
    (Scan.repeat1 P.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
wenzelm@5832
   129
wenzelm@5832
   130
wenzelm@5832
   131
(* consts and syntax *)
wenzelm@5832
   132
wenzelm@24868
   133
val _ =
wenzelm@8227
   134
  OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
wenzelm@12876
   135
    (P.const >> (Toplevel.theory o ObjectLogic.add_judgment));
wenzelm@8227
   136
wenzelm@24868
   137
val _ =
wenzelm@6723
   138
  OuterSyntax.command "consts" "declare constants" K.thy_decl
wenzelm@22796
   139
    (Scan.repeat1 P.const >> (Toplevel.theory o Sign.add_consts));
wenzelm@5832
   140
wenzelm@14642
   141
val opt_overloaded = P.opt_keyword "overloaded";
skalberg@14223
   142
wenzelm@24868
   143
val _ =
skalberg@14223
   144
  OuterSyntax.command "finalconsts" "declare constants as final" K.thy_decl
skalberg@14223
   145
    (opt_overloaded -- Scan.repeat1 P.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
wenzelm@9731
   146
wenzelm@12142
   147
val mode_spec =
wenzelm@9731
   148
  (P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true;
wenzelm@9731
   149
wenzelm@14900
   150
val opt_mode =
wenzelm@24960
   151
  Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) Syntax.mode_default;
wenzelm@5832
   152
wenzelm@24868
   153
val _ =
wenzelm@6723
   154
  OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
wenzelm@22796
   155
    (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Sign.add_modesyntax));
wenzelm@5832
   156
wenzelm@24868
   157
val _ =
wenzelm@15748
   158
  OuterSyntax.command "no_syntax" "delete syntax declarations" K.thy_decl
wenzelm@22796
   159
    (opt_mode -- Scan.repeat1 P.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@6723
   165
  Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
wenzelm@5832
   166
wenzelm@5832
   167
fun trans_arrow toks =
wenzelm@10688
   168
  ((P.$$$ "\\<rightharpoonup>" || P.$$$ "=>") >> K Syntax.ParseRule ||
wenzelm@10688
   169
    (P.$$$ "\\<leftharpoondown>" || P.$$$ "<=") >> K Syntax.PrintRule ||
wenzelm@10688
   170
    (P.$$$ "\\<rightleftharpoons>" || P.$$$ "==") >> K Syntax.ParsePrintRule) toks;
wenzelm@5832
   171
wenzelm@5832
   172
val trans_line =
wenzelm@6723
   173
  trans_pat -- P.!!! (trans_arrow -- trans_pat)
wenzelm@5832
   174
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@5832
   175
wenzelm@24868
   176
val _ =
wenzelm@6723
   177
  OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
wenzelm@22796
   178
    (Scan.repeat1 trans_line >> (Toplevel.theory o Sign.add_trrules));
wenzelm@5832
   179
wenzelm@24868
   180
val _ =
wenzelm@19260
   181
  OuterSyntax.command "no_translations" "remove syntax translation rules" K.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@6723
   188
  OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
wenzelm@22117
   189
    (Scan.repeat1 SpecParse.spec_name >> (Toplevel.theory o IsarCmd.add_axioms));
wenzelm@5832
   190
wenzelm@19631
   191
val opt_unchecked_overloaded =
wenzelm@19631
   192
  Scan.optional (P.$$$ "(" |-- P.!!!
wenzelm@19631
   193
    (((P.$$$ "unchecked" >> K true) -- Scan.optional (P.$$$ "overloaded" >> K true) false ||
wenzelm@19631
   194
      P.$$$ "overloaded" >> K (false, true)) --| P.$$$ ")")) (false, false);
wenzelm@19631
   195
wenzelm@24868
   196
val _ =
wenzelm@6723
   197
  OuterSyntax.command "defs" "define constants" K.thy_decl
wenzelm@22117
   198
    (opt_unchecked_overloaded -- Scan.repeat1 SpecParse.spec_name
wenzelm@21350
   199
      >> (Toplevel.theory o IsarCmd.add_defs));
wenzelm@6370
   200
wenzelm@14642
   201
wenzelm@21601
   202
(* old constdefs *)
wenzelm@14642
   203
wenzelm@21601
   204
val old_constdecl =
wenzelm@28083
   205
  P.binding --| P.where_ >> (fn x => (x, NONE, NoSyn)) ||
wenzelm@28083
   206
  P.binding -- (P.$$$ "::" |-- P.!!! P.typ >> SOME) -- P.opt_mixfix'
wenzelm@21601
   207
    --| Scan.option P.where_ >> P.triple1 ||
wenzelm@28083
   208
  P.binding -- (P.mixfix >> pair NONE) --| Scan.option P.where_ >> P.triple2;
wenzelm@19076
   209
wenzelm@22117
   210
val old_constdef = Scan.option old_constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
wenzelm@14642
   211
wenzelm@19076
   212
val structs =
wenzelm@19076
   213
  Scan.optional ((P.$$$ "(" -- P.$$$ "structure") |-- P.!!! (P.simple_fixes --| P.$$$ ")")) [];
wenzelm@19076
   214
wenzelm@24868
   215
val _ =
wenzelm@19076
   216
  OuterSyntax.command "constdefs" "old-style constant definition" K.thy_decl
wenzelm@21601
   217
    (structs -- Scan.repeat1 old_constdef >> (Toplevel.theory o Constdefs.add_constdefs));
wenzelm@21601
   218
wenzelm@21601
   219
wenzelm@21601
   220
(* constant definitions and abbreviations *)
wenzelm@21601
   221
wenzelm@21601
   222
val constdecl =
wenzelm@28083
   223
  P.binding --
wenzelm@21601
   224
    (P.where_ >> K (NONE, NoSyn) ||
wenzelm@21601
   225
      P.$$$ "::" |-- P.!!! ((P.typ >> SOME) -- P.opt_mixfix' --| P.where_) ||
wenzelm@21601
   226
      Scan.ahead (P.$$$ "(") |-- P.!!! (P.mixfix' --| P.where_ >> pair NONE))
wenzelm@21601
   227
  >> P.triple2;
wenzelm@21601
   228
wenzelm@22117
   229
val constdef = Scan.option constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
wenzelm@5832
   230
wenzelm@24868
   231
val _ =
wenzelm@26988
   232
  OuterSyntax.local_theory "definition" "constant definition" K.thy_decl
wenzelm@26988
   233
    (constdef >> (fn args => #2 o Specification.definition_cmd args));
wenzelm@18780
   234
wenzelm@24868
   235
val _ =
wenzelm@26988
   236
  OuterSyntax.local_theory "abbreviation" "constant abbreviation" K.thy_decl
wenzelm@26988
   237
    (opt_mode -- (Scan.option constdecl -- P.prop)
wenzelm@26988
   238
    >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
wenzelm@19659
   239
wenzelm@24868
   240
val _ =
wenzelm@26988
   241
  OuterSyntax.local_theory "notation" "add notation for constants / fixed variables" K.thy_decl
wenzelm@26988
   242
    (opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
wenzelm@26988
   243
    >> (fn (mode, args) => Specification.notation_cmd true mode args));
wenzelm@24950
   244
wenzelm@24950
   245
val _ =
wenzelm@26988
   246
  OuterSyntax.local_theory "no_notation" "delete notation for constants / fixed variables" K.thy_decl
wenzelm@26988
   247
    (opt_mode -- P.and_list1 (P.xname -- SpecParse.locale_mixfix)
wenzelm@26988
   248
    >> (fn (mode, args) => Specification.notation_cmd false mode args));
wenzelm@19076
   249
wenzelm@5832
   250
wenzelm@18616
   251
(* constant specifications *)
wenzelm@18616
   252
wenzelm@24868
   253
val _ =
wenzelm@28114
   254
  OuterSyntax.command "axiomatization" "axiomatic constant specification" K.thy_decl
wenzelm@26988
   255
    (Scan.optional P.fixes [] --
wenzelm@26988
   256
      Scan.optional (P.where_ |-- P.!!! (P.and_list1 SpecParse.spec)) []
wenzelm@28114
   257
    >> (fn (x, y) => Toplevel.theory (#2 o Specification.axiomatization_cmd x y)));
wenzelm@18616
   258
wenzelm@18616
   259
wenzelm@5914
   260
(* theorems *)
wenzelm@5914
   261
wenzelm@26988
   262
fun theorems kind =
wenzelm@26988
   263
  SpecParse.name_facts >> (fn args => #2 o Specification.theorems_cmd kind args);
wenzelm@12712
   264
wenzelm@24868
   265
val _ =
wenzelm@26988
   266
  OuterSyntax.local_theory "theorems" "define theorems" K.thy_decl (theorems Thm.theoremK);
wenzelm@5914
   267
wenzelm@24868
   268
val _ =
wenzelm@26988
   269
  OuterSyntax.local_theory "lemmas" "define lemmas" K.thy_decl (theorems Thm.lemmaK);
wenzelm@5914
   270
wenzelm@24868
   271
val _ =
wenzelm@26988
   272
  OuterSyntax.local_theory "declare" "declare theorems (improper)" K.thy_decl
wenzelm@26988
   273
    (P.and_list1 SpecParse.xthms1
haftmann@28965
   274
      >> (fn args => #2 o Specification.theorems_cmd "" [(Attrib.empty_binding, flat args)]));
wenzelm@9589
   275
wenzelm@5914
   276
wenzelm@5832
   277
(* name space entry path *)
wenzelm@5832
   278
wenzelm@24868
   279
val _ =
wenzelm@6723
   280
  OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
wenzelm@16447
   281
    (Scan.succeed (Toplevel.theory Sign.root_path));
wenzelm@5832
   282
wenzelm@24868
   283
val _ =
wenzelm@6723
   284
  OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
wenzelm@16447
   285
    (Scan.succeed (Toplevel.theory Sign.local_path));
wenzelm@8723
   286
wenzelm@24868
   287
val _ =
wenzelm@8723
   288
  OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
wenzelm@17397
   289
    ((P.opt_keyword "open" >> not) -- (P.name -- Scan.repeat1 P.xname) >>
wenzelm@26672
   290
      (Toplevel.theory o uncurry IsarCmd.hide_names));
wenzelm@5832
   291
wenzelm@5832
   292
wenzelm@5832
   293
(* use ML text *)
wenzelm@5832
   294
wenzelm@24868
   295
val _ =
wenzelm@26490
   296
  OuterSyntax.command "use" "eval ML text from file" (K.tag_ml K.thy_decl)
wenzelm@26490
   297
    (P.path >> (Toplevel.generic_theory o ThyInfo.exec_file false));
wenzelm@5832
   298
wenzelm@24868
   299
val _ =
wenzelm@28269
   300
  OuterSyntax.command "ML" "eval ML text within theory" (K.tag_ml K.thy_decl)
wenzelm@27877
   301
    (P.ML_source >> (fn (txt, pos) =>
wenzelm@26490
   302
      Toplevel.generic_theory (ML_Context.exec (fn () => ML_Context.eval true pos txt))));
wenzelm@7891
   303
wenzelm@24868
   304
val _ =
wenzelm@28269
   305
  OuterSyntax.command "ML_prf" "eval ML text within proof" (K.tag_proof K.prf_decl)
wenzelm@28269
   306
    (P.ML_source >> (fn (txt, pos) =>
wenzelm@28269
   307
      Toplevel.proof (Proof.map_context (Context.proof_map
wenzelm@28277
   308
        (ML_Context.exec (fn () => ML_Context.eval true pos txt))) #>
wenzelm@28277
   309
          (fn prf => Proof.map_contexts (ML_Context.inherit_env (Proof.context_of prf)) prf))));
wenzelm@28269
   310
wenzelm@28269
   311
val _ =
wenzelm@26396
   312
  OuterSyntax.command "ML_val" "eval ML text (diagnostic)" (K.tag_ml K.diag)
wenzelm@27877
   313
    (P.ML_source >> IsarCmd.ml_diag true);
wenzelm@26396
   314
wenzelm@26396
   315
val _ =
wenzelm@26396
   316
  OuterSyntax.command "ML_command" "silently eval ML text (diagnostic)" (K.tag_ml K.diag)
wenzelm@27877
   317
    (P.ML_source >> (Toplevel.no_timing oo IsarCmd.ml_diag false));
wenzelm@5832
   318
wenzelm@24868
   319
val _ =
wenzelm@17068
   320
  OuterSyntax.command "setup" "apply ML theory setup" (K.tag_ml K.thy_decl)
wenzelm@27877
   321
    (P.ML_source >> (Toplevel.theory o IsarCmd.generic_setup));
wenzelm@5832
   322
wenzelm@24868
   323
val _ =
wenzelm@17068
   324
  OuterSyntax.command "method_setup" "define proof method in ML" (K.tag_ml K.thy_decl)
wenzelm@27877
   325
    (P.name -- P.!!! (P.$$$ "=" |-- P.ML_source -- P.text)
wenzelm@26385
   326
    >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
wenzelm@9197
   327
wenzelm@24868
   328
val _ =
wenzelm@26988
   329
  OuterSyntax.local_theory "declaration" "generic ML declaration" (K.tag_ml K.thy_decl)
wenzelm@27877
   330
    (P.ML_source >> IsarCmd.declaration);
wenzelm@22088
   331
wenzelm@24868
   332
val _ =
wenzelm@26988
   333
  OuterSyntax.local_theory "simproc_setup" "define simproc in ML" (K.tag_ml K.thy_decl)
wenzelm@26988
   334
    (P.name -- (P.$$$ "(" |-- P.enum1 "|" P.term --| P.$$$ ")" --| P.$$$ "=") --
wenzelm@27877
   335
      P.ML_source -- Scan.optional (P.$$$ "identifier" |-- Scan.repeat1 P.xname) []
wenzelm@26988
   336
    >> (fn (((a, b), c), d) => IsarCmd.simproc_setup a b c d));
wenzelm@22202
   337
wenzelm@5832
   338
wenzelm@5832
   339
(* translation functions *)
wenzelm@5832
   340
wenzelm@27877
   341
val trfun = P.opt_keyword "advanced" -- P.ML_source;
wenzelm@14642
   342
wenzelm@24868
   343
val _ =
wenzelm@17068
   344
  OuterSyntax.command "parse_ast_translation" "install parse ast translation functions"
wenzelm@17068
   345
    (K.tag_ml K.thy_decl)
wenzelm@22117
   346
    (trfun >> (Toplevel.theory o IsarCmd.parse_ast_translation));
wenzelm@5832
   347
wenzelm@24868
   348
val _ =
wenzelm@17068
   349
  OuterSyntax.command "parse_translation" "install parse translation functions"
wenzelm@17068
   350
    (K.tag_ml K.thy_decl)
wenzelm@22117
   351
    (trfun >> (Toplevel.theory o IsarCmd.parse_translation));
wenzelm@5832
   352
wenzelm@24868
   353
val _ =
wenzelm@17068
   354
  OuterSyntax.command "print_translation" "install print translation functions"
wenzelm@17068
   355
    (K.tag_ml K.thy_decl)
wenzelm@22117
   356
    (trfun >> (Toplevel.theory o IsarCmd.print_translation));
wenzelm@5832
   357
wenzelm@24868
   358
val _ =
wenzelm@6370
   359
  OuterSyntax.command "typed_print_translation" "install typed print translation functions"
wenzelm@17068
   360
    (K.tag_ml K.thy_decl)
wenzelm@22117
   361
    (trfun >> (Toplevel.theory o IsarCmd.typed_print_translation));
wenzelm@5832
   362
wenzelm@24868
   363
val _ =
wenzelm@17068
   364
  OuterSyntax.command "print_ast_translation" "install print ast translation functions"
wenzelm@17068
   365
    (K.tag_ml K.thy_decl)
wenzelm@22117
   366
    (trfun >> (Toplevel.theory o IsarCmd.print_ast_translation));
wenzelm@5832
   367
wenzelm@5832
   368
wenzelm@5832
   369
(* oracles *)
wenzelm@5832
   370
wenzelm@24868
   371
val _ =
wenzelm@17068
   372
  OuterSyntax.command "oracle" "declare oracle" (K.tag_ml K.thy_decl)
wenzelm@28290
   373
    (P.name -- (P.$$$ "=" |-- P.ML_source) >> (fn (x, y) => Toplevel.theory (IsarCmd.oracle x y)));
wenzelm@5832
   374
wenzelm@5832
   375
wenzelm@21306
   376
(* local theories *)
wenzelm@21306
   377
wenzelm@24868
   378
val _ =
wenzelm@21306
   379
  OuterSyntax.command "context" "enter local theory context" K.thy_decl
wenzelm@21306
   380
    (P.name --| P.begin >> (fn name =>
wenzelm@25290
   381
      Toplevel.print o Toplevel.begin_local_theory true (TheoryTarget.context name)));
wenzelm@21306
   382
wenzelm@21306
   383
wenzelm@12061
   384
(* locales *)
wenzelm@12061
   385
wenzelm@12758
   386
val locale_val =
ballarin@29223
   387
  SpecParse.locale_expression --
wenzelm@22117
   388
    Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
ballarin@29223
   389
  Scan.repeat1 SpecParse.context_element >> pair ([], []);
wenzelm@12061
   390
wenzelm@24868
   391
val _ =
wenzelm@12061
   392
  OuterSyntax.command "locale" "define named proof context" K.thy_decl
ballarin@29223
   393
    (P.name -- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (([], []), []) -- P.opt_begin
haftmann@27681
   394
      >> (fn ((name, (expr, elems)), begin) =>
wenzelm@21843
   395
          (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
haftmann@29358
   396
            (Expression.add_locale_cmd name name expr elems #> snd)));
ballarin@28085
   397
wenzelm@24868
   398
val _ =
ballarin@28895
   399
  OuterSyntax.command "sublocale"
ballarin@28895
   400
    "prove sublocale relation between a locale and a locale expression" K.thy_goal
ballarin@29033
   401
    (P.xname --| (P.$$$ "\\<subseteq>" || P.$$$ "<") -- P.!!! SpecParse.locale_expression
ballarin@28895
   402
      >> (fn (loc, expr) =>
ballarin@28951
   403
        Toplevel.print o (Toplevel.theory_to_proof (Expression.sublocale_cmd loc expr))));
ballarin@28895
   404
ballarin@28895
   405
val _ =
ballarin@15598
   406
  OuterSyntax.command "interpretation"
ballarin@29223
   407
    "prove interpretation of locale expression in theory" K.thy_goal
ballarin@29225
   408
    (P.!!! SpecParse.locale_expression --
ballarin@29225
   409
      Scan.optional (P.$$$ "where" |-- P.and_list1 (SpecParse.opt_thm_name ":" -- P.prop)) []
ballarin@29225
   410
        >> (fn (expr, equations) => Toplevel.print o
ballarin@29225
   411
            Toplevel.theory_to_proof (Expression.interpretation_cmd expr equations)));
ballarin@29223
   412
ballarin@29223
   413
val _ =
ballarin@29223
   414
  OuterSyntax.command "interpret"
ballarin@29223
   415
    "prove interpretation of locale expression in proof context"
ballarin@29223
   416
    (K.tag_proof K.prf_goal)
ballarin@29223
   417
    (P.!!! SpecParse.locale_expression
ballarin@29223
   418
        >> (fn expr => Toplevel.print o
ballarin@29223
   419
            Toplevel.proof' (fn int => Expression.interpret_cmd expr int)));
ballarin@29223
   420
ballarin@29223
   421
local
ballarin@29223
   422
ballarin@29223
   423
val opt_prefix = Scan.optional (P.binding --| P.$$$ ":") Binding.empty;
ballarin@29223
   424
ballarin@29223
   425
in
ballarin@29223
   426
ballarin@29223
   427
val locale_val =
ballarin@29223
   428
  SpecParse.locale_expr --
ballarin@29223
   429
    Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
haftmann@29360
   430
  Scan.repeat1 SpecParse.context_element >> pair Old_Locale.empty;
ballarin@29223
   431
ballarin@29223
   432
val _ =
ballarin@29223
   433
  OuterSyntax.command "class_locale" "define named proof context based on classes" K.thy_decl
haftmann@29360
   434
    (P.name -- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (Old_Locale.empty, []) -- P.opt_begin
ballarin@29223
   435
      >> (fn ((name, (expr, elems)), begin) =>
ballarin@29223
   436
          (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
haftmann@29360
   437
            (Old_Locale.add_locale_cmd name expr elems #-> TheoryTarget.begin)));
ballarin@29223
   438
ballarin@29223
   439
val _ =
ballarin@29223
   440
  OuterSyntax.command "class_interpretation"
ballarin@16736
   441
    "prove and register interpretation of locale expression in theory or locale" K.thy_goal
wenzelm@22117
   442
    (P.xname --| (P.$$$ "\\<subseteq>" || P.$$$ "<") -- P.!!! SpecParse.locale_expr
haftmann@29360
   443
      >> (Toplevel.print oo (Toplevel.theory_to_proof o Old_Locale.interpretation_in_locale I)) ||
ballarin@28085
   444
      opt_prefix  -- SpecParse.locale_expr -- SpecParse.locale_insts
ballarin@28085
   445
        >> (fn ((name, expr), insts) => Toplevel.print o
wenzelm@28083
   446
            Toplevel.theory_to_proof
haftmann@29360
   447
              (Old_Locale.interpretation_cmd (Binding.base_name name) expr insts)));
wenzelm@12061
   448
wenzelm@24868
   449
val _ =
ballarin@29223
   450
  OuterSyntax.command "class_interpret"
wenzelm@17068
   451
    "prove and register interpretation of locale expression in proof context"
wenzelm@17068
   452
    (K.tag_proof K.prf_goal)
ballarin@28085
   453
    (opt_prefix -- SpecParse.locale_expr -- SpecParse.locale_insts
ballarin@28085
   454
      >> (fn ((name, expr), insts) => Toplevel.print o
wenzelm@28083
   455
          Toplevel.proof'
haftmann@29360
   456
            (fn int => Old_Locale.interpret_cmd (Binding.base_name name) expr insts int)));
wenzelm@15703
   457
ballarin@29223
   458
end;
ballarin@29223
   459
wenzelm@15703
   460
haftmann@22299
   461
(* classes *)
haftmann@22299
   462
wenzelm@24868
   463
val class_val =
wenzelm@24868
   464
  SpecParse.class_expr --
haftmann@26248
   465
    Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
haftmann@26248
   466
  Scan.repeat1 SpecParse.context_element >> pair [];
haftmann@22299
   467
wenzelm@24868
   468
val _ =
wenzelm@24868
   469
  OuterSyntax.command "class" "define type class" K.thy_decl
haftmann@26516
   470
   (P.name -- (P.$$$ "=" |-- class_val) -- P.opt_begin
haftmann@26516
   471
    >> (fn ((name, (supclasses, elems)), begin) =>
wenzelm@24938
   472
        (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
haftmann@29378
   473
          (Class.class_cmd name supclasses elems #> snd)));
haftmann@22299
   474
wenzelm@24868
   475
val _ =
wenzelm@26988
   476
  OuterSyntax.local_theory_to_proof "subclass" "prove a subclass relation" K.thy_goal
haftmann@29358
   477
    (P.xname >> Class.subclass_cmd);
haftmann@24914
   478
haftmann@24914
   479
val _ =
haftmann@25519
   480
  OuterSyntax.command "instantiation" "instantiate and prove type arity" K.thy_decl
haftmann@25536
   481
   (P.multi_arity --| P.begin
haftmann@25462
   482
     >> (fn arities => Toplevel.print o
haftmann@29358
   483
         Toplevel.begin_local_theory true (TheoryTarget.instantiation_cmd arities)));
haftmann@24589
   484
haftmann@25485
   485
val _ =
haftmann@25485
   486
  OuterSyntax.command "instance" "prove type arity or subclass relation" K.thy_goal
haftmann@25485
   487
  ((P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) >> Class.classrel_cmd ||
haftmann@27113
   488
    P.arity >> Class.instance_arity_cmd)
haftmann@25485
   489
    >> (Toplevel.print oo Toplevel.theory_to_proof)
haftmann@25485
   490
  || Scan.succeed (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
haftmann@22299
   491
haftmann@22299
   492
haftmann@25519
   493
(* arbitrary overloading *)
haftmann@25519
   494
haftmann@25519
   495
val _ =
haftmann@25519
   496
  OuterSyntax.command "overloading" "overloaded definitions" K.thy_decl
haftmann@25861
   497
   (Scan.repeat1 (P.name --| (P.$$$ "\\<equiv>" || P.$$$ "==") -- P.term --
wenzelm@26048
   498
      Scan.optional (P.$$$ "(" |-- (P.$$$ "unchecked" >> K false) --| P.$$$ ")") true
wenzelm@26048
   499
      >> P.triple1) --| P.begin
haftmann@25519
   500
   >> (fn operations => Toplevel.print o
haftmann@25519
   501
         Toplevel.begin_local_theory true (TheoryTarget.overloading_cmd operations)));
haftmann@25519
   502
haftmann@25519
   503
wenzelm@22866
   504
(* code generation *)
wenzelm@22866
   505
wenzelm@24868
   506
val _ =
wenzelm@22866
   507
  OuterSyntax.command "code_datatype" "define set of code datatype constructors" K.thy_decl
haftmann@24423
   508
    (Scan.repeat1 P.term >> (Toplevel.theory o Code.add_datatype_cmd));
wenzelm@22866
   509
wenzelm@22866
   510
wenzelm@5832
   511
wenzelm@5832
   512
(** proof commands **)
wenzelm@5832
   513
wenzelm@5832
   514
(* statements *)
wenzelm@5832
   515
wenzelm@17353
   516
fun gen_theorem kind =
wenzelm@26988
   517
  OuterSyntax.local_theory_to_proof' kind ("state " ^ kind) K.thy_goal
wenzelm@26988
   518
    (Scan.optional (SpecParse.opt_thm_name ":" --|
haftmann@28965
   519
      Scan.ahead (SpecParse.locale_keyword || SpecParse.statement_keyword)) Attrib.empty_binding --
wenzelm@26988
   520
      SpecParse.general_statement >> (fn (a, (elems, concl)) =>
wenzelm@26988
   521
        (Specification.theorem_cmd kind NONE (K I) a elems concl)));
wenzelm@5832
   522
wenzelm@24868
   523
val _ = gen_theorem Thm.theoremK;
wenzelm@24868
   524
val _ = gen_theorem Thm.lemmaK;
wenzelm@24868
   525
val _ = gen_theorem Thm.corollaryK;
wenzelm@5832
   526
wenzelm@24868
   527
val _ =
wenzelm@17353
   528
  OuterSyntax.command "have" "state local goal"
wenzelm@17353
   529
    (K.tag_proof K.prf_goal)
wenzelm@22117
   530
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.have));
wenzelm@17353
   531
wenzelm@24868
   532
val _ =
wenzelm@17353
   533
  OuterSyntax.command "hence" "abbreviates \"then have\""
wenzelm@17353
   534
    (K.tag_proof K.prf_goal)
wenzelm@22117
   535
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.hence));
wenzelm@17353
   536
wenzelm@24868
   537
val _ =
wenzelm@17068
   538
  OuterSyntax.command "show" "state local goal, solving current obligation"
wenzelm@21800
   539
    (K.tag_proof K.prf_asm_goal)
wenzelm@22117
   540
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.show));
wenzelm@5832
   541
wenzelm@24868
   542
val _ =
wenzelm@17068
   543
  OuterSyntax.command "thus" "abbreviates \"then show\""
wenzelm@21800
   544
    (K.tag_proof K.prf_asm_goal)
wenzelm@22117
   545
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.thus));
wenzelm@6501
   546
wenzelm@5832
   547
wenzelm@5914
   548
(* facts *)
wenzelm@5832
   549
wenzelm@22117
   550
val facts = P.and_list1 SpecParse.xthms1;
wenzelm@9197
   551
wenzelm@24868
   552
val _ =
wenzelm@17068
   553
  OuterSyntax.command "then" "forward chaining"
wenzelm@17068
   554
    (K.tag_proof K.prf_chain)
wenzelm@17900
   555
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
wenzelm@5832
   556
wenzelm@24868
   557
val _ =
wenzelm@17068
   558
  OuterSyntax.command "from" "forward chaining from given facts"
wenzelm@17068
   559
    (K.tag_proof K.prf_chain)
wenzelm@17900
   560
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss)));
wenzelm@5914
   561
wenzelm@24868
   562
val _ =
wenzelm@17068
   563
  OuterSyntax.command "with" "forward chaining from given and current facts"
wenzelm@17068
   564
    (K.tag_proof K.prf_chain)
wenzelm@17900
   565
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss)));
wenzelm@6878
   566
wenzelm@24868
   567
val _ =
wenzelm@17068
   568
  OuterSyntax.command "note" "define facts"
wenzelm@17068
   569
    (K.tag_proof K.prf_decl)
wenzelm@22117
   570
    (SpecParse.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss)));
wenzelm@5832
   571
wenzelm@24868
   572
val _ =
wenzelm@17068
   573
  OuterSyntax.command "using" "augment goal facts"
wenzelm@17068
   574
    (K.tag_proof K.prf_decl)
wenzelm@18544
   575
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using)));
wenzelm@18544
   576
wenzelm@24868
   577
val _ =
wenzelm@18544
   578
  OuterSyntax.command "unfolding" "unfold definitions in goal and facts"
wenzelm@18544
   579
    (K.tag_proof K.prf_decl)
wenzelm@18544
   580
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding)));
wenzelm@12926
   581
wenzelm@5832
   582
wenzelm@5832
   583
(* proof context *)
wenzelm@5832
   584
wenzelm@24868
   585
val _ =
wenzelm@17068
   586
  OuterSyntax.command "fix" "fix local variables (Skolem constants)"
wenzelm@17068
   587
    (K.tag_proof K.prf_asm)
wenzelm@19844
   588
    (P.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix)));
wenzelm@11890
   589
wenzelm@24868
   590
val _ =
wenzelm@17068
   591
  OuterSyntax.command "assume" "assume propositions"
wenzelm@17068
   592
    (K.tag_proof K.prf_asm)
wenzelm@22117
   593
    (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume)));
wenzelm@5832
   594
wenzelm@24868
   595
val _ =
wenzelm@17068
   596
  OuterSyntax.command "presume" "assume propositions, to be established later"
wenzelm@17068
   597
    (K.tag_proof K.prf_asm)
wenzelm@22117
   598
    (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume)));
wenzelm@6850
   599
wenzelm@24868
   600
val _ =
wenzelm@17068
   601
  OuterSyntax.command "def" "local definition"
wenzelm@17068
   602
    (K.tag_proof K.prf_asm)
wenzelm@18308
   603
    (P.and_list1
wenzelm@22117
   604
      (SpecParse.opt_thm_name ":" --
wenzelm@28083
   605
        ((P.binding -- P.opt_mixfix) -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp)))
wenzelm@18308
   606
    >> (Toplevel.print oo (Toplevel.proof o Proof.def)));
wenzelm@6953
   607
wenzelm@24868
   608
val _ =
wenzelm@11890
   609
  OuterSyntax.command "obtain" "generalized existence"
wenzelm@17068
   610
    (K.tag_proof K.prf_asm_goal)
wenzelm@22117
   611
    (P.parname -- Scan.optional (P.fixes --| P.where_) [] -- SpecParse.statement
wenzelm@18895
   612
      >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain x y z)));
wenzelm@5832
   613
wenzelm@24868
   614
val _ =
wenzelm@17854
   615
  OuterSyntax.command "guess" "wild guessing (unstructured)"
wenzelm@17854
   616
    (K.tag_proof K.prf_asm_goal)
wenzelm@19844
   617
    (Scan.optional P.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess)));
wenzelm@17854
   618
wenzelm@24868
   619
val _ =
wenzelm@17068
   620
  OuterSyntax.command "let" "bind text variables"
wenzelm@17068
   621
    (K.tag_proof K.prf_decl)
wenzelm@27378
   622
    (P.and_list1 (P.and_list1 P.term -- (P.$$$ "=" |-- P.term))
wenzelm@17900
   623
      >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind)));
wenzelm@5832
   624
wenzelm@11793
   625
val case_spec =
wenzelm@15703
   626
  (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 (P.maybe P.name) --| P.$$$ ")") ||
wenzelm@22117
   627
    P.xname >> rpair []) -- SpecParse.opt_attribs >> P.triple1;
wenzelm@11793
   628
wenzelm@24868
   629
val _ =
wenzelm@17068
   630
  OuterSyntax.command "case" "invoke local context"
wenzelm@17068
   631
    (K.tag_proof K.prf_asm)
wenzelm@17900
   632
    (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case)));
wenzelm@8370
   633
wenzelm@5832
   634
wenzelm@5832
   635
(* proof structure *)
wenzelm@5832
   636
wenzelm@24868
   637
val _ =
wenzelm@17068
   638
  OuterSyntax.command "{" "begin explicit proof block"
wenzelm@17068
   639
    (K.tag_proof K.prf_open)
wenzelm@17900
   640
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
wenzelm@5832
   641
wenzelm@24868
   642
val _ =
wenzelm@17068
   643
  OuterSyntax.command "}" "end explicit proof block"
wenzelm@17068
   644
    (K.tag_proof K.prf_close)
wenzelm@20305
   645
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
wenzelm@6687
   646
wenzelm@24868
   647
val _ =
wenzelm@17068
   648
  OuterSyntax.command "next" "enter next proof block"
wenzelm@17068
   649
    (K.tag_proof K.prf_block)
wenzelm@17900
   650
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
wenzelm@5832
   651
wenzelm@5832
   652
wenzelm@5832
   653
(* end proof *)
wenzelm@5832
   654
wenzelm@24868
   655
val _ =
wenzelm@17068
   656
  OuterSyntax.command "qed" "conclude (sub-)proof"
wenzelm@17068
   657
    (K.tag_proof K.qed_block)
wenzelm@26676
   658
    (Scan.option Method.parse >> IsarCmd.qed);
wenzelm@5832
   659
wenzelm@24868
   660
val _ =
wenzelm@17068
   661
  OuterSyntax.command "by" "terminal backward proof"
wenzelm@17068
   662
    (K.tag_proof K.qed)
wenzelm@26676
   663
    (Method.parse -- Scan.option Method.parse >> IsarCmd.terminal_proof);
wenzelm@6404
   664
wenzelm@24868
   665
val _ =
wenzelm@17068
   666
  OuterSyntax.command ".." "default proof"
wenzelm@17068
   667
    (K.tag_proof K.qed)
wenzelm@26676
   668
    (Scan.succeed IsarCmd.default_proof);
wenzelm@8966
   669
wenzelm@24868
   670
val _ =
wenzelm@17068
   671
  OuterSyntax.command "." "immediate proof"
wenzelm@17068
   672
    (K.tag_proof K.qed)
wenzelm@26676
   673
    (Scan.succeed IsarCmd.immediate_proof);
wenzelm@6404
   674
wenzelm@24868
   675
val _ =
wenzelm@17068
   676
  OuterSyntax.command "done" "done proof"
wenzelm@17068
   677
    (K.tag_proof K.qed)
wenzelm@26676
   678
    (Scan.succeed IsarCmd.done_proof);
wenzelm@5832
   679
wenzelm@24868
   680
val _ =
wenzelm@25108
   681
  OuterSyntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
wenzelm@17068
   682
    (K.tag_proof K.qed)
wenzelm@26676
   683
    (Scan.succeed IsarCmd.skip_proof);
wenzelm@6888
   684
wenzelm@24868
   685
val _ =
wenzelm@17068
   686
  OuterSyntax.command "oops" "forget proof"
wenzelm@17068
   687
    (K.tag_proof K.qed_global)
wenzelm@18561
   688
    (Scan.succeed Toplevel.forget_proof);
wenzelm@8210
   689
wenzelm@5832
   690
wenzelm@5832
   691
(* proof steps *)
wenzelm@5832
   692
wenzelm@24868
   693
val _ =
wenzelm@17068
   694
  OuterSyntax.command "defer" "shuffle internal proof state"
wenzelm@17068
   695
    (K.tag_proof K.prf_script)
wenzelm@17900
   696
    (Scan.option P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
wenzelm@8165
   697
wenzelm@24868
   698
val _ =
wenzelm@17068
   699
  OuterSyntax.command "prefer" "shuffle internal proof state"
wenzelm@17068
   700
    (K.tag_proof K.prf_script)
wenzelm@17900
   701
    (P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
wenzelm@8165
   702
wenzelm@24868
   703
val _ =
wenzelm@17068
   704
  OuterSyntax.command "apply" "initial refinement step (unstructured)"
wenzelm@17068
   705
    (K.tag_proof K.prf_script)
wenzelm@22117
   706
    (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
wenzelm@5832
   707
wenzelm@24868
   708
val _ =
wenzelm@17068
   709
  OuterSyntax.command "apply_end" "terminal refinement (unstructured)"
wenzelm@17068
   710
    (K.tag_proof K.prf_script)
wenzelm@22117
   711
    (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
wenzelm@5832
   712
wenzelm@24868
   713
val _ =
wenzelm@17068
   714
  OuterSyntax.command "proof" "backward proof"
wenzelm@17068
   715
    (K.tag_proof K.prf_block)
wenzelm@22117
   716
    (Scan.option Method.parse >> (fn m => Toplevel.print o
wenzelm@27563
   717
      Toplevel.actual_proof (ProofNode.applys (Proof.proof m)) o
wenzelm@27563
   718
      Toplevel.skip_proof (fn i => i + 1)));
wenzelm@5832
   719
wenzelm@5832
   720
wenzelm@6773
   721
(* calculational proof commands *)
wenzelm@6773
   722
wenzelm@6878
   723
val calc_args =
wenzelm@22117
   724
  Scan.option (P.$$$ "(" |-- P.!!! ((SpecParse.xthms1 --| P.$$$ ")")));
wenzelm@6878
   725
wenzelm@24868
   726
val _ =
wenzelm@17068
   727
  OuterSyntax.command "also" "combine calculation and current facts"
wenzelm@17068
   728
    (K.tag_proof K.prf_decl)
wenzelm@17900
   729
    (calc_args >> (Toplevel.proofs' o Calculation.also));
wenzelm@6773
   730
wenzelm@24868
   731
val _ =
wenzelm@17068
   732
  OuterSyntax.command "finally" "combine calculation and current facts, exhibit result"
wenzelm@17068
   733
    (K.tag_proof K.prf_chain)
wenzelm@22573
   734
    (calc_args >> (Toplevel.proofs' o Calculation.finally_));
wenzelm@6773
   735
wenzelm@24868
   736
val _ =
wenzelm@17068
   737
  OuterSyntax.command "moreover" "augment calculation by current facts"
wenzelm@17068
   738
    (K.tag_proof K.prf_decl)
wenzelm@17900
   739
    (Scan.succeed (Toplevel.proof' Calculation.moreover));
wenzelm@8562
   740
wenzelm@24868
   741
val _ =
wenzelm@8588
   742
  OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
wenzelm@17068
   743
    (K.tag_proof K.prf_chain)
wenzelm@17900
   744
    (Scan.succeed (Toplevel.proof' Calculation.ultimately));
wenzelm@8588
   745
wenzelm@6773
   746
wenzelm@6742
   747
(* proof navigation *)
wenzelm@5944
   748
wenzelm@24868
   749
val _ =
wenzelm@17068
   750
  OuterSyntax.command "back" "backtracking of proof command"
wenzelm@17068
   751
    (K.tag_proof K.prf_script)
wenzelm@27563
   752
    (Scan.succeed (Toplevel.print o Toplevel.actual_proof ProofNode.back o Toplevel.skip_proof I));
wenzelm@6742
   753
haftmann@22744
   754
wenzelm@27614
   755
(* nested commands *)
wenzelm@25578
   756
wenzelm@29309
   757
val props_text =
wenzelm@29309
   758
  Scan.optional ValueParse.properties [] -- P.position P.string >> (fn (props, (str, pos)) =>
wenzelm@29309
   759
    (Position.of_properties (Position.default_properties pos props), str));
wenzelm@29309
   760
wenzelm@25578
   761
val _ =
wenzelm@25578
   762
  OuterSyntax.improper_command "Isabelle.command" "nested Isabelle command" K.control
wenzelm@29309
   763
    (props_text :|-- (fn (pos, str) =>
wenzelm@27838
   764
      (case OuterSyntax.parse pos str of
wenzelm@27838
   765
        [tr] => Scan.succeed (K tr)
wenzelm@27838
   766
      | _ => Scan.fail_with (K "exactly one command expected"))
wenzelm@27838
   767
      handle ERROR msg => Scan.fail_with (K msg)));
wenzelm@25578
   768
wenzelm@25578
   769
wenzelm@27563
   770
(* global history commands *)
wenzelm@27525
   771
wenzelm@27525
   772
val _ =
wenzelm@27534
   773
  OuterSyntax.improper_command "init_toplevel" "init toplevel point-of-interest" K.control
wenzelm@29349
   774
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Isar.init));
wenzelm@27531
   775
wenzelm@27531
   776
val _ =
wenzelm@27534
   777
  OuterSyntax.improper_command "linear_undo" "undo commands" K.control
wenzelm@27529
   778
    (Scan.optional P.nat 1 >>
wenzelm@27529
   779
      (fn n => Toplevel.no_timing o Toplevel.imperative (fn () => Isar.linear_undo n)));
wenzelm@27529
   780
wenzelm@27529
   781
val _ =
wenzelm@27534
   782
  OuterSyntax.improper_command "undo" "undo commands (skipping closed proofs)" K.control
wenzelm@27525
   783
    (Scan.optional P.nat 1 >>
wenzelm@27525
   784
      (fn n => Toplevel.no_timing o Toplevel.imperative (fn () => Isar.undo n)));
wenzelm@27525
   785
wenzelm@27531
   786
val _ =
wenzelm@27534
   787
  OuterSyntax.improper_command "undos_proof" "undo commands (skipping closed proofs)" K.control
wenzelm@27534
   788
    (Scan.optional P.nat 1 >> (fn n => Toplevel.no_timing o
wenzelm@27534
   789
      Toplevel.keep (fn state =>
wenzelm@27534
   790
        if Toplevel.is_proof state then (Isar.undo n; Isar.print ()) else raise Toplevel.UNDEF)));
wenzelm@27534
   791
wenzelm@27534
   792
val _ =
wenzelm@27563
   793
  OuterSyntax.improper_command "cannot_undo" "partial undo -- Proof General legacy" K.control
wenzelm@27563
   794
    (P.name >>
wenzelm@27563
   795
      (fn "end" => Toplevel.no_timing o Toplevel.imperative (fn () => Isar.undo 1)
wenzelm@27563
   796
        | txt => Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt))));
wenzelm@27563
   797
wenzelm@27563
   798
val _ =
wenzelm@27534
   799
  OuterSyntax.improper_command "kill" "kill partial proof or theory development" K.control
wenzelm@27531
   800
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Isar.kill));
wenzelm@27531
   801
wenzelm@27525
   802
haftmann@22744
   803
wenzelm@5832
   804
(** diagnostic commands (for interactive mode only) **)
wenzelm@5832
   805
wenzelm@8464
   806
val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
wenzelm@20621
   807
val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
wenzelm@8464
   808
wenzelm@24868
   809
val _ =
wenzelm@7124
   810
  OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
wenzelm@9010
   811
    K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
wenzelm@7124
   812
wenzelm@24868
   813
val _ =
wenzelm@21714
   814
  OuterSyntax.improper_command "help" "print outer syntax commands" K.diag
wenzelm@24871
   815
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
wenzelm@21714
   816
wenzelm@24868
   817
val _ =
wenzelm@21714
   818
  OuterSyntax.improper_command "print_commands" "print outer syntax commands" K.diag
wenzelm@24871
   819
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
wenzelm@5832
   820
wenzelm@24868
   821
val _ =
wenzelm@24115
   822
  OuterSyntax.improper_command "print_configs" "print configuration options" K.diag
wenzelm@24115
   823
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_configs));
wenzelm@23989
   824
wenzelm@24868
   825
val _ =
wenzelm@7308
   826
  OuterSyntax.improper_command "print_context" "print theory context name" K.diag
wenzelm@9010
   827
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
wenzelm@7308
   828
wenzelm@24868
   829
val _ =
wenzelm@6723
   830
  OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
wenzelm@20621
   831
    (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theory));
wenzelm@5832
   832
wenzelm@24868
   833
val _ =
wenzelm@21726
   834
  OuterSyntax.improper_command "print_syntax" "print inner syntax of context (verbose!)" K.diag
wenzelm@9010
   835
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
wenzelm@5832
   836
wenzelm@24868
   837
val _ =
wenzelm@21726
   838
  OuterSyntax.improper_command "print_abbrevs" "print constant abbreviation of context" K.diag
wenzelm@21726
   839
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_abbrevs));
wenzelm@21726
   840
wenzelm@24868
   841
val _ =
wenzelm@17068
   842
  OuterSyntax.improper_command "print_theorems"
wenzelm@17068
   843
      "print theorems of local theory or proof context" K.diag
wenzelm@9010
   844
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theorems));
wenzelm@5881
   845
wenzelm@24868
   846
val _ =
wenzelm@12061
   847
  OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
wenzelm@12061
   848
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales));
wenzelm@12061
   849
wenzelm@24868
   850
val _ =
haftmann@22744
   851
  OuterSyntax.improper_command "print_classes" "print classes of this theory" K.diag
haftmann@22744
   852
    (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
haftmann@24219
   853
      o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
haftmann@22744
   854
wenzelm@24868
   855
val _ =
ballarin@15596
   856
  OuterSyntax.improper_command "print_locale" "print locale expression in this theory" K.diag
ballarin@29223
   857
    (opt_bang -- P.xname >> (Toplevel.no_timing oo IsarCmd.print_locale));
wenzelm@12061
   858
wenzelm@24868
   859
val _ =
ballarin@15598
   860
  OuterSyntax.improper_command "print_interps"
ballarin@16102
   861
    "print interpretations of named locale" K.diag
wenzelm@18670
   862
    (Scan.optional (P.$$$ "!" >> K true) false -- P.xname
wenzelm@18670
   863
      >> (Toplevel.no_timing oo uncurry IsarCmd.print_registrations));
ballarin@15596
   864
wenzelm@24868
   865
val _ =
wenzelm@12061
   866
  OuterSyntax.improper_command "print_attributes" "print attributes of this theory" K.diag
wenzelm@9010
   867
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
wenzelm@5832
   868
wenzelm@24868
   869
val _ =
wenzelm@16027
   870
  OuterSyntax.improper_command "print_simpset" "print context of Simplifier" K.diag
wenzelm@16027
   871
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_simpset));
wenzelm@16027
   872
wenzelm@24868
   873
val _ =
wenzelm@12383
   874
  OuterSyntax.improper_command "print_rules" "print intro/elim rules" K.diag
wenzelm@12383
   875
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules));
wenzelm@12383
   876
wenzelm@24868
   877
val _ =
wenzelm@11666
   878
  OuterSyntax.improper_command "print_trans_rules" "print transitivity rules" K.diag
wenzelm@9221
   879
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules));
wenzelm@9221
   880
wenzelm@24868
   881
val _ =
wenzelm@12061
   882
  OuterSyntax.improper_command "print_methods" "print methods of this theory" K.diag
wenzelm@9010
   883
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
wenzelm@5832
   884
wenzelm@24868
   885
val _ =
wenzelm@9221
   886
  OuterSyntax.improper_command "print_antiquotations" "print antiquotations (global)" K.diag
wenzelm@9221
   887
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations));
wenzelm@9221
   888
wenzelm@24868
   889
val _ =
haftmann@22485
   890
  OuterSyntax.improper_command "thy_deps" "visualize theory dependencies"
haftmann@22485
   891
    K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.thy_deps));
haftmann@22485
   892
wenzelm@24868
   893
val _ =
wenzelm@20574
   894
  OuterSyntax.improper_command "class_deps" "visualize class dependencies"
wenzelm@20574
   895
    K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
wenzelm@20574
   896
wenzelm@24868
   897
val _ =
wenzelm@9454
   898
  OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
wenzelm@22117
   899
    K.diag (SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
wenzelm@9454
   900
wenzelm@22866
   901
local
wenzelm@22866
   902
wenzelm@16027
   903
val criterion =
wenzelm@16027
   904
  P.reserved "name" |-- P.!!! (P.$$$ ":" |-- P.xname) >> FindTheorems.Name ||
wenzelm@16027
   905
  P.reserved "intro" >> K FindTheorems.Intro ||
wenzelm@16027
   906
  P.reserved "elim" >> K FindTheorems.Elim ||
wenzelm@16027
   907
  P.reserved "dest" >> K FindTheorems.Dest ||
kleing@16074
   908
  P.reserved "simp" |-- P.!!! (P.$$$ ":" |-- P.term) >> FindTheorems.Simp ||
wenzelm@16027
   909
  P.term >> FindTheorems.Pattern;
wenzelm@16027
   910
wenzelm@22866
   911
val options =
wenzelm@22866
   912
  Scan.optional
wenzelm@22866
   913
    (P.$$$ "(" |--
wenzelm@22866
   914
      P.!!! (Scan.option P.nat -- Scan.optional (P.reserved "with_dups" >> K false) true
wenzelm@22866
   915
        --| P.$$$ ")")) (NONE, true);
wenzelm@22866
   916
in
wenzelm@22866
   917
wenzelm@24868
   918
val _ =
wenzelm@22866
   919
  OuterSyntax.improper_command "find_theorems" "print theorems meeting specified criteria" K.diag
wenzelm@22866
   920
    (options -- Scan.repeat (((Scan.option P.minus >> is_none) -- criterion))
wenzelm@17219
   921
      >> (Toplevel.no_timing oo IsarCmd.find_theorems));
wenzelm@17219
   922
wenzelm@22866
   923
end;
wenzelm@22866
   924
wenzelm@24868
   925
val _ =
wenzelm@6723
   926
  OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
wenzelm@9010
   927
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
wenzelm@5832
   928
wenzelm@24868
   929
val _ =
wenzelm@8370
   930
  OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag
wenzelm@21004
   931
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_facts));
wenzelm@5832
   932
wenzelm@24868
   933
val _ =
wenzelm@8370
   934
  OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
wenzelm@9010
   935
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
wenzelm@8370
   936
wenzelm@24868
   937
val _ =
wenzelm@19269
   938
  OuterSyntax.improper_command "print_statement" "print theorems as long statements" K.diag
wenzelm@22117
   939
    (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_stmts));
wenzelm@19269
   940
wenzelm@24868
   941
val _ =
wenzelm@8464
   942
  OuterSyntax.improper_command "thm" "print theorems" K.diag
wenzelm@22117
   943
    (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
wenzelm@5832
   944
wenzelm@24868
   945
val _ =
berghofe@11524
   946
  OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
wenzelm@22866
   947
    (opt_modes -- Scan.option SpecParse.xthms1
wenzelm@22866
   948
      >> (Toplevel.no_timing oo IsarCmd.print_prfs false));
berghofe@11524
   949
wenzelm@24868
   950
val _ =
berghofe@11524
   951
  OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
wenzelm@22117
   952
    (opt_modes -- Scan.option SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true));
berghofe@11524
   953
wenzelm@24868
   954
val _ =
wenzelm@6723
   955
  OuterSyntax.improper_command "prop" "read and print proposition" K.diag
wenzelm@12876
   956
    (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
wenzelm@5832
   957
wenzelm@24868
   958
val _ =
wenzelm@6723
   959
  OuterSyntax.improper_command "term" "read and print term" K.diag
wenzelm@12876
   960
    (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term));
wenzelm@5832
   961
wenzelm@24868
   962
val _ =
wenzelm@6723
   963
  OuterSyntax.improper_command "typ" "read and print type" K.diag
wenzelm@12876
   964
    (opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
wenzelm@5832
   965
wenzelm@24868
   966
val _ =
haftmann@22744
   967
  OuterSyntax.improper_command "print_codesetup" "print code generator setup of this theory" K.diag
haftmann@22744
   968
    (Scan.succeed
haftmann@22744
   969
      (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
haftmann@24219
   970
        (Code.print_codesetup o Toplevel.theory_of)));
wenzelm@5832
   971
berghofe@26184
   972
val _ =
berghofe@26184
   973
  OuterSyntax.improper_command "unused_thms" "find unused theorems" K.diag
berghofe@26184
   974
    (Scan.option ((Scan.repeat1 (Scan.unless P.minus P.name) --| P.minus) --
berghofe@26184
   975
       Scan.option (Scan.repeat1 (Scan.unless P.minus P.name))) >>
berghofe@26184
   976
         (Toplevel.no_timing oo IsarCmd.unused_thms));
berghofe@26184
   977
wenzelm@5832
   978
wenzelm@5832
   979
(** system commands (for interactive mode only) **)
wenzelm@5832
   980
wenzelm@24868
   981
val _ =
wenzelm@8650
   982
  OuterSyntax.improper_command "cd" "change current working directory" K.diag
wenzelm@14950
   983
    (P.path >> (Toplevel.no_timing oo IsarCmd.cd));
wenzelm@5832
   984
wenzelm@24868
   985
val _ =
wenzelm@6723
   986
  OuterSyntax.improper_command "pwd" "print current working directory" K.diag
wenzelm@9010
   987
    (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
wenzelm@5832
   988
wenzelm@24868
   989
val _ =
wenzelm@6723
   990
  OuterSyntax.improper_command "use_thy" "use theory file" K.diag
wenzelm@26404
   991
    (P.name >> (fn name =>
wenzelm@26404
   992
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.use_thy name)));
wenzelm@5832
   993
wenzelm@24868
   994
val _ =
wenzelm@7102
   995
  OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
wenzelm@27494
   996
    (P.name >> (fn name =>
wenzelm@27494
   997
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.touch_thy name)));
wenzelm@7908
   998
wenzelm@24868
   999
val _ =
wenzelm@7102
  1000
  OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
wenzelm@27494
  1001
    (P.name >> (fn name =>
wenzelm@27494
  1002
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.remove_thy name)));
wenzelm@7102
  1003
wenzelm@24868
  1004
val _ =
wenzelm@7931
  1005
  OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
wenzelm@27494
  1006
    K.diag (P.name >> (fn name =>
wenzelm@27494
  1007
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.kill_thy name)));
wenzelm@7931
  1008
wenzelm@24868
  1009
val _ =
wenzelm@14934
  1010
  OuterSyntax.improper_command "display_drafts" "display raw source files with symbols"
wenzelm@14950
  1011
    K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.display_drafts));
wenzelm@14934
  1012
wenzelm@24868
  1013
val _ =
wenzelm@14934
  1014
  OuterSyntax.improper_command "print_drafts" "print raw source files with symbols"
wenzelm@14950
  1015
    K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.print_drafts));
wenzelm@14934
  1016
wenzelm@9731
  1017
val opt_limits =
wenzelm@9731
  1018
  Scan.option P.nat -- Scan.option (P.$$$ "," |-- P.!!! P.nat);
wenzelm@9731
  1019
wenzelm@24868
  1020
val _ =
wenzelm@8886
  1021
  OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag
wenzelm@9731
  1022
    (opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr));
wenzelm@7199
  1023
wenzelm@24868
  1024
val _ =
wenzelm@7222
  1025
  OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
wenzelm@9010
  1026
    (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
wenzelm@5832
  1027
wenzelm@24868
  1028
val _ =
wenzelm@7222
  1029
  OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
wenzelm@9010
  1030
    (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
wenzelm@7222
  1031
wenzelm@24868
  1032
val _ =
wenzelm@6723
  1033
  OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
wenzelm@26490
  1034
    (P.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
wenzelm@5832
  1035
wenzelm@24868
  1036
val _ =
wenzelm@6723
  1037
  OuterSyntax.improper_command "quit" "quit Isabelle" K.control
wenzelm@9010
  1038
    (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
wenzelm@5832
  1039
wenzelm@24868
  1040
val _ =
wenzelm@6723
  1041
  OuterSyntax.improper_command "exit" "exit Isar loop" K.control
wenzelm@9010
  1042
    (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
wenzelm@5832
  1043
wenzelm@24868
  1044
val _ =
wenzelm@8678
  1045
  OuterSyntax.improper_command "welcome" "print welcome message" K.diag
wenzelm@9010
  1046
    (Scan.succeed (Toplevel.no_timing o IsarCmd.welcome));
wenzelm@7462
  1047
wenzelm@5832
  1048
end;
wenzelm@27614
  1049