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