author | wenzelm |
Sat, 15 Oct 2005 00:08:03 +0200 | |
changeset 17854 | 44b6dde80bf4 |
parent 17512 | 854d061f6c10 |
child 17900 | 5f44c71c4ca4 |
permissions | -rw-r--r-- |
5832 | 1 |
(* Title: Pure/Isar/isar_syn.ML |
2 |
ID: $Id$ |
|
3 |
Author: Markus Wenzel, TU Muenchen |
|
4 |
||
6353 | 5 |
Isar/Pure outer syntax. |
5832 | 6 |
*) |
7 |
||
17353 | 8 |
structure IsarSyn: sig end = |
5832 | 9 |
struct |
10 |
||
17068 | 11 |
structure P = OuterParse and K = OuterKeyword; |
5832 | 12 |
|
13 |
||
14 |
(** init and exit **) |
|
15 |
||
16 |
val theoryP = |
|
17068 | 17 |
OuterSyntax.command "theory" "begin theory" (K.tag_theory K.thy_begin) |
9129 | 18 |
(ThyHeader.args >> (Toplevel.print oo IsarThy.theory)); |
5832 | 19 |
|
6687 | 20 |
val end_excursionP = |
17068 | 21 |
OuterSyntax.command "end" "end current excursion" (K.tag_theory K.thy_end) |
6687 | 22 |
(Scan.succeed (Toplevel.print o Toplevel.exit)); |
23 |
||
6245 | 24 |
val contextP = |
17068 | 25 |
OuterSyntax.improper_command "context" "switch theory context" (K.tag_theory K.thy_switch) |
6723 | 26 |
(P.name >> (Toplevel.print oo IsarThy.context)); |
6245 | 27 |
|
5832 | 28 |
|
29 |
||
7749 | 30 |
(** markup commands **) |
5832 | 31 |
|
9129 | 32 |
val headerP = OuterSyntax.markup_command IsarOutput.Markup "header" "theory header" K.diag |
12940 | 33 |
(P.position P.text >> IsarCmd.add_header); |
6353 | 34 |
|
9129 | 35 |
val chapterP = OuterSyntax.markup_command IsarOutput.Markup "chapter" "chapter heading" |
17264
c5b280a52a67
chapter/section/subsection/subsubsection/text: optional locale specification;
wenzelm
parents:
17228
diff
changeset
|
36 |
K.thy_heading (P.opt_locale_target -- P.position P.text >> IsarCmd.add_chapter); |
5958 | 37 |
|
9129 | 38 |
val sectionP = OuterSyntax.markup_command IsarOutput.Markup "section" "section heading" |
17264
c5b280a52a67
chapter/section/subsection/subsubsection/text: optional locale specification;
wenzelm
parents:
17228
diff
changeset
|
39 |
K.thy_heading (P.opt_locale_target -- P.position P.text >> IsarCmd.add_section); |
5958 | 40 |
|
9129 | 41 |
val subsectionP = OuterSyntax.markup_command IsarOutput.Markup "subsection" "subsection heading" |
17264
c5b280a52a67
chapter/section/subsection/subsubsection/text: optional locale specification;
wenzelm
parents:
17228
diff
changeset
|
42 |
K.thy_heading (P.opt_locale_target -- P.position P.text >> IsarCmd.add_subsection); |
5958 | 43 |
|
7749 | 44 |
val subsubsectionP = |
9129 | 45 |
OuterSyntax.markup_command IsarOutput.Markup "subsubsection" "subsubsection heading" |
17264
c5b280a52a67
chapter/section/subsection/subsubsection/text: optional locale specification;
wenzelm
parents:
17228
diff
changeset
|
46 |
K.thy_heading (P.opt_locale_target -- P.position P.text >> IsarCmd.add_subsubsection); |
5832 | 47 |
|
9129 | 48 |
val textP = OuterSyntax.markup_command IsarOutput.MarkupEnv "text" "formal comment (theory)" |
17264
c5b280a52a67
chapter/section/subsection/subsubsection/text: optional locale specification;
wenzelm
parents:
17228
diff
changeset
|
49 |
K.thy_decl (P.opt_locale_target -- P.position P.text >> IsarCmd.add_text); |
7172 | 50 |
|
9129 | 51 |
val text_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "text_raw" |
17264
c5b280a52a67
chapter/section/subsection/subsubsection/text: optional locale specification;
wenzelm
parents:
17228
diff
changeset
|
52 |
"raw document preparation text" |
c5b280a52a67
chapter/section/subsection/subsubsection/text: optional locale specification;
wenzelm
parents:
17228
diff
changeset
|
53 |
K.thy_decl (P.position P.text >> IsarCmd.add_text_raw); |
7172 | 54 |
|
9552 | 55 |
val sectP = OuterSyntax.markup_command IsarOutput.Markup "sect" "formal comment (proof)" |
17068 | 56 |
(K.tag_proof K.prf_heading) (P.position P.text >> IsarCmd.add_sect); |
7172 | 57 |
|
9129 | 58 |
val subsectP = OuterSyntax.markup_command IsarOutput.Markup "subsect" "formal comment (proof)" |
17068 | 59 |
(K.tag_proof K.prf_heading) (P.position P.text >> IsarCmd.add_subsect); |
7172 | 60 |
|
9129 | 61 |
val subsubsectP = OuterSyntax.markup_command IsarOutput.Markup "subsubsect" |
17068 | 62 |
"formal comment (proof)" (K.tag_proof K.prf_heading) |
12940 | 63 |
(P.position P.text >> IsarCmd.add_subsubsect); |
7172 | 64 |
|
9129 | 65 |
val txtP = OuterSyntax.markup_command IsarOutput.MarkupEnv "txt" "formal comment (proof)" |
17068 | 66 |
(K.tag_proof K.prf_decl) (P.position P.text >> IsarCmd.add_txt); |
7172 | 67 |
|
9129 | 68 |
val txt_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "txt_raw" |
17068 | 69 |
"raw document preparation text (proof)" (K.tag_proof K.prf_decl) |
12940 | 70 |
(P.position P.text >> IsarCmd.add_txt_raw); |
7775 | 71 |
|
5832 | 72 |
|
6886 | 73 |
|
74 |
(** theory sections **) |
|
75 |
||
5832 | 76 |
(* classes and sorts *) |
77 |
||
78 |
val classesP = |
|
6723 | 79 |
OuterSyntax.command "classes" "declare type classes" K.thy_decl |
11101
014e7b5c77ba
support \<subseteq> syntax in classes/classrel/axclass/instance;
wenzelm
parents:
11017
diff
changeset
|
80 |
(Scan.repeat1 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
81 |
P.!!! (P.list1 P.xname)) []) >> (Toplevel.theory o Theory.add_classes)); |
5832 | 82 |
|
83 |
val classrelP = |
|
6723 | 84 |
OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl |
14779 | 85 |
(P.and_list1 (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname)) |
86 |
>> (Toplevel.theory o Theory.add_classrel)); |
|
5832 | 87 |
|
88 |
val defaultsortP = |
|
6723 | 89 |
OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
90 |
(P.sort >> (Toplevel.theory o Theory.add_defsort)); |
5832 | 91 |
|
92 |
||
93 |
(* types *) |
|
94 |
||
95 |
val typedeclP = |
|
12624 | 96 |
OuterSyntax.command "typedecl" "type declaration" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
97 |
(P.type_args -- P.name -- P.opt_infix >> (fn ((args, a), mx) => |
16447 | 98 |
Toplevel.theory (Theory.add_typedecls [(a, args, mx)]))); |
5832 | 99 |
|
100 |
val typeabbrP = |
|
6723 | 101 |
OuterSyntax.command "types" "declare type abbreviations" K.thy_decl |
6727 | 102 |
(Scan.repeat1 |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
103 |
(P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix'))) |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
104 |
>> (Toplevel.theory o Theory.add_tyabbrs o |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
105 |
map (fn ((args, a), (T, mx)) => (a, args, T, mx)))); |
5832 | 106 |
|
107 |
val nontermP = |
|
6370 | 108 |
OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols" |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
109 |
K.thy_decl (Scan.repeat1 P.name >> (Toplevel.theory o Theory.add_nonterminals)); |
5832 | 110 |
|
111 |
val aritiesP = |
|
6723 | 112 |
OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
113 |
(Scan.repeat1 (P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2) |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
114 |
>> (Toplevel.theory o Theory.add_arities)); |
5832 | 115 |
|
116 |
||
117 |
(* consts and syntax *) |
|
118 |
||
8227 | 119 |
val judgmentP = |
120 |
OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
121 |
(P.const >> (Toplevel.theory o ObjectLogic.add_judgment)); |
8227 | 122 |
|
5832 | 123 |
val constsP = |
6723 | 124 |
OuterSyntax.command "consts" "declare constants" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
125 |
(Scan.repeat1 P.const >> (Toplevel.theory o Theory.add_consts)); |
5832 | 126 |
|
14642 | 127 |
val opt_overloaded = P.opt_keyword "overloaded"; |
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
13802
diff
changeset
|
128 |
|
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
13802
diff
changeset
|
129 |
val finalconstsP = |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
13802
diff
changeset
|
130 |
OuterSyntax.command "finalconsts" "declare constants as final" K.thy_decl |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
13802
diff
changeset
|
131 |
(opt_overloaded -- Scan.repeat1 P.term >> (uncurry (Toplevel.theory oo Theory.add_finals))); |
9731 | 132 |
|
12142 | 133 |
val mode_spec = |
9731 | 134 |
(P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true; |
135 |
||
14900 | 136 |
val opt_mode = |
137 |
Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) Syntax.default_mode; |
|
5832 | 138 |
|
139 |
val syntaxP = |
|
6723 | 140 |
OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
141 |
(opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Theory.add_modesyntax)); |
5832 | 142 |
|
15748 | 143 |
val no_syntaxP = |
144 |
OuterSyntax.command "no_syntax" "delete syntax declarations" K.thy_decl |
|
145 |
(opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Theory.del_modesyntax)); |
|
146 |
||
5832 | 147 |
|
148 |
(* translations *) |
|
149 |
||
150 |
val trans_pat = |
|
6723 | 151 |
Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string; |
5832 | 152 |
|
153 |
fun trans_arrow toks = |
|
10688 | 154 |
((P.$$$ "\\<rightharpoonup>" || P.$$$ "=>") >> K Syntax.ParseRule || |
155 |
(P.$$$ "\\<leftharpoondown>" || P.$$$ "<=") >> K Syntax.PrintRule || |
|
156 |
(P.$$$ "\\<rightleftharpoons>" || P.$$$ "==") >> K Syntax.ParsePrintRule) toks; |
|
5832 | 157 |
|
158 |
val trans_line = |
|
6723 | 159 |
trans_pat -- P.!!! (trans_arrow -- trans_pat) |
5832 | 160 |
>> (fn (left, (arr, right)) => arr (left, right)); |
161 |
||
162 |
val translationsP = |
|
6723 | 163 |
OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
164 |
(Scan.repeat1 trans_line >> (Toplevel.theory o Theory.add_trrules)); |
5832 | 165 |
|
166 |
||
167 |
(* axioms and definitions *) |
|
168 |
||
169 |
val axiomsP = |
|
6723 | 170 |
OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
171 |
(Scan.repeat1 P.spec_name >> (Toplevel.theory o IsarThy.add_axioms)); |
5832 | 172 |
|
173 |
val defsP = |
|
6723 | 174 |
OuterSyntax.command "defs" "define constants" K.thy_decl |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
175 |
(opt_overloaded -- Scan.repeat1 P.spec_name >> (Toplevel.theory o IsarThy.add_defs)); |
6370 | 176 |
|
14642 | 177 |
|
178 |
(* constant definitions *) |
|
179 |
||
180 |
val vars = P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ)); |
|
181 |
||
182 |
val structs = |
|
183 |
Scan.optional ((P.$$$ "(" -- P.$$$ "structure") |-- P.!!! (vars --| P.$$$ ")")) []; |
|
184 |
||
185 |
val constdecl = |
|
15531 | 186 |
(P.name --| P.$$$ "where") >> (fn x => (x, NONE, Syntax.NoSyn)) || |
187 |
P.name -- (P.$$$ "::" |-- P.!!! P.typ >> SOME) -- P.opt_mixfix' >> P.triple1 || |
|
188 |
P.name -- (P.mixfix' >> pair NONE) >> P.triple2; |
|
14642 | 189 |
|
190 |
val constdef = Scan.option constdecl -- (P.opt_thm_name ":" -- P.prop); |
|
191 |
||
6370 | 192 |
val constdefsP = |
14642 | 193 |
OuterSyntax.command "constdefs" "standard constant definitions" K.thy_decl |
194 |
(structs -- Scan.repeat1 constdef >> (Toplevel.theory o Constdefs.add_constdefs)); |
|
5832 | 195 |
|
196 |
||
5914 | 197 |
(* theorems *) |
198 |
||
17353 | 199 |
fun theorems kind = P.opt_locale_target -- P.name_facts |
200 |
>> (Toplevel.theory_context o uncurry (IsarThy.smart_theorems kind)); |
|
12712 | 201 |
|
5914 | 202 |
val theoremsP = |
17353 | 203 |
OuterSyntax.command "theorems" "define theorems" K.thy_decl (theorems Drule.theoremK); |
5914 | 204 |
|
205 |
val lemmasP = |
|
17353 | 206 |
OuterSyntax.command "lemmas" "define lemmas" K.thy_decl (theorems Drule.lemmaK); |
5914 | 207 |
|
9589 | 208 |
val declareP = |
9776 | 209 |
OuterSyntax.command "declare" "declare theorems (improper)" K.thy_script |
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16604
diff
changeset
|
210 |
(P.opt_locale_target -- (P.and_list1 P.xthms1 >> List.concat) |
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
211 |
>> (Toplevel.theory_context o uncurry IsarThy.declare_theorems)); |
9589 | 212 |
|
5914 | 213 |
|
5832 | 214 |
(* name space entry path *) |
215 |
||
216 |
val globalP = |
|
6723 | 217 |
OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl |
16447 | 218 |
(Scan.succeed (Toplevel.theory Sign.root_path)); |
5832 | 219 |
|
220 |
val localP = |
|
6723 | 221 |
OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl |
16447 | 222 |
(Scan.succeed (Toplevel.theory Sign.local_path)); |
8723 | 223 |
|
224 |
val hideP = |
|
225 |
OuterSyntax.command "hide" "hide names from given name space" K.thy_decl |
|
17397 | 226 |
((P.opt_keyword "open" >> not) -- (P.name -- Scan.repeat1 P.xname) >> |
227 |
(Toplevel.theory o uncurry Sign.hide_names)); |
|
5832 | 228 |
|
229 |
||
230 |
(* use ML text *) |
|
231 |
||
232 |
val useP = |
|
17068 | 233 |
OuterSyntax.command "use" "eval ML text from file" (K.tag_ml K.diag) |
14950 | 234 |
(P.path >> (Toplevel.no_timing oo IsarCmd.use)); |
5832 | 235 |
|
236 |
val mlP = |
|
17068 | 237 |
OuterSyntax.command "ML" "eval ML text (diagnostic)" (K.tag_ml K.diag) |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
238 |
(P.text >> IsarCmd.use_mltext true); |
7891 | 239 |
|
240 |
val ml_commandP = |
|
17068 | 241 |
OuterSyntax.command "ML_command" "eval ML text" (K.tag_ml K.diag) |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
242 |
(P.text >> (Toplevel.no_timing oo IsarCmd.use_mltext false)); |
7616 | 243 |
|
244 |
val ml_setupP = |
|
17068 | 245 |
OuterSyntax.command "ML_setup" "eval ML text (may change theory)" (K.tag_ml K.thy_decl) |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
246 |
(P.text >> IsarCmd.use_mltext_theory); |
5832 | 247 |
|
248 |
val setupP = |
|
17068 | 249 |
OuterSyntax.command "setup" "apply ML theory setup" (K.tag_ml K.thy_decl) |
17353 | 250 |
(P.text >> (Toplevel.theory o PureThy.generic_setup)); |
5832 | 251 |
|
9197 | 252 |
val method_setupP = |
17068 | 253 |
OuterSyntax.command "method_setup" "define proof method in ML" (K.tag_ml K.thy_decl) |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
254 |
(((P.name -- P.!!! (P.$$$ "=" |-- P.text -- P.text) >> P.triple2)) |
17353 | 255 |
>> (Toplevel.theory o Method.method_setup)); |
9197 | 256 |
|
5832 | 257 |
|
258 |
(* translation functions *) |
|
259 |
||
14642 | 260 |
val trfun = P.opt_keyword "advanced" -- P.text; |
261 |
||
5832 | 262 |
val parse_ast_translationP = |
17068 | 263 |
OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" |
264 |
(K.tag_ml K.thy_decl) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
265 |
(trfun >> (Toplevel.theory o Sign.parse_ast_translation)); |
5832 | 266 |
|
267 |
val parse_translationP = |
|
17068 | 268 |
OuterSyntax.command "parse_translation" "install parse translation functions" |
269 |
(K.tag_ml K.thy_decl) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
270 |
(trfun >> (Toplevel.theory o Sign.parse_translation)); |
5832 | 271 |
|
272 |
val print_translationP = |
|
17068 | 273 |
OuterSyntax.command "print_translation" "install print translation functions" |
274 |
(K.tag_ml K.thy_decl) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
275 |
(trfun >> (Toplevel.theory o Sign.print_translation)); |
5832 | 276 |
|
277 |
val typed_print_translationP = |
|
6370 | 278 |
OuterSyntax.command "typed_print_translation" "install typed print translation functions" |
17068 | 279 |
(K.tag_ml K.thy_decl) |
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
280 |
(trfun >> (Toplevel.theory o Sign.typed_print_translation)); |
5832 | 281 |
|
282 |
val print_ast_translationP = |
|
17068 | 283 |
OuterSyntax.command "print_ast_translation" "install print ast translation functions" |
284 |
(K.tag_ml K.thy_decl) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
285 |
(trfun >> (Toplevel.theory o Sign.print_ast_translation)); |
5832 | 286 |
|
287 |
val token_translationP = |
|
17068 | 288 |
OuterSyntax.command "token_translation" "install token translation functions" |
289 |
(K.tag_ml K.thy_decl) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
290 |
(P.text >> (Toplevel.theory o Sign.token_translation)); |
5832 | 291 |
|
292 |
||
293 |
(* oracles *) |
|
294 |
||
295 |
val oracleP = |
|
17068 | 296 |
OuterSyntax.command "oracle" "declare oracle" (K.tag_ml K.thy_decl) |
16849 | 297 |
(P.name -- (P.$$$ "(" |-- P.text --| P.$$$ ")" --| P.$$$ "=") |
17353 | 298 |
-- P.text >> (Toplevel.theory o PureThy.add_oracle o P.triple1)); |
5832 | 299 |
|
300 |
||
12061 | 301 |
(* locales *) |
302 |
||
12758 | 303 |
val locale_val = |
304 |
(P.locale_expr -- |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
305 |
Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 P.locale_element)) [] || |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
306 |
Scan.repeat1 P.locale_element >> pair Locale.empty); |
12061 | 307 |
|
308 |
val localeP = |
|
309 |
OuterSyntax.command "locale" "define named proof context" K.thy_decl |
|
14642 | 310 |
((P.opt_keyword "open" >> not) -- P.name |
311 |
-- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (Locale.empty, []) |
|
17142
76a5a2cc3171
add_locale_context(_i) now exporting elements (still some refinements to be done)
haftmann
parents:
17139
diff
changeset
|
312 |
>> (Toplevel.theory_context o (fn ((x, y), (z, w)) => Locale.add_locale_context x y z w #> (fn ((_, ctxt), thy) => (thy, ctxt))))); |
12061 | 313 |
|
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16604
diff
changeset
|
314 |
val opt_inst = |
17353 | 315 |
Scan.optional (P.$$$ "[" |-- P.!!! (Scan.repeat1 (P.maybe P.term) --| P.$$$ "]")) []; |
15596 | 316 |
|
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
317 |
val interpretationP = |
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
318 |
OuterSyntax.command "interpretation" |
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16604
diff
changeset
|
319 |
"prove and register interpretation of locale expression in theory or locale" K.thy_goal |
17353 | 320 |
(P.xname --| (P.$$$ "\\<subseteq>" || P.$$$ "<") -- P.!!! P.locale_expr |
321 |
>> (Toplevel.print oo (Toplevel.theory_to_proof o Locale.interpretation_in_locale)) || |
|
322 |
P.opt_thm_name ":" -- P.locale_expr -- opt_inst >> (fn ((x, y), z) => |
|
323 |
Toplevel.print o Toplevel.theory_to_proof (Locale.interpretation x y z))); |
|
12061 | 324 |
|
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
325 |
val interpretP = |
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
326 |
OuterSyntax.command "interpret" |
17068 | 327 |
"prove and register interpretation of locale expression in proof context" |
328 |
(K.tag_proof K.prf_goal) |
|
17353 | 329 |
(P.opt_thm_name ":" -- P.locale_expr -- opt_inst >> (fn ((x, y), z) => |
330 |
Toplevel.print o Toplevel.proof' (ProofHistory.apply o Locale.interpret x y z))); |
|
15703 | 331 |
|
332 |
||
5832 | 333 |
|
334 |
(** proof commands **) |
|
335 |
||
336 |
(* statements *) |
|
337 |
||
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
338 |
val statement = P.and_list1 (P.opt_thm_name ":" -- Scan.repeat1 P.propp); |
12956 | 339 |
val general_statement = |
15127 | 340 |
statement >> pair [] || Scan.repeat P.locale_elem_or_expr -- (P.$$$ "shows" |-- statement); |
5832 | 341 |
|
17353 | 342 |
fun gen_theorem kind = |
343 |
OuterSyntax.command kind ("state " ^ kind) K.thy_goal |
|
16736
1e792b32abef
Preparations for interpretation of locales in locales.
ballarin
parents:
16604
diff
changeset
|
344 |
(P.opt_locale_target -- Scan.optional (P.opt_thm_name ":" --| |
12956 | 345 |
Scan.ahead (P.locale_keyword || P.$$$ "shows")) ("", []) -- |
346 |
general_statement >> (fn ((x, y), (z, w)) => |
|
17353 | 347 |
(Toplevel.print o Toplevel.theory_to_proof (Locale.smart_theorem kind x y z w)))); |
5832 | 348 |
|
12242
282a92bc5655
multi_theorem: common statement header (covers *all* results);
wenzelm
parents:
12142
diff
changeset
|
349 |
val theoremP = gen_theorem Drule.theoremK; |
282a92bc5655
multi_theorem: common statement header (covers *all* results);
wenzelm
parents:
12142
diff
changeset
|
350 |
val lemmaP = gen_theorem Drule.lemmaK; |
282a92bc5655
multi_theorem: common statement header (covers *all* results);
wenzelm
parents:
12142
diff
changeset
|
351 |
val corollaryP = gen_theorem Drule.corollaryK; |
5832 | 352 |
|
17353 | 353 |
val haveP = |
354 |
OuterSyntax.command "have" "state local goal" |
|
355 |
(K.tag_proof K.prf_goal) |
|
356 |
(statement >> ((Toplevel.print oo Toplevel.proof') o (ProofHistory.apply oo IsarThy.have))); |
|
357 |
||
358 |
val henceP = |
|
359 |
OuterSyntax.command "hence" "abbreviates \"then have\"" |
|
360 |
(K.tag_proof K.prf_goal) |
|
361 |
(statement >> ((Toplevel.print oo Toplevel.proof') o (ProofHistory.apply oo IsarThy.hence))); |
|
362 |
||
5832 | 363 |
val showP = |
17068 | 364 |
OuterSyntax.command "show" "state local goal, solving current obligation" |
365 |
(K.tag_proof K.prf_goal) |
|
17353 | 366 |
(statement >> ((Toplevel.print oo Toplevel.proof') o (ProofHistory.apply oo IsarThy.show))); |
5832 | 367 |
|
6501 | 368 |
val thusP = |
17068 | 369 |
OuterSyntax.command "thus" "abbreviates \"then show\"" |
370 |
(K.tag_proof K.prf_goal) |
|
17353 | 371 |
(statement >> ((Toplevel.print oo Toplevel.proof') o (ProofHistory.apply oo IsarThy.thus))); |
6501 | 372 |
|
5832 | 373 |
|
5914 | 374 |
(* facts *) |
5832 | 375 |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
376 |
val facts = P.and_list1 P.xthms1; |
9197 | 377 |
|
5832 | 378 |
val thenP = |
17068 | 379 |
OuterSyntax.command "then" "forward chaining" |
380 |
(K.tag_proof K.prf_chain) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
381 |
(Scan.succeed (Toplevel.print o Toplevel.proof (ProofHistory.apply Proof.chain))); |
5832 | 382 |
|
383 |
val fromP = |
|
17068 | 384 |
OuterSyntax.command "from" "forward chaining from given facts" |
385 |
(K.tag_proof K.prf_chain) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
386 |
(facts >> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.from_thmss))); |
5914 | 387 |
|
6878 | 388 |
val withP = |
17068 | 389 |
OuterSyntax.command "with" "forward chaining from given and current facts" |
390 |
(K.tag_proof K.prf_chain) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
391 |
(facts >> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.with_thmss))); |
6878 | 392 |
|
6773 | 393 |
val noteP = |
17068 | 394 |
OuterSyntax.command "note" "define facts" |
395 |
(K.tag_proof K.prf_decl) |
|
17353 | 396 |
(P.name_facts >> |
397 |
(Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.note_thmss))); |
|
5832 | 398 |
|
12926 | 399 |
val usingP = |
17068 | 400 |
OuterSyntax.command "using" "augment goal facts" |
401 |
(K.tag_proof K.prf_decl) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
402 |
(facts >> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.using_thmss))); |
12926 | 403 |
|
5832 | 404 |
|
405 |
(* proof context *) |
|
406 |
||
11890 | 407 |
val fixP = |
17068 | 408 |
OuterSyntax.command "fix" "fix local variables (Skolem constants)" |
409 |
(K.tag_proof K.prf_asm) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
410 |
(vars >> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.fix))); |
11890 | 411 |
|
5832 | 412 |
val assumeP = |
17068 | 413 |
OuterSyntax.command "assume" "assume propositions" |
414 |
(K.tag_proof K.prf_asm) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
415 |
(statement >> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.assume))); |
5832 | 416 |
|
6850 | 417 |
val presumeP = |
17068 | 418 |
OuterSyntax.command "presume" "assume propositions, to be established later" |
419 |
(K.tag_proof K.prf_asm) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
420 |
(statement >> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.presume))); |
6850 | 421 |
|
6953 | 422 |
val defP = |
17068 | 423 |
OuterSyntax.command "def" "local definition" |
424 |
(K.tag_proof K.prf_asm) |
|
10688 | 425 |
(P.opt_thm_name ":" -- (P.name -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp)) |
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
426 |
>> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o uncurry Proof.def))); |
6953 | 427 |
|
11890 | 428 |
val obtainP = |
429 |
OuterSyntax.command "obtain" "generalized existence" |
|
17068 | 430 |
(K.tag_proof K.prf_asm_goal) |
11890 | 431 |
(Scan.optional |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
432 |
(P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ)) |
17353 | 433 |
--| P.$$$ "where") [] -- statement |
434 |
>> (Toplevel.print oo (Toplevel.proof' o (ProofHistory.apply oo uncurry Obtain.obtain)))); |
|
5832 | 435 |
|
17854 | 436 |
val guessP = |
437 |
OuterSyntax.command "guess" "wild guessing (unstructured)" |
|
438 |
(K.tag_proof K.prf_asm_goal) |
|
439 |
(P.and_list (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ)) |
|
440 |
>> (Toplevel.print oo (Toplevel.proof' o (ProofHistory.applys oo Obtain.guess)))); |
|
441 |
||
5832 | 442 |
val letP = |
17068 | 443 |
OuterSyntax.command "let" "bind text variables" |
444 |
(K.tag_proof K.prf_decl) |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
445 |
(P.and_list1 (P.enum1 "and" P.term -- (P.$$$ "=" |-- P.term)) |
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
446 |
>> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.let_bind))); |
5832 | 447 |
|
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
448 |
val case_spec = |
15703 | 449 |
(P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 (P.maybe P.name) --| P.$$$ ")") || |
12267 | 450 |
P.xname >> rpair []) -- P.opt_attribs >> P.triple1; |
11793
5f0ab6f5c280
support impromptu terminology of cases parameters;
wenzelm
parents:
11742
diff
changeset
|
451 |
|
8370 | 452 |
val caseP = |
17068 | 453 |
OuterSyntax.command "case" "invoke local context" |
454 |
(K.tag_proof K.prf_asm) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
455 |
(case_spec >> (Toplevel.print oo (Toplevel.proof o ProofHistory.apply o Proof.invoke_case))); |
8370 | 456 |
|
5832 | 457 |
|
458 |
(* proof structure *) |
|
459 |
||
460 |
val beginP = |
|
17068 | 461 |
OuterSyntax.command "{" "begin explicit proof block" |
462 |
(K.tag_proof K.prf_open) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
463 |
(Scan.succeed (Toplevel.print o (Toplevel.proof (ProofHistory.apply Proof.begin_block)))); |
5832 | 464 |
|
6687 | 465 |
val endP = |
17068 | 466 |
OuterSyntax.command "}" "end explicit proof block" |
467 |
(K.tag_proof K.prf_close) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
468 |
(Scan.succeed (Toplevel.print o (Toplevel.proof (ProofHistory.applys Proof.end_block)))); |
6687 | 469 |
|
5832 | 470 |
val nextP = |
17068 | 471 |
OuterSyntax.command "next" "enter next proof block" |
472 |
(K.tag_proof K.prf_block) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
473 |
(Scan.succeed (Toplevel.print o (Toplevel.proof (ProofHistory.apply Proof.next_block)))); |
5832 | 474 |
|
475 |
||
476 |
(* end proof *) |
|
477 |
||
6404 | 478 |
val qedP = |
17068 | 479 |
OuterSyntax.command "qed" "conclude (sub-)proof" |
480 |
(K.tag_proof K.qed_block) |
|
17353 | 481 |
(Scan.option P.method >> (Toplevel.print3 oo IsarThy.qed)); |
5832 | 482 |
|
6404 | 483 |
val terminal_proofP = |
17068 | 484 |
OuterSyntax.command "by" "terminal backward proof" |
485 |
(K.tag_proof K.qed) |
|
17353 | 486 |
(P.method -- Scan.option P.method >> (Toplevel.print3 oo IsarThy.terminal_proof)); |
6404 | 487 |
|
8966 | 488 |
val default_proofP = |
17068 | 489 |
OuterSyntax.command ".." "default proof" |
490 |
(K.tag_proof K.qed) |
|
17353 | 491 |
(Scan.succeed (Toplevel.print3 o IsarThy.default_proof)); |
8966 | 492 |
|
6404 | 493 |
val immediate_proofP = |
17068 | 494 |
OuterSyntax.command "." "immediate proof" |
495 |
(K.tag_proof K.qed) |
|
17353 | 496 |
(Scan.succeed (Toplevel.print3 o IsarThy.immediate_proof)); |
6404 | 497 |
|
8966 | 498 |
val done_proofP = |
17068 | 499 |
OuterSyntax.command "done" "done proof" |
500 |
(K.tag_proof K.qed) |
|
17353 | 501 |
(Scan.succeed (Toplevel.print3 o IsarThy.done_proof)); |
5832 | 502 |
|
6888
d0c68ebdabc5
skip_proof feature 'sorry' (for quick_and_dirty mode only);
wenzelm
parents:
6886
diff
changeset
|
503 |
val skip_proofP = |
17068 | 504 |
OuterSyntax.improper_command "sorry" "skip proof (quick-and-dirty mode only!)" |
505 |
(K.tag_proof K.qed) |
|
17353 | 506 |
(Scan.succeed (Toplevel.print3 o IsarThy.skip_proof)); |
6888
d0c68ebdabc5
skip_proof feature 'sorry' (for quick_and_dirty mode only);
wenzelm
parents:
6886
diff
changeset
|
507 |
|
8210 | 508 |
val forget_proofP = |
17068 | 509 |
OuterSyntax.command "oops" "forget proof" |
510 |
(K.tag_proof K.qed_global) |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
511 |
(Scan.succeed IsarThy.forget_proof); |
8210 | 512 |
|
5832 | 513 |
|
514 |
(* proof steps *) |
|
515 |
||
8165 | 516 |
val deferP = |
17068 | 517 |
OuterSyntax.command "defer" "shuffle internal proof state" |
518 |
(K.tag_proof K.prf_script) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
519 |
(Scan.option P.nat >> |
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
520 |
(Toplevel.print oo (Toplevel.proof o ProofHistory.applys o Proof.defer))); |
8165 | 521 |
|
522 |
val preferP = |
|
17068 | 523 |
OuterSyntax.command "prefer" "shuffle internal proof state" |
524 |
(K.tag_proof K.prf_script) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
525 |
(P.nat >> (Toplevel.print oo (Toplevel.proof o ProofHistory.applys o Proof.prefer))); |
8165 | 526 |
|
6850 | 527 |
val applyP = |
17068 | 528 |
OuterSyntax.command "apply" "initial refinement step (unstructured)" |
529 |
(K.tag_proof K.prf_script) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
530 |
(P.method >> (Toplevel.print oo (Toplevel.proof o ProofHistory.applys o Proof.apply))); |
5832 | 531 |
|
8235 | 532 |
val apply_endP = |
17068 | 533 |
OuterSyntax.command "apply_end" "terminal refinement (unstructured)" |
534 |
(K.tag_proof K.prf_script) |
|
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
535 |
(P.method >> (Toplevel.print oo (Toplevel.proof o ProofHistory.applys o Proof.apply_end))); |
5832 | 536 |
|
6404 | 537 |
val proofP = |
17068 | 538 |
OuterSyntax.command "proof" "backward proof" |
539 |
(K.tag_proof K.prf_block) |
|
16812 | 540 |
(Scan.option P.method >> (fn m => Toplevel.print o |
17107
2c35e00ee2ab
various Toplevel.theory_context commands: proper presentation in context;
wenzelm
parents:
17068
diff
changeset
|
541 |
Toplevel.actual_proof (ProofHistory.applys (Proof.proof m)) o |
15237
250e9be7a09d
Some changes to allow skipping of proof scripts.
berghofe
parents:
15141
diff
changeset
|
542 |
Toplevel.skip_proof (History.apply (fn i => i + 1)))); |
5832 | 543 |
|
544 |
||
6773 | 545 |
(* calculational proof commands *) |
546 |
||
6878 | 547 |
val calc_args = |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
548 |
Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")"))); |
6878 | 549 |
|
6773 | 550 |
val alsoP = |
17068 | 551 |
OuterSyntax.command "also" "combine calculation and current facts" |
552 |
(K.tag_proof K.prf_decl) |
|
17353 | 553 |
(calc_args >> (Toplevel.proof' o (ProofHistory.applys oo Calculation.also))); |
6773 | 554 |
|
555 |
val finallyP = |
|
17068 | 556 |
OuterSyntax.command "finally" "combine calculation and current facts, exhibit result" |
557 |
(K.tag_proof K.prf_chain) |
|
17353 | 558 |
(calc_args >> (Toplevel.proof' o (ProofHistory.applys oo Calculation.finally))); |
6773 | 559 |
|
8562 | 560 |
val moreoverP = |
17068 | 561 |
OuterSyntax.command "moreover" "augment calculation by current facts" |
562 |
(K.tag_proof K.prf_decl) |
|
17353 | 563 |
(Scan.succeed (Toplevel.proof' (ProofHistory.apply o Calculation.moreover))); |
8562 | 564 |
|
8588 | 565 |
val ultimatelyP = |
566 |
OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result" |
|
17068 | 567 |
(K.tag_proof K.prf_chain) |
17353 | 568 |
(Scan.succeed (Toplevel.proof' (ProofHistory.apply o Calculation.ultimately))); |
8588 | 569 |
|
6773 | 570 |
|
6742 | 571 |
(* proof navigation *) |
5944 | 572 |
|
5832 | 573 |
val backP = |
17068 | 574 |
OuterSyntax.command "back" "backtracking of proof command" |
575 |
(K.tag_proof K.prf_script) |
|
576 |
(Scan.succeed (Toplevel.print o IsarCmd.back)); |
|
5832 | 577 |
|
578 |
||
6742 | 579 |
(* history *) |
580 |
||
581 |
val cannot_undoP = |
|
582 |
OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control |
|
9010 | 583 |
(P.name >> (Toplevel.no_timing oo IsarCmd.cannot_undo)); |
6742 | 584 |
|
7733 | 585 |
val clear_undosP = |
586 |
OuterSyntax.improper_command "clear_undos" "clear theory-level undo information" K.control |
|
9010 | 587 |
(P.nat >> (Toplevel.no_timing oo IsarCmd.clear_undos_theory)); |
6742 | 588 |
|
589 |
val redoP = |
|
590 |
OuterSyntax.improper_command "redo" "redo last command" K.control |
|
9010 | 591 |
(Scan.succeed (Toplevel.no_timing o Toplevel.print o IsarCmd.redo)); |
6742 | 592 |
|
593 |
val undos_proofP = |
|
594 |
OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control |
|
9010 | 595 |
(P.nat >> ((Toplevel.no_timing o Toplevel.print) oo IsarCmd.undos_proof)); |
6742 | 596 |
|
597 |
val undoP = |
|
598 |
OuterSyntax.improper_command "undo" "undo last command" K.control |
|
9010 | 599 |
(Scan.succeed ((Toplevel.no_timing o Toplevel.print) o IsarCmd.undo)); |
6742 | 600 |
|
8500 | 601 |
val killP = |
602 |
OuterSyntax.improper_command "kill" "kill current history node" K.control |
|
9010 | 603 |
(Scan.succeed ((Toplevel.no_timing o Toplevel.print) o IsarCmd.kill)); |
8500 | 604 |
|
6742 | 605 |
|
5832 | 606 |
|
607 |
(** diagnostic commands (for interactive mode only) **) |
|
608 |
||
8464 | 609 |
val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) []; |
610 |
||
611 |
||
7124 | 612 |
val pretty_setmarginP = |
613 |
OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing" |
|
9010 | 614 |
K.diag (P.nat >> (Toplevel.no_timing oo IsarCmd.pretty_setmargin)); |
7124 | 615 |
|
5832 | 616 |
val print_commandsP = |
9221 | 617 |
OuterSyntax.improper_command "print_commands" "print outer syntax (global)" K.diag |
618 |
(Scan.succeed (Toplevel.no_timing o OuterSyntax.print_commands)); |
|
5832 | 619 |
|
7308 | 620 |
val print_contextP = |
621 |
OuterSyntax.improper_command "print_context" "print theory context name" K.diag |
|
9010 | 622 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_context)); |
7308 | 623 |
|
5832 | 624 |
val print_theoryP = |
6723 | 625 |
OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag |
9010 | 626 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_theory)); |
5832 | 627 |
|
628 |
val print_syntaxP = |
|
6723 | 629 |
OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)" K.diag |
9010 | 630 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_syntax)); |
5832 | 631 |
|
5881 | 632 |
val print_theoremsP = |
17068 | 633 |
OuterSyntax.improper_command "print_theorems" |
634 |
"print theorems of local theory or proof context" K.diag |
|
9010 | 635 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_theorems)); |
5881 | 636 |
|
12061 | 637 |
val print_localesP = |
638 |
OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag |
|
639 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_locales)); |
|
640 |
||
641 |
val print_localeP = |
|
15596 | 642 |
OuterSyntax.improper_command "print_locale" "print locale expression in this theory" K.diag |
17228 | 643 |
(Scan.optional (P.$$$ "!" >> K true) false -- locale_val >> (Toplevel.no_timing oo IsarCmd.print_locale)); |
12061 | 644 |
|
15596 | 645 |
val print_registrationsP = |
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
646 |
OuterSyntax.improper_command "print_interps" |
16102
c5f6726d9bb1
Locale expressions: rename with optional mixfix syntax.
ballarin
parents:
16074
diff
changeset
|
647 |
"print interpretations of named locale" K.diag |
17139
165c97f9bb63
Printing of interpretations: option to show witness theorems;
ballarin
parents:
17107
diff
changeset
|
648 |
(Scan.optional (P.$$$ "!" >> K true) false -- P.xname >> |
165c97f9bb63
Printing of interpretations: option to show witness theorems;
ballarin
parents:
17107
diff
changeset
|
649 |
(Toplevel.no_timing oo uncurry IsarCmd.print_registrations)); |
15596 | 650 |
|
5832 | 651 |
val print_attributesP = |
12061 | 652 |
OuterSyntax.improper_command "print_attributes" "print attributes of this theory" K.diag |
9010 | 653 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_attributes)); |
5832 | 654 |
|
16027 | 655 |
val print_simpsetP = |
656 |
OuterSyntax.improper_command "print_simpset" "print context of Simplifier" K.diag |
|
657 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_simpset)); |
|
658 |
||
12383 | 659 |
val print_rulesP = |
660 |
OuterSyntax.improper_command "print_rules" "print intro/elim rules" K.diag |
|
661 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_rules)); |
|
662 |
||
11666 | 663 |
val print_induct_rulesP = |
664 |
OuterSyntax.improper_command "print_induct_rules" "print induction and cases rules" K.diag |
|
665 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_induct_rules)); |
|
666 |
||
9221 | 667 |
val print_trans_rulesP = |
11666 | 668 |
OuterSyntax.improper_command "print_trans_rules" "print transitivity rules" K.diag |
9221 | 669 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_trans_rules)); |
670 |
||
5832 | 671 |
val print_methodsP = |
12061 | 672 |
OuterSyntax.improper_command "print_methods" "print methods of this theory" K.diag |
9010 | 673 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_methods)); |
5832 | 674 |
|
9221 | 675 |
val print_antiquotationsP = |
676 |
OuterSyntax.improper_command "print_antiquotations" "print antiquotations (global)" K.diag |
|
677 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_antiquotations)); |
|
678 |
||
9454 | 679 |
val thm_depsP = |
680 |
OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies" |
|
681 |
K.diag (P.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps)); |
|
682 |
||
16027 | 683 |
val criterion = |
684 |
P.reserved "name" |-- P.!!! (P.$$$ ":" |-- P.xname) >> FindTheorems.Name || |
|
685 |
P.reserved "intro" >> K FindTheorems.Intro || |
|
686 |
P.reserved "elim" >> K FindTheorems.Elim || |
|
687 |
P.reserved "dest" >> K FindTheorems.Dest || |
|
16074 | 688 |
P.reserved "simp" |-- P.!!! (P.$$$ ":" |-- P.term) >> FindTheorems.Simp || |
16027 | 689 |
P.term >> FindTheorems.Pattern; |
690 |
||
691 |
val find_theoremsP = |
|
17219
515badbfc4d6
renamed 'thms_containing' to 'find_theorems' -- keep old version for the time being;
wenzelm
parents:
17142
diff
changeset
|
692 |
OuterSyntax.improper_command "find_theorems" |
515badbfc4d6
renamed 'thms_containing' to 'find_theorems' -- keep old version for the time being;
wenzelm
parents:
17142
diff
changeset
|
693 |
"print theorems meeting specified criteria" K.diag |
515badbfc4d6
renamed 'thms_containing' to 'find_theorems' -- keep old version for the time being;
wenzelm
parents:
17142
diff
changeset
|
694 |
(Scan.option (P.$$$ "(" |-- P.!!! (P.nat --| P.$$$ ")")) -- |
515badbfc4d6
renamed 'thms_containing' to 'find_theorems' -- keep old version for the time being;
wenzelm
parents:
17142
diff
changeset
|
695 |
Scan.repeat (((Scan.option P.minus >> is_none) -- criterion)) |
515badbfc4d6
renamed 'thms_containing' to 'find_theorems' -- keep old version for the time being;
wenzelm
parents:
17142
diff
changeset
|
696 |
>> (Toplevel.no_timing oo IsarCmd.find_theorems)); |
515badbfc4d6
renamed 'thms_containing' to 'find_theorems' -- keep old version for the time being;
wenzelm
parents:
17142
diff
changeset
|
697 |
|
5832 | 698 |
val print_bindsP = |
6723 | 699 |
OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag |
9010 | 700 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds)); |
5832 | 701 |
|
702 |
val print_lthmsP = |
|
8370 | 703 |
OuterSyntax.improper_command "print_facts" "print facts of proof context" K.diag |
9010 | 704 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_lthms)); |
5832 | 705 |
|
8370 | 706 |
val print_casesP = |
707 |
OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag |
|
9010 | 708 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases)); |
8370 | 709 |
|
5896 | 710 |
val print_thmsP = |
8464 | 711 |
OuterSyntax.improper_command "thm" "print theorems" K.diag |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
712 |
(opt_modes -- P.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms)); |
5832 | 713 |
|
11524
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11101
diff
changeset
|
714 |
val print_prfsP = |
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11101
diff
changeset
|
715 |
OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
716 |
(opt_modes -- Scan.option P.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs false)); |
11524
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11101
diff
changeset
|
717 |
|
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11101
diff
changeset
|
718 |
val print_full_prfsP = |
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11101
diff
changeset
|
719 |
OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
720 |
(opt_modes -- Scan.option P.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true)); |
11524
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11101
diff
changeset
|
721 |
|
5832 | 722 |
val print_propP = |
6723 | 723 |
OuterSyntax.improper_command "prop" "read and print proposition" K.diag |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
724 |
(opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop)); |
5832 | 725 |
|
726 |
val print_termP = |
|
6723 | 727 |
OuterSyntax.improper_command "term" "read and print term" K.diag |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
728 |
(opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term)); |
5832 | 729 |
|
730 |
val print_typeP = |
|
6723 | 731 |
OuterSyntax.improper_command "typ" "read and print type" K.diag |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12768
diff
changeset
|
732 |
(opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type)); |
5832 | 733 |
|
734 |
||
735 |
||
736 |
(** system commands (for interactive mode only) **) |
|
737 |
||
738 |
val cdP = |
|
8650 | 739 |
OuterSyntax.improper_command "cd" "change current working directory" K.diag |
14950 | 740 |
(P.path >> (Toplevel.no_timing oo IsarCmd.cd)); |
5832 | 741 |
|
742 |
val pwdP = |
|
6723 | 743 |
OuterSyntax.improper_command "pwd" "print current working directory" K.diag |
9010 | 744 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.pwd)); |
5832 | 745 |
|
746 |
val use_thyP = |
|
6723 | 747 |
OuterSyntax.improper_command "use_thy" "use theory file" K.diag |
9010 | 748 |
(P.name >> (Toplevel.no_timing oo IsarCmd.use_thy)); |
5832 | 749 |
|
6694 | 750 |
val use_thy_onlyP = |
7102 | 751 |
OuterSyntax.improper_command "use_thy_only" "use theory file only, ignoring associated ML" |
9010 | 752 |
K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.use_thy_only)); |
6694 | 753 |
|
6196 | 754 |
val update_thyP = |
6723 | 755 |
OuterSyntax.improper_command "update_thy" "update theory file" K.diag |
9010 | 756 |
(P.name >> (Toplevel.no_timing oo IsarCmd.update_thy)); |
5832 | 757 |
|
7102 | 758 |
val update_thy_onlyP = |
759 |
OuterSyntax.improper_command "update_thy_only" "update theory file, ignoring associated ML" |
|
9010 | 760 |
K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.update_thy_only)); |
7102 | 761 |
|
762 |
val touch_thyP = |
|
763 |
OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag |
|
9010 | 764 |
(P.name >> (Toplevel.no_timing oo IsarCmd.touch_thy)); |
7102 | 765 |
|
766 |
val touch_all_thysP = |
|
767 |
OuterSyntax.improper_command "touch_all_thys" "outdate all non-finished theories" K.diag |
|
9010 | 768 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.touch_all_thys)); |
7102 | 769 |
|
7908 | 770 |
val touch_child_thysP = |
771 |
OuterSyntax.improper_command "touch_child_thys" "outdate child theories" K.diag |
|
9010 | 772 |
(P.name >> (Toplevel.no_timing oo IsarCmd.touch_child_thys)); |
7908 | 773 |
|
7102 | 774 |
val remove_thyP = |
775 |
OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag |
|
9010 | 776 |
(P.name >> (Toplevel.no_timing oo IsarCmd.remove_thy)); |
7102 | 777 |
|
7931 | 778 |
val kill_thyP = |
779 |
OuterSyntax.improper_command "kill_thy" "kill theory -- try to remove from loader database" |
|
9010 | 780 |
K.diag (P.name >> (Toplevel.no_timing oo IsarCmd.kill_thy)); |
7931 | 781 |
|
14934 | 782 |
val display_draftsP = |
783 |
OuterSyntax.improper_command "display_drafts" "display raw source files with symbols" |
|
14950 | 784 |
K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.display_drafts)); |
14934 | 785 |
|
786 |
val print_draftsP = |
|
787 |
OuterSyntax.improper_command "print_drafts" "print raw source files with symbols" |
|
14950 | 788 |
K.diag (Scan.repeat1 P.path >> (Toplevel.no_timing oo IsarCmd.print_drafts)); |
14934 | 789 |
|
9731 | 790 |
val opt_limits = |
791 |
Scan.option P.nat -- Scan.option (P.$$$ "," |-- P.!!! P.nat); |
|
792 |
||
5832 | 793 |
val prP = |
8886 | 794 |
OuterSyntax.improper_command "pr" "print current proof state (if present)" K.diag |
9731 | 795 |
(opt_modes -- opt_limits >> (Toplevel.no_timing oo IsarCmd.pr)); |
7199 | 796 |
|
7222 | 797 |
val disable_prP = |
798 |
OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag |
|
9010 | 799 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.disable_pr)); |
5832 | 800 |
|
7222 | 801 |
val enable_prP = |
802 |
OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag |
|
9010 | 803 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.enable_pr)); |
7222 | 804 |
|
5832 | 805 |
val commitP = |
6723 | 806 |
OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag |
9010 | 807 |
(P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.use_commit)); |
5832 | 808 |
|
809 |
val quitP = |
|
6723 | 810 |
OuterSyntax.improper_command "quit" "quit Isabelle" K.control |
9010 | 811 |
(P.opt_unit >> (Toplevel.no_timing oo K IsarCmd.quit)); |
5832 | 812 |
|
813 |
val exitP = |
|
6723 | 814 |
OuterSyntax.improper_command "exit" "exit Isar loop" K.control |
9010 | 815 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.exit)); |
5832 | 816 |
|
7102 | 817 |
val init_toplevelP = |
818 |
OuterSyntax.improper_command "init_toplevel" "restart Isar toplevel loop" K.control |
|
9010 | 819 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.init_toplevel)); |
5991 | 820 |
|
7462 | 821 |
val welcomeP = |
8678 | 822 |
OuterSyntax.improper_command "welcome" "print welcome message" K.diag |
9010 | 823 |
(Scan.succeed (Toplevel.no_timing o IsarCmd.welcome)); |
7462 | 824 |
|
5832 | 825 |
|
826 |
||
827 |
(** the Pure outer syntax **) |
|
828 |
||
829 |
(*keep keywords consistent with the parsers, including those in |
|
830 |
outer_parse.ML, otherwise be prepared for unexpected errors*) |
|
831 |
||
16038 | 832 |
val _ = OuterSyntax.add_keywords |
17068 | 833 |
["!", "!!", "%", "(", ")", "+", ",", "--", ":", "::", ";", "<", "<=", |
834 |
"=", "==", "=>", "?", "[", "]", "advanced", "and", "assumes", |
|
16264 | 835 |
"begin", "binder", "concl", "constrains", "defines", "files", |
836 |
"fixes", "imports", "in", "includes", "infix", "infixl", "infixr", |
|
837 |
"is", "notes", "open", "output", "overloaded", "shows", "structure", |
|
838 |
"uses", "where", "|", "\\<equiv>", "\\<leftharpoondown>", |
|
839 |
"\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>"]; |
|
5832 | 840 |
|
16038 | 841 |
val _ = OuterSyntax.add_parsers [ |
5832 | 842 |
(*theory structure*) |
8500 | 843 |
theoryP, end_excursionP, contextP, |
7775 | 844 |
(*markup commands*) |
7733 | 845 |
headerP, chapterP, sectionP, subsectionP, subsubsectionP, textP, |
7862 | 846 |
text_rawP, sectP, subsectP, subsubsectP, txtP, txt_rawP, |
5832 | 847 |
(*theory sections*) |
7172 | 848 |
classesP, classrelP, defaultsortP, typedeclP, typeabbrP, nontermP, |
15748 | 849 |
aritiesP, judgmentP, constsP, finalconstsP, syntaxP, no_syntaxP, |
850 |
translationsP, axiomsP, defsP, constdefsP, theoremsP, lemmasP, |
|
851 |
declareP, globalP, localP, hideP, useP, mlP, ml_commandP, ml_setupP, |
|
852 |
setupP, method_setupP, parse_ast_translationP, parse_translationP, |
|
14223
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
13802
diff
changeset
|
853 |
print_translationP, typed_print_translationP, |
0ee05eef881b
Added support for making constants final, that is, ensuring that no
skalberg
parents:
13802
diff
changeset
|
854 |
print_ast_translationP, token_translationP, oracleP, localeP, |
5832 | 855 |
(*proof commands*) |
17353 | 856 |
theoremP, lemmaP, corollaryP, haveP, henceP, showP, thusP, fixP, |
17854 | 857 |
assumeP, presumeP, defP, obtainP, guessP, letP, caseP, thenP, fromP, |
858 |
withP, noteP, usingP, beginP, endP, nextP, qedP, terminal_proofP, |
|
12926 | 859 |
default_proofP, immediate_proofP, done_proofP, skip_proofP, |
860 |
forget_proofP, deferP, preferP, applyP, apply_endP, proofP, alsoP, |
|
861 |
finallyP, moreoverP, ultimatelyP, backP, cannot_undoP, clear_undosP, |
|
16027 | 862 |
redoP, undos_proofP, undoP, killP, interpretationP, interpretP, |
16168
adb83939177f
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
863 |
(*diagnostic commands*) |
adb83939177f
Locales: new element constrains, parameter renaming with syntax,
ballarin
parents:
16102
diff
changeset
|
864 |
pretty_setmarginP, |
16027 | 865 |
print_commandsP, print_contextP, print_theoryP, print_syntaxP, |
866 |
print_theoremsP, print_localesP, print_localeP, |
|
867 |
print_registrationsP, print_attributesP, print_simpsetP, |
|
868 |
print_rulesP, print_induct_rulesP, print_trans_rulesP, |
|
869 |
print_methodsP, print_antiquotationsP, thm_depsP, find_theoremsP, |
|
870 |
print_bindsP, print_lthmsP, print_casesP, print_thmsP, print_prfsP, |
|
871 |
print_full_prfsP, print_propP, print_termP, print_typeP, |
|
5832 | 872 |
(*system commands*) |
7102 | 873 |
cdP, pwdP, use_thyP, use_thy_onlyP, update_thyP, update_thy_onlyP, |
7931 | 874 |
touch_thyP, touch_all_thysP, touch_child_thysP, remove_thyP, |
14934 | 875 |
kill_thyP, display_draftsP, print_draftsP, prP, disable_prP, |
876 |
enable_prP, commitP, quitP, exitP, init_toplevelP, welcomeP]; |
|
5832 | 877 |
|
878 |
end; |