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