src/Pure/Isar/isar_syn.ML
author wenzelm
Fri Apr 23 16:33:23 1999 +0200 (1999-04-23 ago)
changeset 6501 392333eb31cb
parent 6404 2daaf2943c79
child 6512 d174c937bf93
permissions -rw-r--r--
added thus, hence;
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@5832
    26
(*end current theory / sub-proof / excursion*)
wenzelm@5832
    27
val endP =
wenzelm@6404
    28
  OuterSyntax.command "end" "end current block / theory / excursion"
wenzelm@5832
    29
    (Scan.succeed (Toplevel.print o Toplevel.exit o Toplevel.proof IsarThy.end_block));
wenzelm@5832
    30
wenzelm@6245
    31
val contextP =
wenzelm@6370
    32
  OuterSyntax.improper_command "context" "switch theory context"
wenzelm@6245
    33
    (name >> (Toplevel.print oo IsarThy.context));
wenzelm@6245
    34
wenzelm@6245
    35
val update_contextP =
wenzelm@6370
    36
  OuterSyntax.improper_command "update_context" "switch theory context, forcing update"
wenzelm@6245
    37
    (name >> (Toplevel.print oo IsarThy.update_context));
wenzelm@6245
    38
wenzelm@5832
    39
wenzelm@5832
    40
wenzelm@5832
    41
(** theory sections **)
wenzelm@5832
    42
wenzelm@5832
    43
(* formal comments *)
wenzelm@5832
    44
wenzelm@6370
    45
val textP = OuterSyntax.command "text" "formal comments"
wenzelm@5958
    46
  (text >> (Toplevel.theory o IsarThy.add_text));
wenzelm@5958
    47
wenzelm@6370
    48
val titleP = OuterSyntax.command "title" "document title"
wenzelm@6353
    49
  ((text -- Scan.optional text "" -- Scan.optional text "")
wenzelm@6353
    50
    >> (fn ((x, y), z) => Toplevel.theory (IsarThy.add_title x y z)));
wenzelm@6353
    51
wenzelm@6370
    52
val chapterP = OuterSyntax.command "chapter" "chapter heading"
wenzelm@5958
    53
  (text >> (Toplevel.theory o IsarThy.add_chapter));
wenzelm@5958
    54
wenzelm@6370
    55
val sectionP = OuterSyntax.command "section" "section heading"
wenzelm@5958
    56
  (text >> (Toplevel.theory o IsarThy.add_section));
wenzelm@5958
    57
wenzelm@6370
    58
val subsectionP = OuterSyntax.command "subsection" "subsection heading"
wenzelm@5958
    59
  (text >> (Toplevel.theory o IsarThy.add_subsection));
wenzelm@5958
    60
wenzelm@6370
    61
val subsubsectionP = OuterSyntax.command "subsubsection" "subsubsection heading"
wenzelm@5958
    62
  (text >> (Toplevel.theory o IsarThy.add_subsubsection));
wenzelm@5832
    63
wenzelm@5832
    64
wenzelm@5832
    65
(* classes and sorts *)
wenzelm@5832
    66
wenzelm@5832
    67
val classesP =
wenzelm@6370
    68
  OuterSyntax.command "classes" "declare type classes"
wenzelm@5832
    69
    (Scan.repeat1 (name -- Scan.optional ($$$ "<" |-- !!! (list1 xname)) [])
wenzelm@5832
    70
      >> (Toplevel.theory o Theory.add_classes));
wenzelm@5832
    71
wenzelm@5832
    72
val classrelP =
wenzelm@6370
    73
  OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)"
wenzelm@5832
    74
    (xname -- ($$$ "<" |-- !!! xname) >> (Toplevel.theory o Theory.add_classrel o single));
wenzelm@5832
    75
wenzelm@5832
    76
val defaultsortP =
wenzelm@6370
    77
  OuterSyntax.command "defaultsort" "declare default sort"
wenzelm@5832
    78
    (sort >> (Toplevel.theory o Theory.add_defsort));
wenzelm@5832
    79
wenzelm@5832
    80
wenzelm@5832
    81
(* types *)
wenzelm@5832
    82
wenzelm@5832
    83
val typedeclP =
wenzelm@6370
    84
  OuterSyntax.command "typedecl" "Pure type declaration"
wenzelm@5832
    85
    (type_args -- name -- opt_infix
wenzelm@5832
    86
      >> (fn ((args, a), mx) => Toplevel.theory (PureThy.add_typedecls [(a, args, mx)])));
wenzelm@5832
    87
wenzelm@5832
    88
val typeabbrP =
wenzelm@6370
    89
  OuterSyntax.command "types" "declare type abbreviations"
wenzelm@5832
    90
    (Scan.repeat1 (type_args -- name -- ($$$ "=" |-- !!! (typ -- opt_infix)))
wenzelm@5832
    91
      >> (Toplevel.theory o Theory.add_tyabbrs o
wenzelm@5832
    92
        map (fn ((args, a), (T, mx)) => (a, args, T, mx))));
wenzelm@5832
    93
wenzelm@5832
    94
val nontermP =
wenzelm@6370
    95
  OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
wenzelm@5832
    96
    (Scan.repeat1 name >> (Toplevel.theory o Theory.add_nonterminals));
wenzelm@5832
    97
wenzelm@5832
    98
val aritiesP =
wenzelm@6370
    99
  OuterSyntax.command "arities" "state type arities (axiomatic!)"
wenzelm@5832
   100
    (Scan.repeat1 (xname -- ($$$ "::" |-- !!! arity) >> triple2)
wenzelm@5832
   101
      >> (Toplevel.theory o Theory.add_arities));
wenzelm@5832
   102
wenzelm@5832
   103
wenzelm@5832
   104
(* consts and syntax *)
wenzelm@5832
   105
wenzelm@5832
   106
val constsP =
wenzelm@6370
   107
  OuterSyntax.command "consts" "declare constants"
wenzelm@5832
   108
    (Scan.repeat1 const >> (Toplevel.theory o Theory.add_consts));
wenzelm@5832
   109
wenzelm@5832
   110
val opt_mode =
wenzelm@5832
   111
  Scan.optional
wenzelm@5832
   112
    ($$$ "(" |-- !!! (name -- Scan.optional ($$$ "output" >> K false) true --| $$$ ")"))
wenzelm@5832
   113
    ("", true);
wenzelm@5832
   114
wenzelm@5832
   115
val syntaxP =
wenzelm@6370
   116
  OuterSyntax.command "syntax" "declare syntactic constants"
wenzelm@5832
   117
    (opt_mode -- Scan.repeat1 const >> (Toplevel.theory o uncurry Theory.add_modesyntax));
wenzelm@5832
   118
wenzelm@5832
   119
wenzelm@5832
   120
(* translations *)
wenzelm@5832
   121
wenzelm@5832
   122
val trans_pat =
wenzelm@5832
   123
  Scan.optional ($$$ "(" |-- !!! (xname --| $$$ ")")) "logic" -- string;
wenzelm@5832
   124
wenzelm@5832
   125
fun trans_arrow toks =
wenzelm@5832
   126
  ($$$ "=>" >> K Syntax.ParseRule ||
wenzelm@5832
   127
    $$$ "<=" >> K Syntax.PrintRule ||
wenzelm@5832
   128
    $$$ "==" >> K Syntax.ParsePrintRule) toks;
wenzelm@5832
   129
wenzelm@5832
   130
val trans_line =
wenzelm@5832
   131
  trans_pat -- !!! (trans_arrow -- trans_pat)
wenzelm@5832
   132
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@5832
   133
wenzelm@5832
   134
val translationsP =
wenzelm@6370
   135
  OuterSyntax.command "translations" "declare syntax translation rules"
wenzelm@5832
   136
    (Scan.repeat1 trans_line >> (Toplevel.theory o Theory.add_trrules));
wenzelm@5832
   137
wenzelm@5832
   138
wenzelm@5832
   139
(* axioms and definitions *)
wenzelm@5832
   140
wenzelm@5832
   141
val axiomsP =
wenzelm@6370
   142
  OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)"
wenzelm@6370
   143
    (Scan.repeat1 spec_name >> (Toplevel.theory o IsarThy.add_axioms));
wenzelm@5832
   144
wenzelm@5832
   145
val defsP =
wenzelm@6370
   146
  OuterSyntax.command "defs" "define constants"
wenzelm@6370
   147
    (Scan.repeat1 spec_opt_name >> (Toplevel.theory o IsarThy.add_defs));
wenzelm@6370
   148
wenzelm@6370
   149
val constdefsP =
wenzelm@6370
   150
  OuterSyntax.command "constdefs" "declare and define constants"
wenzelm@6370
   151
    (Scan.repeat1 (const -- term) >> (Toplevel.theory o IsarThy.add_constdefs));
wenzelm@5832
   152
wenzelm@5832
   153
wenzelm@5914
   154
(* theorems *)
wenzelm@5914
   155
wenzelm@5914
   156
val facts = opt_thm_name "=" -- xthms1;
wenzelm@5914
   157
wenzelm@5914
   158
val theoremsP =
wenzelm@6370
   159
  OuterSyntax.command "theorems" "define theorems"
wenzelm@5914
   160
    (facts >> (Toplevel.theory o IsarThy.have_theorems));
wenzelm@5914
   161
wenzelm@5914
   162
val lemmasP =
wenzelm@6370
   163
  OuterSyntax.command "lemmas" "define lemmas"
wenzelm@5914
   164
    (facts >> (Toplevel.theory o IsarThy.have_lemmas));
wenzelm@5914
   165
wenzelm@5914
   166
wenzelm@5832
   167
(* name space entry path *)
wenzelm@5832
   168
wenzelm@5832
   169
val globalP =
wenzelm@6370
   170
  OuterSyntax.command "global" "disable prefixing of theory name"
wenzelm@5832
   171
    (Scan.succeed (Toplevel.theory PureThy.global_path));
wenzelm@5832
   172
wenzelm@5832
   173
val localP =
wenzelm@6370
   174
  OuterSyntax.command "local" "enable prefixing of theory name"
wenzelm@5832
   175
    (Scan.succeed (Toplevel.theory PureThy.local_path));
wenzelm@5832
   176
wenzelm@5832
   177
val pathP =
wenzelm@6370
   178
  OuterSyntax.command "path" "modify name-space entry path"
wenzelm@5832
   179
    (xname >> (Toplevel.theory o Theory.add_path));
wenzelm@5832
   180
wenzelm@5832
   181
wenzelm@5832
   182
(* use ML text *)
wenzelm@5832
   183
wenzelm@5832
   184
val useP =
wenzelm@6370
   185
  OuterSyntax.command "use" "eval ML text from file"
wenzelm@5958
   186
    (name >> IsarCmd.use);
wenzelm@5832
   187
wenzelm@5832
   188
val mlP =
wenzelm@6370
   189
  OuterSyntax.command "ML" "eval ML text"
wenzelm@5832
   190
    (text >> (fn txt => IsarCmd.use_mltext txt o IsarCmd.use_mltext_theory txt));
wenzelm@5832
   191
wenzelm@5832
   192
val setupP =
wenzelm@6370
   193
  OuterSyntax.command "setup" "apply ML theory transformer"
wenzelm@5832
   194
    (text >> (Toplevel.theory o IsarThy.use_setup));
wenzelm@5832
   195
wenzelm@5832
   196
wenzelm@5832
   197
(* translation functions *)
wenzelm@5832
   198
wenzelm@5832
   199
val parse_ast_translationP =
wenzelm@6370
   200
  OuterSyntax.command "parse_ast_translation" "install parse ast translation functions"
wenzelm@5832
   201
    (text >> (Toplevel.theory o IsarThy.parse_ast_translation));
wenzelm@5832
   202
wenzelm@5832
   203
val parse_translationP =
wenzelm@6370
   204
  OuterSyntax.command "parse_translation" "install parse translation functions"
wenzelm@5832
   205
    (text >> (Toplevel.theory o IsarThy.parse_translation));
wenzelm@5832
   206
wenzelm@5832
   207
val print_translationP =
wenzelm@6370
   208
  OuterSyntax.command "print_translation" "install print translation functions"
wenzelm@5832
   209
    (text >> (Toplevel.theory o IsarThy.print_translation));
wenzelm@5832
   210
wenzelm@5832
   211
val typed_print_translationP =
wenzelm@6370
   212
  OuterSyntax.command "typed_print_translation" "install typed print translation functions"
wenzelm@5832
   213
    (text >> (Toplevel.theory o IsarThy.typed_print_translation));
wenzelm@5832
   214
wenzelm@5832
   215
val print_ast_translationP =
wenzelm@6370
   216
  OuterSyntax.command "print_ast_translation" "install print ast translation functions"
wenzelm@5832
   217
    (text >> (Toplevel.theory o IsarThy.print_ast_translation));
wenzelm@5832
   218
wenzelm@5832
   219
val token_translationP =
wenzelm@6370
   220
  OuterSyntax.command "token_translation" "install token translation functions"
wenzelm@5832
   221
    (text >> (Toplevel.theory o IsarThy.token_translation));
wenzelm@5832
   222
wenzelm@5832
   223
wenzelm@5832
   224
(* oracles *)
wenzelm@5832
   225
wenzelm@5832
   226
val oracleP =
wenzelm@6370
   227
  OuterSyntax.command "oracle" "install oracle"
wenzelm@5832
   228
    (name -- text >> (Toplevel.theory o IsarThy.add_oracle));
wenzelm@5832
   229
wenzelm@5832
   230
wenzelm@5832
   231
wenzelm@5832
   232
(** proof commands **)
wenzelm@5832
   233
wenzelm@5832
   234
(* statements *)
wenzelm@5832
   235
wenzelm@5937
   236
val is_props = $$$ "(" |-- !!! (Scan.repeat1 ($$$ "is" |-- prop) --| $$$ ")");
wenzelm@5937
   237
val propp = prop -- Scan.optional is_props [];
wenzelm@5937
   238
fun statement f = opt_thm_name ":" -- propp >> (fn ((x, y), z) => f x y z);
wenzelm@5832
   239
wenzelm@5832
   240
val theoremP =
wenzelm@6370
   241
  OuterSyntax.command "theorem" "state theorem"
wenzelm@5832
   242
    (statement IsarThy.theorem >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
wenzelm@5832
   243
wenzelm@5832
   244
val lemmaP =
wenzelm@6370
   245
  OuterSyntax.command "lemma" "state lemma"
wenzelm@5832
   246
    (statement IsarThy.lemma >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
wenzelm@5832
   247
wenzelm@5832
   248
val showP =
wenzelm@6370
   249
  OuterSyntax.command "show" "state local goal, solving current obligation"
wenzelm@5832
   250
    (statement IsarThy.show >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   251
wenzelm@5832
   252
val haveP =
wenzelm@6370
   253
  OuterSyntax.command "have" "state local goal"
wenzelm@5832
   254
    (statement IsarThy.have >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@5832
   255
wenzelm@6501
   256
val thusP =
wenzelm@6501
   257
  OuterSyntax.command "thus" "abbreviates \"then show\""
wenzelm@6501
   258
    (statement IsarThy.thus >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@6501
   259
wenzelm@6501
   260
val henceP =
wenzelm@6501
   261
  OuterSyntax.command "hence" "abbreviates \"then have\""
wenzelm@6501
   262
    (statement IsarThy.hence >> (fn f => Toplevel.print o Toplevel.proof f));
wenzelm@6501
   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@6501
   512
  theoremP, lemmaP, showP, haveP, thusP, henceP, assumeP, fixP, letP,
wenzelm@6501
   513
  thenP, fromP, 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;