src/Pure/Isar/isar_syn.ML
author wenzelm
Wed May 31 14:29:42 2000 +0200 (2000-05-31 ago)
changeset 9010 ce78dc5e1a73
parent 8966 916966f68907
child 9032 ad0b9f048bbf
permissions -rw-r--r--
Toplevel.no_timing;
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@6245
    25
    (OuterSyntax.theory_header >> (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@7749
    39
val headerP = OuterSyntax.markup_command "header" "theory header" K.diag
wenzelm@7733
    40
  (P.comment >> IsarThy.add_header);
wenzelm@6353
    41
wenzelm@7749
    42
val chapterP = OuterSyntax.markup_command "chapter" "chapter heading" K.thy_heading
wenzelm@6723
    43
  (P.comment >> (Toplevel.theory o IsarThy.add_chapter));
wenzelm@5958
    44
wenzelm@7749
    45
val sectionP = OuterSyntax.markup_command "section" "section heading" K.thy_heading
wenzelm@6723
    46
  (P.comment >> (Toplevel.theory o IsarThy.add_section));
wenzelm@5958
    47
wenzelm@7749
    48
val subsectionP = OuterSyntax.markup_command "subsection" "subsection heading" K.thy_heading
wenzelm@6723
    49
  (P.comment >> (Toplevel.theory o IsarThy.add_subsection));
wenzelm@5958
    50
wenzelm@7749
    51
val subsubsectionP =
wenzelm@7749
    52
  OuterSyntax.markup_command "subsubsection" "subsubsection heading" K.thy_heading
wenzelm@7749
    53
    (P.comment >> (Toplevel.theory o IsarThy.add_subsubsection));
wenzelm@5832
    54
wenzelm@8661
    55
val textP = OuterSyntax.markup_env_command "text" "formal comment (theory)" K.thy_decl
wenzelm@7172
    56
  (P.comment >> (Toplevel.theory o IsarThy.add_text));
wenzelm@7172
    57
wenzelm@7862
    58
val text_rawP = OuterSyntax.verbatim_command "text_raw" "raw document preparation text"
wenzelm@7862
    59
  K.thy_decl (P.comment >> (Toplevel.theory o IsarThy.add_text_raw));
wenzelm@7775
    60
wenzelm@7172
    61
wenzelm@7749
    62
val sectP = OuterSyntax.markup_command "sect" "formal comment (proof)" K.prf_decl
wenzelm@7172
    63
  (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_sect)));
wenzelm@7172
    64
wenzelm@7749
    65
val subsectP = OuterSyntax.markup_command "subsect" "formal comment (proof)" K.prf_decl
wenzelm@7172
    66
  (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsect)));
wenzelm@7172
    67
wenzelm@7749
    68
val subsubsectP = OuterSyntax.markup_command "subsubsect" "formal comment (proof)" K.prf_decl
wenzelm@7172
    69
  (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsubsect)));
wenzelm@7172
    70
wenzelm@8661
    71
val txtP = OuterSyntax.markup_env_command "txt" "formal comment (proof)" K.prf_decl
wenzelm@7172
    72
  (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt)));
wenzelm@7172
    73
wenzelm@7862
    74
val txt_rawP = OuterSyntax.verbatim_command "txt_raw" "raw document preparation text (proof)"
wenzelm@7862
    75
  K.prf_decl (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt_raw)));
wenzelm@7775
    76
wenzelm@5832
    77
wenzelm@6886
    78
wenzelm@6886
    79
(** theory sections **)
wenzelm@6886
    80
wenzelm@5832
    81
(* classes and sorts *)
wenzelm@5832
    82
wenzelm@5832
    83
val classesP =
wenzelm@6723
    84
  OuterSyntax.command "classes" "declare type classes" K.thy_decl
wenzelm@6723
    85
    (Scan.repeat1 (P.name -- Scan.optional (P.$$$ "<" |-- P.!!! (P.list1 P.xname)) [])
wenzelm@6727
    86
      -- P.marg_comment >> (Toplevel.theory o IsarThy.add_classes));
wenzelm@5832
    87
wenzelm@5832
    88
val classrelP =
wenzelm@6723
    89
  OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
wenzelm@6727
    90
    (P.xname -- (P.$$$ "<" |-- P.!!! P.xname) -- P.marg_comment
wenzelm@6727
    91
      >> (Toplevel.theory o IsarThy.add_classrel));
wenzelm@5832
    92
wenzelm@5832
    93
val defaultsortP =
wenzelm@6723
    94
  OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
wenzelm@6727
    95
    (P.sort -- P.marg_comment >> (Toplevel.theory o IsarThy.add_defsort));
wenzelm@5832
    96
wenzelm@5832
    97
wenzelm@5832
    98
(* types *)
wenzelm@5832
    99
wenzelm@5832
   100
val typedeclP =
wenzelm@6723
   101
  OuterSyntax.command "typedecl" "Pure type declaration" K.thy_decl
wenzelm@6727
   102
    (P.type_args -- P.name -- P.opt_infix -- P.marg_comment >> (fn (((args, a), mx), cmt) =>
wenzelm@6727
   103
      Toplevel.theory (IsarThy.add_typedecl ((a, args, mx), cmt))));
wenzelm@5832
   104
wenzelm@5832
   105
val typeabbrP =
wenzelm@6723
   106
  OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
wenzelm@6727
   107
    (Scan.repeat1
wenzelm@6727
   108
      (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix)) -- P.marg_comment)
wenzelm@6727
   109
      >> (Toplevel.theory o IsarThy.add_tyabbrs o
wenzelm@6727
   110
        map (fn (((args, a), (T, mx)), cmt) => ((a, args, T, mx), cmt))));
wenzelm@5832
   111
wenzelm@5832
   112
val nontermP =
wenzelm@6370
   113
  OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
wenzelm@6727
   114
    K.thy_decl (Scan.repeat1 (P.name -- P.marg_comment)
wenzelm@6727
   115
      >> (Toplevel.theory o IsarThy.add_nonterminals));
wenzelm@5832
   116
wenzelm@5832
   117
val aritiesP =
wenzelm@6723
   118
  OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
wenzelm@6727
   119
    (Scan.repeat1 ((P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2) -- P.marg_comment)
wenzelm@6727
   120
      >> (Toplevel.theory o IsarThy.add_arities));
wenzelm@5832
   121
wenzelm@5832
   122
wenzelm@5832
   123
(* consts and syntax *)
wenzelm@5832
   124
wenzelm@8227
   125
val judgmentP =
wenzelm@8227
   126
  OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
wenzelm@8227
   127
    (P.const -- P.marg_comment >> (Toplevel.theory o IsarThy.add_judgment));
wenzelm@8227
   128
wenzelm@5832
   129
val constsP =
wenzelm@6723
   130
  OuterSyntax.command "consts" "declare constants" K.thy_decl
wenzelm@6727
   131
    (Scan.repeat1 (P.const -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_consts));
wenzelm@5832
   132
wenzelm@5832
   133
val opt_mode =
wenzelm@5832
   134
  Scan.optional
wenzelm@6723
   135
    (P.$$$ "(" |-- P.!!! (P.name -- Scan.optional (P.$$$ "output" >> K false) true --| P.$$$ ")"))
wenzelm@5832
   136
    ("", true);
wenzelm@5832
   137
wenzelm@5832
   138
val syntaxP =
wenzelm@6723
   139
  OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
wenzelm@6727
   140
    (opt_mode -- Scan.repeat1 (P.const -- P.marg_comment)
wenzelm@6727
   141
      >> (Toplevel.theory o uncurry IsarThy.add_modesyntax));
wenzelm@5832
   142
wenzelm@5832
   143
wenzelm@5832
   144
(* translations *)
wenzelm@5832
   145
wenzelm@5832
   146
val trans_pat =
wenzelm@6723
   147
  Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
wenzelm@5832
   148
wenzelm@5832
   149
fun trans_arrow toks =
wenzelm@6723
   150
  (P.$$$ "=>" >> K Syntax.ParseRule ||
wenzelm@6723
   151
    P.$$$ "<=" >> K Syntax.PrintRule ||
wenzelm@6723
   152
    P.$$$ "==" >> K Syntax.ParsePrintRule) toks;
wenzelm@5832
   153
wenzelm@5832
   154
val trans_line =
wenzelm@6723
   155
  trans_pat -- P.!!! (trans_arrow -- trans_pat)
wenzelm@5832
   156
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@5832
   157
wenzelm@5832
   158
val translationsP =
wenzelm@6723
   159
  OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
wenzelm@6727
   160
    (Scan.repeat1 (trans_line -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_trrules));
wenzelm@5832
   161
wenzelm@5832
   162
wenzelm@5832
   163
(* axioms and definitions *)
wenzelm@5832
   164
wenzelm@5832
   165
val axiomsP =
wenzelm@6723
   166
  OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
wenzelm@6727
   167
    (Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_axioms));
wenzelm@5832
   168
wenzelm@5832
   169
val defsP =
wenzelm@6723
   170
  OuterSyntax.command "defs" "define constants" K.thy_decl
wenzelm@7603
   171
    (Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_defs));
wenzelm@6370
   172
wenzelm@6370
   173
val constdefsP =
wenzelm@6723
   174
  OuterSyntax.command "constdefs" "declare and define constants" K.thy_decl
wenzelm@6727
   175
    (Scan.repeat1 ((P.const -- P.marg_comment) -- (P.term -- P.marg_comment))
wenzelm@6727
   176
      >> (Toplevel.theory o IsarThy.add_constdefs));
wenzelm@5832
   177
wenzelm@5832
   178
wenzelm@5914
   179
(* theorems *)
wenzelm@5914
   180
wenzelm@6723
   181
val facts = P.opt_thm_name "=" -- P.xthms1;
wenzelm@5914
   182
wenzelm@5914
   183
val theoremsP =
wenzelm@6723
   184
  OuterSyntax.command "theorems" "define theorems" K.thy_decl
wenzelm@6727
   185
    (facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_theorems));
wenzelm@5914
   186
wenzelm@5914
   187
val lemmasP =
wenzelm@6723
   188
  OuterSyntax.command "lemmas" "define lemmas" K.thy_decl
wenzelm@6727
   189
    (facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_lemmas));
wenzelm@5914
   190
wenzelm@5914
   191
wenzelm@5832
   192
(* name space entry path *)
wenzelm@5832
   193
wenzelm@5832
   194
val globalP =
wenzelm@6723
   195
  OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
wenzelm@8723
   196
    (P.marg_comment >> (Toplevel.theory o IsarThy.global_path));
wenzelm@5832
   197
wenzelm@5832
   198
val localP =
wenzelm@6723
   199
  OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
wenzelm@8723
   200
    (P.marg_comment >> (Toplevel.theory o IsarThy.local_path));
wenzelm@8723
   201
wenzelm@8723
   202
val hideP =
wenzelm@8723
   203
  OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
wenzelm@8723
   204
    (P.name -- Scan.repeat1 P.xname -- P.marg_comment >> (Toplevel.theory o IsarThy.hide_space));
wenzelm@5832
   205
wenzelm@5832
   206
wenzelm@5832
   207
(* use ML text *)
wenzelm@5832
   208
wenzelm@5832
   209
val useP =
wenzelm@6723
   210
  OuterSyntax.command "use" "eval ML text from file" K.diag
wenzelm@9010
   211
    (P.name >> (Toplevel.no_timing oo IsarCmd.use));
wenzelm@5832
   212
wenzelm@5832
   213
val mlP =
wenzelm@7616
   214
  OuterSyntax.command "ML" "eval ML text (diagnostic)" K.diag
wenzelm@7891
   215
    (P.text >> IsarCmd.use_mltext true);
wenzelm@7891
   216
wenzelm@7891
   217
val ml_commandP =
wenzelm@7891
   218
  OuterSyntax.command "ML_command" "eval ML text" K.diag
wenzelm@7891
   219
    (P.text >> IsarCmd.use_mltext false);
wenzelm@7616
   220
wenzelm@7616
   221
val ml_setupP =
wenzelm@7616
   222
  OuterSyntax.command "ML_setup" "eval ML text (may change theory)" K.thy_decl
wenzelm@7616
   223
    (P.text >> IsarCmd.use_mltext_theory);
wenzelm@5832
   224
wenzelm@5832
   225
val setupP =
wenzelm@7616
   226
  OuterSyntax.command "setup" "apply ML theory setup" K.thy_decl
wenzelm@8349
   227
    (P.text >> (Toplevel.theory o Context.use_setup));
wenzelm@5832
   228
wenzelm@5832
   229
wenzelm@5832
   230
(* translation functions *)
wenzelm@5832
   231
wenzelm@5832
   232
val parse_ast_translationP =
wenzelm@6723
   233
  OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" K.thy_decl
wenzelm@6723
   234
    (P.text >> (Toplevel.theory o IsarThy.parse_ast_translation));
wenzelm@5832
   235
wenzelm@5832
   236
val parse_translationP =
wenzelm@6723
   237
  OuterSyntax.command "parse_translation" "install parse translation functions" K.thy_decl
wenzelm@6723
   238
    (P.text >> (Toplevel.theory o IsarThy.parse_translation));
wenzelm@5832
   239
wenzelm@5832
   240
val print_translationP =
wenzelm@6723
   241
  OuterSyntax.command "print_translation" "install print translation functions" K.thy_decl
wenzelm@6723
   242
    (P.text >> (Toplevel.theory o IsarThy.print_translation));
wenzelm@5832
   243
wenzelm@5832
   244
val typed_print_translationP =
wenzelm@6370
   245
  OuterSyntax.command "typed_print_translation" "install typed print translation functions"
wenzelm@6723
   246
    K.thy_decl (P.text >> (Toplevel.theory o IsarThy.typed_print_translation));
wenzelm@5832
   247
wenzelm@5832
   248
val print_ast_translationP =
wenzelm@6723
   249
  OuterSyntax.command "print_ast_translation" "install print ast translation functions" K.thy_decl
wenzelm@6723
   250
    (P.text >> (Toplevel.theory o IsarThy.print_ast_translation));
wenzelm@5832
   251
wenzelm@5832
   252
val token_translationP =
wenzelm@6723
   253
  OuterSyntax.command "token_translation" "install token translation functions" K.thy_decl
wenzelm@6723
   254
    (P.text >> (Toplevel.theory o IsarThy.token_translation));
wenzelm@5832
   255
wenzelm@5832
   256
wenzelm@5832
   257
(* oracles *)
wenzelm@5832
   258
wenzelm@5832
   259
val oracleP =
wenzelm@6723
   260
  OuterSyntax.command "oracle" "install oracle" K.thy_decl
wenzelm@7140
   261
    ((P.name --| P.$$$ "=") -- P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.add_oracle));
wenzelm@5832
   262
wenzelm@5832
   263
wenzelm@5832
   264
wenzelm@5832
   265
(** proof commands **)
wenzelm@5832
   266
wenzelm@5832
   267
(* statements *)
wenzelm@5832
   268
wenzelm@6936
   269
fun statement f = (P.opt_thm_name ":" -- P.propp >> P.triple1) -- P.marg_comment >> f;
wenzelm@5832
   270
wenzelm@5832
   271
val theoremP =
wenzelm@6723
   272
  OuterSyntax.command "theorem" "state theorem" K.thy_goal
wenzelm@5832
   273
    (statement IsarThy.theorem >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
wenzelm@5832
   274
wenzelm@5832
   275
val lemmaP =
wenzelm@6723
   276
  OuterSyntax.command "lemma" "state lemma" K.thy_goal
wenzelm@5832
   277
    (statement IsarThy.lemma >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
wenzelm@5832
   278
wenzelm@5832
   279
val showP =
wenzelm@6723
   280
  OuterSyntax.command "show" "state local goal, solving current obligation" K.prf_goal
wenzelm@5832
   281
    (statement IsarThy.show >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   282
wenzelm@5832
   283
val haveP =
wenzelm@6723
   284
  OuterSyntax.command "have" "state local goal" K.prf_goal
wenzelm@5832
   285
    (statement IsarThy.have >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   286
wenzelm@6501
   287
val thusP =
wenzelm@6723
   288
  OuterSyntax.command "thus" "abbreviates \"then show\"" K.prf_goal
wenzelm@6501
   289
    (statement IsarThy.thus >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@6501
   290
wenzelm@6501
   291
val henceP =
wenzelm@6723
   292
  OuterSyntax.command "hence" "abbreviates \"then have\"" K.prf_goal
wenzelm@6501
   293
    (statement IsarThy.hence >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@6501
   294
wenzelm@5832
   295
wenzelm@5914
   296
(* facts *)
wenzelm@5832
   297
wenzelm@5832
   298
val thenP =
wenzelm@6723
   299
  OuterSyntax.command "then" "forward chaining" K.prf_chain
wenzelm@6727
   300
    (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.chain)));
wenzelm@5832
   301
wenzelm@5832
   302
val fromP =
wenzelm@6723
   303
  OuterSyntax.command "from" "forward chaining from given facts" K.prf_chain
wenzelm@6727
   304
    (P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.from_facts)));
wenzelm@5914
   305
wenzelm@6878
   306
val withP =
wenzelm@6878
   307
  OuterSyntax.command "with" "forward chaining from given and current facts" K.prf_chain
wenzelm@6878
   308
    (P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.with_facts)));
wenzelm@6878
   309
wenzelm@6773
   310
val noteP =
wenzelm@6723
   311
  OuterSyntax.command "note" "define facts" K.prf_decl
wenzelm@6755
   312
    (facts -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.have_facts)));
wenzelm@5832
   313
wenzelm@5832
   314
wenzelm@5832
   315
(* proof context *)
wenzelm@5832
   316
wenzelm@5832
   317
val assumeP =
wenzelm@6869
   318
  OuterSyntax.command "assume" "assume propositions" K.prf_asm
wenzelm@7269
   319
    (P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment)
wenzelm@6727
   320
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.assume)));
wenzelm@5832
   321
wenzelm@6850
   322
val presumeP =
wenzelm@6869
   323
  OuterSyntax.command "presume" "assume propositions, to be established later" K.prf_asm
wenzelm@7269
   324
    (P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment)
wenzelm@6850
   325
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.presume)));
wenzelm@6850
   326
wenzelm@6953
   327
val defP =
wenzelm@6953
   328
  OuterSyntax.command "def" "local definition" K.prf_asm
wenzelm@6953
   329
    ((P.opt_thm_name ":" -- (P.name -- Scan.option (P.$$$ "::" |-- P.typ) --
wenzelm@6972
   330
      (P.$$$ "==" |-- P.termp)) >> P.triple1) -- P.marg_comment
wenzelm@6953
   331
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.local_def)));
wenzelm@6953
   332
wenzelm@5832
   333
val fixP =
wenzelm@6869
   334
  OuterSyntax.command "fix" "fix variables (Skolem constants)" K.prf_asm
wenzelm@7415
   335
    (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment)
wenzelm@6727
   336
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.fix)));
wenzelm@5832
   337
wenzelm@5832
   338
val letP =
wenzelm@6723
   339
  OuterSyntax.command "let" "bind text variables" K.prf_decl
wenzelm@8669
   340
    (P.and_list1 (P.enum1 "and" P.term -- (P.$$$ "=" |-- P.term) -- P.marg_comment)
wenzelm@8615
   341
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.let_bind)));
wenzelm@5832
   342
wenzelm@8370
   343
val caseP =
wenzelm@8370
   344
  OuterSyntax.command "case" "invoke local context" K.prf_asm
wenzelm@8450
   345
    (P.xthm -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.invoke_case)));
wenzelm@8370
   346
wenzelm@5832
   347
wenzelm@5832
   348
(* proof structure *)
wenzelm@5832
   349
wenzelm@5832
   350
val beginP =
wenzelm@8896
   351
  OuterSyntax.command "{" "begin explicit proof block" K.prf_block
wenzelm@5832
   352
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.begin_block));
wenzelm@5832
   353
wenzelm@6687
   354
val endP =
wenzelm@8896
   355
  OuterSyntax.command "}" "end explicit proof block" K.prf_block
wenzelm@6687
   356
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.end_block));
wenzelm@6687
   357
wenzelm@5832
   358
val nextP =
wenzelm@6723
   359
  OuterSyntax.command "next" "enter next proof block" K.prf_block
wenzelm@5832
   360
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.next_block));
wenzelm@5832
   361
wenzelm@5832
   362
wenzelm@5832
   363
(* end proof *)
wenzelm@5832
   364
wenzelm@6404
   365
val qedP =
wenzelm@6735
   366
  OuterSyntax.command "qed" "conclude (sub-)proof" K.qed_block
wenzelm@7002
   367
    (Scan.option (P.method -- P.interest) -- P.marg_comment >> IsarThy.qed);
wenzelm@5832
   368
wenzelm@6404
   369
val terminal_proofP =
wenzelm@6723
   370
  OuterSyntax.command "by" "terminal backward proof" K.qed
wenzelm@7002
   371
    (P.method -- P.interest -- Scan.option (P.method -- P.interest)
wenzelm@7002
   372
      -- P.marg_comment >> IsarThy.terminal_proof);
wenzelm@6404
   373
wenzelm@8966
   374
val default_proofP =
wenzelm@8966
   375
  OuterSyntax.command ".." "default proof" K.qed
wenzelm@8966
   376
    (P.marg_comment >> IsarThy.default_proof);
wenzelm@8966
   377
wenzelm@6404
   378
val immediate_proofP =
wenzelm@6723
   379
  OuterSyntax.command "." "immediate proof" K.qed
wenzelm@7002
   380
    (P.marg_comment >> IsarThy.immediate_proof);
wenzelm@6404
   381
wenzelm@8966
   382
val done_proofP =
wenzelm@8966
   383
  OuterSyntax.command "done" "done proof" K.qed
wenzelm@8966
   384
    (P.marg_comment >> IsarThy.done_proof);
wenzelm@5832
   385
wenzelm@6888
   386
val skip_proofP =
wenzelm@7172
   387
  OuterSyntax.improper_command "sorry" "skip proof (quick-and-dirty mode only!)" K.qed
wenzelm@7002
   388
    (P.marg_comment >> IsarThy.skip_proof);
wenzelm@6888
   389
wenzelm@8210
   390
val forget_proofP =
wenzelm@8521
   391
  OuterSyntax.command "oops" "forget proof" K.qed_global
wenzelm@8210
   392
    (P.marg_comment >> IsarThy.forget_proof);
wenzelm@8210
   393
wenzelm@8210
   394
wenzelm@5832
   395
wenzelm@5832
   396
(* proof steps *)
wenzelm@5832
   397
wenzelm@8165
   398
val deferP =
wenzelm@8681
   399
  OuterSyntax.command "defer" "shuffle internal proof state" K.prf_script
wenzelm@8681
   400
    (Scan.option P.nat -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.defer)));
wenzelm@8165
   401
wenzelm@8165
   402
val preferP =
wenzelm@8681
   403
  OuterSyntax.command "prefer" "shuffle internal proof state" K.prf_script
wenzelm@8681
   404
    (P.nat -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.prefer)));
wenzelm@8165
   405
wenzelm@6850
   406
val applyP =
wenzelm@8681
   407
  OuterSyntax.command "apply" "initial refinement step (unstructured)" K.prf_script
wenzelm@8681
   408
    (P.method -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply)));
wenzelm@5832
   409
wenzelm@8235
   410
val apply_endP =
wenzelm@8681
   411
  OuterSyntax.command "apply_end" "terminal refinement (unstructured)" K.prf_script
wenzelm@8681
   412
    (P.method -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply_end)));
wenzelm@5832
   413
wenzelm@6404
   414
val proofP =
wenzelm@6723
   415
  OuterSyntax.command "proof" "backward proof" K.prf_block
wenzelm@7002
   416
    (P.interest -- Scan.option (P.method -- P.interest) -- P.marg_comment
wenzelm@6727
   417
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.proof)));
wenzelm@5832
   418
wenzelm@5832
   419
wenzelm@6773
   420
(* calculational proof commands *)
wenzelm@6773
   421
wenzelm@6878
   422
val calc_args =
wenzelm@6878
   423
  Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")") -- P.interest));
wenzelm@6878
   424
wenzelm@6773
   425
val alsoP =
wenzelm@8562
   426
  OuterSyntax.command "also" "combine calculation and current facts" K.prf_decl
wenzelm@6878
   427
    (calc_args -- P.marg_comment >> IsarThy.also);
wenzelm@6773
   428
wenzelm@6773
   429
val finallyP =
wenzelm@8562
   430
  OuterSyntax.command "finally" "combine calculation and current facts, exhibit result" K.prf_chain
wenzelm@6878
   431
    (calc_args -- P.marg_comment >> IsarThy.finally);
wenzelm@6773
   432
wenzelm@8562
   433
val moreoverP =
wenzelm@8562
   434
  OuterSyntax.command "moreover" "augment calculation by current facts" K.prf_decl
wenzelm@8562
   435
    (P.marg_comment >> IsarThy.moreover);
wenzelm@8562
   436
wenzelm@8588
   437
val ultimatelyP =
wenzelm@8588
   438
  OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
wenzelm@8588
   439
    K.prf_chain (P.marg_comment >> IsarThy.ultimately);
wenzelm@8588
   440
wenzelm@6773
   441
wenzelm@6742
   442
(* proof navigation *)
wenzelm@5944
   443
wenzelm@5832
   444
val backP =
wenzelm@8235
   445
  OuterSyntax.command "back" "backtracking of proof command" K.prf_script
wenzelm@7368
   446
    (Scan.optional (P.$$$ "!" >> K true) false >>
wenzelm@7368
   447
      (Toplevel.print oo (Toplevel.proof o ProofHistory.back)));
wenzelm@5832
   448
wenzelm@5832
   449
wenzelm@6742
   450
(* history *)
wenzelm@6742
   451
wenzelm@6742
   452
val cannot_undoP =
wenzelm@6742
   453
  OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control
wenzelm@9010
   454
    (P.name >> (Toplevel.no_timing oo IsarCmd.cannot_undo));
wenzelm@6742
   455
wenzelm@7733
   456
val clear_undosP =
wenzelm@7733
   457
  OuterSyntax.improper_command "clear_undos" "clear theory-level undo information" K.control
wenzelm@9010
   458
    (P.nat >> (Toplevel.no_timing oo IsarCmd.clear_undos_theory));
wenzelm@6742
   459
wenzelm@6742
   460
val redoP =
wenzelm@6742
   461
  OuterSyntax.improper_command "redo" "redo last command" K.control
wenzelm@9010
   462
    (Scan.succeed (Toplevel.no_timing o Toplevel.print o IsarCmd.redo));
wenzelm@6742
   463
wenzelm@6742
   464
val undos_proofP =
wenzelm@6742
   465
  OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control
wenzelm@9010
   466
    (P.nat >> ((Toplevel.no_timing o Toplevel.print) oo IsarCmd.undos_proof));
wenzelm@6742
   467
wenzelm@6742
   468
val undoP =
wenzelm@6742
   469
  OuterSyntax.improper_command "undo" "undo last command" K.control
wenzelm@9010
   470
    (Scan.succeed ((Toplevel.no_timing o Toplevel.print) o IsarCmd.undo));
wenzelm@6742
   471
wenzelm@8500
   472
val killP =
wenzelm@8500
   473
  OuterSyntax.improper_command "kill" "kill current history node" K.control
wenzelm@9010
   474
    (Scan.succeed ((Toplevel.no_timing o Toplevel.print) o IsarCmd.kill));
wenzelm@8500
   475
wenzelm@6742
   476
wenzelm@5832
   477
wenzelm@5832
   478
(** diagnostic commands (for interactive mode only) **)
wenzelm@5832
   479
wenzelm@8464
   480
val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
wenzelm@8464
   481
wenzelm@8464
   482
wenzelm@7124
   483
val pretty_setmarginP =
wenzelm@7124
   484
  OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
wenzelm@9010
   485
    K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin));
wenzelm@7124
   486
wenzelm@5832
   487
val print_commandsP =
wenzelm@6723
   488
  OuterSyntax.improper_command "help" "print outer syntax (global)" K.diag
wenzelm@9010
   489
    (Scan.succeed (Toplevel.no_timing o OuterSyntax.print_help));
wenzelm@5832
   490
wenzelm@7308
   491
val print_contextP =
wenzelm@7308
   492
  OuterSyntax.improper_command "print_context" "print theory context name" K.diag
wenzelm@9010
   493
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_context));
wenzelm@7308
   494
wenzelm@5832
   495
val print_theoryP =
wenzelm@6723
   496
  OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
wenzelm@9010
   497
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theory));
wenzelm@5832
   498
wenzelm@5832
   499
val print_syntaxP =
wenzelm@6723
   500
  OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)" K.diag
wenzelm@9010
   501
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax));
wenzelm@5832
   502
wenzelm@5881
   503
val print_theoremsP =
wenzelm@6723
   504
  OuterSyntax.improper_command "print_theorems" "print theorems known in this theory" K.diag
wenzelm@9010
   505
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_theorems));
wenzelm@5881
   506
wenzelm@5832
   507
val print_attributesP =
wenzelm@6723
   508
  OuterSyntax.improper_command "print_attributes" "print attributes known in this theory" K.diag
wenzelm@9010
   509
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes));
wenzelm@5832
   510
wenzelm@5832
   511
val print_methodsP =
wenzelm@6723
   512
  OuterSyntax.improper_command "print_methods" "print methods known in this theory" K.diag
wenzelm@9010
   513
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods));
wenzelm@5832
   514
wenzelm@7616
   515
val thms_containingP =
wenzelm@7616
   516
  OuterSyntax.improper_command "thms_containing" "print theorems containing all given constants"
wenzelm@9010
   517
    K.diag (Scan.repeat P.xname >> (Toplevel.no_timing oo IsarCmd.print_thms_containing));
wenzelm@7616
   518
wenzelm@5832
   519
val print_bindsP =
wenzelm@6723
   520
  OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
wenzelm@9010
   521
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
wenzelm@5832
   522
wenzelm@5832
   523
val print_lthmsP =
wenzelm@8370
   524
  OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag
wenzelm@9010
   525
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_lthms));
wenzelm@5832
   526
wenzelm@8370
   527
val print_casesP =
wenzelm@8370
   528
  OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
wenzelm@9010
   529
    (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
wenzelm@8370
   530
wenzelm@5896
   531
val print_thmsP =
wenzelm@8464
   532
  OuterSyntax.improper_command "thm" "print theorems" K.diag
wenzelm@9010
   533
    (opt_modes -- P.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
wenzelm@5832
   534
wenzelm@5832
   535
val print_propP =
wenzelm@6723
   536
  OuterSyntax.improper_command "prop" "read and print proposition" K.diag
wenzelm@9010
   537
    (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
wenzelm@5832
   538
wenzelm@5832
   539
val print_termP =
wenzelm@6723
   540
  OuterSyntax.improper_command "term" "read and print term" K.diag
wenzelm@9010
   541
    (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term));
wenzelm@5832
   542
wenzelm@5832
   543
val print_typeP =
wenzelm@6723
   544
  OuterSyntax.improper_command "typ" "read and print type" K.diag
wenzelm@9010
   545
    (opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
wenzelm@5832
   546
wenzelm@5832
   547
wenzelm@5832
   548
wenzelm@5832
   549
(** system commands (for interactive mode only) **)
wenzelm@5832
   550
wenzelm@5832
   551
val cdP =
wenzelm@8650
   552
  OuterSyntax.improper_command "cd" "change current working directory" K.diag
wenzelm@9010
   553
    (P.name >> (Toplevel.no_timing oo IsarCmd.cd));
wenzelm@5832
   554
wenzelm@5832
   555
val pwdP =
wenzelm@6723
   556
  OuterSyntax.improper_command "pwd" "print current working directory" K.diag
wenzelm@9010
   557
    (Scan.succeed (Toplevel.no_timing o IsarCmd.pwd));
wenzelm@5832
   558
wenzelm@5832
   559
val use_thyP =
wenzelm@6723
   560
  OuterSyntax.improper_command "use_thy" "use theory file" K.diag
wenzelm@9010
   561
    (P.name >> (Toplevel.no_timing oo IsarCmd.use_thy));
wenzelm@5832
   562
wenzelm@6694
   563
val use_thy_onlyP =
wenzelm@7102
   564
  OuterSyntax.improper_command "use_thy_only" "use theory file only, ignoring associated ML"
wenzelm@9010
   565
    K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.use_thy_only));
wenzelm@6694
   566
wenzelm@6196
   567
val update_thyP =
wenzelm@6723
   568
  OuterSyntax.improper_command "update_thy" "update theory file" K.diag
wenzelm@9010
   569
    (P.name >> (Toplevel.no_timing oo IsarCmd.update_thy));
wenzelm@5832
   570
wenzelm@7102
   571
val update_thy_onlyP =
wenzelm@7102
   572
  OuterSyntax.improper_command "update_thy_only" "update theory file, ignoring associated ML"
wenzelm@9010
   573
    K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.update_thy_only));
wenzelm@7102
   574
wenzelm@7102
   575
val touch_thyP =
wenzelm@7102
   576
  OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
wenzelm@9010
   577
    (P.name >> (Toplevel.no_timing oo IsarCmd.touch_thy));
wenzelm@7102
   578
wenzelm@7102
   579
val touch_all_thysP =
wenzelm@7102
   580
  OuterSyntax.improper_command "touch_all_thys" "outdate all non-finished theories" K.diag
wenzelm@9010
   581
    (Scan.succeed (Toplevel.no_timing o IsarCmd.touch_all_thys));
wenzelm@7102
   582
wenzelm@7908
   583
val touch_child_thysP =
wenzelm@7908
   584
  OuterSyntax.improper_command "touch_child_thys" "outdate child theories" K.diag
wenzelm@9010
   585
    (P.name >> (Toplevel.no_timing oo IsarCmd.touch_child_thys));
wenzelm@7908
   586
wenzelm@7102
   587
val remove_thyP =
wenzelm@7102
   588
  OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
wenzelm@9010
   589
    (P.name >> (Toplevel.no_timing oo IsarCmd.remove_thy));
wenzelm@7102
   590
wenzelm@7931
   591
val kill_thyP =
wenzelm@7931
   592
  OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
wenzelm@9010
   593
    K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.kill_thy));
wenzelm@7931
   594
wenzelm@5832
   595
val prP =
wenzelm@8886
   596
  OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag
wenzelm@9010
   597
    (opt_modes -- Scan.option P.nat >> (Toplevel.no_timing oo IsarCmd.pr));
wenzelm@7199
   598
wenzelm@7222
   599
val disable_prP =
wenzelm@7222
   600
  OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
wenzelm@9010
   601
    (Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr));
wenzelm@5832
   602
wenzelm@7222
   603
val enable_prP =
wenzelm@7222
   604
  OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
wenzelm@9010
   605
    (Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr));
wenzelm@7222
   606
wenzelm@5832
   607
val commitP =
wenzelm@6723
   608
  OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
wenzelm@9010
   609
    (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.use_commit));
wenzelm@5832
   610
wenzelm@5832
   611
val quitP =
wenzelm@6723
   612
  OuterSyntax.improper_command "quit" "quit Isabelle" K.control
wenzelm@9010
   613
    (P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit));
wenzelm@5832
   614
wenzelm@5832
   615
val exitP =
wenzelm@6723
   616
  OuterSyntax.improper_command "exit" "exit Isar loop" K.control
wenzelm@9010
   617
    (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
wenzelm@5832
   618
wenzelm@7102
   619
val init_toplevelP =
wenzelm@7102
   620
  OuterSyntax.improper_command "init_toplevel" "restart Isar toplevel loop" K.control
wenzelm@9010
   621
    (Scan.succeed (Toplevel.no_timing o IsarCmd.init_toplevel));
wenzelm@5991
   622
wenzelm@7462
   623
val welcomeP =
wenzelm@8678
   624
  OuterSyntax.improper_command "welcome" "print welcome message" K.diag
wenzelm@9010
   625
    (Scan.succeed (Toplevel.no_timing o IsarCmd.welcome));
wenzelm@7462
   626
wenzelm@5832
   627
wenzelm@5832
   628
wenzelm@5832
   629
(** the Pure outer syntax **)
wenzelm@5832
   630
wenzelm@5832
   631
(*keep keywords consistent with the parsers, including those in
wenzelm@5832
   632
  outer_parse.ML, otherwise be prepared for unexpected errors*)
wenzelm@5832
   633
wenzelm@5832
   634
val keywords =
wenzelm@7415
   635
 ["!", "!!", "%", "%%", "(", ")", "+", ",", "--", ":", "::", ";", "<",
wenzelm@8669
   636
  "<=", "=", "==", "=>", "?", "[", "]", "and", "binder", "concl",
wenzelm@8896
   637
  "files", "in", "infixl", "infixr", "is", "output", "|"];
wenzelm@5832
   638
wenzelm@5832
   639
val parsers = [
wenzelm@5832
   640
  (*theory structure*)
wenzelm@8500
   641
  theoryP, end_excursionP, contextP,
wenzelm@7775
   642
  (*markup commands*)
wenzelm@7733
   643
  headerP, chapterP, sectionP, subsectionP, subsubsectionP, textP,
wenzelm@7862
   644
  text_rawP, sectP, subsectP, subsubsectP, txtP, txt_rawP,
wenzelm@5832
   645
  (*theory sections*)
wenzelm@7172
   646
  classesP, classrelP, defaultsortP, typedeclP, typeabbrP, nontermP,
wenzelm@8227
   647
  aritiesP, judgmentP, constsP, syntaxP, translationsP, axiomsP,
wenzelm@8723
   648
  defsP, constdefsP, theoremsP, lemmasP, globalP, localP, hideP, useP,
wenzelm@8723
   649
  mlP, ml_commandP, ml_setupP, setupP, parse_ast_translationP,
wenzelm@7891
   650
  parse_translationP, print_translationP, typed_print_translationP,
wenzelm@7616
   651
  print_ast_translationP, token_translationP, oracleP,
wenzelm@5832
   652
  (*proof commands*)
wenzelm@6850
   653
  theoremP, lemmaP, showP, haveP, thusP, henceP, assumeP, presumeP,
wenzelm@8464
   654
  defP, fixP, letP, caseP, thenP, fromP, withP, noteP, beginP, endP,
wenzelm@8966
   655
  nextP, qedP, terminal_proofP, default_proofP, immediate_proofP,
wenzelm@8966
   656
  done_proofP, skip_proofP, forget_proofP, deferP, preferP, applyP,
wenzelm@8966
   657
  apply_endP, proofP, alsoP, finallyP, moreoverP, ultimatelyP, backP,
wenzelm@8588
   658
  cannot_undoP, clear_undosP, redoP, undos_proofP, undoP, killP,
wenzelm@5832
   659
  (*diagnostic commands*)
wenzelm@7308
   660
  pretty_setmarginP, print_commandsP, print_contextP, print_theoryP,
wenzelm@7616
   661
  print_syntaxP, print_theoremsP, print_attributesP, print_methodsP,
wenzelm@8370
   662
  thms_containingP, print_bindsP, print_lthmsP, print_casesP,
wenzelm@8370
   663
  print_thmsP, print_propP, print_termP, print_typeP,
wenzelm@5832
   664
  (*system commands*)
wenzelm@7102
   665
  cdP, pwdP, use_thyP, use_thy_onlyP, update_thyP, update_thy_onlyP,
wenzelm@7931
   666
  touch_thyP, touch_all_thysP, touch_child_thysP, remove_thyP,
wenzelm@7931
   667
  kill_thyP, prP, disable_prP, enable_prP, commitP, quitP, exitP,
wenzelm@7931
   668
  init_toplevelP, welcomeP];
wenzelm@5832
   669
wenzelm@5832
   670
wenzelm@5832
   671
end;
wenzelm@5832
   672
wenzelm@5832
   673
wenzelm@6196
   674
(*install the Pure outer syntax*)
wenzelm@5832
   675
OuterSyntax.add_keywords IsarSyn.keywords;
wenzelm@5832
   676
OuterSyntax.add_parsers IsarSyn.parsers;