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