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