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