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