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