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