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