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