src/Pure/Isar/isar_syn.ML
author wenzelm
Wed Mar 17 13:34:49 1999 +0100 (1999-03-17 ago)
changeset 6370 e71ac23a9111
parent 6353 5a76eb9030df
child 6404 2daaf2943c79
permissions -rw-r--r--
OuterSyntax.(improper_)command;
moved axclass / instance to Pure/axclass.ML;
moved spec(') to outer_parse.ML;
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@6370
    36
  OuterSyntax.command "end" "end current theory / sub-proof / 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@5832
   311
val qedP =
wenzelm@6370
   312
  OuterSyntax.command "qed" "conclude proof"
wenzelm@5832
   313
    (Scan.succeed (Toplevel.proof_to_theory IsarThy.qed));
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@5832
   317
    (Scan.option name -- Scan.option attribs >> (Toplevel.proof_to_theory o IsarThy.qed_with));
wenzelm@5832
   318
wenzelm@5832
   319
val kill_proofP =
wenzelm@6370
   320
  OuterSyntax.improper_command "kill" "abort current proof"
wenzelm@5832
   321
    (Scan.succeed (Toplevel.print o Toplevel.proof_to_theory IsarThy.kill_proof));
wenzelm@5832
   322
wenzelm@5832
   323
wenzelm@5832
   324
(* proof steps *)
wenzelm@5832
   325
wenzelm@5832
   326
fun gen_stepP meth int name cmt f =
wenzelm@5832
   327
  OuterSyntax.parser int name cmt
wenzelm@5832
   328
    (meth >> (fn txt => Toplevel.print o Toplevel.proof (f txt)));
wenzelm@5832
   329
wenzelm@5832
   330
val stepP = gen_stepP method;
wenzelm@5832
   331
wenzelm@5881
   332
val refineP = stepP true "refine" "unstructured backward proof step, ignoring facts" IsarThy.tac;
wenzelm@5881
   333
val then_refineP =
wenzelm@5881
   334
  stepP true "then_refine" "unstructured backward proof step, using facts" IsarThy.then_tac;
wenzelm@5832
   335
wenzelm@5832
   336
wenzelm@5832
   337
val proofP = gen_stepP (Scan.option method) false "proof" "backward proof" IsarThy.proof;
wenzelm@5832
   338
val terminal_proofP = stepP false "by" "terminal backward proof" IsarThy.terminal_proof;
wenzelm@5832
   339
wenzelm@6108
   340
val immediate_proofP =
wenzelm@6370
   341
  OuterSyntax.command "." "immediate proof"
wenzelm@6108
   342
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.immediate_proof));
wenzelm@5832
   343
wenzelm@5832
   344
val default_proofP =
wenzelm@6370
   345
  OuterSyntax.command ".." "default proof"
wenzelm@5832
   346
    (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.default_proof));
wenzelm@5832
   347
wenzelm@5832
   348
wenzelm@5832
   349
(* proof history *)
wenzelm@5832
   350
wenzelm@5832
   351
val clear_undoP =
wenzelm@6370
   352
  OuterSyntax.improper_command "clear_undo" "clear proof command undo information"
wenzelm@5832
   353
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.clear));
wenzelm@5832
   354
wenzelm@5832
   355
val undoP =
wenzelm@6370
   356
  OuterSyntax.improper_command "undo" "undo proof command"
wenzelm@5832
   357
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.undo));
wenzelm@5832
   358
wenzelm@5832
   359
val redoP =
wenzelm@6370
   360
  OuterSyntax.improper_command "redo" "redo proof command"
wenzelm@5832
   361
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.redo));
wenzelm@5832
   362
wenzelm@5944
   363
val undosP =
wenzelm@6370
   364
  OuterSyntax.improper_command "undos" "undo proof commands"
wenzelm@5944
   365
    (nat >> (fn n => Toplevel.print o Toplevel.proof (ProofHistory.undos n)));
wenzelm@5944
   366
wenzelm@5944
   367
val redosP =
wenzelm@6370
   368
  OuterSyntax.improper_command "redos" "redo proof commands"
wenzelm@5944
   369
    (nat >> (fn n => Toplevel.print o Toplevel.proof (ProofHistory.redos n)));
wenzelm@5944
   370
wenzelm@5832
   371
val backP =
wenzelm@6370
   372
  OuterSyntax.improper_command "back" "backtracking of proof command"
wenzelm@5832
   373
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.back));
wenzelm@5832
   374
wenzelm@5832
   375
val prevP =
wenzelm@6370
   376
  OuterSyntax.improper_command "prev" "previous proof state"
wenzelm@5832
   377
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.prev));
wenzelm@5832
   378
wenzelm@5832
   379
val upP =
wenzelm@6370
   380
  OuterSyntax.improper_command "up" "upper proof state"
wenzelm@5832
   381
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.up));
wenzelm@5832
   382
wenzelm@5832
   383
val topP =
wenzelm@6370
   384
  OuterSyntax.improper_command "top" "to initial proof state"
wenzelm@5832
   385
    (Scan.succeed (Toplevel.print o Toplevel.proof ProofHistory.top));
wenzelm@5832
   386
wenzelm@5832
   387
wenzelm@5832
   388
wenzelm@5832
   389
(** diagnostic commands (for interactive mode only) **)
wenzelm@5832
   390
wenzelm@5832
   391
val print_commandsP =
wenzelm@6370
   392
  OuterSyntax.improper_command "help" "print outer syntax (global)"
wenzelm@5832
   393
    (Scan.succeed (Toplevel.imperative OuterSyntax.print_outer_syntax));
wenzelm@5832
   394
wenzelm@5832
   395
val print_theoryP =
wenzelm@6370
   396
  OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)"
wenzelm@5832
   397
    (Scan.succeed IsarCmd.print_theory);
wenzelm@5832
   398
wenzelm@5832
   399
val print_syntaxP =
wenzelm@6370
   400
  OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)"
wenzelm@5832
   401
    (Scan.succeed IsarCmd.print_syntax);
wenzelm@5832
   402
wenzelm@5881
   403
val print_theoremsP =
wenzelm@6370
   404
  OuterSyntax.improper_command "print_theorems" "print theorems known in this theory"
wenzelm@5881
   405
    (Scan.succeed IsarCmd.print_theorems);
wenzelm@5881
   406
wenzelm@5832
   407
val print_attributesP =
wenzelm@6370
   408
  OuterSyntax.improper_command "print_attributes" "print attributes known in this theory"
wenzelm@5832
   409
    (Scan.succeed IsarCmd.print_attributes);
wenzelm@5832
   410
wenzelm@5832
   411
val print_methodsP =
wenzelm@6370
   412
  OuterSyntax.improper_command "print_methods" "print methods known in this theory"
wenzelm@5832
   413
    (Scan.succeed IsarCmd.print_methods);
wenzelm@5832
   414
wenzelm@5832
   415
val print_bindsP =
wenzelm@6370
   416
  OuterSyntax.improper_command "print_binds" "print term bindings of proof context"
wenzelm@5832
   417
    (Scan.succeed IsarCmd.print_binds);
wenzelm@5832
   418
wenzelm@5832
   419
val print_lthmsP =
wenzelm@6370
   420
  OuterSyntax.improper_command "print_facts" "print local theorems of proof context"
wenzelm@5832
   421
    (Scan.succeed IsarCmd.print_lthms);
wenzelm@5832
   422
wenzelm@5896
   423
val print_thmsP =
wenzelm@6370
   424
  OuterSyntax.improper_command "thm" "print theorems" (xthm >> IsarCmd.print_thms);
wenzelm@5832
   425
wenzelm@5832
   426
val print_propP =
wenzelm@6370
   427
  OuterSyntax.improper_command "prop" "read and print proposition"
wenzelm@5832
   428
    (term >> IsarCmd.print_prop);
wenzelm@5832
   429
wenzelm@5832
   430
val print_termP =
wenzelm@6370
   431
  OuterSyntax.improper_command "term" "read and print term"
wenzelm@5832
   432
    (term >> IsarCmd.print_term);
wenzelm@5832
   433
wenzelm@5832
   434
val print_typeP =
wenzelm@6370
   435
  OuterSyntax.improper_command "type" "read and print type"
wenzelm@5832
   436
    (typ >> IsarCmd.print_type);
wenzelm@5832
   437
wenzelm@5832
   438
wenzelm@5832
   439
wenzelm@5832
   440
(** system commands (for interactive mode only) **)
wenzelm@5832
   441
wenzelm@5832
   442
val cdP =
wenzelm@6370
   443
  OuterSyntax.improper_command "cd" "change current working directory"
wenzelm@5958
   444
    (name >> IsarCmd.cd);
wenzelm@5832
   445
wenzelm@5832
   446
val pwdP =
wenzelm@6370
   447
  OuterSyntax.improper_command "pwd" "print current working directory"
wenzelm@5832
   448
    (Scan.succeed IsarCmd.pwd);
wenzelm@5832
   449
wenzelm@5832
   450
val use_thyP =
wenzelm@6370
   451
  OuterSyntax.improper_command "use_thy" "use theory file"
wenzelm@5958
   452
    (name >> IsarCmd.use_thy);
wenzelm@5832
   453
wenzelm@6196
   454
val update_thyP =
wenzelm@6370
   455
  OuterSyntax.improper_command "update_thy" "update theory file"
wenzelm@6197
   456
    (name >> IsarCmd.update_thy);
wenzelm@5832
   457
wenzelm@5832
   458
val prP =
wenzelm@6370
   459
  OuterSyntax.improper_command "pr" "print current toplevel state"
wenzelm@5832
   460
    (Scan.succeed (Toplevel.print o Toplevel.imperative (K ())));
wenzelm@5832
   461
wenzelm@5832
   462
wenzelm@5832
   463
val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) ();
wenzelm@5832
   464
wenzelm@5832
   465
val commitP =
wenzelm@6370
   466
  OuterSyntax.improper_command "commit" "commit current session to ML database"
wenzelm@5832
   467
    (opt_unit >> (K IsarCmd.use_commit));
wenzelm@5832
   468
wenzelm@5832
   469
val quitP =
wenzelm@6370
   470
  OuterSyntax.improper_command "quit" "quit Isabelle"
wenzelm@5832
   471
    (opt_unit >> (K IsarCmd.quit));
wenzelm@5832
   472
wenzelm@5832
   473
val exitP =
wenzelm@6370
   474
  OuterSyntax.improper_command "exit" "exit Isar loop"
wenzelm@5832
   475
    (Scan.succeed IsarCmd.exit);
wenzelm@5832
   476
wenzelm@5991
   477
val restartP =
wenzelm@6370
   478
  OuterSyntax.improper_command "restart" "restart Isar loop"
wenzelm@5991
   479
    (Scan.succeed IsarCmd.restart);
wenzelm@5991
   480
wenzelm@5832
   481
val breakP =
wenzelm@6370
   482
  OuterSyntax.improper_command "break" "discontinue excursion (keep current state)"
wenzelm@5832
   483
    (Scan.succeed IsarCmd.break);
wenzelm@5832
   484
wenzelm@5832
   485
wenzelm@5832
   486
wenzelm@5832
   487
(** the Pure outer syntax **)
wenzelm@5832
   488
wenzelm@5832
   489
(*keep keywords consistent with the parsers, including those in
wenzelm@5832
   490
  outer_parse.ML, otherwise be prepared for unexpected errors*)
wenzelm@5832
   491
wenzelm@5832
   492
val keywords =
wenzelm@5958
   493
 ["(", ")", "*", "+", "--", ",", ":", "::", ";", "<", "<=", "=", "==", "=>",
wenzelm@6265
   494
  "?", "[", "]", "and", "as", "binder", "files", "infixl", "infixr", "is",
wenzelm@6013
   495
  "output", "{", "|", "}"];
wenzelm@5832
   496
wenzelm@5832
   497
val parsers = [
wenzelm@5832
   498
  (*theory structure*)
wenzelm@6245
   499
  theoryP, endP, contextP, update_contextP,
wenzelm@5832
   500
  (*theory sections*)
wenzelm@6370
   501
  textP, titleP, chapterP, sectionP, subsectionP, subsubsectionP,
wenzelm@6370
   502
  classesP, classrelP, defaultsortP, typedeclP, typeabbrP, nontermP,
wenzelm@6370
   503
  aritiesP, constsP, syntaxP, translationsP, axiomsP, defsP,
wenzelm@6370
   504
  constdefsP, theoremsP, lemmasP, globalP, localP, pathP, useP, mlP,
wenzelm@6370
   505
  setupP, parse_ast_translationP, parse_translationP,
wenzelm@6370
   506
  print_translationP, typed_print_translationP,
wenzelm@6370
   507
  print_ast_translationP, token_translationP, oracleP,
wenzelm@5832
   508
  (*proof commands*)
wenzelm@5832
   509
  theoremP, lemmaP, showP, haveP, assumeP, fixP, letP, thenP, fromP,
wenzelm@5914
   510
  factsP, beginP, nextP, qedP, qed_withP, kill_proofP, refineP,
wenzelm@6108
   511
  then_refineP, proofP, terminal_proofP, immediate_proofP,
wenzelm@5944
   512
  default_proofP, clear_undoP, undoP, redoP, undosP, redosP, backP,
wenzelm@5944
   513
  prevP, upP, topP,
wenzelm@5832
   514
  (*diagnostic commands*)
wenzelm@5832
   515
  print_commandsP, print_theoryP, print_syntaxP, print_attributesP,
wenzelm@5881
   516
  print_methodsP, print_theoremsP, print_bindsP, print_lthmsP,
wenzelm@5914
   517
  print_thmsP, print_propP, print_termP, print_typeP,
wenzelm@5832
   518
  (*system commands*)
wenzelm@6196
   519
  cdP, pwdP, use_thyP, update_thyP, prP, commitP, quitP, exitP,
wenzelm@6196
   520
  restartP, breakP];
wenzelm@5832
   521
wenzelm@5832
   522
wenzelm@5832
   523
end;
wenzelm@5832
   524
wenzelm@5832
   525
wenzelm@6196
   526
(*install the Pure outer syntax*)
wenzelm@5832
   527
OuterSyntax.add_keywords IsarSyn.keywords;
wenzelm@5832
   528
OuterSyntax.add_parsers IsarSyn.parsers;