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