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