author | wenzelm |
Tue, 05 Oct 1999 15:34:54 +0200 | |
changeset 7728 | 2e737ce3cdb5 |
parent 7678 | 027b6ec2f084 |
child 7733 | a469d66aa417 |
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 |
||
8 |
signature ISAR_SYN = |
|
9 |
sig |
|
10 |
val keywords: string list |
|
11 |
val parsers: OuterSyntax.parser list |
|
12 |
end; |
|
13 |
||
14 |
structure IsarSyn: ISAR_SYN = |
|
15 |
struct |
|
16 |
||
6723 | 17 |
structure P = OuterParse and K = OuterSyntax.Keyword; |
5832 | 18 |
|
19 |
||
20 |
(** init and exit **) |
|
21 |
||
22 |
val theoryP = |
|
6723 | 23 |
OuterSyntax.command "theory" "begin theory" K.thy_begin |
6245 | 24 |
(OuterSyntax.theory_header >> (Toplevel.print oo IsarThy.theory)); |
5832 | 25 |
|
6687 | 26 |
val end_excursionP = |
6723 | 27 |
OuterSyntax.command "end" "end current excursion" K.thy_end |
6687 | 28 |
(Scan.succeed (Toplevel.print o Toplevel.exit)); |
29 |
||
30 |
val kill_excursionP = |
|
6757 | 31 |
OuterSyntax.improper_command "kill" "kill current excursion" K.control |
7415 | 32 |
(Scan.succeed (Toplevel.print o Toplevel.kill)); |
5832 | 33 |
|
6245 | 34 |
val contextP = |
7102 | 35 |
OuterSyntax.improper_command "context" "switch theory context" K.thy_switch |
6723 | 36 |
(P.name >> (Toplevel.print oo IsarThy.context)); |
6245 | 37 |
|
5832 | 38 |
|
39 |
||
6886 | 40 |
(** formal comments **) |
5832 | 41 |
|
6723 | 42 |
val titleP = OuterSyntax.command "title" "document title" K.thy_heading |
6727 | 43 |
((P.comment -- Scan.optional P.comment Comment.none -- Scan.optional P.comment Comment.none) |
6353 | 44 |
>> (fn ((x, y), z) => Toplevel.theory (IsarThy.add_title x y z))); |
45 |
||
6723 | 46 |
val chapterP = OuterSyntax.command "chapter" "chapter heading" K.thy_heading |
47 |
(P.comment >> (Toplevel.theory o IsarThy.add_chapter)); |
|
5958 | 48 |
|
6723 | 49 |
val sectionP = OuterSyntax.command "section" "section heading" K.thy_heading |
50 |
(P.comment >> (Toplevel.theory o IsarThy.add_section)); |
|
5958 | 51 |
|
6723 | 52 |
val subsectionP = OuterSyntax.command "subsection" "subsection heading" K.thy_heading |
53 |
(P.comment >> (Toplevel.theory o IsarThy.add_subsection)); |
|
5958 | 54 |
|
6723 | 55 |
val subsubsectionP = OuterSyntax.command "subsubsection" "subsubsection heading" K.thy_heading |
56 |
(P.comment >> (Toplevel.theory o IsarThy.add_subsubsection)); |
|
5832 | 57 |
|
7172 | 58 |
val textP = OuterSyntax.command "text" "formal comment (theory)" K.thy_decl |
59 |
(P.comment >> (Toplevel.theory o IsarThy.add_text)); |
|
60 |
||
61 |
||
62 |
val sectP = OuterSyntax.command "sect" "formal comment (proof)" K.prf_decl |
|
63 |
(P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_sect))); |
|
64 |
||
65 |
val subsectP = OuterSyntax.command "subsect" "formal comment (proof)" K.prf_decl |
|
66 |
(P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsect))); |
|
67 |
||
68 |
val subsubsectP = OuterSyntax.command "subsubsect" "formal comment (proof)" K.prf_decl |
|
69 |
(P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsubsect))); |
|
70 |
||
71 |
val txtP = OuterSyntax.command "txt" "formal comment (proof)" K.prf_decl |
|
72 |
(P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt))); |
|
73 |
||
5832 | 74 |
|
6886 | 75 |
|
76 |
(** theory sections **) |
|
77 |
||
5832 | 78 |
(* classes and sorts *) |
79 |
||
80 |
val classesP = |
|
6723 | 81 |
OuterSyntax.command "classes" "declare type classes" K.thy_decl |
82 |
(Scan.repeat1 (P.name -- Scan.optional (P.$$$ "<" |-- P.!!! (P.list1 P.xname)) []) |
|
6727 | 83 |
-- P.marg_comment >> (Toplevel.theory o IsarThy.add_classes)); |
5832 | 84 |
|
85 |
val classrelP = |
|
6723 | 86 |
OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl |
6727 | 87 |
(P.xname -- (P.$$$ "<" |-- P.!!! P.xname) -- P.marg_comment |
88 |
>> (Toplevel.theory o IsarThy.add_classrel)); |
|
5832 | 89 |
|
90 |
val defaultsortP = |
|
6723 | 91 |
OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl |
6727 | 92 |
(P.sort -- P.marg_comment >> (Toplevel.theory o IsarThy.add_defsort)); |
5832 | 93 |
|
94 |
||
95 |
(* types *) |
|
96 |
||
97 |
val typedeclP = |
|
6723 | 98 |
OuterSyntax.command "typedecl" "Pure type declaration" K.thy_decl |
6727 | 99 |
(P.type_args -- P.name -- P.opt_infix -- P.marg_comment >> (fn (((args, a), mx), cmt) => |
100 |
Toplevel.theory (IsarThy.add_typedecl ((a, args, mx), cmt)))); |
|
5832 | 101 |
|
102 |
val typeabbrP = |
|
6723 | 103 |
OuterSyntax.command "types" "declare type abbreviations" K.thy_decl |
6727 | 104 |
(Scan.repeat1 |
105 |
(P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix)) -- P.marg_comment) |
|
106 |
>> (Toplevel.theory o IsarThy.add_tyabbrs o |
|
107 |
map (fn (((args, a), (T, mx)), cmt) => ((a, args, T, mx), cmt)))); |
|
5832 | 108 |
|
109 |
val nontermP = |
|
6370 | 110 |
OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols" |
6727 | 111 |
K.thy_decl (Scan.repeat1 (P.name -- P.marg_comment) |
112 |
>> (Toplevel.theory o IsarThy.add_nonterminals)); |
|
5832 | 113 |
|
114 |
val aritiesP = |
|
6723 | 115 |
OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl |
6727 | 116 |
(Scan.repeat1 ((P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2) -- P.marg_comment) |
117 |
>> (Toplevel.theory o IsarThy.add_arities)); |
|
5832 | 118 |
|
119 |
||
120 |
(* consts and syntax *) |
|
121 |
||
122 |
val constsP = |
|
6723 | 123 |
OuterSyntax.command "consts" "declare constants" K.thy_decl |
6727 | 124 |
(Scan.repeat1 (P.const -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_consts)); |
5832 | 125 |
|
126 |
val opt_mode = |
|
127 |
Scan.optional |
|
6723 | 128 |
(P.$$$ "(" |-- P.!!! (P.name -- Scan.optional (P.$$$ "output" >> K false) true --| P.$$$ ")")) |
5832 | 129 |
("", true); |
130 |
||
131 |
val syntaxP = |
|
6723 | 132 |
OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl |
6727 | 133 |
(opt_mode -- Scan.repeat1 (P.const -- P.marg_comment) |
134 |
>> (Toplevel.theory o uncurry IsarThy.add_modesyntax)); |
|
5832 | 135 |
|
136 |
||
137 |
(* translations *) |
|
138 |
||
139 |
val trans_pat = |
|
6723 | 140 |
Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string; |
5832 | 141 |
|
142 |
fun trans_arrow toks = |
|
6723 | 143 |
(P.$$$ "=>" >> K Syntax.ParseRule || |
144 |
P.$$$ "<=" >> K Syntax.PrintRule || |
|
145 |
P.$$$ "==" >> K Syntax.ParsePrintRule) toks; |
|
5832 | 146 |
|
147 |
val trans_line = |
|
6723 | 148 |
trans_pat -- P.!!! (trans_arrow -- trans_pat) |
5832 | 149 |
>> (fn (left, (arr, right)) => arr (left, right)); |
150 |
||
151 |
val translationsP = |
|
6723 | 152 |
OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl |
6727 | 153 |
(Scan.repeat1 (trans_line -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_trrules)); |
5832 | 154 |
|
155 |
||
156 |
(* axioms and definitions *) |
|
157 |
||
158 |
val axiomsP = |
|
6723 | 159 |
OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl |
6727 | 160 |
(Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_axioms)); |
5832 | 161 |
|
162 |
val defsP = |
|
6723 | 163 |
OuterSyntax.command "defs" "define constants" K.thy_decl |
7603 | 164 |
(Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_defs)); |
6370 | 165 |
|
166 |
val constdefsP = |
|
6723 | 167 |
OuterSyntax.command "constdefs" "declare and define constants" K.thy_decl |
6727 | 168 |
(Scan.repeat1 ((P.const -- P.marg_comment) -- (P.term -- P.marg_comment)) |
169 |
>> (Toplevel.theory o IsarThy.add_constdefs)); |
|
5832 | 170 |
|
171 |
||
5914 | 172 |
(* theorems *) |
173 |
||
6723 | 174 |
val facts = P.opt_thm_name "=" -- P.xthms1; |
5914 | 175 |
|
176 |
val theoremsP = |
|
6723 | 177 |
OuterSyntax.command "theorems" "define theorems" K.thy_decl |
6727 | 178 |
(facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_theorems)); |
5914 | 179 |
|
180 |
val lemmasP = |
|
6723 | 181 |
OuterSyntax.command "lemmas" "define lemmas" K.thy_decl |
6727 | 182 |
(facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_lemmas)); |
5914 | 183 |
|
184 |
||
5832 | 185 |
(* name space entry path *) |
186 |
||
187 |
val globalP = |
|
6723 | 188 |
OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl |
5832 | 189 |
(Scan.succeed (Toplevel.theory PureThy.global_path)); |
190 |
||
191 |
val localP = |
|
6723 | 192 |
OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl |
5832 | 193 |
(Scan.succeed (Toplevel.theory PureThy.local_path)); |
194 |
||
195 |
||
196 |
(* use ML text *) |
|
197 |
||
198 |
val useP = |
|
6723 | 199 |
OuterSyntax.command "use" "eval ML text from file" K.diag |
200 |
(P.name >> IsarCmd.use); |
|
5832 | 201 |
|
202 |
val mlP = |
|
7616 | 203 |
OuterSyntax.command "ML" "eval ML text (diagnostic)" K.diag |
204 |
(P.text >> IsarCmd.use_mltext) |
|
205 |
||
206 |
val ml_setupP = |
|
207 |
OuterSyntax.command "ML_setup" "eval ML text (may change theory)" K.thy_decl |
|
208 |
(P.text >> IsarCmd.use_mltext_theory); |
|
5832 | 209 |
|
210 |
val setupP = |
|
7616 | 211 |
OuterSyntax.command "setup" "apply ML theory setup" K.thy_decl |
6723 | 212 |
(P.text >> (Toplevel.theory o IsarThy.use_setup)); |
5832 | 213 |
|
214 |
||
215 |
(* translation functions *) |
|
216 |
||
217 |
val parse_ast_translationP = |
|
6723 | 218 |
OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" K.thy_decl |
219 |
(P.text >> (Toplevel.theory o IsarThy.parse_ast_translation)); |
|
5832 | 220 |
|
221 |
val parse_translationP = |
|
6723 | 222 |
OuterSyntax.command "parse_translation" "install parse translation functions" K.thy_decl |
223 |
(P.text >> (Toplevel.theory o IsarThy.parse_translation)); |
|
5832 | 224 |
|
225 |
val print_translationP = |
|
6723 | 226 |
OuterSyntax.command "print_translation" "install print translation functions" K.thy_decl |
227 |
(P.text >> (Toplevel.theory o IsarThy.print_translation)); |
|
5832 | 228 |
|
229 |
val typed_print_translationP = |
|
6370 | 230 |
OuterSyntax.command "typed_print_translation" "install typed print translation functions" |
6723 | 231 |
K.thy_decl (P.text >> (Toplevel.theory o IsarThy.typed_print_translation)); |
5832 | 232 |
|
233 |
val print_ast_translationP = |
|
6723 | 234 |
OuterSyntax.command "print_ast_translation" "install print ast translation functions" K.thy_decl |
235 |
(P.text >> (Toplevel.theory o IsarThy.print_ast_translation)); |
|
5832 | 236 |
|
237 |
val token_translationP = |
|
6723 | 238 |
OuterSyntax.command "token_translation" "install token translation functions" K.thy_decl |
239 |
(P.text >> (Toplevel.theory o IsarThy.token_translation)); |
|
5832 | 240 |
|
241 |
||
242 |
(* oracles *) |
|
243 |
||
244 |
val oracleP = |
|
6723 | 245 |
OuterSyntax.command "oracle" "install oracle" K.thy_decl |
7140 | 246 |
((P.name --| P.$$$ "=") -- P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.add_oracle)); |
5832 | 247 |
|
248 |
||
249 |
||
250 |
(** proof commands **) |
|
251 |
||
252 |
(* statements *) |
|
253 |
||
6936 | 254 |
fun statement f = (P.opt_thm_name ":" -- P.propp >> P.triple1) -- P.marg_comment >> f; |
5832 | 255 |
|
256 |
val theoremP = |
|
6723 | 257 |
OuterSyntax.command "theorem" "state theorem" K.thy_goal |
5832 | 258 |
(statement IsarThy.theorem >> (fn f => Toplevel.print o Toplevel.theory_to_proof f)); |
259 |
||
260 |
val lemmaP = |
|
6723 | 261 |
OuterSyntax.command "lemma" "state lemma" K.thy_goal |
5832 | 262 |
(statement IsarThy.lemma >> (fn f => Toplevel.print o Toplevel.theory_to_proof f)); |
263 |
||
264 |
val showP = |
|
6723 | 265 |
OuterSyntax.command "show" "state local goal, solving current obligation" K.prf_goal |
5832 | 266 |
(statement IsarThy.show >> (fn f => Toplevel.print o Toplevel.proof f)); |
267 |
||
268 |
val haveP = |
|
6723 | 269 |
OuterSyntax.command "have" "state local goal" K.prf_goal |
5832 | 270 |
(statement IsarThy.have >> (fn f => Toplevel.print o Toplevel.proof f)); |
271 |
||
6501 | 272 |
val thusP = |
6723 | 273 |
OuterSyntax.command "thus" "abbreviates \"then show\"" K.prf_goal |
6501 | 274 |
(statement IsarThy.thus >> (fn f => Toplevel.print o Toplevel.proof f)); |
275 |
||
276 |
val henceP = |
|
6723 | 277 |
OuterSyntax.command "hence" "abbreviates \"then have\"" K.prf_goal |
6501 | 278 |
(statement IsarThy.hence >> (fn f => Toplevel.print o Toplevel.proof f)); |
279 |
||
5832 | 280 |
|
5914 | 281 |
(* facts *) |
5832 | 282 |
|
283 |
val thenP = |
|
6723 | 284 |
OuterSyntax.command "then" "forward chaining" K.prf_chain |
6727 | 285 |
(P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.chain))); |
5832 | 286 |
|
6936 | 287 |
val thenceP = |
7678 | 288 |
OuterSyntax.command "thence" "forward chaining, including full export (EXPERIMENTAL!)" K.prf_chain |
6936 | 289 |
(P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.export_chain))); |
290 |
||
5832 | 291 |
val fromP = |
6723 | 292 |
OuterSyntax.command "from" "forward chaining from given facts" K.prf_chain |
6727 | 293 |
(P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.from_facts))); |
5914 | 294 |
|
6878 | 295 |
val withP = |
296 |
OuterSyntax.command "with" "forward chaining from given and current facts" K.prf_chain |
|
297 |
(P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.with_facts))); |
|
298 |
||
6773 | 299 |
val noteP = |
6723 | 300 |
OuterSyntax.command "note" "define facts" K.prf_decl |
6755 | 301 |
(facts -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.have_facts))); |
5832 | 302 |
|
303 |
||
304 |
(* proof context *) |
|
305 |
||
306 |
val assumeP = |
|
6869 | 307 |
OuterSyntax.command "assume" "assume propositions" K.prf_asm |
7269 | 308 |
(P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment) |
6727 | 309 |
>> (Toplevel.print oo (Toplevel.proof o IsarThy.assume))); |
5832 | 310 |
|
6850 | 311 |
val presumeP = |
6869 | 312 |
OuterSyntax.command "presume" "assume propositions, to be established later" K.prf_asm |
7269 | 313 |
(P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment) |
6850 | 314 |
>> (Toplevel.print oo (Toplevel.proof o IsarThy.presume))); |
315 |
||
6953 | 316 |
val defP = |
317 |
OuterSyntax.command "def" "local definition" K.prf_asm |
|
318 |
((P.opt_thm_name ":" -- (P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- |
|
6972 | 319 |
(P.$$$ "==" |-- P.termp)) >> P.triple1) -- P.marg_comment |
6953 | 320 |
>> (Toplevel.print oo (Toplevel.proof o IsarThy.local_def))); |
321 |
||
5832 | 322 |
val fixP = |
6869 | 323 |
OuterSyntax.command "fix" "fix variables (Skolem constants)" K.prf_asm |
7415 | 324 |
(P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment) |
6727 | 325 |
>> (Toplevel.print oo (Toplevel.proof o IsarThy.fix))); |
5832 | 326 |
|
327 |
val letP = |
|
6723 | 328 |
OuterSyntax.command "let" "bind text variables" K.prf_decl |
6727 | 329 |
(P.and_list1 (P.enum1 "as" P.term -- (P.$$$ "=" |-- P.term) -- P.marg_comment) |
330 |
>> (Toplevel.print oo (Toplevel.proof o IsarThy.match_bind))); |
|
5832 | 331 |
|
332 |
||
333 |
(* proof structure *) |
|
334 |
||
335 |
val beginP = |
|
6723 | 336 |
OuterSyntax.command "{{" "begin explicit proof block" K.prf_block |
5832 | 337 |
(Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.begin_block)); |
338 |
||
6687 | 339 |
val endP = |
6723 | 340 |
OuterSyntax.command "}}" "end explicit proof block" K.prf_block |
6687 | 341 |
(Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.end_block)); |
342 |
||
5832 | 343 |
val nextP = |
6723 | 344 |
OuterSyntax.command "next" "enter next proof block" K.prf_block |
5832 | 345 |
(Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.next_block)); |
346 |
||
347 |
||
348 |
(* end proof *) |
|
349 |
||
6404 | 350 |
val qedP = |
6735 | 351 |
OuterSyntax.command "qed" "conclude (sub-)proof" K.qed_block |
7002 | 352 |
(Scan.option (P.method -- P.interest) -- P.marg_comment >> IsarThy.qed); |
5832 | 353 |
|
6404 | 354 |
val terminal_proofP = |
6723 | 355 |
OuterSyntax.command "by" "terminal backward proof" K.qed |
7002 | 356 |
(P.method -- P.interest -- Scan.option (P.method -- P.interest) |
357 |
-- P.marg_comment >> IsarThy.terminal_proof); |
|
6404 | 358 |
|
359 |
val immediate_proofP = |
|
6723 | 360 |
OuterSyntax.command "." "immediate proof" K.qed |
7002 | 361 |
(P.marg_comment >> IsarThy.immediate_proof); |
6404 | 362 |
|
363 |
val default_proofP = |
|
6723 | 364 |
OuterSyntax.command ".." "default proof" K.qed |
7002 | 365 |
(P.marg_comment >> IsarThy.default_proof); |
5832 | 366 |
|
6888
d0c68ebdabc5
skip_proof feature 'sorry' (for quick_and_dirty mode only);
wenzelm
parents:
6886
diff
changeset
|
367 |
val skip_proofP = |
7172 | 368 |
OuterSyntax.improper_command "sorry" "skip proof (quick-and-dirty mode only!)" K.qed |
7002 | 369 |
(P.marg_comment >> IsarThy.skip_proof); |
6888
d0c68ebdabc5
skip_proof feature 'sorry' (for quick_and_dirty mode only);
wenzelm
parents:
6886
diff
changeset
|
370 |
|
5832 | 371 |
|
372 |
(* proof steps *) |
|
373 |
||
6850 | 374 |
val applyP = |
375 |
OuterSyntax.improper_command "apply" "unstructured backward proof step, ignoring facts" |
|
6723 | 376 |
K.prf_script (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.tac))); |
5832 | 377 |
|
6850 | 378 |
val then_applyP = |
379 |
OuterSyntax.improper_command "then_apply" "unstructured backward proof step, using facts" |
|
6723 | 380 |
K.prf_script (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.then_tac))); |
5832 | 381 |
|
6404 | 382 |
val proofP = |
6723 | 383 |
OuterSyntax.command "proof" "backward proof" K.prf_block |
7002 | 384 |
(P.interest -- Scan.option (P.method -- P.interest) -- P.marg_comment |
6727 | 385 |
>> (Toplevel.print oo (Toplevel.proof o IsarThy.proof))); |
5832 | 386 |
|
387 |
||
6773 | 388 |
(* calculational proof commands *) |
389 |
||
6878 | 390 |
val calc_args = |
391 |
Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")") -- P.interest)); |
|
392 |
||
6773 | 393 |
val alsoP = |
394 |
OuterSyntax.command "also" "intermediate calculational proof step" K.prf_decl |
|
6878 | 395 |
(calc_args -- P.marg_comment >> IsarThy.also); |
6773 | 396 |
|
397 |
val finallyP = |
|
398 |
OuterSyntax.command "finally" "terminal calculational proof step" K.prf_chain |
|
6878 | 399 |
(calc_args -- P.marg_comment >> IsarThy.finally); |
6773 | 400 |
|
401 |
||
7678 | 402 |
(* obtain *) |
403 |
||
404 |
val obtainP = |
|
405 |
OuterSyntax.command "obtain" "document-level existential quantifier (EXPERIMENTAL!)" |
|
406 |
K.prf_asm_goal |
|
407 |
(Scan.optional |
|
408 |
(P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment) |
|
409 |
--| P.$$$ "in") [] -- |
|
410 |
P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment) |
|
411 |
>> (Toplevel.print oo (Toplevel.proof o IsarThy.obtain))); |
|
412 |
||
413 |
||
6742 | 414 |
(* proof navigation *) |
5944 | 415 |
|
5832 | 416 |
val backP = |
6723 | 417 |
OuterSyntax.improper_command "back" "backtracking of proof command" K.prf_script |
7368 | 418 |
(Scan.optional (P.$$$ "!" >> K true) false >> |
419 |
(Toplevel.print oo (Toplevel.proof o ProofHistory.back))); |
|
5832 | 420 |
|
421 |
||
6742 | 422 |
(* history *) |
423 |
||
424 |
val cannot_undoP = |
|
425 |
OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control |
|
7269 | 426 |
(P.name >> IsarCmd.cannot_undo); |
6742 | 427 |
|
428 |
val clear_undoP = |
|
429 |
OuterSyntax.improper_command "clear_undo" "clear undo information" K.control |
|
7269 | 430 |
(Scan.succeed IsarCmd.clear_undo); |
6742 | 431 |
|
432 |
val redoP = |
|
433 |
OuterSyntax.improper_command "redo" "redo last command" K.control |
|
434 |
(Scan.succeed (Toplevel.print o IsarCmd.redo)); |
|
435 |
||
436 |
val undos_proofP = |
|
437 |
OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control |
|
438 |
(P.nat >> (Toplevel.print oo IsarCmd.undos_proof)); |
|
439 |
||
440 |
val kill_proofP = |
|
441 |
OuterSyntax.improper_command "kill_proof" "undo current proof" K.control |
|
7269 | 442 |
(Scan.succeed IsarCmd.kill_proof); |
6742 | 443 |
|
444 |
val undoP = |
|
445 |
OuterSyntax.improper_command "undo" "undo last command" K.control |
|
7269 | 446 |
(Scan.succeed IsarCmd.undo); |
6742 | 447 |
|
448 |
||
5832 | 449 |
|
450 |
(** diagnostic commands (for interactive mode only) **) |
|
451 |
||
7124 | 452 |
val pretty_setmarginP = |
453 |
OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing" |
|
454 |
K.diag (P.nat >> IsarCmd.pretty_setmargin); |
|
455 |
||
5832 | 456 |
val print_commandsP = |
6723 | 457 |
OuterSyntax.improper_command "help" "print outer syntax (global)" K.diag |
7368 | 458 |
(Scan.succeed OuterSyntax.print_help); |
5832 | 459 |
|
7308 | 460 |
val print_contextP = |
461 |
OuterSyntax.improper_command "print_context" "print theory context name" K.diag |
|
462 |
(Scan.succeed IsarCmd.print_context); |
|
463 |
||
5832 | 464 |
val print_theoryP = |
6723 | 465 |
OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag |
5832 | 466 |
(Scan.succeed IsarCmd.print_theory); |
467 |
||
468 |
val print_syntaxP = |
|
6723 | 469 |
OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)" K.diag |
5832 | 470 |
(Scan.succeed IsarCmd.print_syntax); |
471 |
||
5881 | 472 |
val print_theoremsP = |
6723 | 473 |
OuterSyntax.improper_command "print_theorems" "print theorems known in this theory" K.diag |
5881 | 474 |
(Scan.succeed IsarCmd.print_theorems); |
475 |
||
5832 | 476 |
val print_attributesP = |
6723 | 477 |
OuterSyntax.improper_command "print_attributes" "print attributes known in this theory" K.diag |
5832 | 478 |
(Scan.succeed IsarCmd.print_attributes); |
479 |
||
480 |
val print_methodsP = |
|
6723 | 481 |
OuterSyntax.improper_command "print_methods" "print methods known in this theory" K.diag |
5832 | 482 |
(Scan.succeed IsarCmd.print_methods); |
483 |
||
7616 | 484 |
val thms_containingP = |
485 |
OuterSyntax.improper_command "thms_containing" "print theorems containing all given constants" |
|
486 |
K.diag (Scan.repeat P.xname >> IsarCmd.print_thms_containing); |
|
487 |
||
5832 | 488 |
val print_bindsP = |
6723 | 489 |
OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag |
5832 | 490 |
(Scan.succeed IsarCmd.print_binds); |
491 |
||
492 |
val print_lthmsP = |
|
6723 | 493 |
OuterSyntax.improper_command "print_facts" "print local theorems of proof context" K.diag |
5832 | 494 |
(Scan.succeed IsarCmd.print_lthms); |
495 |
||
5896 | 496 |
val print_thmsP = |
7012 | 497 |
OuterSyntax.improper_command "thm" "print theorems" K.diag (P.xthms1 >> IsarCmd.print_thms); |
5832 | 498 |
|
499 |
val print_propP = |
|
6723 | 500 |
OuterSyntax.improper_command "prop" "read and print proposition" K.diag |
501 |
(P.term >> IsarCmd.print_prop); |
|
5832 | 502 |
|
503 |
val print_termP = |
|
6723 | 504 |
OuterSyntax.improper_command "term" "read and print term" K.diag |
505 |
(P.term >> IsarCmd.print_term); |
|
5832 | 506 |
|
507 |
val print_typeP = |
|
6723 | 508 |
OuterSyntax.improper_command "typ" "read and print type" K.diag |
509 |
(P.typ >> IsarCmd.print_type); |
|
5832 | 510 |
|
511 |
||
512 |
||
513 |
(** system commands (for interactive mode only) **) |
|
514 |
||
515 |
val cdP = |
|
6723 | 516 |
OuterSyntax.improper_command "cd" "change current working directory" K.control |
517 |
(P.name >> IsarCmd.cd); |
|
5832 | 518 |
|
519 |
val pwdP = |
|
6723 | 520 |
OuterSyntax.improper_command "pwd" "print current working directory" K.diag |
5832 | 521 |
(Scan.succeed IsarCmd.pwd); |
522 |
||
523 |
val use_thyP = |
|
6723 | 524 |
OuterSyntax.improper_command "use_thy" "use theory file" K.diag |
525 |
(P.name >> IsarCmd.use_thy); |
|
5832 | 526 |
|
6694 | 527 |
val use_thy_onlyP = |
7102 | 528 |
OuterSyntax.improper_command "use_thy_only" "use theory file only, ignoring associated ML" |
529 |
K.diag (P.name >> IsarCmd.use_thy_only); |
|
6694 | 530 |
|
6196 | 531 |
val update_thyP = |
6723 | 532 |
OuterSyntax.improper_command "update_thy" "update theory file" K.diag |
533 |
(P.name >> IsarCmd.update_thy); |
|
5832 | 534 |
|
7102 | 535 |
val update_thy_onlyP = |
536 |
OuterSyntax.improper_command "update_thy_only" "update theory file, ignoring associated ML" |
|
537 |
K.diag (P.name >> IsarCmd.update_thy); |
|
538 |
||
539 |
val touch_thyP = |
|
540 |
OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag |
|
541 |
(P.name >> IsarCmd.touch_thy); |
|
542 |
||
543 |
val touch_all_thysP = |
|
544 |
OuterSyntax.improper_command "touch_all_thys" "outdate all non-finished theories" K.diag |
|
545 |
(Scan.succeed IsarCmd.touch_all_thys); |
|
546 |
||
547 |
val remove_thyP = |
|
548 |
OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag |
|
549 |
(P.name >> IsarCmd.remove_thy); |
|
550 |
||
5832 | 551 |
val prP = |
6723 | 552 |
OuterSyntax.improper_command "pr" "print current toplevel state" K.diag |
7199 | 553 |
(Scan.succeed (Toplevel.print o Toplevel.imperative (fn () => Toplevel.quiet := false))); |
554 |
||
7222 | 555 |
val disable_prP = |
556 |
OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag |
|
7199 | 557 |
(Scan.succeed (Toplevel.imperative (fn () => Toplevel.quiet := true))); |
5832 | 558 |
|
7222 | 559 |
val enable_prP = |
560 |
OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag |
|
561 |
(Scan.succeed (Toplevel.imperative (fn () => Toplevel.quiet := false))); |
|
562 |
||
5832 | 563 |
|
6723 | 564 |
val opt_unit = Scan.optional (P.$$$ "(" -- P.$$$ ")" >> (K ())) (); |
5832 | 565 |
|
566 |
val commitP = |
|
6723 | 567 |
OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag |
5832 | 568 |
(opt_unit >> (K IsarCmd.use_commit)); |
569 |
||
570 |
val quitP = |
|
6723 | 571 |
OuterSyntax.improper_command "quit" "quit Isabelle" K.control |
5832 | 572 |
(opt_unit >> (K IsarCmd.quit)); |
573 |
||
574 |
val exitP = |
|
6723 | 575 |
OuterSyntax.improper_command "exit" "exit Isar loop" K.control |
5832 | 576 |
(Scan.succeed IsarCmd.exit); |
577 |
||
7102 | 578 |
val init_toplevelP = |
579 |
OuterSyntax.improper_command "init_toplevel" "restart Isar toplevel loop" K.control |
|
580 |
(Scan.succeed IsarCmd.init_toplevel); |
|
5991 | 581 |
|
7462 | 582 |
val welcomeP = |
583 |
OuterSyntax.improper_command "welcome" "print welcome message" K.control |
|
584 |
(Scan.succeed IsarCmd.welcome); |
|
585 |
||
5832 | 586 |
|
587 |
||
588 |
(** the Pure outer syntax **) |
|
589 |
||
590 |
(*keep keywords consistent with the parsers, including those in |
|
591 |
outer_parse.ML, otherwise be prepared for unexpected errors*) |
|
592 |
||
593 |
val keywords = |
|
7415 | 594 |
["!", "!!", "%", "%%", "(", ")", "+", ",", "--", ":", "::", ";", "<", |
595 |
"<=", "=", "==", "=>", "?", "[", "]", "and", "as", "binder", |
|
7678 | 596 |
"concl", "files", "in", "infixl", "infixr", "is", "output", "{", |
597 |
"|", "}"]; |
|
5832 | 598 |
|
599 |
val parsers = [ |
|
600 |
(*theory structure*) |
|
7102 | 601 |
theoryP, end_excursionP, kill_excursionP, contextP, |
7172 | 602 |
(*formal comments*) |
603 |
titleP, chapterP, sectionP, subsectionP, subsubsectionP, textP, |
|
604 |
sectP, subsectP, subsubsectP, txtP, |
|
5832 | 605 |
(*theory sections*) |
7172 | 606 |
classesP, classrelP, defaultsortP, typedeclP, typeabbrP, nontermP, |
607 |
aritiesP, constsP, syntaxP, translationsP, axiomsP, defsP, |
|
7616 | 608 |
constdefsP, theoremsP, lemmasP, globalP, localP, useP, mlP, |
609 |
ml_setupP, setupP, parse_ast_translationP, parse_translationP, |
|
610 |
print_translationP, typed_print_translationP, |
|
611 |
print_ast_translationP, token_translationP, oracleP, |
|
5832 | 612 |
(*proof commands*) |
6850 | 613 |
theoremP, lemmaP, showP, haveP, thusP, henceP, assumeP, presumeP, |
6953 | 614 |
defP, fixP, letP, thenP, thenceP, fromP, withP, noteP, beginP, endP, |
615 |
nextP, qedP, terminal_proofP, immediate_proofP, default_proofP, |
|
7678 | 616 |
skip_proofP, applyP, then_applyP, proofP, alsoP, finallyP, obtainP, |
617 |
backP, cannot_undoP, clear_undoP, redoP, undos_proofP, kill_proofP, undoP, |
|
5832 | 618 |
(*diagnostic commands*) |
7308 | 619 |
pretty_setmarginP, print_commandsP, print_contextP, print_theoryP, |
7616 | 620 |
print_syntaxP, print_theoremsP, print_attributesP, print_methodsP, |
621 |
thms_containingP, print_bindsP, print_lthmsP, print_thmsP, |
|
622 |
print_propP, print_termP, print_typeP, |
|
5832 | 623 |
(*system commands*) |
7102 | 624 |
cdP, pwdP, use_thyP, use_thy_onlyP, update_thyP, update_thy_onlyP, |
7222 | 625 |
touch_thyP, touch_all_thysP, remove_thyP, prP, disable_prP, |
7462 | 626 |
enable_prP, commitP, quitP, exitP, init_toplevelP, welcomeP]; |
5832 | 627 |
|
628 |
||
629 |
end; |
|
630 |
||
631 |
||
6196 | 632 |
(*install the Pure outer syntax*) |
5832 | 633 |
OuterSyntax.add_keywords IsarSyn.keywords; |
634 |
OuterSyntax.add_parsers IsarSyn.parsers; |