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