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