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