src/Pure/Isar/isar_syn.ML
author wenzelm
Fri May 21 11:41:46 1999 +0200 (1999-05-21 ago)
changeset 6687 134df1440f6e
parent 6551 de4047b03017
child 6694 335833a8b10a
permissions -rw-r--r--
renamed 'begin' / 'end' to '{{' / '}}';
added 'kill';
rename 'type' to 'typ';
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@5832
    17
open OuterParse;
wenzelm@5832
    18
wenzelm@5832
    19
wenzelm@5832
    20
(** init and exit **)
wenzelm@5832
    21
wenzelm@5832
    22
val theoryP =
wenzelm@6370
    23
  OuterSyntax.command "theory" "begin theory"
wenzelm@6245
    24
    (OuterSyntax.theory_header >> (Toplevel.print oo IsarThy.theory));
wenzelm@5832
    25
wenzelm@6687
    26
val end_excursionP =
wenzelm@6687
    27
  OuterSyntax.command "end" "end current excursion"
wenzelm@6687
    28
    (Scan.succeed (Toplevel.print o Toplevel.exit));
wenzelm@6687
    29
wenzelm@6687
    30
val kill_excursionP =
wenzelm@6687
    31
  OuterSyntax.command "kill" "kill current excursion"
wenzelm@6687
    32
    (Scan.succeed (Toplevel.print o Toplevel.kill));
wenzelm@5832
    33
wenzelm@6245
    34
val contextP =
wenzelm@6370
    35
  OuterSyntax.improper_command "context" "switch theory context"
wenzelm@6245
    36
    (name >> (Toplevel.print oo IsarThy.context));
wenzelm@6245
    37
wenzelm@6245
    38
val update_contextP =
wenzelm@6370
    39
  OuterSyntax.improper_command "update_context" "switch theory context, forcing update"
wenzelm@6245
    40
    (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@6370
    48
val textP = OuterSyntax.command "text" "formal comments"
wenzelm@6551
    49
  (comment >> (Toplevel.theory o IsarThy.add_text));
wenzelm@5958
    50
wenzelm@6370
    51
val titleP = OuterSyntax.command "title" "document title"
wenzelm@6551
    52
  ((comment -- Scan.optional comment Comment.empty -- Scan.optional comment Comment.empty)
wenzelm@6353
    53
    >> (fn ((x, y), z) => Toplevel.theory (IsarThy.add_title x y z)));
wenzelm@6353
    54
wenzelm@6370
    55
val chapterP = OuterSyntax.command "chapter" "chapter heading"
wenzelm@6551
    56
  (comment >> (Toplevel.theory o IsarThy.add_chapter));
wenzelm@5958
    57
wenzelm@6370
    58
val sectionP = OuterSyntax.command "section" "section heading"
wenzelm@6551
    59
  (comment >> (Toplevel.theory o IsarThy.add_section));
wenzelm@5958
    60
wenzelm@6370
    61
val subsectionP = OuterSyntax.command "subsection" "subsection heading"
wenzelm@6551
    62
  (comment >> (Toplevel.theory o IsarThy.add_subsection));
wenzelm@5958
    63
wenzelm@6370
    64
val subsubsectionP = OuterSyntax.command "subsubsection" "subsubsection heading"
wenzelm@6551
    65
  (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@6370
    71
  OuterSyntax.command "classes" "declare type classes"
wenzelm@5832
    72
    (Scan.repeat1 (name -- Scan.optional ($$$ "<" |-- !!! (list1 xname)) [])
wenzelm@5832
    73
      >> (Toplevel.theory o Theory.add_classes));
wenzelm@5832
    74
wenzelm@5832
    75
val classrelP =
wenzelm@6370
    76
  OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)"
wenzelm@5832
    77
    (xname -- ($$$ "<" |-- !!! xname) >> (Toplevel.theory o Theory.add_classrel o single));
wenzelm@5832
    78
wenzelm@5832
    79
val defaultsortP =
wenzelm@6370
    80
  OuterSyntax.command "defaultsort" "declare default sort"
wenzelm@5832
    81
    (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@6370
    87
  OuterSyntax.command "typedecl" "Pure type declaration"
wenzelm@5832
    88
    (type_args -- name -- 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@6370
    92
  OuterSyntax.command "types" "declare type abbreviations"
wenzelm@5832
    93
    (Scan.repeat1 (type_args -- name -- ($$$ "=" |-- !!! (typ -- 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@5832
    99
    (Scan.repeat1 name >> (Toplevel.theory o Theory.add_nonterminals));
wenzelm@5832
   100
wenzelm@5832
   101
val aritiesP =
wenzelm@6370
   102
  OuterSyntax.command "arities" "state type arities (axiomatic!)"
wenzelm@5832
   103
    (Scan.repeat1 (xname -- ($$$ "::" |-- !!! arity) >> 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@6370
   110
  OuterSyntax.command "consts" "declare constants"
wenzelm@5832
   111
    (Scan.repeat1 const >> (Toplevel.theory o Theory.add_consts));
wenzelm@5832
   112
wenzelm@5832
   113
val opt_mode =
wenzelm@5832
   114
  Scan.optional
wenzelm@5832
   115
    ($$$ "(" |-- !!! (name -- Scan.optional ($$$ "output" >> K false) true --| $$$ ")"))
wenzelm@5832
   116
    ("", true);
wenzelm@5832
   117
wenzelm@5832
   118
val syntaxP =
wenzelm@6370
   119
  OuterSyntax.command "syntax" "declare syntactic constants"
wenzelm@5832
   120
    (opt_mode -- Scan.repeat1 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@5832
   126
  Scan.optional ($$$ "(" |-- !!! (xname --| $$$ ")")) "logic" -- string;
wenzelm@5832
   127
wenzelm@5832
   128
fun trans_arrow toks =
wenzelm@5832
   129
  ($$$ "=>" >> K Syntax.ParseRule ||
wenzelm@5832
   130
    $$$ "<=" >> K Syntax.PrintRule ||
wenzelm@5832
   131
    $$$ "==" >> K Syntax.ParsePrintRule) toks;
wenzelm@5832
   132
wenzelm@5832
   133
val trans_line =
wenzelm@5832
   134
  trans_pat -- !!! (trans_arrow -- trans_pat)
wenzelm@5832
   135
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@5832
   136
wenzelm@5832
   137
val translationsP =
wenzelm@6370
   138
  OuterSyntax.command "translations" "declare syntax translation rules"
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@6370
   145
  OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)"
wenzelm@6370
   146
    (Scan.repeat1 spec_name >> (Toplevel.theory o IsarThy.add_axioms));
wenzelm@5832
   147
wenzelm@5832
   148
val defsP =
wenzelm@6370
   149
  OuterSyntax.command "defs" "define constants"
wenzelm@6370
   150
    (Scan.repeat1 spec_opt_name >> (Toplevel.theory o IsarThy.add_defs));
wenzelm@6370
   151
wenzelm@6370
   152
val constdefsP =
wenzelm@6370
   153
  OuterSyntax.command "constdefs" "declare and define constants"
wenzelm@6370
   154
    (Scan.repeat1 (const -- term) >> (Toplevel.theory o IsarThy.add_constdefs));
wenzelm@5832
   155
wenzelm@5832
   156
wenzelm@5914
   157
(* theorems *)
wenzelm@5914
   158
wenzelm@5914
   159
val facts = opt_thm_name "=" -- xthms1;
wenzelm@5914
   160
wenzelm@5914
   161
val theoremsP =
wenzelm@6370
   162
  OuterSyntax.command "theorems" "define theorems"
wenzelm@5914
   163
    (facts >> (Toplevel.theory o IsarThy.have_theorems));
wenzelm@5914
   164
wenzelm@5914
   165
val lemmasP =
wenzelm@6370
   166
  OuterSyntax.command "lemmas" "define lemmas"
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@6370
   173
  OuterSyntax.command "global" "disable prefixing of theory name"
wenzelm@5832
   174
    (Scan.succeed (Toplevel.theory PureThy.global_path));
wenzelm@5832
   175
wenzelm@5832
   176
val localP =
wenzelm@6370
   177
  OuterSyntax.command "local" "enable prefixing of theory name"
wenzelm@5832
   178
    (Scan.succeed (Toplevel.theory PureThy.local_path));
wenzelm@5832
   179
wenzelm@5832
   180
val pathP =
wenzelm@6370
   181
  OuterSyntax.command "path" "modify name-space entry path"
wenzelm@5832
   182
    (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@6370
   188
  OuterSyntax.command "use" "eval ML text from file"
wenzelm@5958
   189
    (name >> IsarCmd.use);
wenzelm@5832
   190
wenzelm@5832
   191
val mlP =
wenzelm@6370
   192
  OuterSyntax.command "ML" "eval ML text"
wenzelm@5832
   193
    (text >> (fn txt => IsarCmd.use_mltext txt o IsarCmd.use_mltext_theory txt));
wenzelm@5832
   194
wenzelm@5832
   195
val setupP =
wenzelm@6370
   196
  OuterSyntax.command "setup" "apply ML theory transformer"
wenzelm@5832
   197
    (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@6370
   203
  OuterSyntax.command "parse_ast_translation" "install parse ast translation functions"
wenzelm@5832
   204
    (text >> (Toplevel.theory o IsarThy.parse_ast_translation));
wenzelm@5832
   205
wenzelm@5832
   206
val parse_translationP =
wenzelm@6370
   207
  OuterSyntax.command "parse_translation" "install parse translation functions"
wenzelm@5832
   208
    (text >> (Toplevel.theory o IsarThy.parse_translation));
wenzelm@5832
   209
wenzelm@5832
   210
val print_translationP =
wenzelm@6370
   211
  OuterSyntax.command "print_translation" "install print translation functions"
wenzelm@5832
   212
    (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@5832
   216
    (text >> (Toplevel.theory o IsarThy.typed_print_translation));
wenzelm@5832
   217
wenzelm@5832
   218
val print_ast_translationP =
wenzelm@6370
   219
  OuterSyntax.command "print_ast_translation" "install print ast translation functions"
wenzelm@5832
   220
    (text >> (Toplevel.theory o IsarThy.print_ast_translation));
wenzelm@5832
   221
wenzelm@5832
   222
val token_translationP =
wenzelm@6370
   223
  OuterSyntax.command "token_translation" "install token translation functions"
wenzelm@5832
   224
    (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@6370
   230
  OuterSyntax.command "oracle" "install oracle"
wenzelm@5832
   231
    (name -- 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@5937
   239
val is_props = $$$ "(" |-- !!! (Scan.repeat1 ($$$ "is" |-- prop) --| $$$ ")");
wenzelm@5937
   240
val propp = prop -- Scan.optional is_props [];
wenzelm@5937
   241
fun statement f = opt_thm_name ":" -- propp >> (fn ((x, y), z) => f x y z);
wenzelm@5832
   242
wenzelm@5832
   243
val theoremP =
wenzelm@6370
   244
  OuterSyntax.command "theorem" "state theorem"
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@6370
   248
  OuterSyntax.command "lemma" "state lemma"
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@6370
   252
  OuterSyntax.command "show" "state local goal, solving current obligation"
wenzelm@5832
   253
    (statement IsarThy.show >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   254
wenzelm@5832
   255
val haveP =
wenzelm@6370
   256
  OuterSyntax.command "have" "state local goal"
wenzelm@5832
   257
    (statement IsarThy.have >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   258
wenzelm@6501
   259
val thusP =
wenzelm@6501
   260
  OuterSyntax.command "thus" "abbreviates \"then show\""
wenzelm@6501
   261
    (statement IsarThy.thus >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@6501
   262
wenzelm@6501
   263
val henceP =
wenzelm@6501
   264
  OuterSyntax.command "hence" "abbreviates \"then have\""
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@6370
   271
  OuterSyntax.command "then" "forward chaining"
wenzelm@5832
   272
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.chain));
wenzelm@5832
   273
wenzelm@5832
   274
val fromP =
wenzelm@6370
   275
  OuterSyntax.command "from" "forward chaining from given facts"
wenzelm@5914
   276
    (xthms1 >> (fn x => Toplevel.print o Toplevel.proof (IsarThy.from_facts x)));
wenzelm@5914
   277
wenzelm@5914
   278
val factsP =
wenzelm@6370
   279
  OuterSyntax.command "note" "define facts"
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@6370
   286
  OuterSyntax.command "assume" "assume propositions"
wenzelm@6370
   287
    (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@6370
   291
  OuterSyntax.command "fix" "fix variables (Skolem constants)"
wenzelm@6370
   292
    (Scan.repeat1 (name -- Scan.option ($$$ "::" |-- typ))
wenzelm@5832
   293
      >> (fn xs => Toplevel.print o Toplevel.proof (IsarThy.fix xs)));
wenzelm@5832
   294
wenzelm@5832
   295
val letP =
wenzelm@6370
   296
  OuterSyntax.command "let" "bind text variables"
wenzelm@6013
   297
    (and_list1 (enum1 "as" term -- ($$$ "=" |-- 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@6687
   304
  OuterSyntax.command "{{" "begin explicit proof block"
wenzelm@5832
   305
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.begin_block));
wenzelm@5832
   306
wenzelm@6687
   307
val endP =
wenzelm@6687
   308
  OuterSyntax.command "}}" "end explicit proof block"
wenzelm@6687
   309
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.end_block));
wenzelm@6687
   310
wenzelm@5832
   311
val nextP =
wenzelm@6687
   312
  OuterSyntax.command "next" "enter next proof 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@6687
   319
  OuterSyntax.improper_command "kill_proof" "abort current proof"
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@6370
   323
  OuterSyntax.improper_command "qed_with" "conclude proof, may patch name and attributes"
wenzelm@6404
   324
    (Scan.option name -- Scan.option attribs -- Scan.option method
wenzelm@6404
   325
      >> (uncurry IsarThy.global_qed_with));
wenzelm@6404
   326
wenzelm@6404
   327
val qedP =
wenzelm@6404
   328
  OuterSyntax.command "qed" "conclude (sub-)proof"
wenzelm@6404
   329
    (Scan.option method >> IsarThy.qed);
wenzelm@5832
   330
wenzelm@6404
   331
val terminal_proofP =
wenzelm@6404
   332
  OuterSyntax.command "by" "terminal backward proof"
wenzelm@6530
   333
    (method >> IsarThy.terminal_proof)
wenzelm@6404
   334
wenzelm@6404
   335
val immediate_proofP =
wenzelm@6404
   336
  OuterSyntax.command "." "immediate proof"
wenzelm@6530
   337
    (Scan.succeed IsarThy.immediate_proof);
wenzelm@6404
   338
wenzelm@6404
   339
val default_proofP =
wenzelm@6404
   340
  OuterSyntax.command ".." "default proof"
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@6404
   348
    (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@6404
   352
    (method >> (Toplevel.print oo (Toplevel.proof o IsarThy.then_tac)));
wenzelm@5832
   353
wenzelm@6404
   354
val proofP =
wenzelm@6404
   355
  OuterSyntax.command "proof" "backward proof"
wenzelm@6404
   356
    (Scan.option 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@6687
   362
  OuterSyntax.improper_command "clear_undo" "clear undo information"
wenzelm@6687
   363
    (Scan.succeed (Toplevel.print o IsarCmd.clear_undo));
wenzelm@5832
   364
wenzelm@5832
   365
val undoP =
wenzelm@6687
   366
  OuterSyntax.improper_command "undo" "undo last command"
wenzelm@6687
   367
    (Scan.succeed (Toplevel.print o IsarCmd.undo));
wenzelm@5832
   368
wenzelm@5832
   369
val redoP =
wenzelm@6687
   370
  OuterSyntax.improper_command "redo" "redo last command"
wenzelm@6687
   371
    (Scan.succeed (Toplevel.print o IsarCmd.redo));
wenzelm@5832
   372
wenzelm@5944
   373
val undosP =
wenzelm@6687
   374
  OuterSyntax.improper_command "undos" "undo last commands"
wenzelm@6687
   375
    (nat >> (fn n => Toplevel.print o IsarCmd.undos n));
wenzelm@5944
   376
wenzelm@5832
   377
val backP =
wenzelm@6370
   378
  OuterSyntax.improper_command "back" "backtracking of proof command"
wenzelm@5832
   379
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.back));
wenzelm@5832
   380
wenzelm@5832
   381
val prevP =
wenzelm@6370
   382
  OuterSyntax.improper_command "prev" "previous proof state"
wenzelm@5832
   383
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.prev));
wenzelm@5832
   384
wenzelm@5832
   385
val upP =
wenzelm@6370
   386
  OuterSyntax.improper_command "up" "upper proof state"
wenzelm@5832
   387
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.up));
wenzelm@5832
   388
wenzelm@5832
   389
val topP =
wenzelm@6370
   390
  OuterSyntax.improper_command "top" "to initial proof state"
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@6370
   398
  OuterSyntax.improper_command "help" "print outer syntax (global)"
wenzelm@5832
   399
    (Scan.succeed (Toplevel.imperative OuterSyntax.print_outer_syntax));
wenzelm@5832
   400
wenzelm@5832
   401
val print_theoryP =
wenzelm@6370
   402
  OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)"
wenzelm@5832
   403
    (Scan.succeed IsarCmd.print_theory);
wenzelm@5832
   404
wenzelm@5832
   405
val print_syntaxP =
wenzelm@6370
   406
  OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)"
wenzelm@5832
   407
    (Scan.succeed IsarCmd.print_syntax);
wenzelm@5832
   408
wenzelm@5881
   409
val print_theoremsP =
wenzelm@6370
   410
  OuterSyntax.improper_command "print_theorems" "print theorems known in this theory"
wenzelm@5881
   411
    (Scan.succeed IsarCmd.print_theorems);
wenzelm@5881
   412
wenzelm@5832
   413
val print_attributesP =
wenzelm@6370
   414
  OuterSyntax.improper_command "print_attributes" "print attributes known in this theory"
wenzelm@5832
   415
    (Scan.succeed IsarCmd.print_attributes);
wenzelm@5832
   416
wenzelm@5832
   417
val print_methodsP =
wenzelm@6370
   418
  OuterSyntax.improper_command "print_methods" "print methods known in this theory"
wenzelm@5832
   419
    (Scan.succeed IsarCmd.print_methods);
wenzelm@5832
   420
wenzelm@5832
   421
val print_bindsP =
wenzelm@6370
   422
  OuterSyntax.improper_command "print_binds" "print term bindings of proof context"
wenzelm@5832
   423
    (Scan.succeed IsarCmd.print_binds);
wenzelm@5832
   424
wenzelm@5832
   425
val print_lthmsP =
wenzelm@6370
   426
  OuterSyntax.improper_command "print_facts" "print local theorems of proof context"
wenzelm@5832
   427
    (Scan.succeed IsarCmd.print_lthms);
wenzelm@5832
   428
wenzelm@5896
   429
val print_thmsP =
wenzelm@6370
   430
  OuterSyntax.improper_command "thm" "print theorems" (xthm >> IsarCmd.print_thms);
wenzelm@5832
   431
wenzelm@5832
   432
val print_propP =
wenzelm@6370
   433
  OuterSyntax.improper_command "prop" "read and print proposition"
wenzelm@5832
   434
    (term >> IsarCmd.print_prop);
wenzelm@5832
   435
wenzelm@5832
   436
val print_termP =
wenzelm@6370
   437
  OuterSyntax.improper_command "term" "read and print term"
wenzelm@5832
   438
    (term >> IsarCmd.print_term);
wenzelm@5832
   439
wenzelm@5832
   440
val print_typeP =
wenzelm@6687
   441
  OuterSyntax.improper_command "typ" "read and print type"
wenzelm@5832
   442
    (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@6370
   449
  OuterSyntax.improper_command "cd" "change current working directory"
wenzelm@5958
   450
    (name >> IsarCmd.cd);
wenzelm@5832
   451
wenzelm@5832
   452
val pwdP =
wenzelm@6370
   453
  OuterSyntax.improper_command "pwd" "print current working directory"
wenzelm@5832
   454
    (Scan.succeed IsarCmd.pwd);
wenzelm@5832
   455
wenzelm@5832
   456
val use_thyP =
wenzelm@6370
   457
  OuterSyntax.improper_command "use_thy" "use theory file"
wenzelm@5958
   458
    (name >> IsarCmd.use_thy);
wenzelm@5832
   459
wenzelm@6196
   460
val update_thyP =
wenzelm@6370
   461
  OuterSyntax.improper_command "update_thy" "update theory file"
wenzelm@6197
   462
    (name >> IsarCmd.update_thy);
wenzelm@5832
   463
wenzelm@5832
   464
val prP =
wenzelm@6370
   465
  OuterSyntax.improper_command "pr" "print current toplevel state"
wenzelm@5832
   466
    (Scan.succeed (Toplevel.print o Toplevel.imperative (K ())));
wenzelm@5832
   467
wenzelm@5832
   468
wenzelm@5832
   469
val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) ();
wenzelm@5832
   470
wenzelm@5832
   471
val commitP =
wenzelm@6370
   472
  OuterSyntax.improper_command "commit" "commit current session to ML database"
wenzelm@5832
   473
    (opt_unit >> (K IsarCmd.use_commit));
wenzelm@5832
   474
wenzelm@5832
   475
val quitP =
wenzelm@6370
   476
  OuterSyntax.improper_command "quit" "quit Isabelle"
wenzelm@5832
   477
    (opt_unit >> (K IsarCmd.quit));
wenzelm@5832
   478
wenzelm@5832
   479
val exitP =
wenzelm@6370
   480
  OuterSyntax.improper_command "exit" "exit Isar loop"
wenzelm@5832
   481
    (Scan.succeed IsarCmd.exit);
wenzelm@5832
   482
wenzelm@5991
   483
val restartP =
wenzelm@6370
   484
  OuterSyntax.improper_command "restart" "restart Isar loop"
wenzelm@5991
   485
    (Scan.succeed IsarCmd.restart);
wenzelm@5991
   486
wenzelm@5832
   487
val breakP =
wenzelm@6370
   488
  OuterSyntax.improper_command "break" "discontinue excursion (keep current state)"
wenzelm@5832
   489
    (Scan.succeed IsarCmd.break);
wenzelm@5832
   490
wenzelm@5832
   491
wenzelm@5832
   492
wenzelm@5832
   493
(** the Pure outer syntax **)
wenzelm@5832
   494
wenzelm@5832
   495
(*keep keywords consistent with the parsers, including those in
wenzelm@5832
   496
  outer_parse.ML, otherwise be prepared for unexpected errors*)
wenzelm@5832
   497
wenzelm@5832
   498
val keywords =
wenzelm@6551
   499
 ["!", "%", "(", ")", "*", "+", ",", "--", ":", "::", ";", "<", "<=",
wenzelm@6551
   500
  "=", "==", "=>", "?", "[", "]", "and", "as", "binder", "files",
wenzelm@6551
   501
  "infixl", "infixr", "is", "output", "{", "|", "}"];
wenzelm@5832
   502
wenzelm@5832
   503
val parsers = [
wenzelm@5832
   504
  (*theory structure*)
wenzelm@6687
   505
  theoryP, end_excursionP, kill_excursionP, contextP, update_contextP,
wenzelm@5832
   506
  (*theory sections*)
wenzelm@6370
   507
  textP, titleP, chapterP, sectionP, subsectionP, subsubsectionP,
wenzelm@6370
   508
  classesP, classrelP, defaultsortP, typedeclP, typeabbrP, nontermP,
wenzelm@6370
   509
  aritiesP, constsP, syntaxP, translationsP, axiomsP, defsP,
wenzelm@6370
   510
  constdefsP, theoremsP, lemmasP, globalP, localP, pathP, useP, mlP,
wenzelm@6370
   511
  setupP, parse_ast_translationP, parse_translationP,
wenzelm@6370
   512
  print_translationP, typed_print_translationP,
wenzelm@6370
   513
  print_ast_translationP, token_translationP, oracleP,
wenzelm@5832
   514
  (*proof commands*)
wenzelm@6501
   515
  theoremP, lemmaP, showP, haveP, thusP, henceP, assumeP, fixP, letP,
wenzelm@6687
   516
  thenP, fromP, factsP, beginP, endP, nextP, kill_proofP, qed_withP,
wenzelm@6687
   517
  qedP, terminal_proofP, immediate_proofP, default_proofP, refineP,
wenzelm@6687
   518
  then_refineP, proofP, clear_undoP, undoP, redoP, undosP, backP,
wenzelm@6687
   519
  prevP, upP, topP,
wenzelm@5832
   520
  (*diagnostic commands*)
wenzelm@5832
   521
  print_commandsP, print_theoryP, print_syntaxP, print_attributesP,
wenzelm@5881
   522
  print_methodsP, print_theoremsP, print_bindsP, print_lthmsP,
wenzelm@5914
   523
  print_thmsP, print_propP, print_termP, print_typeP,
wenzelm@5832
   524
  (*system commands*)
wenzelm@6196
   525
  cdP, pwdP, use_thyP, update_thyP, prP, commitP, quitP, exitP,
wenzelm@6196
   526
  restartP, breakP];
wenzelm@5832
   527
wenzelm@5832
   528
wenzelm@5832
   529
end;
wenzelm@5832
   530
wenzelm@5832
   531
wenzelm@6196
   532
(*install the Pure outer syntax*)
wenzelm@5832
   533
OuterSyntax.add_keywords IsarSyn.keywords;
wenzelm@5832
   534
OuterSyntax.add_parsers IsarSyn.parsers;