68154
|
1 |
(* Title: Pure/Thy/export_theory.ML
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Export foundational theory content.
|
|
5 |
*)
|
|
6 |
|
|
7 |
signature EXPORT_THEORY =
|
|
8 |
sig
|
|
9 |
val export_table_diff: ('a -> XML.tree list option) ->
|
|
10 |
'a Name_Space.table list -> 'a Name_Space.table -> XML.tree list
|
|
11 |
end;
|
|
12 |
|
|
13 |
structure Export_Theory: EXPORT_THEORY =
|
|
14 |
struct
|
|
15 |
|
|
16 |
(* export namespace table *)
|
|
17 |
|
|
18 |
fun export_table_diff export_decl prev_tables table =
|
|
19 |
(table, []) |-> Name_Space.fold_table (fn (name, decl) =>
|
|
20 |
if exists (fn prev => Name_Space.defined prev name) prev_tables then I
|
|
21 |
else
|
|
22 |
(case export_decl decl of
|
|
23 |
NONE => I
|
|
24 |
| SOME body =>
|
|
25 |
let val markup = Name_Space.markup_def (Name_Space.space_of_table table) name
|
|
26 |
in cons (name, XML.Elem (markup, body)) end))
|
|
27 |
|> sort_by #1 |> map #2;
|
|
28 |
|
|
29 |
|
|
30 |
(* present *)
|
|
31 |
|
|
32 |
fun present get export name thy =
|
|
33 |
if Options.default_bool "export_theory" then
|
|
34 |
(case export (map get (Theory.parents_of thy)) (get thy) of
|
|
35 |
[] => ()
|
|
36 |
| body => Export.export thy ("theory/" ^ name) [YXML.string_of_body body])
|
|
37 |
else ();
|
|
38 |
|
|
39 |
|
|
40 |
(* types *)
|
|
41 |
|
|
42 |
val present_types = present (#types o Type.rep_tsig o Sign.tsig_of) o export_table_diff;
|
|
43 |
|
|
44 |
fun export_logical_type (Type.LogicalType n) = SOME (XML.Encode.int n)
|
|
45 |
| export_logical_type _ = NONE;
|
|
46 |
|
|
47 |
fun export_abbreviation (Type.Abbreviation (vs, U, _)) =
|
|
48 |
let open XML.Encode Term_XML.Encode
|
|
49 |
in SOME (pair (list string) typ (vs, U)) end
|
|
50 |
| export_abbreviation _ = NONE;
|
|
51 |
|
|
52 |
fun export_nonterminal Type.Nonterminal = SOME []
|
|
53 |
| export_nonterminal _ = NONE;
|
|
54 |
|
|
55 |
val _ =
|
|
56 |
Theory.setup
|
|
57 |
(Thy_Info.add_presentation (present_types export_logical_type "types") #>
|
|
58 |
Thy_Info.add_presentation (present_types export_abbreviation "type_synonyms") #>
|
|
59 |
Thy_Info.add_presentation (present_types export_nonterminal "nonterminals"));
|
|
60 |
|
|
61 |
end;
|