18537
|
1 |
|
|
2 |
local structure O = IsarOutput
|
|
3 |
|
|
4 |
val str_of_source = space_implode " " o map Args.string_of o #2 o #1 o Args.dest_src;
|
|
5 |
|
|
6 |
fun ml_val txt = "fn _ => (" ^ txt ^ ");";
|
|
7 |
fun ml_type txt = "val _ = NONE : (" ^ txt ^ ") option;";
|
|
8 |
fun ml_structure txt = "functor DUMMY_FUNCTOR() = struct structure DUMMY = " ^ txt ^ " end;"
|
|
9 |
fun ml_functor txt = "val _ = ();"; (*no check!*)
|
|
10 |
|
|
11 |
val verbatim = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
|
|
12 |
|
|
13 |
fun index_ml kind ml src ctxt (txt1, txt2) =
|
|
14 |
let
|
|
15 |
val txt = if txt2 = "" then txt1 else txt1 ^ ": " ^ txt2;
|
|
16 |
val txt' = if kind = "" then txt else kind ^ " " ^ txt;
|
|
17 |
val _ = Context.use_mltext (ml txt) false (SOME (ProofContext.theory_of ctxt));
|
|
18 |
in
|
|
19 |
"\\indexml" ^ kind ^ enclose "{" "}"
|
|
20 |
(translate_string (fn "_" => "-" | ">" => "$>$" | c => c) txt1) ^
|
|
21 |
((if ! O.source then str_of_source src else txt')
|
|
22 |
|> (if ! O.quotes then quote else I)
|
|
23 |
|> (if ! O.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
|
|
24 |
else split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))
|
|
25 |
end;
|
|
26 |
|
|
27 |
fun output_verbatim _ _ = split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n";
|
|
28 |
|
|
29 |
fun arguments x = O.args (Scan.lift (Args.name -- Scan.optional (Args.colon |-- Args.name) "")) x;
|
|
30 |
|
|
31 |
val _ = O.add_commands
|
|
32 |
[("index_ML", arguments (index_ml "" ml_val)),
|
|
33 |
("index_ML_type", arguments (index_ml "type" ml_type)),
|
|
34 |
("index_ML_structure", arguments (index_ml "structure" ml_structure)),
|
|
35 |
("index_ML_functor", arguments (index_ml "functor" ml_functor)),
|
|
36 |
("verbatim", O.args (Scan.lift Args.name) output_verbatim)];
|
|
37 |
|
|
38 |
in val _ = () end;
|