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