23
|
1 |
theory Base
|
264
|
2 |
imports Main LaTeXsugar
|
23
|
3 |
uses
|
346
|
4 |
("output_tutorial.ML")
|
|
5 |
("antiquote_setup.ML")
|
23
|
6 |
begin
|
|
7 |
|
317
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
8 |
(* rebinding of writeln and tracing so that it can *)
|
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
9 |
(* be compared in intiquotations *)
|
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
10 |
ML {*
|
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
11 |
fun writeln s = (Output.writeln s; s)
|
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
12 |
fun tracing s = (Output.tracing s; s)
|
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
13 |
*}
|
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
14 |
|
346
|
15 |
(* re-definition of various ML antiquotations *)
|
|
16 |
(* to have a special tag for text enclosed in ML; *)
|
|
17 |
(* they also write the code into a separate file *)
|
301
|
18 |
|
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
19 |
ML {*
|
346
|
20 |
val (filename, setup_filename) = Attrib.config_string "filename" "File_Code.ML"
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
21 |
*}
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
22 |
|
346
|
23 |
setup {* setup_filename *}
|
|
24 |
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
25 |
ML {*
|
346
|
26 |
fun write_file txt thy =
|
|
27 |
let
|
|
28 |
val stream = Config.get_thy thy filename
|
|
29 |
|> TextIO.openAppend
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
30 |
in
|
346
|
31 |
TextIO.output (stream, txt);
|
|
32 |
TextIO.flushOut stream; (* needed ?*)
|
|
33 |
TextIO.closeOut stream
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
34 |
end
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
35 |
*}
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
36 |
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
37 |
ML {*
|
346
|
38 |
fun write_file_ml_blk txt thy =
|
|
39 |
let
|
|
40 |
val pre = implode ["\n", "ML ", "{", "*", "\n"]
|
|
41 |
val post = implode ["\n", "*", "}", "\n"]
|
|
42 |
val _ = write_file (enclose pre post txt) thy
|
|
43 |
in
|
|
44 |
thy
|
|
45 |
end
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
46 |
|
346
|
47 |
fun write_file_setup_blk txt thy =
|
|
48 |
let
|
|
49 |
val pre = implode ["\n", "setup ", "{", "*", "\n"]
|
|
50 |
val post = implode ["\n", "*", "}", "\n"]
|
|
51 |
val _ = write_file (enclose pre post txt) thy
|
|
52 |
in
|
|
53 |
thy
|
|
54 |
end
|
|
55 |
|
|
56 |
fun write_file_lsetup_blk txt lthy =
|
|
57 |
let
|
|
58 |
val pre = implode ["\n", "local_setup ", "{", "*", "\n"]
|
|
59 |
val post = implode ["\n", "*", "}", "\n"]
|
|
60 |
val _ = write_file (enclose pre post txt) (ProofContext.theory_of lthy)
|
|
61 |
in
|
|
62 |
lthy
|
|
63 |
end
|
|
64 |
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
65 |
*}
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
66 |
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
67 |
ML {*
|
346
|
68 |
fun open_file name thy =
|
|
69 |
let
|
|
70 |
val _ = tracing ("Open File: " ^ name)
|
|
71 |
val _ = TextIO.openOut name
|
|
72 |
in
|
|
73 |
Config.put_thy filename name thy
|
|
74 |
end
|
|
75 |
*}
|
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
76 |
|
346
|
77 |
ML {*
|
|
78 |
fun open_file_with_prelude name txts thy =
|
|
79 |
let
|
|
80 |
val thy' = open_file name thy
|
|
81 |
val _ = write_file (cat_lines txts) thy'
|
|
82 |
in
|
|
83 |
thy'
|
|
84 |
end
|
|
85 |
*}
|
|
86 |
|
|
87 |
ML {*
|
260
|
88 |
fun propagate_env (context as Context.Proof lthy) =
|
|
89 |
Context.Proof (LocalTheory.map_contexts (ML_Env.inherit context) lthy)
|
264
|
90 |
| propagate_env context = context
|
210
|
91 |
|
260
|
92 |
fun propagate_env_prf prf = Proof.map_contexts
|
264
|
93 |
(Context.proof_map (ML_Env.inherit (Context.Proof (Proof.context_of prf)))) prf
|
346
|
94 |
*}
|
210
|
95 |
|
346
|
96 |
ML {*
|
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
97 |
val _ =
|
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
98 |
OuterSyntax.command "ML" "eval ML text within theory"
|
106
bdd82350cf22
renamed in the pdf all instances of cookbook to tutorial (in order to sound more serious)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
99 |
(OuterKeyword.tag "TutorialML" OuterKeyword.thy_decl)
|
346
|
100 |
(OuterParse.position OuterParse.text >>
|
|
101 |
(fn (txt, pos) =>
|
|
102 |
Toplevel.generic_theory
|
|
103 |
(ML_Context.exec
|
|
104 |
(fn () => ML_Context.eval true pos txt)
|
|
105 |
#> propagate_env #> Context.map_theory (write_file_ml_blk txt))))
|
210
|
106 |
|
|
107 |
val _ =
|
|
108 |
OuterSyntax.command "ML_prf" "ML text within proof"
|
|
109 |
(OuterKeyword.tag "TutorialML" OuterKeyword.prf_decl)
|
|
110 |
(OuterParse.ML_source >> (fn (txt, pos) =>
|
|
111 |
Toplevel.proof (Proof.map_context (Context.proof_map
|
260
|
112 |
(ML_Context.exec (fn () => ML_Context.eval true pos txt))) #> propagate_env_prf)))
|
210
|
113 |
|
224
|
114 |
val _ =
|
|
115 |
OuterSyntax.command "ML_val" "diagnostic ML text"
|
|
116 |
(OuterKeyword.tag "TutorialML" OuterKeyword.diag)
|
264
|
117 |
(OuterParse.ML_source >> IsarCmd.ml_diag true)
|
346
|
118 |
*}
|
224
|
119 |
|
346
|
120 |
ML {*
|
|
121 |
val _ =
|
|
122 |
OuterSyntax.command "setup" "ML theory setup"
|
|
123 |
(OuterKeyword.tag_ml OuterKeyword.thy_decl)
|
|
124 |
(OuterParse.ML_source >> (fn (txt, pos) =>
|
|
125 |
(Toplevel.theory (IsarCmd.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>
diff
changeset
|
126 |
*}
|
239
|
127 |
|
346
|
128 |
ML {* Context.proof_map *}
|
|
129 |
ML {* IsarCmd.local_setup ; Context.map_proof (write_file_lsetup_blk "") *}
|
|
130 |
|
|
131 |
|
|
132 |
ML {*
|
|
133 |
val _ =
|
|
134 |
OuterSyntax.local_theory "local_setup" "ML local theory setup"
|
|
135 |
(OuterKeyword.tag_ml OuterKeyword.thy_decl)
|
|
136 |
(OuterParse.ML_source >> (fn (txt, pos) =>
|
|
137 |
IsarCmd.local_setup (txt, pos) #> write_file_lsetup_blk txt));
|
|
138 |
*}
|
|
139 |
|
|
140 |
|
|
141 |
use "output_tutorial.ML"
|
|
142 |
use "antiquote_setup.ML"
|
|
143 |
|
|
144 |
|
239
|
145 |
end |