src/Pure/Isar/isar_syn.ML
author wenzelm
Fri Jul 02 19:04:32 1999 +0200 (1999-07-02 ago)
changeset 6888 d0c68ebdabc5
parent 6886 7d0f7ad5a35f
child 6890 05732285677e
permissions -rw-r--r--
skip_proof feature 'sorry' (for quick_and_dirty mode only);
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@6742
    32
    (Scan.succeed (Toplevel.print o IsarCmd.kill_theory));
wenzelm@5832
    33
wenzelm@6245
    34
val contextP =
wenzelm@6723
    35
  OuterSyntax.improper_command "context" "switch theory context" K.thy_begin
wenzelm@6723
    36
    (P.name >> (Toplevel.print oo IsarThy.context));
wenzelm@6245
    37
wenzelm@6245
    38
val update_contextP =
wenzelm@6723
    39
  OuterSyntax.improper_command "update_context" "switch theory context, forcing update" K.thy_begin
wenzelm@6723
    40
    (P.name >> (Toplevel.print oo IsarThy.update_context));
wenzelm@6245
    41
wenzelm@5832
    42
wenzelm@5832
    43
wenzelm@6886
    44
(** formal comments **)
wenzelm@5832
    45
wenzelm@6886
    46
val txtP = OuterSyntax.command "txt" "formal comment (proof)" K.prf_decl
wenzelm@6886
    47
  (P.comment >> (Toplevel.proof o IsarThy.add_txt));
wenzelm@5832
    48
wenzelm@6886
    49
val textP = OuterSyntax.command "text" "formal comment (theory)" K.thy_decl
wenzelm@6723
    50
  (P.comment >> (Toplevel.theory o IsarThy.add_text));
wenzelm@5958
    51
wenzelm@6723
    52
val titleP = OuterSyntax.command "title" "document title" K.thy_heading
wenzelm@6727
    53
  ((P.comment -- Scan.optional P.comment Comment.none -- Scan.optional P.comment Comment.none)
wenzelm@6353
    54
    >> (fn ((x, y), z) => Toplevel.theory (IsarThy.add_title x y z)));
wenzelm@6353
    55
wenzelm@6723
    56
val chapterP = OuterSyntax.command "chapter" "chapter heading" K.thy_heading
wenzelm@6723
    57
  (P.comment >> (Toplevel.theory o IsarThy.add_chapter));
wenzelm@5958
    58
wenzelm@6723
    59
val sectionP = OuterSyntax.command "section" "section heading" K.thy_heading
wenzelm@6723
    60
  (P.comment >> (Toplevel.theory o IsarThy.add_section));
wenzelm@5958
    61
wenzelm@6723
    62
val subsectionP = OuterSyntax.command "subsection" "subsection heading" K.thy_heading
wenzelm@6723
    63
  (P.comment >> (Toplevel.theory o IsarThy.add_subsection));
wenzelm@5958
    64
wenzelm@6723
    65
val subsubsectionP = OuterSyntax.command "subsubsection" "subsubsection heading" K.thy_heading
wenzelm@6723
    66
  (P.comment >> (Toplevel.theory o IsarThy.add_subsubsection));
wenzelm@5832
    67
wenzelm@5832
    68
wenzelm@6886
    69
wenzelm@6886
    70
(** theory sections **)
wenzelm@6886
    71
wenzelm@5832
    72
(* classes and sorts *)
wenzelm@5832
    73
wenzelm@5832
    74
val classesP =
wenzelm@6723
    75
  OuterSyntax.command "classes" "declare type classes" K.thy_decl
wenzelm@6723
    76
    (Scan.repeat1 (P.name -- Scan.optional (P.$$$ "<" |-- P.!!! (P.list1 P.xname)) [])
wenzelm@6727
    77
      -- P.marg_comment >> (Toplevel.theory o IsarThy.add_classes));
wenzelm@5832
    78
wenzelm@5832
    79
val classrelP =
wenzelm@6723
    80
  OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
wenzelm@6727
    81
    (P.xname -- (P.$$$ "<" |-- P.!!! P.xname) -- P.marg_comment
wenzelm@6727
    82
      >> (Toplevel.theory o IsarThy.add_classrel));
wenzelm@5832
    83
wenzelm@5832
    84
val defaultsortP =
wenzelm@6723
    85
  OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
wenzelm@6727
    86
    (P.sort -- P.marg_comment >> (Toplevel.theory o IsarThy.add_defsort));
wenzelm@5832
    87
wenzelm@5832
    88
wenzelm@5832
    89
(* types *)
wenzelm@5832
    90
wenzelm@5832
    91
val typedeclP =
wenzelm@6723
    92
  OuterSyntax.command "typedecl" "Pure type declaration" K.thy_decl
wenzelm@6727
    93
    (P.type_args -- P.name -- P.opt_infix -- P.marg_comment >> (fn (((args, a), mx), cmt) =>
wenzelm@6727
    94
      Toplevel.theory (IsarThy.add_typedecl ((a, args, mx), cmt))));
wenzelm@5832
    95
wenzelm@5832
    96
val typeabbrP =
wenzelm@6723
    97
  OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
wenzelm@6727
    98
    (Scan.repeat1
wenzelm@6727
    99
      (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix)) -- P.marg_comment)
wenzelm@6727
   100
      >> (Toplevel.theory o IsarThy.add_tyabbrs o
wenzelm@6727
   101
        map (fn (((args, a), (T, mx)), cmt) => ((a, args, T, mx), cmt))));
wenzelm@5832
   102
wenzelm@5832
   103
val nontermP =
wenzelm@6370
   104
  OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
wenzelm@6727
   105
    K.thy_decl (Scan.repeat1 (P.name -- P.marg_comment)
wenzelm@6727
   106
      >> (Toplevel.theory o IsarThy.add_nonterminals));
wenzelm@5832
   107
wenzelm@5832
   108
val aritiesP =
wenzelm@6723
   109
  OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
wenzelm@6727
   110
    (Scan.repeat1 ((P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2) -- P.marg_comment)
wenzelm@6727
   111
      >> (Toplevel.theory o IsarThy.add_arities));
wenzelm@5832
   112
wenzelm@5832
   113
wenzelm@5832
   114
(* consts and syntax *)
wenzelm@5832
   115
wenzelm@5832
   116
val constsP =
wenzelm@6723
   117
  OuterSyntax.command "consts" "declare constants" K.thy_decl
wenzelm@6727
   118
    (Scan.repeat1 (P.const -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_consts));
wenzelm@5832
   119
wenzelm@5832
   120
val opt_mode =
wenzelm@5832
   121
  Scan.optional
wenzelm@6723
   122
    (P.$$$ "(" |-- P.!!! (P.name -- Scan.optional (P.$$$ "output" >> K false) true --| P.$$$ ")"))
wenzelm@5832
   123
    ("", true);
wenzelm@5832
   124
wenzelm@5832
   125
val syntaxP =
wenzelm@6723
   126
  OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
wenzelm@6727
   127
    (opt_mode -- Scan.repeat1 (P.const -- P.marg_comment)
wenzelm@6727
   128
      >> (Toplevel.theory o uncurry IsarThy.add_modesyntax));
wenzelm@5832
   129
wenzelm@5832
   130
wenzelm@5832
   131
(* translations *)
wenzelm@5832
   132
wenzelm@5832
   133
val trans_pat =
wenzelm@6723
   134
  Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
wenzelm@5832
   135
wenzelm@5832
   136
fun trans_arrow toks =
wenzelm@6723
   137
  (P.$$$ "=>" >> K Syntax.ParseRule ||
wenzelm@6723
   138
    P.$$$ "<=" >> K Syntax.PrintRule ||
wenzelm@6723
   139
    P.$$$ "==" >> K Syntax.ParsePrintRule) toks;
wenzelm@5832
   140
wenzelm@5832
   141
val trans_line =
wenzelm@6723
   142
  trans_pat -- P.!!! (trans_arrow -- trans_pat)
wenzelm@5832
   143
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@5832
   144
wenzelm@5832
   145
val translationsP =
wenzelm@6723
   146
  OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
wenzelm@6727
   147
    (Scan.repeat1 (trans_line -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_trrules));
wenzelm@5832
   148
wenzelm@5832
   149
wenzelm@5832
   150
(* axioms and definitions *)
wenzelm@5832
   151
wenzelm@5832
   152
val axiomsP =
wenzelm@6723
   153
  OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
wenzelm@6727
   154
    (Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_axioms));
wenzelm@5832
   155
wenzelm@5832
   156
val defsP =
wenzelm@6723
   157
  OuterSyntax.command "defs" "define constants" K.thy_decl
wenzelm@6727
   158
    (Scan.repeat1 (P.spec_opt_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_defs));
wenzelm@6370
   159
wenzelm@6370
   160
val constdefsP =
wenzelm@6723
   161
  OuterSyntax.command "constdefs" "declare and define constants" K.thy_decl
wenzelm@6727
   162
    (Scan.repeat1 ((P.const -- P.marg_comment) -- (P.term -- P.marg_comment))
wenzelm@6727
   163
      >> (Toplevel.theory o IsarThy.add_constdefs));
wenzelm@5832
   164
wenzelm@5832
   165
wenzelm@5914
   166
(* theorems *)
wenzelm@5914
   167
wenzelm@6723
   168
val facts = P.opt_thm_name "=" -- P.xthms1;
wenzelm@5914
   169
wenzelm@5914
   170
val theoremsP =
wenzelm@6723
   171
  OuterSyntax.command "theorems" "define theorems" K.thy_decl
wenzelm@6727
   172
    (facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_theorems));
wenzelm@5914
   173
wenzelm@5914
   174
val lemmasP =
wenzelm@6723
   175
  OuterSyntax.command "lemmas" "define lemmas" K.thy_decl
wenzelm@6727
   176
    (facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_lemmas));
wenzelm@5914
   177
wenzelm@5914
   178
wenzelm@5832
   179
(* name space entry path *)
wenzelm@5832
   180
wenzelm@5832
   181
val globalP =
wenzelm@6723
   182
  OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
wenzelm@5832
   183
    (Scan.succeed (Toplevel.theory PureThy.global_path));
wenzelm@5832
   184
wenzelm@5832
   185
val localP =
wenzelm@6723
   186
  OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
wenzelm@5832
   187
    (Scan.succeed (Toplevel.theory PureThy.local_path));
wenzelm@5832
   188
wenzelm@5832
   189
val pathP =
wenzelm@6723
   190
  OuterSyntax.command "path" "modify name-space entry path" K.thy_decl
wenzelm@6723
   191
    (P.xname >> (Toplevel.theory o Theory.add_path));
wenzelm@5832
   192
wenzelm@5832
   193
wenzelm@5832
   194
(* use ML text *)
wenzelm@5832
   195
wenzelm@5832
   196
val useP =
wenzelm@6723
   197
  OuterSyntax.command "use" "eval ML text from file" K.diag
wenzelm@6723
   198
    (P.name >> IsarCmd.use);
wenzelm@5832
   199
wenzelm@5832
   200
val mlP =
wenzelm@6723
   201
  OuterSyntax.command "ML" "eval ML text" K.diag
wenzelm@6723
   202
    (P.text >> (fn txt => IsarCmd.use_mltext txt o IsarCmd.use_mltext_theory txt));
wenzelm@5832
   203
wenzelm@5832
   204
val setupP =
wenzelm@6723
   205
  OuterSyntax.command "setup" "apply ML theory transformer" K.thy_decl
wenzelm@6723
   206
    (P.text >> (Toplevel.theory o IsarThy.use_setup));
wenzelm@5832
   207
wenzelm@5832
   208
wenzelm@5832
   209
(* translation functions *)
wenzelm@5832
   210
wenzelm@5832
   211
val parse_ast_translationP =
wenzelm@6723
   212
  OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" K.thy_decl
wenzelm@6723
   213
    (P.text >> (Toplevel.theory o IsarThy.parse_ast_translation));
wenzelm@5832
   214
wenzelm@5832
   215
val parse_translationP =
wenzelm@6723
   216
  OuterSyntax.command "parse_translation" "install parse translation functions" K.thy_decl
wenzelm@6723
   217
    (P.text >> (Toplevel.theory o IsarThy.parse_translation));
wenzelm@5832
   218
wenzelm@5832
   219
val print_translationP =
wenzelm@6723
   220
  OuterSyntax.command "print_translation" "install print translation functions" K.thy_decl
wenzelm@6723
   221
    (P.text >> (Toplevel.theory o IsarThy.print_translation));
wenzelm@5832
   222
wenzelm@5832
   223
val typed_print_translationP =
wenzelm@6370
   224
  OuterSyntax.command "typed_print_translation" "install typed print translation functions"
wenzelm@6723
   225
    K.thy_decl (P.text >> (Toplevel.theory o IsarThy.typed_print_translation));
wenzelm@5832
   226
wenzelm@5832
   227
val print_ast_translationP =
wenzelm@6723
   228
  OuterSyntax.command "print_ast_translation" "install print ast translation functions" K.thy_decl
wenzelm@6723
   229
    (P.text >> (Toplevel.theory o IsarThy.print_ast_translation));
wenzelm@5832
   230
wenzelm@5832
   231
val token_translationP =
wenzelm@6723
   232
  OuterSyntax.command "token_translation" "install token translation functions" K.thy_decl
wenzelm@6723
   233
    (P.text >> (Toplevel.theory o IsarThy.token_translation));
wenzelm@5832
   234
wenzelm@5832
   235
wenzelm@5832
   236
(* oracles *)
wenzelm@5832
   237
wenzelm@5832
   238
val oracleP =
wenzelm@6723
   239
  OuterSyntax.command "oracle" "install oracle" K.thy_decl
wenzelm@6727
   240
    (P.name -- P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.add_oracle));
wenzelm@5832
   241
wenzelm@5832
   242
wenzelm@5832
   243
wenzelm@5832
   244
(** proof commands **)
wenzelm@5832
   245
wenzelm@5832
   246
(* statements *)
wenzelm@5832
   247
wenzelm@6723
   248
val is_props = P.$$$ "(" |-- P.!!! (Scan.repeat1 (P.$$$ "is" |-- P.prop) --| P.$$$ ")");
wenzelm@6723
   249
val propp = P.prop -- Scan.optional is_props [];
wenzelm@6727
   250
fun statement f = (P.opt_thm_name ":" -- propp >> P.triple1) -- P.marg_comment >> f;
wenzelm@5832
   251
wenzelm@5832
   252
val theoremP =
wenzelm@6723
   253
  OuterSyntax.command "theorem" "state theorem" K.thy_goal
wenzelm@5832
   254
    (statement IsarThy.theorem >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
wenzelm@5832
   255
wenzelm@5832
   256
val lemmaP =
wenzelm@6723
   257
  OuterSyntax.command "lemma" "state lemma" K.thy_goal
wenzelm@5832
   258
    (statement IsarThy.lemma >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
wenzelm@5832
   259
wenzelm@5832
   260
val showP =
wenzelm@6723
   261
  OuterSyntax.command "show" "state local goal, solving current obligation" K.prf_goal
wenzelm@5832
   262
    (statement IsarThy.show >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   263
wenzelm@5832
   264
val haveP =
wenzelm@6723
   265
  OuterSyntax.command "have" "state local goal" K.prf_goal
wenzelm@5832
   266
    (statement IsarThy.have >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   267
wenzelm@6501
   268
val thusP =
wenzelm@6723
   269
  OuterSyntax.command "thus" "abbreviates \"then show\"" K.prf_goal
wenzelm@6501
   270
    (statement IsarThy.thus >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@6501
   271
wenzelm@6501
   272
val henceP =
wenzelm@6723
   273
  OuterSyntax.command "hence" "abbreviates \"then have\"" K.prf_goal
wenzelm@6501
   274
    (statement IsarThy.hence >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@6501
   275
wenzelm@5832
   276
wenzelm@5914
   277
(* facts *)
wenzelm@5832
   278
wenzelm@5832
   279
val thenP =
wenzelm@6723
   280
  OuterSyntax.command "then" "forward chaining" K.prf_chain
wenzelm@6727
   281
    (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.chain)));
wenzelm@5832
   282
wenzelm@5832
   283
val fromP =
wenzelm@6723
   284
  OuterSyntax.command "from" "forward chaining from given facts" K.prf_chain
wenzelm@6727
   285
    (P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.from_facts)));
wenzelm@5914
   286
wenzelm@6878
   287
val withP =
wenzelm@6878
   288
  OuterSyntax.command "with" "forward chaining from given and current facts" K.prf_chain
wenzelm@6878
   289
    (P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.with_facts)));
wenzelm@6878
   290
wenzelm@6773
   291
val noteP =
wenzelm@6723
   292
  OuterSyntax.command "note" "define facts" K.prf_decl
wenzelm@6755
   293
    (facts -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.have_facts)));
wenzelm@5832
   294
wenzelm@5832
   295
wenzelm@5832
   296
(* proof context *)
wenzelm@5832
   297
wenzelm@5832
   298
val assumeP =
wenzelm@6869
   299
  OuterSyntax.command "assume" "assume propositions" K.prf_asm
wenzelm@6727
   300
    ((P.opt_thm_name ":" -- Scan.repeat1 propp >> P.triple1) -- P.marg_comment
wenzelm@6727
   301
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.assume)));
wenzelm@5832
   302
wenzelm@6850
   303
val presumeP =
wenzelm@6869
   304
  OuterSyntax.command "presume" "assume propositions, to be established later" K.prf_asm
wenzelm@6850
   305
    ((P.opt_thm_name ":" -- Scan.repeat1 propp >> P.triple1) -- P.marg_comment
wenzelm@6850
   306
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.presume)));
wenzelm@6850
   307
wenzelm@5832
   308
val fixP =
wenzelm@6869
   309
  OuterSyntax.command "fix" "fix variables (Skolem constants)" K.prf_asm
wenzelm@6727
   310
    (Scan.repeat1 (P.name -- Scan.option (P.$$$ "::" |-- P.typ)) -- P.marg_comment
wenzelm@6727
   311
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.fix)));
wenzelm@5832
   312
wenzelm@5832
   313
val letP =
wenzelm@6723
   314
  OuterSyntax.command "let" "bind text variables" K.prf_decl
wenzelm@6727
   315
    (P.and_list1 (P.enum1 "as" P.term -- (P.$$$ "=" |-- P.term) -- P.marg_comment)
wenzelm@6727
   316
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.match_bind)));
wenzelm@5832
   317
wenzelm@5832
   318
wenzelm@5832
   319
(* proof structure *)
wenzelm@5832
   320
wenzelm@5832
   321
val beginP =
wenzelm@6723
   322
  OuterSyntax.command "{{" "begin explicit proof block" K.prf_block
wenzelm@5832
   323
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.begin_block));
wenzelm@5832
   324
wenzelm@6687
   325
val endP =
wenzelm@6723
   326
  OuterSyntax.command "}}" "end explicit proof block" K.prf_block
wenzelm@6687
   327
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.end_block));
wenzelm@6687
   328
wenzelm@5832
   329
val nextP =
wenzelm@6723
   330
  OuterSyntax.command "next" "enter next proof block" K.prf_block
wenzelm@5832
   331
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.next_block));
wenzelm@5832
   332
wenzelm@5832
   333
wenzelm@5832
   334
(* end proof *)
wenzelm@5832
   335
wenzelm@5832
   336
val qed_withP =
wenzelm@6735
   337
  OuterSyntax.improper_command "qed_with" "conclude proof, may patch name and attributes"
wenzelm@6735
   338
    K.qed_block
wenzelm@6727
   339
    (Scan.option P.name -- Scan.option P.attribs -- Scan.option (P.method -- P.interest)
wenzelm@6404
   340
      >> (uncurry IsarThy.global_qed_with));
wenzelm@6404
   341
wenzelm@6404
   342
val qedP =
wenzelm@6735
   343
  OuterSyntax.command "qed" "conclude (sub-)proof" K.qed_block
wenzelm@6727
   344
    (Scan.option (P.method -- P.interest) >> IsarThy.qed);
wenzelm@5832
   345
wenzelm@6404
   346
val terminal_proofP =
wenzelm@6723
   347
  OuterSyntax.command "by" "terminal backward proof" K.qed
wenzelm@6727
   348
    (P.method -- P.interest >> IsarThy.terminal_proof);
wenzelm@6404
   349
wenzelm@6404
   350
val immediate_proofP =
wenzelm@6723
   351
  OuterSyntax.command "." "immediate proof" K.qed
wenzelm@6530
   352
    (Scan.succeed IsarThy.immediate_proof);
wenzelm@6404
   353
wenzelm@6404
   354
val default_proofP =
wenzelm@6723
   355
  OuterSyntax.command ".." "default proof" K.qed
wenzelm@6530
   356
    (Scan.succeed IsarThy.default_proof);
wenzelm@5832
   357
wenzelm@6888
   358
val skip_proofP =
wenzelm@6888
   359
  OuterSyntax.command "sorry" "skip proof (quick-and-dirty mode only!)" K.qed
wenzelm@6888
   360
    (Scan.succeed IsarThy.skip_proof);
wenzelm@6888
   361
wenzelm@5832
   362
wenzelm@5832
   363
(* proof steps *)
wenzelm@5832
   364
wenzelm@6850
   365
val applyP =
wenzelm@6850
   366
  OuterSyntax.improper_command "apply" "unstructured backward proof step, ignoring facts"
wenzelm@6723
   367
    K.prf_script (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.tac)));
wenzelm@5832
   368
wenzelm@6850
   369
val then_applyP =
wenzelm@6850
   370
  OuterSyntax.improper_command "then_apply" "unstructured backward proof step, using facts"
wenzelm@6723
   371
    K.prf_script (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.then_tac)));
wenzelm@5832
   372
wenzelm@6404
   373
val proofP =
wenzelm@6723
   374
  OuterSyntax.command "proof" "backward proof" K.prf_block
wenzelm@6727
   375
    (P.interest -- Scan.option (P.method -- P.interest)
wenzelm@6727
   376
      >> (Toplevel.print oo (Toplevel.proof o IsarThy.proof)));
wenzelm@5832
   377
wenzelm@5832
   378
wenzelm@6773
   379
(* calculational proof commands *)
wenzelm@6773
   380
wenzelm@6878
   381
val calc_args =
wenzelm@6878
   382
  Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")") -- P.interest));
wenzelm@6878
   383
wenzelm@6773
   384
val alsoP =
wenzelm@6773
   385
  OuterSyntax.command "also" "intermediate calculational proof step" K.prf_decl
wenzelm@6878
   386
    (calc_args -- P.marg_comment >> IsarThy.also);
wenzelm@6773
   387
wenzelm@6773
   388
val finallyP =
wenzelm@6773
   389
  OuterSyntax.command "finally" "terminal calculational proof step" K.prf_chain
wenzelm@6878
   390
    (calc_args -- P.marg_comment >> IsarThy.finally);
wenzelm@6773
   391
wenzelm@6773
   392
wenzelm@6742
   393
(* proof navigation *)
wenzelm@5944
   394
wenzelm@5832
   395
val backP =
wenzelm@6723
   396
  OuterSyntax.improper_command "back" "backtracking of proof command" K.prf_script
wenzelm@5832
   397
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.back));
wenzelm@5832
   398
wenzelm@5832
   399
val prevP =
wenzelm@6723
   400
  OuterSyntax.improper_command "prev" "previous proof state" K.control
wenzelm@5832
   401
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.prev));
wenzelm@5832
   402
wenzelm@5832
   403
val upP =
wenzelm@6723
   404
  OuterSyntax.improper_command "up" "upper proof state" K.control
wenzelm@5832
   405
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.up));
wenzelm@5832
   406
wenzelm@5832
   407
val topP =
wenzelm@6723
   408
  OuterSyntax.improper_command "top" "to initial proof state" K.control
wenzelm@5832
   409
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.top));
wenzelm@5832
   410
wenzelm@5832
   411
wenzelm@6742
   412
(* history *)
wenzelm@6742
   413
wenzelm@6742
   414
val cannot_undoP =
wenzelm@6742
   415
  OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control
wenzelm@6742
   416
    (P.name >> (Toplevel.print oo IsarCmd.cannot_undo));
wenzelm@6742
   417
wenzelm@6742
   418
val clear_undoP =
wenzelm@6742
   419
  OuterSyntax.improper_command "clear_undo" "clear undo information" K.control
wenzelm@6742
   420
    (Scan.succeed (Toplevel.print o IsarCmd.clear_undo));
wenzelm@6742
   421
wenzelm@6742
   422
val redoP =
wenzelm@6742
   423
  OuterSyntax.improper_command "redo" "redo last command" K.control
wenzelm@6742
   424
    (Scan.succeed (Toplevel.print o IsarCmd.redo));
wenzelm@6742
   425
wenzelm@6742
   426
val undos_proofP =
wenzelm@6742
   427
  OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control
wenzelm@6742
   428
    (P.nat >> (Toplevel.print oo IsarCmd.undos_proof));
wenzelm@6742
   429
wenzelm@6742
   430
val kill_proofP =
wenzelm@6742
   431
  OuterSyntax.improper_command "kill_proof" "undo current proof" K.control
wenzelm@6742
   432
    (Scan.succeed (Toplevel.print o IsarCmd.kill_proof));
wenzelm@6742
   433
wenzelm@6742
   434
val undoP =
wenzelm@6742
   435
  OuterSyntax.improper_command "undo" "undo last command" K.control
wenzelm@6742
   436
    (Scan.succeed (Toplevel.print o IsarCmd.undo));
wenzelm@6742
   437
wenzelm@6742
   438
wenzelm@5832
   439
wenzelm@5832
   440
(** diagnostic commands (for interactive mode only) **)
wenzelm@5832
   441
wenzelm@5832
   442
val print_commandsP =
wenzelm@6723
   443
  OuterSyntax.improper_command "help" "print outer syntax (global)" K.diag
wenzelm@5832
   444
    (Scan.succeed (Toplevel.imperative OuterSyntax.print_outer_syntax));
wenzelm@5832
   445
wenzelm@5832
   446
val print_theoryP =
wenzelm@6723
   447
  OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
wenzelm@5832
   448
    (Scan.succeed IsarCmd.print_theory);
wenzelm@5832
   449
wenzelm@5832
   450
val print_syntaxP =
wenzelm@6723
   451
  OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)" K.diag
wenzelm@5832
   452
    (Scan.succeed IsarCmd.print_syntax);
wenzelm@5832
   453
wenzelm@5881
   454
val print_theoremsP =
wenzelm@6723
   455
  OuterSyntax.improper_command "print_theorems" "print theorems known in this theory" K.diag
wenzelm@5881
   456
    (Scan.succeed IsarCmd.print_theorems);
wenzelm@5881
   457
wenzelm@5832
   458
val print_attributesP =
wenzelm@6723
   459
  OuterSyntax.improper_command "print_attributes" "print attributes known in this theory" K.diag
wenzelm@5832
   460
    (Scan.succeed IsarCmd.print_attributes);
wenzelm@5832
   461
wenzelm@5832
   462
val print_methodsP =
wenzelm@6723
   463
  OuterSyntax.improper_command "print_methods" "print methods known in this theory" K.diag
wenzelm@5832
   464
    (Scan.succeed IsarCmd.print_methods);
wenzelm@5832
   465
wenzelm@5832
   466
val print_bindsP =
wenzelm@6723
   467
  OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
wenzelm@5832
   468
    (Scan.succeed IsarCmd.print_binds);
wenzelm@5832
   469
wenzelm@5832
   470
val print_lthmsP =
wenzelm@6723
   471
  OuterSyntax.improper_command "print_facts" "print local theorems of proof context" K.diag
wenzelm@5832
   472
    (Scan.succeed IsarCmd.print_lthms);
wenzelm@5832
   473
wenzelm@5896
   474
val print_thmsP =
wenzelm@6723
   475
  OuterSyntax.improper_command "thm" "print theorems" K.diag (P.xthm >> IsarCmd.print_thms);
wenzelm@5832
   476
wenzelm@5832
   477
val print_propP =
wenzelm@6723
   478
  OuterSyntax.improper_command "prop" "read and print proposition" K.diag
wenzelm@6723
   479
    (P.term >> IsarCmd.print_prop);
wenzelm@5832
   480
wenzelm@5832
   481
val print_termP =
wenzelm@6723
   482
  OuterSyntax.improper_command "term" "read and print term" K.diag
wenzelm@6723
   483
    (P.term >> IsarCmd.print_term);
wenzelm@5832
   484
wenzelm@5832
   485
val print_typeP =
wenzelm@6723
   486
  OuterSyntax.improper_command "typ" "read and print type" K.diag
wenzelm@6723
   487
    (P.typ >> IsarCmd.print_type);
wenzelm@5832
   488
wenzelm@5832
   489
wenzelm@5832
   490
wenzelm@5832
   491
(** system commands (for interactive mode only) **)
wenzelm@5832
   492
wenzelm@5832
   493
val cdP =
wenzelm@6723
   494
  OuterSyntax.improper_command "cd" "change current working directory" K.control
wenzelm@6723
   495
    (P.name >> IsarCmd.cd);
wenzelm@5832
   496
wenzelm@5832
   497
val pwdP =
wenzelm@6723
   498
  OuterSyntax.improper_command "pwd" "print current working directory" K.diag
wenzelm@5832
   499
    (Scan.succeed IsarCmd.pwd);
wenzelm@5832
   500
wenzelm@5832
   501
val use_thyP =
wenzelm@6723
   502
  OuterSyntax.improper_command "use_thy" "use theory file" K.diag
wenzelm@6723
   503
    (P.name >> IsarCmd.use_thy);
wenzelm@5832
   504
wenzelm@6694
   505
val use_thy_onlyP =
wenzelm@6723
   506
  OuterSyntax.improper_command "use_thy_only" "use theory file only, ignoring associated ML" K.diag
wenzelm@6723
   507
    (P.name >> IsarCmd.use_thy_only);
wenzelm@6694
   508
wenzelm@6196
   509
val update_thyP =
wenzelm@6723
   510
  OuterSyntax.improper_command "update_thy" "update theory file" K.diag
wenzelm@6723
   511
    (P.name >> IsarCmd.update_thy);
wenzelm@5832
   512
wenzelm@5832
   513
val prP =
wenzelm@6723
   514
  OuterSyntax.improper_command "pr" "print current toplevel state" K.diag
wenzelm@5832
   515
    (Scan.succeed (Toplevel.print o Toplevel.imperative (K ())));
wenzelm@5832
   516
wenzelm@5832
   517
wenzelm@6723
   518
val opt_unit = Scan.optional (P.$$$ "(" -- P.$$$ ")" >> (K ())) ();
wenzelm@5832
   519
wenzelm@5832
   520
val commitP =
wenzelm@6723
   521
  OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
wenzelm@5832
   522
    (opt_unit >> (K IsarCmd.use_commit));
wenzelm@5832
   523
wenzelm@5832
   524
val quitP =
wenzelm@6723
   525
  OuterSyntax.improper_command "quit" "quit Isabelle" K.control
wenzelm@5832
   526
    (opt_unit >> (K IsarCmd.quit));
wenzelm@5832
   527
wenzelm@5832
   528
val exitP =
wenzelm@6723
   529
  OuterSyntax.improper_command "exit" "exit Isar loop" K.control
wenzelm@5832
   530
    (Scan.succeed IsarCmd.exit);
wenzelm@5832
   531
wenzelm@5991
   532
val restartP =
wenzelm@6723
   533
  OuterSyntax.improper_command "restart" "restart Isar loop" K.control
wenzelm@5991
   534
    (Scan.succeed IsarCmd.restart);
wenzelm@5991
   535
wenzelm@5832
   536
val breakP =
wenzelm@6723
   537
  OuterSyntax.improper_command "break" "discontinue excursion (keep current state)" K.control
wenzelm@5832
   538
    (Scan.succeed IsarCmd.break);
wenzelm@5832
   539
wenzelm@5832
   540
wenzelm@5832
   541
wenzelm@5832
   542
(** the Pure outer syntax **)
wenzelm@5832
   543
wenzelm@5832
   544
(*keep keywords consistent with the parsers, including those in
wenzelm@5832
   545
  outer_parse.ML, otherwise be prepared for unexpected errors*)
wenzelm@5832
   546
wenzelm@5832
   547
val keywords =
wenzelm@6551
   548
 ["!", "%", "(", ")", "*", "+", ",", "--", ":", "::", ";", "<", "<=",
wenzelm@6551
   549
  "=", "==", "=>", "?", "[", "]", "and", "as", "binder", "files",
wenzelm@6551
   550
  "infixl", "infixr", "is", "output", "{", "|", "}"];
wenzelm@5832
   551
wenzelm@5832
   552
val parsers = [
wenzelm@5832
   553
  (*theory structure*)
wenzelm@6687
   554
  theoryP, end_excursionP, kill_excursionP, contextP, update_contextP,
wenzelm@5832
   555
  (*theory sections*)
wenzelm@6886
   556
  txtP, textP, titleP, chapterP, sectionP, subsectionP,
wenzelm@6886
   557
  subsubsectionP, classesP, classrelP, defaultsortP, typedeclP,
wenzelm@6886
   558
  typeabbrP, nontermP, aritiesP, constsP, syntaxP, translationsP,
wenzelm@6886
   559
  axiomsP, defsP, constdefsP, theoremsP, lemmasP, globalP, localP,
wenzelm@6886
   560
  pathP, useP, mlP, setupP, parse_ast_translationP,
wenzelm@6886
   561
  parse_translationP, print_translationP, typed_print_translationP,
wenzelm@6370
   562
  print_ast_translationP, token_translationP, oracleP,
wenzelm@5832
   563
  (*proof commands*)
wenzelm@6850
   564
  theoremP, lemmaP, showP, haveP, thusP, henceP, assumeP, presumeP,
wenzelm@6878
   565
  fixP, letP, thenP, fromP, withP, noteP, beginP, endP, nextP,
wenzelm@6878
   566
  qed_withP, qedP, terminal_proofP, immediate_proofP, default_proofP,
wenzelm@6888
   567
  skip_proofP, applyP, then_applyP, proofP, alsoP, finallyP, backP,
wenzelm@6888
   568
  prevP, upP, topP, cannot_undoP, clear_undoP, redoP, undos_proofP,
wenzelm@6888
   569
  kill_proofP, undoP,
wenzelm@5832
   570
  (*diagnostic commands*)
wenzelm@5832
   571
  print_commandsP, print_theoryP, print_syntaxP, print_attributesP,
wenzelm@5881
   572
  print_methodsP, print_theoremsP, print_bindsP, print_lthmsP,
wenzelm@5914
   573
  print_thmsP, print_propP, print_termP, print_typeP,
wenzelm@5832
   574
  (*system commands*)
wenzelm@6694
   575
  cdP, pwdP, use_thyP, use_thy_onlyP, update_thyP, prP, commitP,
wenzelm@6694
   576
  quitP, exitP, restartP, breakP];
wenzelm@5832
   577
wenzelm@5832
   578
wenzelm@5832
   579
end;
wenzelm@5832
   580
wenzelm@5832
   581
wenzelm@6196
   582
(*install the Pure outer syntax*)
wenzelm@5832
   583
OuterSyntax.add_keywords IsarSyn.keywords;
wenzelm@5832
   584
OuterSyntax.add_parsers IsarSyn.parsers;