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