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