author | Christian Urban <urbanc@in.tum.de> |
Thu, 23 May 2019 00:58:11 +0100 | |
changeset 577 | d1523393dd5a |
parent 574 | 034150db9d91 |
permissions | -rw-r--r-- |
106
bdd82350cf22
renamed in the pdf all instances of cookbook to tutorial (in order to sound more serious)
Christian Urban <urbanc@in.tum.de>
parents:
103
diff
changeset
|
1 |
(* Auxiliary antiquotations for the tutorial. *) |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
|
256
1fb8d62c88a0
added some first index-information
Christian Urban <urbanc@in.tum.de>
parents:
255
diff
changeset
|
3 |
structure AntiquoteSetup = |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
struct |
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
|
256
1fb8d62c88a0
added some first index-information
Christian Urban <urbanc@in.tum.de>
parents:
255
diff
changeset
|
6 |
open OutputTutorial |
1fb8d62c88a0
added some first index-information
Christian Urban <urbanc@in.tum.de>
parents:
255
diff
changeset
|
7 |
|
112 | 8 |
(* functions for generating appropriate expressions *) |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
9 |
fun translate_string f str = |
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
10 |
implode (map f (Symbol.explode str)) |
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
11 |
|
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
12 |
fun prefix_lines prfx txt = |
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
13 |
map (fn s => prfx ^ s) (split_lines txt) |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
|
572
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
15 |
fun is_sep "\<dots>" = true |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
16 |
| is_sep s = Symbol.is_ascii_blank s; |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
17 |
|
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
18 |
fun scan_word sep = |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
19 |
Scan.many1 sep >> K NONE || |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
20 |
Scan.many1 (fn s => not (sep s) andalso Symbol.not_eof s) >> (SOME o implode); |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
21 |
|
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
22 |
fun split_words sep = Symbol.scanner "Bad text" (Scan.repeat (scan_word sep) >> map_filter I); |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
23 |
|
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
24 |
fun explode_words sep = split_words sep o Symbol.explode; |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
25 |
|
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
26 |
fun match_string sep pat str = |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
27 |
let |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
28 |
fun match [] _ = true |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
29 |
| match (p :: ps) s = |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
30 |
size p <= size s andalso |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
31 |
(case try (unprefix p) s of |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
32 |
SOME s' => match ps s' |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
33 |
| NONE => match (p :: ps) (String.substring (s, 1, size s - 1))); |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
34 |
in match (explode_words sep pat) str end; |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
35 |
|
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
36 |
fun ml_with_vars' ys txt = |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
37 |
implode ["fn ", (case ys of [] => "_" | _ => enclose "(" ")" (commas ys)), " => (", txt, ")"] |
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
38 |
|
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
39 |
fun ml_with_vars ys src = |
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
40 |
ML_Lex.read "fn " @ ML_Lex.read (case ys of [] => "_" | _ => enclose "(" ")" (commas ys)) @ |
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
41 |
ML_Lex.read " => (" @ src @ ML_Lex.read ")" |
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
42 |
|
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
43 |
fun ml_with_struct (NONE) src = ML_Lex.read_source src |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
44 |
| ml_with_struct (SOME st) src = |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
45 |
ML_Lex.read ("let open " ^ st ^ " in ") @ ML_Lex.read_source src @ ML_Lex.read " end" |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
46 |
|
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
47 |
fun ml_val vs stru txt = |
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
48 |
txt |> ml_with_struct stru |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
49 |
|> ml_with_vars vs |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
|
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
51 |
fun ml_pat pat lhs = |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
52 |
ML_Lex.read "val " @ ML_Lex.read_source pat @ |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
53 |
ML_Lex.read " = " @ |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
54 |
ML_Lex.read_source lhs |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
|
566
6103b0eadbf2
tuned parser for patterns in ML_response... antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
564
diff
changeset
|
56 |
|
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
57 |
fun ml_struct src = |
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
58 |
ML_Lex.read "functor DUMMY_FUNCTOR() = struct structure DUMMY = " @ |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
59 |
ML_Lex.read_source src @ |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
60 |
ML_Lex.read " end" |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
61 |
|
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
62 |
fun ml_type src = |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
63 |
ML_Lex.read "val _ = NONE : (" @ ML_Lex.read_source src @ ML_Lex.read ") option" |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
|
112 | 65 |
(* eval function *) |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
66 |
fun eval_fn ctxt prep exp = |
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
67 |
ML_Context.eval_in (SOME ctxt) ML_Compiler.flags (Input.pos_of exp) (prep exp) |
57
065f472c09ab
Repaired output of marginal comments in ML antiquotation.
berghofe
parents:
54
diff
changeset
|
68 |
|
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
69 |
(* Evalate expression and convert result to a string *) |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
70 |
fun eval_response ctxt exp = |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
71 |
let |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
72 |
fun compute exp = |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
73 |
let |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
74 |
val input = ML_Lex.read "(let val r = " @ ML_Lex.read_source exp @ |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
75 |
ML_Lex.read " in (raise ERROR (@{make_string} r); ()) end )" |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
76 |
val _ = ML_Context.eval_in (SOME ctxt) ML_Compiler.flags (Input.pos_of exp) input |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
77 |
in "" |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
78 |
end |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
79 |
in |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
80 |
(compute exp |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
81 |
handle ERROR s => s) |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
82 |
end |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
83 |
|
315
de49d5780f57
simplified a bit the index generation
Christian Urban <urbanc@in.tum.de>
parents:
311
diff
changeset
|
84 |
(* checks and prints a possibly open expressions, no index *) |
de49d5780f57
simplified a bit the index generation
Christian Urban <urbanc@in.tum.de>
parents:
311
diff
changeset
|
85 |
|
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
86 |
fun output_ml ctxt (src, (vs, stru)) = |
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
87 |
(eval_fn ctxt (ml_val vs stru) src; |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
88 |
output ctxt (split_lines (fst (Input.source_content src)))) |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
89 |
|
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
90 |
val parser_ml = Scan.lift (Args.text_input -- |
426 | 91 |
(Scan.optional (Args.$$$ "for" |-- Parse.!!! (Scan.repeat1 Args.name)) [] -- |
92 |
Scan.option (Args.$$$ "in" |-- Parse.!!! Args.name))) |
|
315
de49d5780f57
simplified a bit the index generation
Christian Urban <urbanc@in.tum.de>
parents:
311
diff
changeset
|
93 |
|
572
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
94 |
fun output_ml_response ignore_pat ctxt (src, opat) = |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
95 |
let |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
96 |
val res = eval_response ctxt src |
572
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
97 |
val _ = writeln res |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
98 |
val cnt = YXML.content_of res |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
99 |
val pat = case opat of NONE => cnt |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
100 |
| SOME p => p |> fst o Input.source_content |
572
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
101 |
val _ = if ignore_pat orelse Print_Mode.print_mode_active Latex.latexN orelse match_string is_sep pat cnt then () |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
102 |
else error (cat_lines ["Substring:", pat, "not contained in:", cnt]) |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
103 |
val out = if ignore_pat then cnt else pat |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
104 |
in |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
105 |
OutputTutorial.output ctxt ([fst (Input.source_content src)] @ [Library.prefix_lines "> " out]) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
106 |
end |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
107 |
|
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
108 |
(* checks and prints a single ML-item and produces an index entry *) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
109 |
fun output_ml_ind ctxt (src, stru) = |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
110 |
let |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
111 |
val (txt,_) = Input.source_content src |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
112 |
in |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
113 |
(eval_fn ctxt (ml_val [] stru) src; |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
114 |
case (stru, Long_Name.base_name txt, Long_Name.qualifier txt) of |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
115 |
(NONE, _, "") => output_indexed ctxt {main = Code txt, minor = NoString} (split_lines txt) |
449 | 116 |
| (NONE, bn, qn) => output_indexed ctxt {main = Code bn, minor = Struct qn} (split_lines txt) |
117 |
| (SOME st, _, _) => output_indexed ctxt {main = Code txt, minor = Struct st} (split_lines txt)) |
|
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
118 |
end |
112 | 119 |
|
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
120 |
val parser_ml_ind = Scan.lift (Args.text_input -- |
426 | 121 |
Scan.option (Args.$$$ "in" |-- Parse.!!! Args.name)) |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
122 |
|
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
123 |
(* checks and prints structures *) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
124 |
fun gen_output_struct outfn ctxt src = |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
125 |
let |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
126 |
val (txt, _) = Input.source_content src |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
127 |
in |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
128 |
(eval_fn ctxt ml_struct src; |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
129 |
outfn {main = Code txt, minor = Plain "structure"} (split_lines txt)) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
130 |
end |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
131 |
|
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
132 |
fun output_struct ctxt = gen_output_struct (K (output ctxt)) ctxt |
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
133 |
fun output_struct_ind ctxt = gen_output_struct (output_indexed ctxt) ctxt |
256
1fb8d62c88a0
added some first index-information
Christian Urban <urbanc@in.tum.de>
parents:
255
diff
changeset
|
134 |
|
328
c0cae24b9d46
updated to new Isabelle; more work on the data section
Christian Urban <urbanc@in.tum.de>
parents:
317
diff
changeset
|
135 |
(* prints functors; no checks *) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
136 |
fun gen_output_funct outfn src = |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
137 |
let |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
138 |
val (txt, _) = Input.source_content src |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
139 |
in |
328
c0cae24b9d46
updated to new Isabelle; more work on the data section
Christian Urban <urbanc@in.tum.de>
parents:
317
diff
changeset
|
140 |
(outfn {main = Code txt, minor = Plain "functor"} (split_lines txt)) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
141 |
end |
328
c0cae24b9d46
updated to new Isabelle; more work on the data section
Christian Urban <urbanc@in.tum.de>
parents:
317
diff
changeset
|
142 |
|
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
143 |
fun output_funct ctxt = gen_output_funct (K (output ctxt)) |
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
144 |
fun output_funct_ind ctxt = gen_output_funct (output_indexed ctxt) |
328
c0cae24b9d46
updated to new Isabelle; more work on the data section
Christian Urban <urbanc@in.tum.de>
parents:
317
diff
changeset
|
145 |
|
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
146 |
(* checks and prints types *) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
147 |
fun gen_output_type outfn ctxt src = |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
148 |
let |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
149 |
val (txt, _) = Input.source_content src |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
150 |
in |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
151 |
(eval_fn ctxt ml_type src; |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
152 |
outfn {main = Code txt, minor = Plain "type"} (split_lines txt)) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
153 |
end |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
154 |
|
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
155 |
fun output_type ctxt = gen_output_type (K (output ctxt)) ctxt |
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
156 |
fun output_type_ind ctxt = gen_output_type (output_indexed ctxt) ctxt |
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
|
566
6103b0eadbf2
tuned parser for patterns in ML_response... antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
564
diff
changeset
|
158 |
val dots_pat = translate_string (fn "_" => "\<dots>" | s => s) |
6103b0eadbf2
tuned parser for patterns in ML_response... antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
564
diff
changeset
|
159 |
|
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
160 |
(* checks and expression against a result pattern *) |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
161 |
fun output_response ctxt (lhs, pat) = |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
162 |
(eval_fn ctxt (ml_pat pat) lhs; |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
163 |
output ctxt ((prefix_lines "" (fst (Input.source_content lhs))) @ |
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
164 |
(prefix_lines "> " (dots_pat (fst (Input.source_content pat)))))) |
171
18f90044c777
simplified antiquotations
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
165 |
|
18f90044c777
simplified antiquotations
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
166 |
(* checks the expressions, but does not check it against a result pattern *) |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
167 |
fun output_response_fake ctxt (lhs, pat) = |
564
6e2479089226
tuned parsing in document antiquotations for ML
Norbert Schirmer <norbert.schirmer@web.de>
parents:
562
diff
changeset
|
168 |
(eval_fn ctxt (ml_val [] NONE) lhs; |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
169 |
output ctxt ( (split_lines (fst (Input.source_content lhs))) @ |
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
170 |
(prefix_lines "> " (dots_pat (fst (Input.source_content pat)))))) |
112 | 171 |
|
172 |
(* checks the expressions, but does not check it against a result pattern *) |
|
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
173 |
fun ouput_response_fake_both ctxt (lhs, pat) = |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
174 |
(output ctxt ((split_lines (fst (Input.source_content lhs))) @ |
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
175 |
(prefix_lines "> " (dots_pat (fst ((Input.source_content pat))))))) |
171
18f90044c777
simplified antiquotations
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
176 |
|
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
177 |
val single_arg = Scan.lift (Args.text_input) |
566
6103b0eadbf2
tuned parser for patterns in ML_response... antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
564
diff
changeset
|
178 |
val two_args = Scan.lift (Args.text_input -- Args.text_input) |
572
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
179 |
val maybe_two_args = Scan.lift (Args.text_input -- Scan.option Args.text_input) |
317
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents:
316
diff
changeset
|
180 |
val test = Scan.lift (Args.name -- Args.name -- Scan.option (Args.$$$ "with" |-- Args.name)) |
112 | 181 |
|
471 | 182 |
val ml_setup = |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
183 |
Thy_Output.antiquotation_raw @{binding "ML"} parser_ml output_ml |
572
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
184 |
#> Thy_Output.antiquotation_raw @{binding "ML_response"} maybe_two_args (output_ml_response false) |
438703674711
prefer more result checking in ML antiquotations
Norbert Schirmer <norbert.schirmer@web.de>
parents:
567
diff
changeset
|
185 |
#> Thy_Output.antiquotation_raw @{binding "ML_response_ignore"} maybe_two_args (output_ml_response true) |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
186 |
#> Thy_Output.antiquotation_raw @{binding "ML_ind"} parser_ml_ind output_ml_ind |
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
187 |
#> Thy_Output.antiquotation_raw @{binding "ML_type_ind"} single_arg output_type_ind |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
188 |
#> Thy_Output.antiquotation_raw @{binding "ML_structure_ind"} single_arg output_struct_ind |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
189 |
#> Thy_Output.antiquotation_raw @{binding "ML_functor_ind"} single_arg output_funct_ind |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
190 |
#> Thy_Output.antiquotation_raw @{binding "ML_matchresult"} two_args output_response |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
191 |
#> Thy_Output.antiquotation_raw @{binding "ML_matchresult_fake"} two_args output_response_fake |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
192 |
#> Thy_Output.antiquotation_raw @{binding "ML_matchresult_fake_both"} two_args ouput_response_fake_both |
54
1783211b3494
tuned; added document antiquotation ML_response_fake_both
Christian Urban <urbanc@in.tum.de>
parents:
53
diff
changeset
|
193 |
|
317
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents:
316
diff
changeset
|
194 |
(* checks whether a file exists in the Isabelle distribution *) |
182
4d0e2edd476d
added hyperlinks for every file pointer
Christian Urban <urbanc@in.tum.de>
parents:
171
diff
changeset
|
195 |
fun href_link txt = |
4d0e2edd476d
added hyperlinks for every file pointer
Christian Urban <urbanc@in.tum.de>
parents:
171
diff
changeset
|
196 |
let |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
197 |
val raw = I (* FIXME: Symbol.encode_raw *) |
182
4d0e2edd476d
added hyperlinks for every file pointer
Christian Urban <urbanc@in.tum.de>
parents:
171
diff
changeset
|
198 |
val path = "http://isabelle.in.tum.de/repos/isabelle/raw-file/tip/src/" |
4d0e2edd476d
added hyperlinks for every file pointer
Christian Urban <urbanc@in.tum.de>
parents:
171
diff
changeset
|
199 |
in |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
200 |
implode [raw "\\href{", raw path, raw txt, raw "}{", get_word txt, raw "}"] |
182
4d0e2edd476d
added hyperlinks for every file pointer
Christian Urban <urbanc@in.tum.de>
parents:
171
diff
changeset
|
201 |
end |
4d0e2edd476d
added hyperlinks for every file pointer
Christian Urban <urbanc@in.tum.de>
parents:
171
diff
changeset
|
202 |
|
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
203 |
fun check_file_exists _ src = |
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
204 |
let |
573
321e220a6baa
accomodate to upcoming Isabelle 2019
Norbert Schirmer <norbert.schirmer@web.de>
parents:
572
diff
changeset
|
205 |
val (txt, _) = Input.source_content src |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
206 |
in |
171
18f90044c777
simplified antiquotations
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
207 |
(if File.exists (Path.append (Path.explode ("~~/src")) (Path.explode txt)) |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
208 |
then Latex.string (href_link txt) |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
209 |
else error (implode ["Source file ", quote txt, " does not exist."])) |
567
f7c97e64cc2a
tuned ML-antiquotations; added intro portions.
Norbert Schirmer <norbert.schirmer@web.de>
parents:
566
diff
changeset
|
210 |
end |
316
74f0a06f751f
further polishing of index generation
Christian Urban <urbanc@in.tum.de>
parents:
315
diff
changeset
|
211 |
|
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
212 |
val ml_file_setup = Thy_Output.antiquotation_raw @{binding "ML_file"} single_arg check_file_exists |
171
18f90044c777
simplified antiquotations
Christian Urban <urbanc@in.tum.de>
parents:
165
diff
changeset
|
213 |
|
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
214 |
|
102
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
98
diff
changeset
|
215 |
(* replaces the official subgoal antiquotation with one *) |
5e309df58557
general cleaning up; deleted antiquotation ML_text; adjusted pathnames of various files in the distribution
Christian Urban <urbanc@in.tum.de>
parents:
98
diff
changeset
|
216 |
(* that is closer to the actual output *) |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
217 |
|
303
05e6a33edef6
added an antiquotation for printing the raw proof state; polished the example about proof state
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
218 |
fun proof_state state = |
539
12861a362099
updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
517
diff
changeset
|
219 |
(case try (Proof.goal o Toplevel.proof_of) state of |
12861a362099
updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
517
diff
changeset
|
220 |
SOME {goal, ...} => goal |
12861a362099
updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
517
diff
changeset
|
221 |
| _ => error "No proof state"); |
12861a362099
updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
517
diff
changeset
|
222 |
|
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
223 |
fun output_raw_goal_state ctxt _ = |
539
12861a362099
updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
517
diff
changeset
|
224 |
let |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
225 |
val goals = proof_state (Toplevel.presentation_state ctxt) |
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
226 |
val out = Syntax.string_of_term ctxt (Thm.prop_of goals) |
539
12861a362099
updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
517
diff
changeset
|
227 |
in |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
228 |
output ctxt [out] |
539
12861a362099
updated to new isabelle
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
517
diff
changeset
|
229 |
end |
303
05e6a33edef6
added an antiquotation for printing the raw proof state; polished the example about proof state
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
230 |
|
471 | 231 |
val raw_goal_state_setup = |
562
daf404920ab9
Accomodate to Isabelle 2018
Norbert Schirmer <norbert.schirmer@web.de>
parents:
557
diff
changeset
|
232 |
Thy_Output.antiquotation_raw @{binding "raw_goal_state"} (Scan.succeed ()) output_raw_goal_state |
471 | 233 |
|
234 |
val setup = |
|
235 |
ml_setup #> |
|
236 |
ml_file_setup #> |
|
237 |
raw_goal_state_setup |
|
45
78aeca00bb54
deleted old antiquote_setup and renamed antiquote_setup_plus to antiquuote_setup
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
238 |
end; |