src/Pure/Isar/isar_syn.ML
author wenzelm
Fri Jan 11 00:30:28 2002 +0100 (2002-01-11 ago)
changeset 12712 a659fd913a89
parent 12696 f8dfc7845891
child 12758 f6aceb9d4b8e
permissions -rw-r--r--
localized 'lemmas', 'theorems', 'declare';
wenzelm@5832
     1
(*  Title:      Pure/Isar/isar_syn.ML
wenzelm@5832
     2
    ID:         $Id$
wenzelm@5832
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@8807
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@5832
     5
wenzelm@6353
     6
Isar/Pure outer syntax.
wenzelm@5832
     7
*)
wenzelm@5832
     8
wenzelm@5832
     9
signature ISAR_SYN =
wenzelm@5832
    10
sig
wenzelm@5832
    11
  val keywords: string list
wenzelm@5832
    12
  val parsers: OuterSyntax.parser list
wenzelm@5832
    13
end;
wenzelm@5832
    14
wenzelm@5832
    15
structure IsarSyn: ISAR_SYN =
wenzelm@5832
    16
struct
wenzelm@5832
    17
wenzelm@6723
    18
structure P = OuterParse and K = OuterSyntax.Keyword;
wenzelm@5832
    19
wenzelm@5832
    20
wenzelm@5832
    21
(** init and exit **)
wenzelm@5832
    22
wenzelm@5832
    23
val theoryP =
wenzelm@6723
    24
  OuterSyntax.command "theory" "begin theory" K.thy_begin
wenzelm@9129
    25
    (ThyHeader.args >> (Toplevel.print oo IsarThy.theory));
wenzelm@5832
    26
wenzelm@6687
    27
val end_excursionP =
wenzelm@6723
    28
  OuterSyntax.command "end" "end current excursion" K.thy_end
wenzelm@6687
    29
    (Scan.succeed (Toplevel.print o Toplevel.exit));
wenzelm@6687
    30
wenzelm@6245
    31
val contextP =
wenzelm@7102
    32
  OuterSyntax.improper_command "context" "switch theory context" K.thy_switch
wenzelm@6723
    33
    (P.name >> (Toplevel.print oo IsarThy.context));
wenzelm@6245
    34
wenzelm@5832
    35
wenzelm@5832
    36
wenzelm@7749
    37
(** markup commands **)
wenzelm@5832
    38
wenzelm@9129
    39
val headerP = OuterSyntax.markup_command IsarOutput.Markup "header" "theory header" K.diag
wenzelm@7733
    40
  (P.comment >> IsarThy.add_header);
wenzelm@6353
    41
wenzelm@9129
    42
val chapterP = OuterSyntax.markup_command IsarOutput.Markup "chapter" "chapter heading"
wenzelm@9129
    43
  K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_chapter));
wenzelm@5958
    44
wenzelm@9129
    45
val sectionP = OuterSyntax.markup_command IsarOutput.Markup "section" "section heading"
wenzelm@9129
    46
  K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_section));
wenzelm@5958
    47
wenzelm@9129
    48
val subsectionP = OuterSyntax.markup_command IsarOutput.Markup "subsection" "subsection heading"
wenzelm@9129
    49
  K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_subsection));
wenzelm@5958
    50
wenzelm@7749
    51
val subsubsectionP =
wenzelm@9129
    52
  OuterSyntax.markup_command IsarOutput.Markup "subsubsection" "subsubsection heading"
wenzelm@9129
    53
  K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_subsubsection));
wenzelm@5832
    54
wenzelm@9129
    55
val textP = OuterSyntax.markup_command IsarOutput.MarkupEnv "text" "formal comment (theory)"
wenzelm@9129
    56
  K.thy_decl (P.comment >> (Toplevel.theory o IsarThy.add_text));
wenzelm@7172
    57
wenzelm@9129
    58
val text_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "text_raw"
wenzelm@9129
    59
  "raw document preparation text" K.thy_decl
wenzelm@9129
    60
  (P.comment >> (Toplevel.theory o IsarThy.add_text_raw));
wenzelm@7775
    61
wenzelm@7172
    62
wenzelm@9552
    63
val sectP = OuterSyntax.markup_command IsarOutput.Markup "sect" "formal comment (proof)"
wenzelm@9552
    64
  K.prf_heading (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_sect)));
wenzelm@7172
    65
wenzelm@9129
    66
val subsectP = OuterSyntax.markup_command IsarOutput.Markup "subsect" "formal comment (proof)"
wenzelm@9552
    67
  K.prf_heading (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsect)));
wenzelm@7172
    68
wenzelm@9129
    69
val subsubsectP = OuterSyntax.markup_command IsarOutput.Markup "subsubsect"
wenzelm@9552
    70
  "formal comment (proof)" K.prf_heading
wenzelm@7172
    71
  (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsubsect)));
wenzelm@7172
    72
wenzelm@9129
    73
val txtP = OuterSyntax.markup_command IsarOutput.MarkupEnv "txt" "formal comment (proof)"
wenzelm@9129
    74
  K.prf_decl (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt)));
wenzelm@7172
    75
wenzelm@9129
    76
val txt_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "txt_raw"
wenzelm@9129
    77
  "raw document preparation text (proof)" K.prf_decl
wenzelm@9129
    78
  (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt_raw)));
wenzelm@7775
    79
wenzelm@5832
    80
wenzelm@6886
    81
wenzelm@6886
    82
(** theory sections **)
wenzelm@6886
    83
wenzelm@5832
    84
(* classes and sorts *)
wenzelm@5832
    85
wenzelm@5832
    86
val classesP =
wenzelm@6723
    87
  OuterSyntax.command "classes" "declare type classes" K.thy_decl
wenzelm@11101
    88
    (Scan.repeat1 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
wenzelm@11101
    89
        P.!!! (P.list1 P.xname)) [])
wenzelm@6727
    90
      -- P.marg_comment >> (Toplevel.theory o IsarThy.add_classes));
wenzelm@5832
    91
wenzelm@5832
    92
val classrelP =
wenzelm@6723
    93
  OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
wenzelm@11101
    94
    (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) -- P.marg_comment
wenzelm@6727
    95
      >> (Toplevel.theory o IsarThy.add_classrel));
wenzelm@5832
    96
wenzelm@5832
    97
val defaultsortP =
wenzelm@6723
    98
  OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
wenzelm@6727
    99
    (P.sort -- P.marg_comment >> (Toplevel.theory o IsarThy.add_defsort));
wenzelm@5832
   100
wenzelm@5832
   101
wenzelm@5832
   102
(* types *)
wenzelm@5832
   103
wenzelm@5832
   104
val typedeclP =
wenzelm@12624
   105
  OuterSyntax.command "typedecl" "type declaration" K.thy_decl
wenzelm@6727
   106
    (P.type_args -- P.name -- P.opt_infix -- P.marg_comment >> (fn (((args, a), mx), cmt) =>
wenzelm@6727
   107
      Toplevel.theory (IsarThy.add_typedecl ((a, args, mx), cmt))));
wenzelm@5832
   108
wenzelm@5832
   109
val typeabbrP =
wenzelm@6723
   110
  OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
wenzelm@6727
   111
    (Scan.repeat1
wenzelm@9037
   112
      (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix')) -- P.marg_comment)
wenzelm@6727
   113
      >> (Toplevel.theory o IsarThy.add_tyabbrs o
wenzelm@6727
   114
        map (fn (((args, a), (T, mx)), cmt) => ((a, args, T, mx), cmt))));
wenzelm@5832
   115
wenzelm@5832
   116
val nontermP =
wenzelm@6370
   117
  OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
wenzelm@6727
   118
    K.thy_decl (Scan.repeat1 (P.name -- P.marg_comment)
wenzelm@6727
   119
      >> (Toplevel.theory o IsarThy.add_nonterminals));
wenzelm@5832
   120
wenzelm@5832
   121
val aritiesP =
wenzelm@6723
   122
  OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
wenzelm@6727
   123
    (Scan.repeat1 ((P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2) -- P.marg_comment)
wenzelm@6727
   124
      >> (Toplevel.theory o IsarThy.add_arities));
wenzelm@5832
   125
wenzelm@5832
   126
wenzelm@5832
   127
(* consts and syntax *)
wenzelm@5832
   128
wenzelm@8227
   129
val judgmentP =
wenzelm@8227
   130
  OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
wenzelm@8227
   131
    (P.const -- P.marg_comment >> (Toplevel.theory o IsarThy.add_judgment));
wenzelm@8227
   132
wenzelm@5832
   133
val constsP =
wenzelm@6723
   134
  OuterSyntax.command "consts" "declare constants" K.thy_decl
wenzelm@6727
   135
    (Scan.repeat1 (P.const -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_consts));
wenzelm@5832
   136
wenzelm@9731
   137
wenzelm@12142
   138
val mode_spec =
wenzelm@9731
   139
  (P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true;
wenzelm@9731
   140
wenzelm@9731
   141
val opt_mode = Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) ("", true);
wenzelm@5832
   142
wenzelm@5832
   143
val syntaxP =
wenzelm@6723
   144
  OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
wenzelm@6727
   145
    (opt_mode -- Scan.repeat1 (P.const -- P.marg_comment)
wenzelm@6727
   146
      >> (Toplevel.theory o uncurry IsarThy.add_modesyntax));
wenzelm@5832
   147
wenzelm@5832
   148
wenzelm@5832
   149
(* translations *)
wenzelm@5832
   150
wenzelm@5832
   151
val trans_pat =
wenzelm@6723
   152
  Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
wenzelm@5832
   153
wenzelm@5832
   154
fun trans_arrow toks =
wenzelm@10688
   155
  ((P.$$$ "\\<rightharpoonup>" || P.$$$ "=>") >> K Syntax.ParseRule ||
wenzelm@10688
   156
    (P.$$$ "\\<leftharpoondown>" || P.$$$ "<=") >> K Syntax.PrintRule ||
wenzelm@10688
   157
    (P.$$$ "\\<rightleftharpoons>" || P.$$$ "==") >> K Syntax.ParsePrintRule) toks;
wenzelm@5832
   158
wenzelm@5832
   159
val trans_line =
wenzelm@6723
   160
  trans_pat -- P.!!! (trans_arrow -- trans_pat)
wenzelm@5832
   161
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@5832
   162
wenzelm@5832
   163
val translationsP =
wenzelm@6723
   164
  OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
wenzelm@6727
   165
    (Scan.repeat1 (trans_line -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_trrules));
wenzelm@5832
   166
wenzelm@5832
   167
wenzelm@5832
   168
(* axioms and definitions *)
wenzelm@5832
   169
wenzelm@5832
   170
val axiomsP =
wenzelm@6723
   171
  OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
wenzelm@6727
   172
    (Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_axioms));
wenzelm@5832
   173
wenzelm@9323
   174
val opt_overloaded =
wenzelm@9323
   175
  Scan.optional (P.$$$ "(" |-- P.!!! ((P.$$$ "overloaded" >> K true) --| P.$$$ ")")) false;
wenzelm@9323
   176
wenzelm@5832
   177
val defsP =
wenzelm@6723
   178
  OuterSyntax.command "defs" "define constants" K.thy_decl
wenzelm@9323
   179
    (opt_overloaded -- Scan.repeat1 (P.spec_name -- P.marg_comment)
wenzelm@9323
   180
  >> (Toplevel.theory o IsarThy.add_defs));
wenzelm@6370
   181
wenzelm@6370
   182
val constdefsP =
wenzelm@6723
   183
  OuterSyntax.command "constdefs" "declare and define constants" K.thy_decl
wenzelm@6727
   184
    (Scan.repeat1 ((P.const -- P.marg_comment) -- (P.term -- P.marg_comment))
wenzelm@6727
   185
      >> (Toplevel.theory o IsarThy.add_constdefs));
wenzelm@5832
   186
wenzelm@5832
   187
wenzelm@5914
   188
(* theorems *)
wenzelm@5914
   189
wenzelm@12712
   190
val in_locale = Scan.option ((P.$$$ "(" -- P.$$$ "in") |-- P.!!! (P.xname --| P.$$$ ")"));
wenzelm@9197
   191
val name_facts = P.and_list1 (P.opt_thm_name "=" -- P.xthms1 -- P.marg_comment);
wenzelm@5914
   192
wenzelm@12712
   193
fun theorems kind = in_locale -- name_facts
wenzelm@12712
   194
  >> uncurry (#1 ooo IsarThy.smart_theorems kind);
wenzelm@12712
   195
wenzelm@5914
   196
val theoremsP =
wenzelm@6723
   197
  OuterSyntax.command "theorems" "define theorems" K.thy_decl
wenzelm@12712
   198
    (theorems Drule.theoremK >> Toplevel.theory);
wenzelm@5914
   199
wenzelm@5914
   200
val lemmasP =
wenzelm@6723
   201
  OuterSyntax.command "lemmas" "define lemmas" K.thy_decl
wenzelm@12712
   202
    (theorems Drule.lemmaK >> Toplevel.theory);
wenzelm@5914
   203
wenzelm@9589
   204
val declareP =
wenzelm@9776
   205
  OuterSyntax.command "declare" "declare theorems (improper)" K.thy_script
wenzelm@12712
   206
    (in_locale -- (P.xthms1 -- P.marg_comment)
wenzelm@12712
   207
    >> (Toplevel.theory o uncurry IsarThy.declare_theorems));
wenzelm@9589
   208
wenzelm@5914
   209
wenzelm@5832
   210
(* name space entry path *)
wenzelm@5832
   211
wenzelm@5832
   212
val globalP =
wenzelm@6723
   213
  OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
wenzelm@8723
   214
    (P.marg_comment >> (Toplevel.theory o IsarThy.global_path));
wenzelm@5832
   215
wenzelm@5832
   216
val localP =
wenzelm@6723
   217
  OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
wenzelm@8723
   218
    (P.marg_comment >> (Toplevel.theory o IsarThy.local_path));
wenzelm@8723
   219
wenzelm@8723
   220
val hideP =
wenzelm@8723
   221
  OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
wenzelm@8723
   222
    (P.name -- Scan.repeat1 P.xname -- P.marg_comment >> (Toplevel.theory o IsarThy.hide_space));
wenzelm@5832
   223
wenzelm@5832
   224
wenzelm@5832
   225
(* use ML text *)
wenzelm@5832
   226
wenzelm@5832
   227
val useP =
wenzelm@6723
   228
  OuterSyntax.command "use" "eval ML text from file" K.diag
wenzelm@9273
   229
    (P.name -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.use));
wenzelm@5832
   230
wenzelm@5832
   231
val mlP =
wenzelm@7616
   232
  OuterSyntax.command "ML" "eval ML text (diagnostic)" K.diag
wenzelm@9273
   233
    (P.text -- P.marg_comment >> IsarCmd.use_mltext true);
wenzelm@7891
   234
wenzelm@7891
   235
val ml_commandP =
wenzelm@7891
   236
  OuterSyntax.command "ML_command" "eval ML text" K.diag
wenzelm@9978
   237
    (P.text -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.use_mltext false));
wenzelm@7616
   238
wenzelm@7616
   239
val ml_setupP =
wenzelm@7616
   240
  OuterSyntax.command "ML_setup" "eval ML text (may change theory)" K.thy_decl
wenzelm@9273
   241
    (P.text -- P.marg_comment >> IsarCmd.use_mltext_theory);
wenzelm@5832
   242
wenzelm@5832
   243
val setupP =
wenzelm@7616
   244
  OuterSyntax.command "setup" "apply ML theory setup" K.thy_decl
wenzelm@9273
   245
    (P.text -- P.marg_comment >> (Toplevel.theory o IsarCmd.use_setup));
wenzelm@5832
   246
wenzelm@9197
   247
val method_setupP =
wenzelm@9197
   248
  OuterSyntax.command "method_setup" "define proof method in ML" K.thy_decl
wenzelm@9197
   249
    (((P.name -- P.!!! (P.$$$ "=" |-- P.text -- P.text) >> P.triple2)
wenzelm@9197
   250
      -- P.marg_comment) >> (Toplevel.theory o IsarThy.method_setup));
wenzelm@9197
   251
wenzelm@5832
   252
wenzelm@5832
   253
(* translation functions *)
wenzelm@5832
   254
wenzelm@5832
   255
val parse_ast_translationP =
wenzelm@6723
   256
  OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" K.thy_decl
wenzelm@9273
   257
    (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.parse_ast_translation));
wenzelm@5832
   258
wenzelm@5832
   259
val parse_translationP =
wenzelm@6723
   260
  OuterSyntax.command "parse_translation" "install parse translation functions" K.thy_decl
wenzelm@9273
   261
    (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.parse_translation));
wenzelm@5832
   262
wenzelm@5832
   263
val print_translationP =
wenzelm@6723
   264
  OuterSyntax.command "print_translation" "install print translation functions" K.thy_decl
wenzelm@9273
   265
    (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.print_translation));
wenzelm@5832
   266
wenzelm@5832
   267
val typed_print_translationP =
wenzelm@6370
   268
  OuterSyntax.command "typed_print_translation" "install typed print translation functions"
wenzelm@9273
   269
    K.thy_decl (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.typed_print_translation));
wenzelm@5832
   270
wenzelm@5832
   271
val print_ast_translationP =
wenzelm@6723
   272
  OuterSyntax.command "print_ast_translation" "install print ast translation functions" K.thy_decl
wenzelm@9273
   273
    (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.print_ast_translation));
wenzelm@5832
   274
wenzelm@5832
   275
val token_translationP =
wenzelm@6723
   276
  OuterSyntax.command "token_translation" "install token translation functions" K.thy_decl
wenzelm@9273
   277
    (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.token_translation));
wenzelm@5832
   278
wenzelm@5832
   279
wenzelm@5832
   280
(* oracles *)
wenzelm@5832
   281
wenzelm@5832
   282
val oracleP =
wenzelm@6723
   283
  OuterSyntax.command "oracle" "install oracle" K.thy_decl
wenzelm@7140
   284
    ((P.name --| P.$$$ "=") -- P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.add_oracle));
wenzelm@5832
   285
wenzelm@5832
   286
wenzelm@12061
   287
(* locales *)
wenzelm@12061
   288
wenzelm@12061
   289
val locale_decl =
wenzelm@12061
   290
  (P.name --| P.$$$ "=") --
wenzelm@12270
   291
    (P.locale_expr -- Scan.optional
wenzelm@12270
   292
      (P.$$$ "+" |-- P.!!! (Scan.repeat1 (P.locale_element -- P.marg_comment))) [] ||
wenzelm@12270
   293
    Scan.repeat1 (P.locale_element -- P.marg_comment) >> pair Locale.empty) >> P.triple2;
wenzelm@12061
   294
wenzelm@12061
   295
val localeP =
wenzelm@12061
   296
  OuterSyntax.command "locale" "define named proof context" K.thy_decl
wenzelm@12061
   297
    (locale_decl >> (Toplevel.theory o IsarThy.add_locale));
wenzelm@12061
   298
wenzelm@12061
   299
wenzelm@5832
   300
wenzelm@5832
   301
(** proof commands **)
wenzelm@5832
   302
wenzelm@5832
   303
(* statements *)
wenzelm@5832
   304
wenzelm@12712
   305
val in_locale_elems = in_locale --
wenzelm@12244
   306
  Scan.optional (P.$$$ "(" |-- Scan.repeat1 P.locale_element --| P.!!! (P.$$$ ")")) [];
wenzelm@12044
   307
wenzelm@12142
   308
val statement = P.and_list1 (P.opt_thm_name ":" -- Scan.repeat1 P.propp -- P.marg_comment);
wenzelm@12244
   309
val statement' = P.$$$ "(" |-- statement --| P.!!! (P.$$$ ")") || statement;
wenzelm@5832
   310
wenzelm@12242
   311
fun gen_theorem k =
wenzelm@12242
   312
  OuterSyntax.command k ("state " ^ k) K.thy_goal
wenzelm@12244
   313
    (Scan.optional (P.thm_name ":" --| Scan.ahead (P.$$$ "(")) ("", [])
wenzelm@12244
   314
      -- in_locale_elems -- statement' >> (fn ((x, y), z) =>
wenzelm@12696
   315
      (Toplevel.print o Toplevel.theory_to_proof (IsarThy.smart_multi_theorem k x y z))));
wenzelm@5832
   316
wenzelm@12242
   317
val theoremP = gen_theorem Drule.theoremK;
wenzelm@12242
   318
val lemmaP = gen_theorem Drule.lemmaK;
wenzelm@12242
   319
val corollaryP = gen_theorem Drule.corollaryK;
wenzelm@5832
   320
wenzelm@5832
   321
val showP =
wenzelm@6723
   322
  OuterSyntax.command "show" "state local goal, solving current obligation" K.prf_goal
wenzelm@12006
   323
    (statement >> ((Toplevel.print oo Toplevel.proof') o IsarThy.show));
wenzelm@5832
   324
wenzelm@5832
   325
val haveP =
wenzelm@6723
   326
  OuterSyntax.command "have" "state local goal" K.prf_goal
wenzelm@12006
   327
    (statement >> ((Toplevel.print oo Toplevel.proof) o  IsarThy.have));
wenzelm@5832
   328
wenzelm@6501
   329
val thusP =
wenzelm@6723
   330
  OuterSyntax.command "thus" "abbreviates \"then show\"" K.prf_goal
wenzelm@12006
   331
    (statement >> ((Toplevel.print oo Toplevel.proof') o IsarThy.thus));
wenzelm@6501
   332
wenzelm@6501
   333
val henceP =
wenzelm@6723
   334
  OuterSyntax.command "hence" "abbreviates \"then have\"" K.prf_goal
wenzelm@12006
   335
    (statement >> ((Toplevel.print oo Toplevel.proof) o IsarThy.hence));
wenzelm@6501
   336
wenzelm@5832
   337
wenzelm@5914
   338
(* facts *)
wenzelm@5832
   339
wenzelm@9197
   340
val facts = P.and_list1 (P.xthms1 -- P.marg_comment);
wenzelm@9197
   341
wenzelm@5832
   342
val thenP =
wenzelm@6723
   343
  OuterSyntax.command "then" "forward chaining" K.prf_chain
wenzelm@6727
   344
    (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.chain)));
wenzelm@5832
   345
wenzelm@5832
   346
val fromP =
wenzelm@6723
   347
  OuterSyntax.command "from" "forward chaining from given facts" K.prf_chain
wenzelm@9197
   348
    (facts >> (Toplevel.print oo (Toplevel.proof o IsarThy.from_facts)));
wenzelm@5914
   349
wenzelm@6878
   350
val withP =
wenzelm@6878
   351
  OuterSyntax.command "with" "forward chaining from given and current facts" K.prf_chain
wenzelm@9197
   352
    (facts >> (Toplevel.print oo (Toplevel.proof o IsarThy.with_facts)));
wenzelm@6878
   353
wenzelm@6773
   354
val noteP =
wenzelm@6723
   355
  OuterSyntax.command "note" "define facts" K.prf_decl
wenzelm@9197
   356
    (name_facts >> (Toplevel.print oo (Toplevel.proof o IsarThy.have_facts)));
wenzelm@5832
   357
wenzelm@5832
   358
wenzelm@5832
   359
(* proof context *)
wenzelm@5832
   360
wenzelm@11890
   361
val fixP =
wenzelm@11890
   362
  OuterSyntax.command "fix" "fix variables (Skolem constants)" K.prf_asm
wenzelm@11890
   363
    (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment)
wenzelm@11890
   364
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.fix)));
wenzelm@11890
   365
wenzelm@5832
   366
val assumeP =
wenzelm@6869
   367
  OuterSyntax.command "assume" "assume propositions" K.prf_asm
wenzelm@12142
   368
    (statement >> (Toplevel.print oo (Toplevel.proof o IsarThy.assume)));
wenzelm@5832
   369
wenzelm@6850
   370
val presumeP =
wenzelm@6869
   371
  OuterSyntax.command "presume" "assume propositions, to be established later" K.prf_asm
wenzelm@12142
   372
    (statement >> (Toplevel.print oo (Toplevel.proof o IsarThy.presume)));
wenzelm@6850
   373
wenzelm@6953
   374
val defP =
wenzelm@6953
   375
  OuterSyntax.command "def" "local definition" K.prf_asm
wenzelm@10688
   376
    (P.opt_thm_name ":" -- (P.name -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp))
wenzelm@9465
   377
      -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.local_def)));
wenzelm@6953
   378
wenzelm@11890
   379
val obtainP =
wenzelm@11890
   380
  OuterSyntax.command "obtain" "generalized existence"
wenzelm@11890
   381
    K.prf_asm_goal
wenzelm@11890
   382
    (Scan.optional
wenzelm@11890
   383
      (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment)
wenzelm@12142
   384
        --| P.$$$ "where") [] -- statement
wenzelm@11890
   385
    >> (Toplevel.print oo (Toplevel.proof o IsarThy.obtain)));
wenzelm@5832
   386
wenzelm@5832
   387
val letP =
wenzelm@6723
   388
  OuterSyntax.command "let" "bind text variables" K.prf_decl
wenzelm@8669
   389
    (P.and_list1 (P.enum1 "and" P.term -- (P.$$$ "=" |-- P.term) -- P.marg_comment)
wenzelm@8615
   390
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.let_bind)));
wenzelm@5832
   391
wenzelm@11793
   392
val case_spec =
wenzelm@12267
   393
  (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 P.uname --| P.$$$ ")") ||
wenzelm@12267
   394
    P.xname >> rpair []) -- P.opt_attribs >> P.triple1;
wenzelm@11793
   395
wenzelm@8370
   396
val caseP =
wenzelm@8370
   397
  OuterSyntax.command "case" "invoke local context" K.prf_asm
wenzelm@11793
   398
    (case_spec -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.invoke_case)));
wenzelm@8370
   399
wenzelm@5832
   400
wenzelm@5832
   401
(* proof structure *)
wenzelm@5832
   402
wenzelm@5832
   403
val beginP =
wenzelm@9056
   404
  OuterSyntax.command "{" "begin explicit proof block" K.prf_open
wenzelm@9032
   405
    (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.begin_block)));
wenzelm@5832
   406
wenzelm@6687
   407
val endP =
wenzelm@9056
   408
  OuterSyntax.command "}" "end explicit proof block" K.prf_close
wenzelm@9032
   409
    (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.end_block)));
wenzelm@6687
   410
wenzelm@5832
   411
val nextP =
wenzelm@6723
   412
  OuterSyntax.command "next" "enter next proof block" K.prf_block
wenzelm@9032
   413
    (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.next_block)));
wenzelm@5832
   414
wenzelm@5832
   415
wenzelm@5832
   416
(* end proof *)
wenzelm@5832
   417
wenzelm@6404
   418
val qedP =
wenzelm@6735
   419
  OuterSyntax.command "qed" "conclude (sub-)proof" K.qed_block
wenzelm@7002
   420
    (Scan.option (P.method -- P.interest) -- P.marg_comment >> IsarThy.qed);
wenzelm@5832
   421
wenzelm@6404
   422
val terminal_proofP =
wenzelm@6723
   423
  OuterSyntax.command "by" "terminal backward proof" K.qed
wenzelm@7002
   424
    (P.method -- P.interest -- Scan.option (P.method -- P.interest)
wenzelm@7002
   425
      -- P.marg_comment >> IsarThy.terminal_proof);
wenzelm@6404
   426
wenzelm@8966
   427
val default_proofP =
wenzelm@8966
   428
  OuterSyntax.command ".." "default proof" K.qed
wenzelm@8966
   429
    (P.marg_comment >> IsarThy.default_proof);
wenzelm@8966
   430
wenzelm@6404
   431
val immediate_proofP =
wenzelm@6723
   432
  OuterSyntax.command "." "immediate proof" K.qed
wenzelm@7002
   433
    (P.marg_comment >> IsarThy.immediate_proof);
wenzelm@6404
   434
wenzelm@8966
   435
val done_proofP =
wenzelm@8966
   436
  OuterSyntax.command "done" "done proof" K.qed
wenzelm@8966
   437
    (P.marg_comment >> IsarThy.done_proof);
wenzelm@5832
   438
wenzelm@6888
   439
val skip_proofP =
wenzelm@7172
   440
  OuterSyntax.improper_command "sorry" "skip proof (quick-and-dirty mode only!)" K.qed
wenzelm@7002
   441
    (P.marg_comment >> IsarThy.skip_proof);
wenzelm@6888
   442
wenzelm@8210
   443
val forget_proofP =
wenzelm@8521
   444
  OuterSyntax.command "oops" "forget proof" K.qed_global
wenzelm@8210
   445
    (P.marg_comment >> IsarThy.forget_proof);
wenzelm@8210
   446
wenzelm@8210
   447
wenzelm@5832
   448
wenzelm@5832
   449
(* proof steps *)
wenzelm@5832
   450
wenzelm@8165
   451
val deferP =
wenzelm@8681
   452
  OuterSyntax.command "defer" "shuffle internal proof state" K.prf_script
wenzelm@8681
   453
    (Scan.option P.nat -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.defer)));
wenzelm@8165
   454
wenzelm@8165
   455
val preferP =
wenzelm@8681
   456
  OuterSyntax.command "prefer" "shuffle internal proof state" K.prf_script
wenzelm@8681
   457
    (P.nat -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.prefer)));
wenzelm@8165
   458
wenzelm@6850
   459
val applyP =
wenzelm@8681
   460
  OuterSyntax.command "apply" "initial refinement step (unstructured)" K.prf_script
wenzelm@8681
   461
    (P.method -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply)));
wenzelm@5832
   462
wenzelm@8235
   463
val apply_endP =
wenzelm@8681
   464
  OuterSyntax.command "apply_end" "terminal refinement (unstructured)" K.prf_script
wenzelm@8681
   465
    (P.method -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply_end)));
wenzelm@5832
   466
wenzelm@6404
   467
val proofP =
wenzelm@6723
   468
  OuterSyntax.command "proof" "backward proof" K.prf_block
wenzelm@7002
   469
    (P.interest -- Scan.option (P.method -- P.interest) -- P.marg_comment
wenzelm@6727
   470
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.proof)));
wenzelm@5832
   471
wenzelm@5832
   472
wenzelm@6773
   473
(* calculational proof commands *)
wenzelm@6773
   474
wenzelm@6878
   475
val calc_args =
wenzelm@6878
   476
  Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")") -- P.interest));
wenzelm@6878
   477
wenzelm@6773
   478
val alsoP =
wenzelm@8562
   479
  OuterSyntax.command "also" "combine calculation and current facts" K.prf_decl
wenzelm@6878
   480
    (calc_args -- P.marg_comment >> IsarThy.also);
wenzelm@6773
   481
wenzelm@6773
   482
val finallyP =
wenzelm@8562
   483
  OuterSyntax.command "finally" "combine calculation and current facts, exhibit result" K.prf_chain
wenzelm@6878
   484
    (calc_args -- P.marg_comment >> IsarThy.finally);
wenzelm@6773
   485
wenzelm@8562
   486
val moreoverP =
wenzelm@8562
   487
  OuterSyntax.command "moreover" "augment calculation by current facts" K.prf_decl
wenzelm@8562
   488
    (P.marg_comment >> IsarThy.moreover);
wenzelm@8562
   489
wenzelm@8588
   490
val ultimatelyP =
wenzelm@8588
   491
  OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
wenzelm@8588
   492
    K.prf_chain (P.marg_comment >> IsarThy.ultimately);
wenzelm@8588
   493
wenzelm@6773
   494
wenzelm@6742
   495
(* proof navigation *)
wenzelm@5944
   496
wenzelm@5832
   497
val backP =
wenzelm@8235
   498
  OuterSyntax.command "back" "backtracking of proof command" K.prf_script
wenzelm@9273
   499
    (Scan.optional (P.$$$ "!" >> K true) false -- P.marg_comment >>
wenzelm@9273
   500
      (Toplevel.print oo IsarCmd.back));
wenzelm@5832
   501
wenzelm@5832
   502
wenzelm@6742
   503
(* history *)
wenzelm@6742
   504
wenzelm@6742
   505
val cannot_undoP =
wenzelm@6742
   506
  OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control
wenzelm@9010
   507
    (P.name >> (Toplevel.no_timing oo IsarCmd.cannot_undo));
wenzelm@6742
   508
wenzelm@7733
   509
val clear_undosP =
wenzelm@7733
   510
  OuterSyntax.improper_command "clear_undos" "clear theory-level undo information" K.control
wenzelm@9010
   511
    (P.nat >> (Toplevel.no_timing oo IsarCmd.clear_undos_theory));
wenzelm@6742
   512
wenzelm@6742
   513
val redoP =
wenzelm@6742
   514
  OuterSyntax.improper_command "redo" "redo last command" K.control
wenzelm@9010
   515
    (Scan.succeed (Toplevel.no_timing o Toplevel.print o IsarCmd.redo));
wenzelm@6742
   516
wenzelm@6742
   517
val undos_proofP =
wenzelm@6742
   518
  OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control
wenzelm@9010
   519
    (P.nat >> ((Toplevel.no_timing o Toplevel.print) oo IsarCmd.undos_proof));
wenzelm@6742
   520
wenzelm@6742
   521
val undoP =
wenzelm@6742
   522
  OuterSyntax.improper_command "undo" "undo last command" K.control
wenzelm@9010
   523
    (Scan.succeed ((Toplevel.no_timing o Toplevel.print) o IsarCmd.undo));
wenzelm@6742
   524
wenzelm@8500
   525
val killP =
wenzelm@8500
   526
  OuterSyntax.improper_command "kill" "kill current history node" K.control
wenzelm@9010
   527
    (Scan.succeed ((Toplevel.no_timing o Toplevel.print) o IsarCmd.kill));
wenzelm@8500
   528
wenzelm@6742
   529
wenzelm@5832
   530
wenzelm@5832
   531
(** diagnostic commands (for interactive mode only) **)
wenzelm@5832
   532
wenzelm@8464
   533
val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
wenzelm@8464
   534
wenzelm@8464
   535
wenzelm@7124
   536
val pretty_setmarginP =
wenzelm@7124
   537
  OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
wenzelm@9010
   538
    K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
wenzelm@7124
   539
wenzelm@5832
   540
val print_commandsP =
wenzelm@9221
   541
  OuterSyntax.improper_command "print_commands" "print outer syntax (global)" K.diag
wenzelm@9221
   542
    (Scan.succeed (Toplevel.no_timing o OuterSyntax.print_commands));
wenzelm@5832
   543
wenzelm@7308
   544
val print_contextP =
wenzelm@7308
   545
  OuterSyntax.improper_command "print_context" "print theory context name" K.diag
wenzelm@9010
   546
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
wenzelm@7308
   547
wenzelm@5832
   548
val print_theoryP =
wenzelm@6723
   549
  OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
wenzelm@9010
   550
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theory));
wenzelm@5832
   551
wenzelm@5832
   552
val print_syntaxP =
wenzelm@6723
   553
  OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)" K.diag
wenzelm@9010
   554
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
wenzelm@5832
   555
wenzelm@5881
   556
val print_theoremsP =
wenzelm@12061
   557
  OuterSyntax.improper_command "print_theorems" "print theorems of this theory" K.diag
wenzelm@9010
   558
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theorems));
wenzelm@5881
   559
wenzelm@12061
   560
val print_localesP =
wenzelm@12061
   561
  OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
wenzelm@12061
   562
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales));
wenzelm@12061
   563
wenzelm@12061
   564
val print_localeP =
wenzelm@12061
   565
  OuterSyntax.improper_command "print_locale" "print named locale of this theory" K.diag
wenzelm@12288
   566
    (P.locale_expr >> (Toplevel.no_timing oo IsarCmd.print_locale));
wenzelm@12061
   567
wenzelm@5832
   568
val print_attributesP =
wenzelm@12061
   569
  OuterSyntax.improper_command "print_attributes" "print attributes of this theory" K.diag
wenzelm@9010
   570
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
wenzelm@5832
   571
wenzelm@12383
   572
val print_rulesP =
wenzelm@12383
   573
  OuterSyntax.improper_command "print_rules" "print intro/elim rules" K.diag
wenzelm@12383
   574
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules));
wenzelm@12383
   575
wenzelm@11666
   576
val print_induct_rulesP =
wenzelm@11666
   577
  OuterSyntax.improper_command "print_induct_rules" "print induction and cases rules" K.diag
wenzelm@11666
   578
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_induct_rules));
wenzelm@11666
   579
wenzelm@9221
   580
val print_trans_rulesP =
wenzelm@11666
   581
  OuterSyntax.improper_command "print_trans_rules" "print transitivity rules" K.diag
wenzelm@9221
   582
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules));
wenzelm@9221
   583
wenzelm@5832
   584
val print_methodsP =
wenzelm@12061
   585
  OuterSyntax.improper_command "print_methods" "print methods of this theory" K.diag
wenzelm@9010
   586
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
wenzelm@5832
   587
wenzelm@9221
   588
val print_antiquotationsP =
wenzelm@9221
   589
  OuterSyntax.improper_command "print_antiquotations" "print antiquotations (global)" K.diag
wenzelm@9221
   590
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations));
wenzelm@9221
   591
wenzelm@7616
   592
val thms_containingP =
wenzelm@11017
   593
  OuterSyntax.improper_command "thms_containing" "print theorems containing certain constants"
wenzelm@11017
   594
    K.diag (Scan.repeat P.term >> (Toplevel.no_timing oo IsarCmd.print_thms_containing));
wenzelm@7616
   595
wenzelm@9454
   596
val thm_depsP =
wenzelm@9454
   597
  OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
wenzelm@9454
   598
    K.diag (P.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
wenzelm@9454
   599
wenzelm@5832
   600
val print_bindsP =
wenzelm@6723
   601
  OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
wenzelm@9010
   602
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
wenzelm@5832
   603
wenzelm@5832
   604
val print_lthmsP =
wenzelm@8370
   605
  OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag
wenzelm@9010
   606
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_lthms));
wenzelm@5832
   607
wenzelm@8370
   608
val print_casesP =
wenzelm@8370
   609
  OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
wenzelm@9010
   610
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
wenzelm@8370
   611
wenzelm@5896
   612
val print_thmsP =
wenzelm@8464
   613
  OuterSyntax.improper_command "thm" "print theorems" K.diag
wenzelm@10581
   614
    (opt_modes -- P.xthms1 -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_thms));
wenzelm@5832
   615
berghofe@11524
   616
val print_prfsP =
berghofe@11524
   617
  OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
berghofe@12125
   618
    (opt_modes -- Scan.option P.xthms1 -- P.marg_comment >>
berghofe@12125
   619
      (Toplevel.no_timing oo IsarCmd.print_prfs false));
berghofe@11524
   620
berghofe@11524
   621
val print_full_prfsP =
berghofe@11524
   622
  OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
berghofe@12125
   623
    (opt_modes -- Scan.option P.xthms1 -- P.marg_comment >>
berghofe@12125
   624
      (Toplevel.no_timing oo IsarCmd.print_prfs true));
berghofe@11524
   625
wenzelm@5832
   626
val print_propP =
wenzelm@6723
   627
  OuterSyntax.improper_command "prop" "read and print proposition" K.diag
wenzelm@10581
   628
    (opt_modes -- P.term -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_prop));
wenzelm@5832
   629
wenzelm@5832
   630
val print_termP =
wenzelm@6723
   631
  OuterSyntax.improper_command "term" "read and print term" K.diag
wenzelm@10581
   632
    (opt_modes -- P.term -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_term));
wenzelm@5832
   633
wenzelm@5832
   634
val print_typeP =
wenzelm@6723
   635
  OuterSyntax.improper_command "typ" "read and print type" K.diag
wenzelm@10581
   636
    (opt_modes -- P.typ -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_type));
wenzelm@5832
   637
wenzelm@5832
   638
wenzelm@5832
   639
wenzelm@5832
   640
(** system commands (for interactive mode only) **)
wenzelm@5832
   641
wenzelm@5832
   642
val cdP =
wenzelm@8650
   643
  OuterSyntax.improper_command "cd" "change current working directory" K.diag
wenzelm@9010
   644
    (P.name >> (Toplevel.no_timing oo IsarCmd.cd));
wenzelm@5832
   645
wenzelm@5832
   646
val pwdP =
wenzelm@6723
   647
  OuterSyntax.improper_command "pwd" "print current working directory" K.diag
wenzelm@9010
   648
    (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
wenzelm@5832
   649
wenzelm@5832
   650
val use_thyP =
wenzelm@6723
   651
  OuterSyntax.improper_command "use_thy" "use theory file" K.diag
wenzelm@9010
   652
    (P.name >> (Toplevel.no_timing oo IsarCmd.use_thy));
wenzelm@5832
   653
wenzelm@6694
   654
val use_thy_onlyP =
wenzelm@7102
   655
  OuterSyntax.improper_command "use_thy_only" "use theory file only, ignoring associated ML"
wenzelm@9010
   656
    K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.use_thy_only));
wenzelm@6694
   657
wenzelm@6196
   658
val update_thyP =
wenzelm@6723
   659
  OuterSyntax.improper_command "update_thy" "update theory file" K.diag
wenzelm@9010
   660
    (P.name >> (Toplevel.no_timing oo IsarCmd.update_thy));
wenzelm@5832
   661
wenzelm@7102
   662
val update_thy_onlyP =
wenzelm@7102
   663
  OuterSyntax.improper_command "update_thy_only" "update theory file, ignoring associated ML"
wenzelm@9010
   664
    K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.update_thy_only));
wenzelm@7102
   665
wenzelm@7102
   666
val touch_thyP =
wenzelm@7102
   667
  OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
wenzelm@9010
   668
    (P.name >> (Toplevel.no_timing oo IsarCmd.touch_thy));
wenzelm@7102
   669
wenzelm@7102
   670
val touch_all_thysP =
wenzelm@7102
   671
  OuterSyntax.improper_command "touch_all_thys" "outdate all non-finished theories" K.diag
wenzelm@9010
   672
    (Scan.succeed (Toplevel.no_timing o IsarCmd.touch_all_thys));
wenzelm@7102
   673
wenzelm@7908
   674
val touch_child_thysP =
wenzelm@7908
   675
  OuterSyntax.improper_command "touch_child_thys" "outdate child theories" K.diag
wenzelm@9010
   676
    (P.name >> (Toplevel.no_timing oo IsarCmd.touch_child_thys));
wenzelm@7908
   677
wenzelm@7102
   678
val remove_thyP =
wenzelm@7102
   679
  OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
wenzelm@9010
   680
    (P.name >> (Toplevel.no_timing oo IsarCmd.remove_thy));
wenzelm@7102
   681
wenzelm@7931
   682
val kill_thyP =
wenzelm@7931
   683
  OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
wenzelm@9010
   684
    K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.kill_thy));
wenzelm@7931
   685
wenzelm@9731
   686
val opt_limits =
wenzelm@9731
   687
  Scan.option P.nat -- Scan.option (P.$$$ "," |-- P.!!! P.nat);
wenzelm@9731
   688
wenzelm@5832
   689
val prP =
wenzelm@8886
   690
  OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag
wenzelm@9731
   691
    (opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr));
wenzelm@7199
   692
wenzelm@7222
   693
val disable_prP =
wenzelm@7222
   694
  OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
wenzelm@9010
   695
    (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
wenzelm@5832
   696
wenzelm@7222
   697
val enable_prP =
wenzelm@7222
   698
  OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
wenzelm@9010
   699
    (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
wenzelm@7222
   700
wenzelm@5832
   701
val commitP =
wenzelm@6723
   702
  OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
wenzelm@9010
   703
    (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.use_commit));
wenzelm@5832
   704
wenzelm@5832
   705
val quitP =
wenzelm@6723
   706
  OuterSyntax.improper_command "quit" "quit Isabelle" K.control
wenzelm@9010
   707
    (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
wenzelm@5832
   708
wenzelm@5832
   709
val exitP =
wenzelm@6723
   710
  OuterSyntax.improper_command "exit" "exit Isar loop" K.control
wenzelm@9010
   711
    (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
wenzelm@5832
   712
wenzelm@7102
   713
val init_toplevelP =
wenzelm@7102
   714
  OuterSyntax.improper_command "init_toplevel" "restart Isar toplevel loop" K.control
wenzelm@9010
   715
    (Scan.succeed (Toplevel.no_timing o IsarCmd.init_toplevel));
wenzelm@5991
   716
wenzelm@7462
   717
val welcomeP =
wenzelm@8678
   718
  OuterSyntax.improper_command "welcome" "print welcome message" K.diag
wenzelm@9010
   719
    (Scan.succeed (Toplevel.no_timing o IsarCmd.welcome));
wenzelm@7462
   720
wenzelm@5832
   721
wenzelm@5832
   722
wenzelm@5832
   723
(** the Pure outer syntax **)
wenzelm@5832
   724
wenzelm@5832
   725
(*keep keywords consistent with the parsers, including those in
wenzelm@5832
   726
  outer_parse.ML, otherwise be prepared for unexpected errors*)
wenzelm@5832
   727
wenzelm@5832
   728
val keywords =
wenzelm@7415
   729
 ["!", "!!", "%", "%%", "(", ")", "+", ",", "--", ":", "::", ";", "<",
wenzelm@12044
   730
  "<=", "=", "==", "=>", "?", "[", "]", "and", "assumes", "binder",
wenzelm@12044
   731
  "concl", "defines", "files", "fixes", "in", "infix", "infixl",
wenzelm@12044
   732
  "infixr", "is", "notes", "output", "overloaded", "structure",
wenzelm@12044
   733
  "uses", "where", "|", "\\<equiv>", "\\<leftharpoondown>",
wenzelm@12044
   734
  "\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>"];
wenzelm@5832
   735
wenzelm@5832
   736
val parsers = [
wenzelm@5832
   737
  (*theory structure*)
wenzelm@8500
   738
  theoryP, end_excursionP, contextP,
wenzelm@7775
   739
  (*markup commands*)
wenzelm@7733
   740
  headerP, chapterP, sectionP, subsectionP, subsubsectionP, textP,
wenzelm@7862
   741
  text_rawP, sectP, subsectP, subsubsectP, txtP, txt_rawP,
wenzelm@5832
   742
  (*theory sections*)
wenzelm@7172
   743
  classesP, classrelP, defaultsortP, typedeclP, typeabbrP, nontermP,
wenzelm@8227
   744
  aritiesP, judgmentP, constsP, syntaxP, translationsP, axiomsP,
wenzelm@9589
   745
  defsP, constdefsP, theoremsP, lemmasP, declareP, globalP, localP,
wenzelm@9589
   746
  hideP, useP, mlP, ml_commandP, ml_setupP, setupP, method_setupP,
wenzelm@9197
   747
  parse_ast_translationP, parse_translationP, print_translationP,
wenzelm@9197
   748
  typed_print_translationP, print_ast_translationP,
wenzelm@12061
   749
  token_translationP, oracleP, localeP,
wenzelm@5832
   750
  (*proof commands*)
wenzelm@11890
   751
  theoremP, lemmaP, corollaryP, showP, haveP, thusP, henceP, fixP,
wenzelm@11890
   752
  assumeP, presumeP, defP, obtainP, letP, caseP, thenP, fromP, withP,
wenzelm@11890
   753
  noteP, beginP, endP, nextP, qedP, terminal_proofP, default_proofP,
wenzelm@11742
   754
  immediate_proofP, done_proofP, skip_proofP, forget_proofP, deferP,
wenzelm@11742
   755
  preferP, applyP, apply_endP, proofP, alsoP, finallyP, moreoverP,
wenzelm@11742
   756
  ultimatelyP, backP, cannot_undoP, clear_undosP, redoP, undos_proofP,
wenzelm@11742
   757
  undoP, killP,
wenzelm@5832
   758
  (*diagnostic commands*)
wenzelm@7308
   759
  pretty_setmarginP, print_commandsP, print_contextP, print_theoryP,
wenzelm@12061
   760
  print_syntaxP, print_theoremsP, print_localesP, print_localeP,
wenzelm@12383
   761
  print_attributesP, print_rulesP, print_induct_rulesP,
wenzelm@12383
   762
  print_trans_rulesP, print_methodsP, print_antiquotationsP,
wenzelm@12383
   763
  thms_containingP, thm_depsP, print_bindsP, print_lthmsP,
wenzelm@12383
   764
  print_casesP, print_thmsP, print_prfsP, print_full_prfsP,
wenzelm@12383
   765
  print_propP, print_termP, print_typeP,
wenzelm@5832
   766
  (*system commands*)
wenzelm@7102
   767
  cdP, pwdP, use_thyP, use_thy_onlyP, update_thyP, update_thy_onlyP,
wenzelm@7931
   768
  touch_thyP, touch_all_thysP, touch_child_thysP, remove_thyP,
wenzelm@7931
   769
  kill_thyP, prP, disable_prP, enable_prP, commitP, quitP, exitP,
wenzelm@7931
   770
  init_toplevelP, welcomeP];
wenzelm@5832
   771
wenzelm@5832
   772
end;
wenzelm@5832
   773
wenzelm@5832
   774
wenzelm@6196
   775
(*install the Pure outer syntax*)
wenzelm@5832
   776
OuterSyntax.add_keywords IsarSyn.keywords;
wenzelm@5832
   777
OuterSyntax.add_parsers IsarSyn.parsers;