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