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