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