src/Pure/Isar/isar_syn.ML
author wenzelm
Sun Mar 01 23:36:12 2009 +0100 (2009-03-01)
changeset 30190 479806475f3c
parent 30189 3633f560f4c3
child 30242 aea5d7fa7ef5
permissions -rw-r--r--
use long names for old-style fold combinators;
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@11101
    89
    (Scan.repeat1 (P.name -- 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
haftmann@21462
   103
    (P.name -- 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@12876
   113
    (P.type_args -- P.name -- 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@12876
   119
      (P.type_args -- P.name -- (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@22796
   125
    K.thy_decl (Scan.repeat1 P.name >> (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@12876
   136
    (P.const >> (Toplevel.theory o ObjectLogic.add_judgment));
wenzelm@8227
   137
wenzelm@24868
   138
val _ =
wenzelm@6723
   139
  OuterSyntax.command "consts" "declare constants" K.thy_decl
wenzelm@22796
   140
    (Scan.repeat1 P.const >> (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@24868
   188
val _ =
wenzelm@6723
   189
  OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
wenzelm@22117
   190
    (Scan.repeat1 SpecParse.spec_name >> (Toplevel.theory o IsarCmd.add_axioms));
wenzelm@5832
   191
wenzelm@19631
   192
val opt_unchecked_overloaded =
wenzelm@19631
   193
  Scan.optional (P.$$$ "(" |-- P.!!!
wenzelm@19631
   194
    (((P.$$$ "unchecked" >> K true) -- Scan.optional (P.$$$ "overloaded" >> K true) false ||
wenzelm@19631
   195
      P.$$$ "overloaded" >> K (false, true)) --| P.$$$ ")")) (false, false);
wenzelm@19631
   196
wenzelm@24868
   197
val _ =
wenzelm@6723
   198
  OuterSyntax.command "defs" "define constants" K.thy_decl
wenzelm@22117
   199
    (opt_unchecked_overloaded -- Scan.repeat1 SpecParse.spec_name
wenzelm@21350
   200
      >> (Toplevel.theory o IsarCmd.add_defs));
wenzelm@6370
   201
wenzelm@14642
   202
wenzelm@21601
   203
(* old constdefs *)
wenzelm@14642
   204
wenzelm@21601
   205
val old_constdecl =
wenzelm@28083
   206
  P.binding --| P.where_ >> (fn x => (x, NONE, NoSyn)) ||
wenzelm@28083
   207
  P.binding -- (P.$$$ "::" |-- P.!!! P.typ >> SOME) -- P.opt_mixfix'
wenzelm@21601
   208
    --| Scan.option P.where_ >> P.triple1 ||
wenzelm@28083
   209
  P.binding -- (P.mixfix >> pair NONE) --| Scan.option P.where_ >> P.triple2;
wenzelm@19076
   210
wenzelm@22117
   211
val old_constdef = Scan.option old_constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
wenzelm@14642
   212
wenzelm@19076
   213
val structs =
wenzelm@19076
   214
  Scan.optional ((P.$$$ "(" -- P.$$$ "structure") |-- P.!!! (P.simple_fixes --| P.$$$ ")")) [];
wenzelm@19076
   215
wenzelm@24868
   216
val _ =
wenzelm@19076
   217
  OuterSyntax.command "constdefs" "old-style constant definition" K.thy_decl
wenzelm@21601
   218
    (structs -- Scan.repeat1 old_constdef >> (Toplevel.theory o Constdefs.add_constdefs));
wenzelm@21601
   219
wenzelm@21601
   220
wenzelm@21601
   221
(* constant definitions and abbreviations *)
wenzelm@21601
   222
wenzelm@21601
   223
val constdecl =
wenzelm@28083
   224
  P.binding --
wenzelm@21601
   225
    (P.where_ >> K (NONE, NoSyn) ||
wenzelm@21601
   226
      P.$$$ "::" |-- P.!!! ((P.typ >> SOME) -- P.opt_mixfix' --| P.where_) ||
wenzelm@21601
   227
      Scan.ahead (P.$$$ "(") |-- P.!!! (P.mixfix' --| P.where_ >> pair NONE))
wenzelm@21601
   228
  >> P.triple2;
wenzelm@21601
   229
wenzelm@22117
   230
val constdef = Scan.option constdecl -- (SpecParse.opt_thm_name ":" -- P.prop);
wenzelm@5832
   231
wenzelm@24868
   232
val _ =
wenzelm@26988
   233
  OuterSyntax.local_theory "definition" "constant definition" K.thy_decl
wenzelm@26988
   234
    (constdef >> (fn args => #2 o Specification.definition_cmd args));
wenzelm@18780
   235
wenzelm@24868
   236
val _ =
wenzelm@26988
   237
  OuterSyntax.local_theory "abbreviation" "constant abbreviation" K.thy_decl
wenzelm@26988
   238
    (opt_mode -- (Scan.option constdecl -- P.prop)
wenzelm@26988
   239
    >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
wenzelm@19659
   240
wenzelm@24868
   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@26988
   257
      Scan.optional (P.where_ |-- P.!!! (P.and_list1 SpecParse.spec)) []
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@26988
   273
  OuterSyntax.local_theory "declare" "declare theorems (improper)" 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@24868
   288
val _ =
wenzelm@8723
   289
  OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
wenzelm@17397
   290
    ((P.opt_keyword "open" >> not) -- (P.name -- Scan.repeat1 P.xname) >>
wenzelm@26672
   291
      (Toplevel.theory o uncurry IsarCmd.hide_names));
wenzelm@5832
   292
wenzelm@5832
   293
wenzelm@5832
   294
(* use ML text *)
wenzelm@5832
   295
wenzelm@24868
   296
val _ =
wenzelm@26490
   297
  OuterSyntax.command "use" "eval ML text from file" (K.tag_ml K.thy_decl)
wenzelm@26490
   298
    (P.path >> (Toplevel.generic_theory o ThyInfo.exec_file false));
wenzelm@5832
   299
wenzelm@24868
   300
val _ =
wenzelm@28269
   301
  OuterSyntax.command "ML" "eval ML text within theory" (K.tag_ml K.thy_decl)
wenzelm@27877
   302
    (P.ML_source >> (fn (txt, pos) =>
wenzelm@26490
   303
      Toplevel.generic_theory (ML_Context.exec (fn () => ML_Context.eval true pos txt))));
wenzelm@7891
   304
wenzelm@24868
   305
val _ =
wenzelm@28269
   306
  OuterSyntax.command "ML_prf" "eval ML text within proof" (K.tag_proof K.prf_decl)
wenzelm@28269
   307
    (P.ML_source >> (fn (txt, pos) =>
wenzelm@28269
   308
      Toplevel.proof (Proof.map_context (Context.proof_map
wenzelm@28277
   309
        (ML_Context.exec (fn () => ML_Context.eval true pos txt))) #>
wenzelm@28277
   310
          (fn prf => Proof.map_contexts (ML_Context.inherit_env (Proof.context_of prf)) prf))));
wenzelm@28269
   311
wenzelm@28269
   312
val _ =
wenzelm@26396
   313
  OuterSyntax.command "ML_val" "eval ML text (diagnostic)" (K.tag_ml K.diag)
wenzelm@27877
   314
    (P.ML_source >> IsarCmd.ml_diag true);
wenzelm@26396
   315
wenzelm@26396
   316
val _ =
wenzelm@26396
   317
  OuterSyntax.command "ML_command" "silently eval ML text (diagnostic)" (K.tag_ml K.diag)
wenzelm@27877
   318
    (P.ML_source >> (Toplevel.no_timing oo IsarCmd.ml_diag false));
wenzelm@5832
   319
wenzelm@24868
   320
val _ =
wenzelm@17068
   321
  OuterSyntax.command "setup" "apply ML theory setup" (K.tag_ml K.thy_decl)
wenzelm@27877
   322
    (P.ML_source >> (Toplevel.theory o IsarCmd.generic_setup));
wenzelm@5832
   323
wenzelm@24868
   324
val _ =
wenzelm@17068
   325
  OuterSyntax.command "method_setup" "define proof method in ML" (K.tag_ml K.thy_decl)
wenzelm@27877
   326
    (P.name -- P.!!! (P.$$$ "=" |-- P.ML_source -- P.text)
wenzelm@26385
   327
    >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
wenzelm@9197
   328
wenzelm@24868
   329
val _ =
wenzelm@26988
   330
  OuterSyntax.local_theory "declaration" "generic ML declaration" (K.tag_ml K.thy_decl)
wenzelm@27877
   331
    (P.ML_source >> IsarCmd.declaration);
wenzelm@22088
   332
wenzelm@24868
   333
val _ =
wenzelm@26988
   334
  OuterSyntax.local_theory "simproc_setup" "define simproc in ML" (K.tag_ml K.thy_decl)
wenzelm@26988
   335
    (P.name -- (P.$$$ "(" |-- P.enum1 "|" P.term --| P.$$$ ")" --| P.$$$ "=") --
wenzelm@27877
   336
      P.ML_source -- Scan.optional (P.$$$ "identifier" |-- Scan.repeat1 P.xname) []
wenzelm@26988
   337
    >> (fn (((a, b), c), d) => IsarCmd.simproc_setup a b c d));
wenzelm@22202
   338
wenzelm@5832
   339
wenzelm@5832
   340
(* translation functions *)
wenzelm@5832
   341
wenzelm@27877
   342
val trfun = P.opt_keyword "advanced" -- P.ML_source;
wenzelm@14642
   343
wenzelm@24868
   344
val _ =
wenzelm@17068
   345
  OuterSyntax.command "parse_ast_translation" "install parse ast translation functions"
wenzelm@17068
   346
    (K.tag_ml K.thy_decl)
wenzelm@22117
   347
    (trfun >> (Toplevel.theory o IsarCmd.parse_ast_translation));
wenzelm@5832
   348
wenzelm@24868
   349
val _ =
wenzelm@17068
   350
  OuterSyntax.command "parse_translation" "install parse translation functions"
wenzelm@17068
   351
    (K.tag_ml K.thy_decl)
wenzelm@22117
   352
    (trfun >> (Toplevel.theory o IsarCmd.parse_translation));
wenzelm@5832
   353
wenzelm@24868
   354
val _ =
wenzelm@17068
   355
  OuterSyntax.command "print_translation" "install print translation functions"
wenzelm@17068
   356
    (K.tag_ml K.thy_decl)
wenzelm@22117
   357
    (trfun >> (Toplevel.theory o IsarCmd.print_translation));
wenzelm@5832
   358
wenzelm@24868
   359
val _ =
wenzelm@6370
   360
  OuterSyntax.command "typed_print_translation" "install typed print translation functions"
wenzelm@17068
   361
    (K.tag_ml K.thy_decl)
wenzelm@22117
   362
    (trfun >> (Toplevel.theory o IsarCmd.typed_print_translation));
wenzelm@5832
   363
wenzelm@24868
   364
val _ =
wenzelm@17068
   365
  OuterSyntax.command "print_ast_translation" "install print ast translation functions"
wenzelm@17068
   366
    (K.tag_ml K.thy_decl)
wenzelm@22117
   367
    (trfun >> (Toplevel.theory o IsarCmd.print_ast_translation));
wenzelm@5832
   368
wenzelm@5832
   369
wenzelm@5832
   370
(* oracles *)
wenzelm@5832
   371
wenzelm@24868
   372
val _ =
wenzelm@17068
   373
  OuterSyntax.command "oracle" "declare oracle" (K.tag_ml K.thy_decl)
wenzelm@28290
   374
    (P.name -- (P.$$$ "=" |-- P.ML_source) >> (fn (x, y) => Toplevel.theory (IsarCmd.oracle x y)));
wenzelm@5832
   375
wenzelm@5832
   376
wenzelm@21306
   377
(* local theories *)
wenzelm@21306
   378
wenzelm@24868
   379
val _ =
wenzelm@21306
   380
  OuterSyntax.command "context" "enter local theory context" K.thy_decl
wenzelm@21306
   381
    (P.name --| P.begin >> (fn name =>
wenzelm@25290
   382
      Toplevel.print o Toplevel.begin_local_theory true (TheoryTarget.context name)));
wenzelm@21306
   383
wenzelm@21306
   384
wenzelm@12061
   385
(* locales *)
wenzelm@12061
   386
wenzelm@12758
   387
val locale_val =
ballarin@29223
   388
  SpecParse.locale_expression --
wenzelm@22117
   389
    Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
ballarin@29223
   390
  Scan.repeat1 SpecParse.context_element >> pair ([], []);
wenzelm@12061
   391
wenzelm@24868
   392
val _ =
wenzelm@12061
   393
  OuterSyntax.command "locale" "define named proof context" K.thy_decl
ballarin@29223
   394
    (P.name -- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (([], []), []) -- P.opt_begin
haftmann@27681
   395
      >> (fn ((name, (expr, elems)), begin) =>
wenzelm@21843
   396
          (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
haftmann@29390
   397
            (Expression.add_locale_cmd name "" expr elems #> snd)));
ballarin@28085
   398
wenzelm@24868
   399
val _ =
ballarin@28895
   400
  OuterSyntax.command "sublocale"
ballarin@28895
   401
    "prove sublocale relation between a locale and a locale expression" K.thy_goal
ballarin@29033
   402
    (P.xname --| (P.$$$ "\\<subseteq>" || P.$$$ "<") -- P.!!! SpecParse.locale_expression
ballarin@28895
   403
      >> (fn (loc, expr) =>
ballarin@28951
   404
        Toplevel.print o (Toplevel.theory_to_proof (Expression.sublocale_cmd loc expr))));
ballarin@28895
   405
ballarin@28895
   406
val _ =
ballarin@15598
   407
  OuterSyntax.command "interpretation"
ballarin@29223
   408
    "prove interpretation of locale expression in theory" K.thy_goal
ballarin@29225
   409
    (P.!!! SpecParse.locale_expression --
ballarin@29225
   410
      Scan.optional (P.$$$ "where" |-- P.and_list1 (SpecParse.opt_thm_name ":" -- P.prop)) []
ballarin@29225
   411
        >> (fn (expr, equations) => Toplevel.print o
ballarin@29225
   412
            Toplevel.theory_to_proof (Expression.interpretation_cmd expr equations)));
ballarin@29223
   413
ballarin@29223
   414
val _ =
ballarin@29223
   415
  OuterSyntax.command "interpret"
ballarin@29223
   416
    "prove interpretation of locale expression in proof context"
ballarin@29223
   417
    (K.tag_proof K.prf_goal)
ballarin@29223
   418
    (P.!!! SpecParse.locale_expression
ballarin@29223
   419
        >> (fn expr => Toplevel.print o
ballarin@29223
   420
            Toplevel.proof' (fn int => Expression.interpret_cmd expr int)));
ballarin@29223
   421
wenzelm@15703
   422
haftmann@22299
   423
(* classes *)
haftmann@22299
   424
wenzelm@24868
   425
val class_val =
wenzelm@24868
   426
  SpecParse.class_expr --
haftmann@26248
   427
    Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
haftmann@26248
   428
  Scan.repeat1 SpecParse.context_element >> pair [];
haftmann@22299
   429
wenzelm@24868
   430
val _ =
wenzelm@24868
   431
  OuterSyntax.command "class" "define type class" K.thy_decl
haftmann@29610
   432
   (P.name -- Scan.optional (P.$$$ "=" |-- class_val) ([], []) -- P.opt_begin
haftmann@26516
   433
    >> (fn ((name, (supclasses, elems)), begin) =>
wenzelm@24938
   434
        (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
haftmann@29378
   435
          (Class.class_cmd name supclasses elems #> snd)));
haftmann@22299
   436
wenzelm@24868
   437
val _ =
wenzelm@26988
   438
  OuterSyntax.local_theory_to_proof "subclass" "prove a subclass relation" K.thy_goal
haftmann@29358
   439
    (P.xname >> Class.subclass_cmd);
haftmann@24914
   440
haftmann@24914
   441
val _ =
haftmann@25519
   442
  OuterSyntax.command "instantiation" "instantiate and prove type arity" K.thy_decl
haftmann@25536
   443
   (P.multi_arity --| P.begin
haftmann@25462
   444
     >> (fn arities => Toplevel.print o
haftmann@29358
   445
         Toplevel.begin_local_theory true (TheoryTarget.instantiation_cmd arities)));
haftmann@24589
   446
haftmann@25485
   447
val _ =
haftmann@25485
   448
  OuterSyntax.command "instance" "prove type arity or subclass relation" K.thy_goal
haftmann@25485
   449
  ((P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) >> Class.classrel_cmd ||
haftmann@27113
   450
    P.arity >> Class.instance_arity_cmd)
haftmann@25485
   451
    >> (Toplevel.print oo Toplevel.theory_to_proof)
haftmann@25485
   452
  || Scan.succeed (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
haftmann@22299
   453
haftmann@22299
   454
haftmann@25519
   455
(* arbitrary overloading *)
haftmann@25519
   456
haftmann@25519
   457
val _ =
haftmann@25519
   458
  OuterSyntax.command "overloading" "overloaded definitions" K.thy_decl
haftmann@25861
   459
   (Scan.repeat1 (P.name --| (P.$$$ "\\<equiv>" || P.$$$ "==") -- P.term --
wenzelm@26048
   460
      Scan.optional (P.$$$ "(" |-- (P.$$$ "unchecked" >> K false) --| P.$$$ ")") true
wenzelm@26048
   461
      >> P.triple1) --| P.begin
haftmann@25519
   462
   >> (fn operations => Toplevel.print o
haftmann@25519
   463
         Toplevel.begin_local_theory true (TheoryTarget.overloading_cmd operations)));
haftmann@25519
   464
haftmann@25519
   465
wenzelm@22866
   466
(* code generation *)
wenzelm@22866
   467
wenzelm@24868
   468
val _ =
wenzelm@22866
   469
  OuterSyntax.command "code_datatype" "define set of code datatype constructors" K.thy_decl
haftmann@24423
   470
    (Scan.repeat1 P.term >> (Toplevel.theory o Code.add_datatype_cmd));
wenzelm@22866
   471
wenzelm@22866
   472
wenzelm@5832
   473
wenzelm@5832
   474
(** proof commands **)
wenzelm@5832
   475
wenzelm@5832
   476
(* statements *)
wenzelm@5832
   477
wenzelm@17353
   478
fun gen_theorem kind =
wenzelm@26988
   479
  OuterSyntax.local_theory_to_proof' kind ("state " ^ kind) K.thy_goal
wenzelm@26988
   480
    (Scan.optional (SpecParse.opt_thm_name ":" --|
haftmann@28965
   481
      Scan.ahead (SpecParse.locale_keyword || SpecParse.statement_keyword)) Attrib.empty_binding --
wenzelm@26988
   482
      SpecParse.general_statement >> (fn (a, (elems, concl)) =>
wenzelm@26988
   483
        (Specification.theorem_cmd kind NONE (K I) a elems concl)));
wenzelm@5832
   484
wenzelm@24868
   485
val _ = gen_theorem Thm.theoremK;
wenzelm@24868
   486
val _ = gen_theorem Thm.lemmaK;
wenzelm@24868
   487
val _ = gen_theorem Thm.corollaryK;
wenzelm@5832
   488
wenzelm@24868
   489
val _ =
wenzelm@17353
   490
  OuterSyntax.command "have" "state local goal"
wenzelm@17353
   491
    (K.tag_proof K.prf_goal)
wenzelm@22117
   492
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.have));
wenzelm@17353
   493
wenzelm@24868
   494
val _ =
wenzelm@17353
   495
  OuterSyntax.command "hence" "abbreviates \"then have\""
wenzelm@17353
   496
    (K.tag_proof K.prf_goal)
wenzelm@22117
   497
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.hence));
wenzelm@17353
   498
wenzelm@24868
   499
val _ =
wenzelm@17068
   500
  OuterSyntax.command "show" "state local goal, solving current obligation"
wenzelm@21800
   501
    (K.tag_proof K.prf_asm_goal)
wenzelm@22117
   502
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.show));
wenzelm@5832
   503
wenzelm@24868
   504
val _ =
wenzelm@17068
   505
  OuterSyntax.command "thus" "abbreviates \"then show\""
wenzelm@21800
   506
    (K.tag_proof K.prf_asm_goal)
wenzelm@22117
   507
    (SpecParse.statement >> ((Toplevel.print oo Toplevel.proof') o IsarCmd.thus));
wenzelm@6501
   508
wenzelm@5832
   509
wenzelm@5914
   510
(* facts *)
wenzelm@5832
   511
wenzelm@22117
   512
val facts = P.and_list1 SpecParse.xthms1;
wenzelm@9197
   513
wenzelm@24868
   514
val _ =
wenzelm@17068
   515
  OuterSyntax.command "then" "forward chaining"
wenzelm@17068
   516
    (K.tag_proof K.prf_chain)
wenzelm@17900
   517
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
wenzelm@5832
   518
wenzelm@24868
   519
val _ =
wenzelm@17068
   520
  OuterSyntax.command "from" "forward chaining from given facts"
wenzelm@17068
   521
    (K.tag_proof K.prf_chain)
wenzelm@17900
   522
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss)));
wenzelm@5914
   523
wenzelm@24868
   524
val _ =
wenzelm@17068
   525
  OuterSyntax.command "with" "forward chaining from given and current facts"
wenzelm@17068
   526
    (K.tag_proof K.prf_chain)
wenzelm@17900
   527
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss)));
wenzelm@6878
   528
wenzelm@24868
   529
val _ =
wenzelm@17068
   530
  OuterSyntax.command "note" "define facts"
wenzelm@17068
   531
    (K.tag_proof K.prf_decl)
wenzelm@22117
   532
    (SpecParse.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss)));
wenzelm@5832
   533
wenzelm@24868
   534
val _ =
wenzelm@17068
   535
  OuterSyntax.command "using" "augment goal facts"
wenzelm@17068
   536
    (K.tag_proof K.prf_decl)
wenzelm@18544
   537
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using)));
wenzelm@18544
   538
wenzelm@24868
   539
val _ =
wenzelm@18544
   540
  OuterSyntax.command "unfolding" "unfold definitions in goal and facts"
wenzelm@18544
   541
    (K.tag_proof K.prf_decl)
wenzelm@18544
   542
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding)));
wenzelm@12926
   543
wenzelm@5832
   544
wenzelm@5832
   545
(* proof context *)
wenzelm@5832
   546
wenzelm@24868
   547
val _ =
wenzelm@17068
   548
  OuterSyntax.command "fix" "fix local variables (Skolem constants)"
wenzelm@17068
   549
    (K.tag_proof K.prf_asm)
wenzelm@19844
   550
    (P.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix)));
wenzelm@11890
   551
wenzelm@24868
   552
val _ =
wenzelm@17068
   553
  OuterSyntax.command "assume" "assume propositions"
wenzelm@17068
   554
    (K.tag_proof K.prf_asm)
wenzelm@22117
   555
    (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume)));
wenzelm@5832
   556
wenzelm@24868
   557
val _ =
wenzelm@17068
   558
  OuterSyntax.command "presume" "assume propositions, to be established later"
wenzelm@17068
   559
    (K.tag_proof K.prf_asm)
wenzelm@22117
   560
    (SpecParse.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume)));
wenzelm@6850
   561
wenzelm@24868
   562
val _ =
wenzelm@17068
   563
  OuterSyntax.command "def" "local definition"
wenzelm@17068
   564
    (K.tag_proof K.prf_asm)
wenzelm@18308
   565
    (P.and_list1
wenzelm@22117
   566
      (SpecParse.opt_thm_name ":" --
wenzelm@28083
   567
        ((P.binding -- P.opt_mixfix) -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp)))
wenzelm@18308
   568
    >> (Toplevel.print oo (Toplevel.proof o Proof.def)));
wenzelm@6953
   569
wenzelm@24868
   570
val _ =
wenzelm@11890
   571
  OuterSyntax.command "obtain" "generalized existence"
wenzelm@17068
   572
    (K.tag_proof K.prf_asm_goal)
wenzelm@22117
   573
    (P.parname -- Scan.optional (P.fixes --| P.where_) [] -- SpecParse.statement
wenzelm@18895
   574
      >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain x y z)));
wenzelm@5832
   575
wenzelm@24868
   576
val _ =
wenzelm@17854
   577
  OuterSyntax.command "guess" "wild guessing (unstructured)"
wenzelm@17854
   578
    (K.tag_proof K.prf_asm_goal)
wenzelm@19844
   579
    (Scan.optional P.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess)));
wenzelm@17854
   580
wenzelm@24868
   581
val _ =
wenzelm@17068
   582
  OuterSyntax.command "let" "bind text variables"
wenzelm@17068
   583
    (K.tag_proof K.prf_decl)
wenzelm@27378
   584
    (P.and_list1 (P.and_list1 P.term -- (P.$$$ "=" |-- P.term))
wenzelm@17900
   585
      >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind)));
wenzelm@5832
   586
wenzelm@11793
   587
val case_spec =
wenzelm@15703
   588
  (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 (P.maybe P.name) --| P.$$$ ")") ||
wenzelm@22117
   589
    P.xname >> rpair []) -- SpecParse.opt_attribs >> P.triple1;
wenzelm@11793
   590
wenzelm@24868
   591
val _ =
wenzelm@17068
   592
  OuterSyntax.command "case" "invoke local context"
wenzelm@17068
   593
    (K.tag_proof K.prf_asm)
wenzelm@17900
   594
    (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case)));
wenzelm@8370
   595
wenzelm@5832
   596
wenzelm@5832
   597
(* proof structure *)
wenzelm@5832
   598
wenzelm@24868
   599
val _ =
wenzelm@17068
   600
  OuterSyntax.command "{" "begin explicit proof block"
wenzelm@17068
   601
    (K.tag_proof K.prf_open)
wenzelm@17900
   602
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
wenzelm@5832
   603
wenzelm@24868
   604
val _ =
wenzelm@17068
   605
  OuterSyntax.command "}" "end explicit proof block"
wenzelm@17068
   606
    (K.tag_proof K.prf_close)
wenzelm@20305
   607
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
wenzelm@6687
   608
wenzelm@24868
   609
val _ =
wenzelm@17068
   610
  OuterSyntax.command "next" "enter next proof block"
wenzelm@17068
   611
    (K.tag_proof K.prf_block)
wenzelm@17900
   612
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
wenzelm@5832
   613
wenzelm@5832
   614
wenzelm@5832
   615
(* end proof *)
wenzelm@5832
   616
wenzelm@24868
   617
val _ =
wenzelm@17068
   618
  OuterSyntax.command "qed" "conclude (sub-)proof"
wenzelm@17068
   619
    (K.tag_proof K.qed_block)
wenzelm@26676
   620
    (Scan.option Method.parse >> IsarCmd.qed);
wenzelm@5832
   621
wenzelm@24868
   622
val _ =
wenzelm@17068
   623
  OuterSyntax.command "by" "terminal backward proof"
wenzelm@17068
   624
    (K.tag_proof K.qed)
wenzelm@26676
   625
    (Method.parse -- Scan.option Method.parse >> IsarCmd.terminal_proof);
wenzelm@6404
   626
wenzelm@24868
   627
val _ =
wenzelm@17068
   628
  OuterSyntax.command ".." "default proof"
wenzelm@17068
   629
    (K.tag_proof K.qed)
wenzelm@26676
   630
    (Scan.succeed IsarCmd.default_proof);
wenzelm@8966
   631
wenzelm@24868
   632
val _ =
wenzelm@17068
   633
  OuterSyntax.command "." "immediate proof"
wenzelm@17068
   634
    (K.tag_proof K.qed)
wenzelm@26676
   635
    (Scan.succeed IsarCmd.immediate_proof);
wenzelm@6404
   636
wenzelm@24868
   637
val _ =
wenzelm@17068
   638
  OuterSyntax.command "done" "done proof"
wenzelm@17068
   639
    (K.tag_proof K.qed)
wenzelm@26676
   640
    (Scan.succeed IsarCmd.done_proof);
wenzelm@5832
   641
wenzelm@24868
   642
val _ =
wenzelm@25108
   643
  OuterSyntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
wenzelm@17068
   644
    (K.tag_proof K.qed)
wenzelm@26676
   645
    (Scan.succeed IsarCmd.skip_proof);
wenzelm@6888
   646
wenzelm@24868
   647
val _ =
wenzelm@17068
   648
  OuterSyntax.command "oops" "forget proof"
wenzelm@17068
   649
    (K.tag_proof K.qed_global)
wenzelm@18561
   650
    (Scan.succeed Toplevel.forget_proof);
wenzelm@8210
   651
wenzelm@5832
   652
wenzelm@5832
   653
(* proof steps *)
wenzelm@5832
   654
wenzelm@24868
   655
val _ =
wenzelm@17068
   656
  OuterSyntax.command "defer" "shuffle internal proof state"
wenzelm@17068
   657
    (K.tag_proof K.prf_script)
wenzelm@17900
   658
    (Scan.option P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
wenzelm@8165
   659
wenzelm@24868
   660
val _ =
wenzelm@17068
   661
  OuterSyntax.command "prefer" "shuffle internal proof state"
wenzelm@17068
   662
    (K.tag_proof K.prf_script)
wenzelm@17900
   663
    (P.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
wenzelm@8165
   664
wenzelm@24868
   665
val _ =
wenzelm@17068
   666
  OuterSyntax.command "apply" "initial refinement step (unstructured)"
wenzelm@17068
   667
    (K.tag_proof K.prf_script)
wenzelm@22117
   668
    (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
wenzelm@5832
   669
wenzelm@24868
   670
val _ =
wenzelm@17068
   671
  OuterSyntax.command "apply_end" "terminal refinement (unstructured)"
wenzelm@17068
   672
    (K.tag_proof K.prf_script)
wenzelm@22117
   673
    (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
wenzelm@5832
   674
wenzelm@24868
   675
val _ =
wenzelm@17068
   676
  OuterSyntax.command "proof" "backward proof"
wenzelm@17068
   677
    (K.tag_proof K.prf_block)
wenzelm@22117
   678
    (Scan.option Method.parse >> (fn m => Toplevel.print o
wenzelm@27563
   679
      Toplevel.actual_proof (ProofNode.applys (Proof.proof m)) o
wenzelm@27563
   680
      Toplevel.skip_proof (fn i => i + 1)));
wenzelm@5832
   681
wenzelm@5832
   682
wenzelm@6773
   683
(* calculational proof commands *)
wenzelm@6773
   684
wenzelm@6878
   685
val calc_args =
wenzelm@22117
   686
  Scan.option (P.$$$ "(" |-- P.!!! ((SpecParse.xthms1 --| P.$$$ ")")));
wenzelm@6878
   687
wenzelm@24868
   688
val _ =
wenzelm@17068
   689
  OuterSyntax.command "also" "combine calculation and current facts"
wenzelm@17068
   690
    (K.tag_proof K.prf_decl)
wenzelm@17900
   691
    (calc_args >> (Toplevel.proofs' o Calculation.also));
wenzelm@6773
   692
wenzelm@24868
   693
val _ =
wenzelm@17068
   694
  OuterSyntax.command "finally" "combine calculation and current facts, exhibit result"
wenzelm@17068
   695
    (K.tag_proof K.prf_chain)
wenzelm@30189
   696
    (calc_args >> (Toplevel.proofs' o Calculation.finally));
wenzelm@6773
   697
wenzelm@24868
   698
val _ =
wenzelm@17068
   699
  OuterSyntax.command "moreover" "augment calculation by current facts"
wenzelm@17068
   700
    (K.tag_proof K.prf_decl)
wenzelm@17900
   701
    (Scan.succeed (Toplevel.proof' Calculation.moreover));
wenzelm@8562
   702
wenzelm@24868
   703
val _ =
wenzelm@8588
   704
  OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
wenzelm@17068
   705
    (K.tag_proof K.prf_chain)
wenzelm@17900
   706
    (Scan.succeed (Toplevel.proof' Calculation.ultimately));
wenzelm@8588
   707
wenzelm@6773
   708
wenzelm@6742
   709
(* proof navigation *)
wenzelm@5944
   710
wenzelm@24868
   711
val _ =
wenzelm@17068
   712
  OuterSyntax.command "back" "backtracking of proof command"
wenzelm@17068
   713
    (K.tag_proof K.prf_script)
wenzelm@27563
   714
    (Scan.succeed (Toplevel.print o Toplevel.actual_proof ProofNode.back o Toplevel.skip_proof I));
wenzelm@6742
   715
haftmann@22744
   716
wenzelm@27614
   717
(* nested commands *)
wenzelm@25578
   718
wenzelm@29309
   719
val props_text =
wenzelm@29309
   720
  Scan.optional ValueParse.properties [] -- P.position P.string >> (fn (props, (str, pos)) =>
wenzelm@29309
   721
    (Position.of_properties (Position.default_properties pos props), str));
wenzelm@29309
   722
wenzelm@25578
   723
val _ =
wenzelm@25578
   724
  OuterSyntax.improper_command "Isabelle.command" "nested Isabelle command" K.control
wenzelm@29309
   725
    (props_text :|-- (fn (pos, str) =>
wenzelm@27838
   726
      (case OuterSyntax.parse pos str of
wenzelm@27838
   727
        [tr] => Scan.succeed (K tr)
wenzelm@27838
   728
      | _ => Scan.fail_with (K "exactly one command expected"))
wenzelm@27838
   729
      handle ERROR msg => Scan.fail_with (K msg)));
wenzelm@25578
   730
wenzelm@25578
   731
haftmann@22744
   732
wenzelm@5832
   733
(** diagnostic commands (for interactive mode only) **)
wenzelm@5832
   734
wenzelm@8464
   735
val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
wenzelm@20621
   736
val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
wenzelm@8464
   737
wenzelm@24868
   738
val _ =
wenzelm@7124
   739
  OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
wenzelm@9010
   740
    K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
wenzelm@7124
   741
wenzelm@24868
   742
val _ =
wenzelm@21714
   743
  OuterSyntax.improper_command "help" "print outer syntax commands" K.diag
wenzelm@24871
   744
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
wenzelm@21714
   745
wenzelm@24868
   746
val _ =
wenzelm@21714
   747
  OuterSyntax.improper_command "print_commands" "print outer syntax commands" K.diag
wenzelm@24871
   748
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative OuterSyntax.print_outer_syntax));
wenzelm@5832
   749
wenzelm@24868
   750
val _ =
wenzelm@24115
   751
  OuterSyntax.improper_command "print_configs" "print configuration options" K.diag
wenzelm@24115
   752
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_configs));
wenzelm@23989
   753
wenzelm@24868
   754
val _ =
wenzelm@7308
   755
  OuterSyntax.improper_command "print_context" "print theory context name" K.diag
wenzelm@9010
   756
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
wenzelm@7308
   757
wenzelm@24868
   758
val _ =
wenzelm@6723
   759
  OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
wenzelm@20621
   760
    (opt_bang >> (Toplevel.no_timing oo IsarCmd.print_theory));
wenzelm@5832
   761
wenzelm@24868
   762
val _ =
wenzelm@21726
   763
  OuterSyntax.improper_command "print_syntax" "print inner syntax of context (verbose!)" K.diag
wenzelm@9010
   764
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
wenzelm@5832
   765
wenzelm@24868
   766
val _ =
wenzelm@21726
   767
  OuterSyntax.improper_command "print_abbrevs" "print constant abbreviation of context" K.diag
wenzelm@21726
   768
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_abbrevs));
wenzelm@21726
   769
wenzelm@24868
   770
val _ =
wenzelm@17068
   771
  OuterSyntax.improper_command "print_theorems"
wenzelm@17068
   772
      "print theorems of local theory or proof context" K.diag
wenzelm@9010
   773
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theorems));
wenzelm@5881
   774
wenzelm@24868
   775
val _ =
wenzelm@12061
   776
  OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
wenzelm@12061
   777
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales));
wenzelm@12061
   778
wenzelm@24868
   779
val _ =
haftmann@22744
   780
  OuterSyntax.improper_command "print_classes" "print classes of this theory" K.diag
haftmann@22744
   781
    (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory
haftmann@24219
   782
      o Toplevel.keep (Class.print_classes o Toplevel.theory_of)));
haftmann@22744
   783
wenzelm@24868
   784
val _ =
ballarin@15596
   785
  OuterSyntax.improper_command "print_locale" "print locale expression in this theory" K.diag
ballarin@29223
   786
    (opt_bang -- P.xname >> (Toplevel.no_timing oo IsarCmd.print_locale));
wenzelm@12061
   787
wenzelm@24868
   788
val _ =
wenzelm@12061
   789
  OuterSyntax.improper_command "print_attributes" "print attributes of this theory" K.diag
wenzelm@9010
   790
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
wenzelm@5832
   791
wenzelm@24868
   792
val _ =
wenzelm@16027
   793
  OuterSyntax.improper_command "print_simpset" "print context of Simplifier" K.diag
wenzelm@16027
   794
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_simpset));
wenzelm@16027
   795
wenzelm@24868
   796
val _ =
wenzelm@12383
   797
  OuterSyntax.improper_command "print_rules" "print intro/elim rules" K.diag
wenzelm@12383
   798
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules));
wenzelm@12383
   799
wenzelm@24868
   800
val _ =
wenzelm@11666
   801
  OuterSyntax.improper_command "print_trans_rules" "print transitivity rules" K.diag
wenzelm@9221
   802
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules));
wenzelm@9221
   803
wenzelm@24868
   804
val _ =
wenzelm@12061
   805
  OuterSyntax.improper_command "print_methods" "print methods of this theory" K.diag
wenzelm@9010
   806
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
wenzelm@5832
   807
wenzelm@24868
   808
val _ =
wenzelm@9221
   809
  OuterSyntax.improper_command "print_antiquotations" "print antiquotations (global)" K.diag
wenzelm@9221
   810
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations));
wenzelm@9221
   811
wenzelm@24868
   812
val _ =
haftmann@22485
   813
  OuterSyntax.improper_command "thy_deps" "visualize theory dependencies"
haftmann@22485
   814
    K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.thy_deps));
haftmann@22485
   815
wenzelm@24868
   816
val _ =
wenzelm@20574
   817
  OuterSyntax.improper_command "class_deps" "visualize class dependencies"
wenzelm@20574
   818
    K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
wenzelm@20574
   819
wenzelm@24868
   820
val _ =
wenzelm@9454
   821
  OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
wenzelm@22117
   822
    K.diag (SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
wenzelm@9454
   823
wenzelm@24868
   824
val _ =
wenzelm@6723
   825
  OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
wenzelm@9010
   826
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
wenzelm@5832
   827
wenzelm@24868
   828
val _ =
wenzelm@8370
   829
  OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag
wenzelm@21004
   830
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_facts));
wenzelm@5832
   831
wenzelm@24868
   832
val _ =
wenzelm@8370
   833
  OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
wenzelm@9010
   834
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
wenzelm@8370
   835
wenzelm@24868
   836
val _ =
wenzelm@19269
   837
  OuterSyntax.improper_command "print_statement" "print theorems as long statements" K.diag
wenzelm@22117
   838
    (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_stmts));
wenzelm@19269
   839
wenzelm@24868
   840
val _ =
wenzelm@8464
   841
  OuterSyntax.improper_command "thm" "print theorems" K.diag
wenzelm@22117
   842
    (opt_modes -- SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
wenzelm@5832
   843
wenzelm@24868
   844
val _ =
berghofe@11524
   845
  OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
wenzelm@22866
   846
    (opt_modes -- Scan.option SpecParse.xthms1
wenzelm@22866
   847
      >> (Toplevel.no_timing oo IsarCmd.print_prfs false));
berghofe@11524
   848
wenzelm@24868
   849
val _ =
berghofe@11524
   850
  OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
wenzelm@22117
   851
    (opt_modes -- Scan.option SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true));
berghofe@11524
   852
wenzelm@24868
   853
val _ =
wenzelm@6723
   854
  OuterSyntax.improper_command "prop" "read and print proposition" K.diag
wenzelm@12876
   855
    (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
wenzelm@5832
   856
wenzelm@24868
   857
val _ =
wenzelm@6723
   858
  OuterSyntax.improper_command "term" "read and print term" K.diag
wenzelm@12876
   859
    (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term));
wenzelm@5832
   860
wenzelm@24868
   861
val _ =
wenzelm@6723
   862
  OuterSyntax.improper_command "typ" "read and print type" K.diag
wenzelm@12876
   863
    (opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
wenzelm@5832
   864
wenzelm@24868
   865
val _ =
haftmann@22744
   866
  OuterSyntax.improper_command "print_codesetup" "print code generator setup of this theory" K.diag
haftmann@22744
   867
    (Scan.succeed
haftmann@22744
   868
      (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
haftmann@24219
   869
        (Code.print_codesetup o Toplevel.theory_of)));
wenzelm@5832
   870
berghofe@26184
   871
val _ =
berghofe@26184
   872
  OuterSyntax.improper_command "unused_thms" "find unused theorems" K.diag
berghofe@26184
   873
    (Scan.option ((Scan.repeat1 (Scan.unless P.minus P.name) --| P.minus) --
berghofe@26184
   874
       Scan.option (Scan.repeat1 (Scan.unless P.minus P.name))) >>
berghofe@26184
   875
         (Toplevel.no_timing oo IsarCmd.unused_thms));
berghofe@26184
   876
wenzelm@5832
   877
wenzelm@30142
   878
wenzelm@5832
   879
(** system commands (for interactive mode only) **)
wenzelm@5832
   880
wenzelm@24868
   881
val _ =
wenzelm@8650
   882
  OuterSyntax.improper_command "cd" "change current working directory" K.diag
wenzelm@14950
   883
    (P.path >> (Toplevel.no_timing oo IsarCmd.cd));
wenzelm@5832
   884
wenzelm@24868
   885
val _ =
wenzelm@6723
   886
  OuterSyntax.improper_command "pwd" "print current working directory" K.diag
wenzelm@9010
   887
    (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
wenzelm@5832
   888
wenzelm@24868
   889
val _ =
wenzelm@6723
   890
  OuterSyntax.improper_command "use_thy" "use theory file" K.diag
wenzelm@26404
   891
    (P.name >> (fn name =>
wenzelm@26404
   892
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.use_thy name)));
wenzelm@5832
   893
wenzelm@24868
   894
val _ =
wenzelm@7102
   895
  OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
wenzelm@27494
   896
    (P.name >> (fn name =>
wenzelm@27494
   897
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.touch_thy name)));
wenzelm@7908
   898
wenzelm@24868
   899
val _ =
wenzelm@7102
   900
  OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
wenzelm@27494
   901
    (P.name >> (fn name =>
wenzelm@27494
   902
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.remove_thy name)));
wenzelm@7102
   903
wenzelm@24868
   904
val _ =
wenzelm@7931
   905
  OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
wenzelm@27494
   906
    K.diag (P.name >> (fn name =>
wenzelm@27494
   907
      Toplevel.no_timing o Toplevel.imperative (fn () => ThyInfo.kill_thy name)));
wenzelm@7931
   908
wenzelm@24868
   909
val _ =
wenzelm@14934
   910
  OuterSyntax.improper_command "display_drafts" "display raw source files with symbols"
wenzelm@14950
   911
    K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.display_drafts));
wenzelm@14934
   912
wenzelm@24868
   913
val _ =
wenzelm@14934
   914
  OuterSyntax.improper_command "print_drafts" "print raw source files with symbols"
wenzelm@14950
   915
    K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.print_drafts));
wenzelm@14934
   916
wenzelm@9731
   917
val opt_limits =
wenzelm@9731
   918
  Scan.option P.nat -- Scan.option (P.$$$ "," |-- P.!!! P.nat);
wenzelm@9731
   919
wenzelm@24868
   920
val _ =
wenzelm@8886
   921
  OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag
wenzelm@9731
   922
    (opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr));
wenzelm@7199
   923
wenzelm@24868
   924
val _ =
wenzelm@7222
   925
  OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
wenzelm@9010
   926
    (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
wenzelm@5832
   927
wenzelm@24868
   928
val _ =
wenzelm@7222
   929
  OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
wenzelm@9010
   930
    (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
wenzelm@7222
   931
wenzelm@24868
   932
val _ =
wenzelm@6723
   933
  OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
wenzelm@26490
   934
    (P.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
wenzelm@5832
   935
wenzelm@24868
   936
val _ =
wenzelm@6723
   937
  OuterSyntax.improper_command "quit" "quit Isabelle" K.control
wenzelm@9010
   938
    (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
wenzelm@5832
   939
wenzelm@24868
   940
val _ =
wenzelm@6723
   941
  OuterSyntax.improper_command "exit" "exit Isar loop" K.control
wenzelm@9010
   942
    (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
wenzelm@5832
   943
wenzelm@5832
   944
end;
wenzelm@27614
   945