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