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