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