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