author | Christian Urban <urbanc@in.tum.de> |
Mon, 30 Apr 2012 12:33:17 +0100 | |
changeset 515 | 4b105b97069c |
parent 514 | 7e25716c3744 |
child 517 | d8c376662bb4 |
permissions | -rw-r--r-- |
23 | 1 |
theory Base |
459 | 2 |
imports Main |
3 |
"~~/src/HOL/Library/LaTeXsugar" |
|
514
7e25716c3744
updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents:
488
diff
changeset
|
4 |
keywords "ML" "setup" "local_setup" :: thy_decl and |
7e25716c3744
updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents:
488
diff
changeset
|
5 |
"ML_prf" :: prf_decl and |
7e25716c3744
updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents:
488
diff
changeset
|
6 |
"ML_val" :: diag |
23 | 7 |
uses |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
8 |
("output_tutorial.ML") |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
9 |
("antiquote_setup.ML") |
23 | 10 |
begin |
11 |
||
394 | 12 |
notation (latex output) |
13 |
Cons ("_ # _" [66,65] 65) |
|
14 |
||
317
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents:
316
diff
changeset
|
15 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
16 |
(* re-definition of various ML antiquotations *) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
17 |
(* to have a special tag for text enclosed in ML; *) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
18 |
(* they also write the code into a separate file *) |
301
2728e8daebc0
replaced "writeln" with "tracing"
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
19 |
|
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
20 |
ML {* |
462 | 21 |
val filename = Attrib.setup_config_string @{binding "filename"} (K "File_Code.ML") |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
22 |
*} |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
23 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
24 |
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
25 |
ML {* |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
26 |
fun write_file txt thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
27 |
let |
423 | 28 |
val stream = Config.get_global thy filename |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
29 |
|> TextIO.openAppend |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
30 |
in |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
31 |
TextIO.output (stream, txt); |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
32 |
TextIO.flushOut stream; (* needed ?*) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
33 |
TextIO.closeOut stream |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
34 |
end |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
35 |
*} |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
36 |
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
37 |
ML {* |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
38 |
fun write_file_ml_blk txt thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
39 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
40 |
val pre = implode ["\n", "ML ", "{", "*", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
41 |
val post = implode ["\n", "*", "}", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
42 |
val _ = write_file (enclose pre post txt) thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
43 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
44 |
thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
45 |
end |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
46 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
47 |
fun write_file_setup_blk txt thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
48 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
49 |
val pre = implode ["\n", "setup ", "{", "*", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
50 |
val post = implode ["\n", "*", "}", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
51 |
val _ = write_file (enclose pre post txt) thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
52 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
53 |
thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
54 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
55 |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
56 |
fun write_file_lsetup_blk txt lthy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
57 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
58 |
val pre = implode ["\n", "local_setup ", "{", "*", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
59 |
val post = implode ["\n", "*", "}", "\n"] |
475
25371f74c768
updated to post-2011-1 Isabelle
Christian Urban <urbanc@in.tum.de>
parents:
471
diff
changeset
|
60 |
val _ = write_file (enclose pre post txt) (Proof_Context.theory_of lthy) |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
61 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
62 |
lthy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
63 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
64 |
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
65 |
*} |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
66 |
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
67 |
ML {* |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
68 |
fun open_file name thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
69 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
70 |
val _ = tracing ("Open File: " ^ name) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
71 |
val _ = TextIO.openOut name |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
72 |
in |
423 | 73 |
Config.put_global filename name thy |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
74 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
75 |
*} |
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
76 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
77 |
ML {* |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
78 |
fun open_file_with_prelude name txts thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
79 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
80 |
val thy' = open_file name thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
81 |
val _ = write_file (cat_lines txts) thy' |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
82 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
83 |
thy' |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
84 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
85 |
*} |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
86 |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
87 |
ML {* |
515
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
88 |
val _ = |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
89 |
Outer_Syntax.command ("ML", Keyword.tag "TutorialML" Keyword.thy_decl) |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
90 |
"ML text within theory or local theory" |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
91 |
(Parse.ML_source >> (fn (txt, pos) => |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
92 |
Toplevel.generic_theory |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
93 |
(ML_Context.exec (fn () => ML_Context.eval_text true pos txt) #> |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
94 |
Local_Theory.propagate_ml_env #> Context.map_theory (write_file_ml_blk txt)))) |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
95 |
*} |
210
db8e302f44c8
more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
96 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
97 |
ML {* |
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
98 |
val _ = |
515
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
99 |
Outer_Syntax.command ("ML_prf", Keyword.tag "TutorialMLprf" Keyword.prf_decl) "ML text within proof" |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
100 |
(Parse.ML_source >> (fn (txt, pos) => |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
101 |
Toplevel.proof (Proof.map_context (Context.proof_map |
4b105b97069c
updated to forthcoming Isabelle 2012
Christian Urban <urbanc@in.tum.de>
parents:
514
diff
changeset
|
102 |
(ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> Proof.propagate_ml_env))); |
438 | 103 |
*} |
488 | 104 |
|
210
db8e302f44c8
more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
105 |
|
438 | 106 |
ML {* |
224
647cab4a72c2
finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents:
210
diff
changeset
|
107 |
val _ = |
514
7e25716c3744
updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents:
488
diff
changeset
|
108 |
Outer_Syntax.command ("ML_val", Keyword.tag "TutorialML" Keyword.diag) "diagnostic ML text" |
438 | 109 |
(Parse.ML_source >> Isar_Cmd.ml_diag true) |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
110 |
*} |
224
647cab4a72c2
finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents:
210
diff
changeset
|
111 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
112 |
ML {* |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
113 |
val _ = |
514
7e25716c3744
updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents:
488
diff
changeset
|
114 |
Outer_Syntax.command ("setup", Keyword.tag_ml Keyword.thy_decl) "ML theory setup" |
426 | 115 |
(Parse.ML_source >> (fn (txt, pos) => |
438 | 116 |
(Toplevel.theory (Isar_Cmd.global_setup (txt, pos) #> write_file_setup_blk txt)))) |
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
117 |
*} |
239
b63c72776f03
replaced "warning" with "writeln"
Christian Urban <urbanc@in.tum.de>
parents:
224
diff
changeset
|
118 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
119 |
ML {* |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
120 |
val _ = |
514
7e25716c3744
updated to outer syntax / parser changes
Christian Urban <urbanc@in.tum.de>
parents:
488
diff
changeset
|
121 |
Outer_Syntax.local_theory ("local_setup", Keyword.tag_ml Keyword.thy_decl) "ML local theory setup" |
426 | 122 |
(Parse.ML_source >> (fn (txt, pos) => |
438 | 123 |
Isar_Cmd.local_setup (txt, pos) #> write_file_lsetup_blk txt)); |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
124 |
*} |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
125 |
|
396 | 126 |
ML {* |
127 |
fun P n = @{term "P::nat \<Rightarrow> bool"} $ (HOLogic.mk_number @{typ "nat"} n) |
|
128 |
||
129 |
fun rhs 1 = P 1 |
|
130 |
| rhs n = HOLogic.mk_conj (P n, rhs (n - 1)) |
|
131 |
||
132 |
fun lhs 1 n = HOLogic.mk_imp (HOLogic.mk_eq (P 1, P n), rhs n) |
|
133 |
| lhs m n = HOLogic.mk_conj (HOLogic.mk_imp |
|
134 |
(HOLogic.mk_eq (P (m - 1), P m), rhs n), lhs (m - 1) n) |
|
135 |
||
136 |
fun de_bruijn n = |
|
137 |
HOLogic.mk_Trueprop (HOLogic.mk_imp (lhs n n, rhs n)) |
|
138 |
*} |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
139 |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
140 |
use "output_tutorial.ML" |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
141 |
use "antiquote_setup.ML" |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
142 |
|
471 | 143 |
setup {* OutputTutorial.setup *} |
144 |
setup {* AntiquoteSetup.setup *} |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
145 |
|
239
b63c72776f03
replaced "warning" with "writeln"
Christian Urban <urbanc@in.tum.de>
parents:
224
diff
changeset
|
146 |
end |