author | wenzelm |
Tue, 01 Sep 2020 18:03:17 +0200 | |
changeset 72235 | a5bf0b69c22a |
parent 71660 | 4269db8981b8 |
child 74114 | 700e5bd59c7d |
permissions | -rw-r--r-- |
68154 | 1 |
(* Title: Pure/Thy/export_theory.ML |
2 |
Author: Makarius |
|
3 |
||
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
4 |
Export foundational theory content and locale/class structure. |
68154 | 5 |
*) |
6 |
||
7 |
signature EXPORT_THEORY = |
|
8 |
sig |
|
68201 | 9 |
val setup_presentation: (Thy_Info.presentation_context -> theory -> unit) -> unit |
10 |
val export_body: theory -> string -> XML.body -> unit |
|
68154 | 11 |
end; |
12 |
||
13 |
structure Export_Theory: EXPORT_THEORY = |
|
14 |
struct |
|
15 |
||
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
16 |
(* approximative syntax *) |
69076 | 17 |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
18 |
val get_syntax = Syntax.get_approx o Proof_Context.syn_of; |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
19 |
fun get_syntax_type ctxt = get_syntax ctxt o Lexicon.mark_type; |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
20 |
fun get_syntax_const ctxt = get_syntax ctxt o Lexicon.mark_const; |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
21 |
fun get_syntax_fixed ctxt = get_syntax ctxt o Lexicon.mark_fixed; |
69076 | 22 |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
23 |
fun get_syntax_param ctxt loc x = |
69076 | 24 |
let val thy = Proof_Context.theory_of ctxt in |
25 |
if Class.is_class thy loc then |
|
26 |
(case AList.lookup (op =) (Class.these_params thy [loc]) x of |
|
27 |
NONE => NONE |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
28 |
| SOME (_, (c, _)) => get_syntax_const ctxt c) |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
29 |
else get_syntax_fixed ctxt x |
69076 | 30 |
end; |
31 |
||
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
32 |
val encode_syntax = |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
33 |
XML.Encode.variant |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
34 |
[fn NONE => ([], []), |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
35 |
fn SOME (Syntax.Prefix delim) => ([delim], []), |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
36 |
fn SOME (Syntax.Infix {assoc, delim, pri}) => |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
37 |
let |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
38 |
val ass = |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
39 |
(case assoc of |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
40 |
Printer.No_Assoc => 0 |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
41 |
| Printer.Left_Assoc => 1 |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
42 |
| Printer.Right_Assoc => 2); |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
43 |
open XML.Encode Term_XML.Encode; |
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
44 |
in ([], triple int string int (ass, delim, pri)) end]; |
69076 | 45 |
|
46 |
||
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
47 |
(* free variables: not declared in the context *) |
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
48 |
|
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
49 |
val is_free = not oo Name.is_declared; |
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
50 |
|
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
51 |
fun add_frees used = |
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
52 |
fold_aterms (fn Free (x, T) => is_free used x ? insert (op =) (x, T) | _ => I); |
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
53 |
|
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
54 |
fun add_tfrees used = |
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
55 |
(fold_types o fold_atyps) (fn TFree (a, S) => is_free used a ? insert (op =) (a, S) | _ => I); |
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
56 |
|
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
57 |
|
71209 | 58 |
(* locales *) |
69019 | 59 |
|
69034 | 60 |
fun locale_content thy loc = |
69019 | 61 |
let |
69083
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
62 |
val ctxt = Locale.init loc thy; |
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
63 |
val args = |
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
64 |
Locale.params_of thy loc |
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
65 |
|> map (fn ((x, T), _) => ((x, T), get_syntax_param ctxt loc x)); |
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
66 |
val axioms = |
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
67 |
let |
69083
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
68 |
val (asm, defs) = Locale.specification_of thy loc; |
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
69 |
val cprops = map (Thm.cterm_of ctxt) (the_list asm @ defs); |
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
70 |
val (intro1, intro2) = Locale.intros_of thy loc; |
69083
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
71 |
val intros_tac = Method.try_intros_tac ctxt (the_list intro1 @ the_list intro2) []; |
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
72 |
val res = |
69083
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
73 |
Goal.init (Conjunction.mk_conjunction_balanced cprops) |
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
74 |
|> (ALLGOALS Goal.conjunction_tac THEN intros_tac) |
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
75 |
|> try Seq.hd; |
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
76 |
in |
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
77 |
(case res of |
69083
6f8ae6ddc26b
more direct locale goal: avoid renaming of type_parameters;
wenzelm
parents:
69077
diff
changeset
|
78 |
SOME goal => Thm.prems_of goal |
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
79 |
| NONE => raise Fail ("Cannot unfold locale " ^ quote loc)) |
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
80 |
end; |
69076 | 81 |
val typargs = rev (fold Term.add_tfrees (map (Free o #1) args @ axioms) []); |
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
82 |
in {typargs = typargs, args = args, axioms = axioms} end; |
69019 | 83 |
|
69087
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
84 |
fun get_locales thy = |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
85 |
Locale.get_locales thy |> map_filter (fn loc => |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
86 |
if Experiment.is_experiment thy loc then NONE else SOME (loc, ())); |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
87 |
|
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
88 |
fun get_dependencies prev_thys thy = |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
89 |
Locale.dest_dependencies prev_thys thy |> map_filter (fn dep => |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
90 |
if Experiment.is_experiment thy (#source dep) orelse |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
91 |
Experiment.is_experiment thy (#target dep) then NONE |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
92 |
else |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
93 |
let |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
94 |
val (type_params, params) = Locale.parameters_of thy (#source dep); |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
95 |
val typargs = fold (Term.add_tfreesT o #2 o #1) params type_params; |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
96 |
val substT = |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
97 |
typargs |> map_filter (fn v => |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
98 |
let |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
99 |
val T = TFree v; |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
100 |
val T' = Morphism.typ (#morphism dep) T; |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
101 |
in if T = T' then NONE else SOME (v, T') end); |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
102 |
val subst = |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
103 |
params |> map_filter (fn (v, _) => |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
104 |
let |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
105 |
val t = Free v; |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
106 |
val t' = Morphism.term (#morphism dep) t; |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
107 |
in if t aconv t' then NONE else SOME (v, t') end); |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
108 |
in SOME (dep, (substT, subst)) end); |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
109 |
|
69019 | 110 |
|
68201 | 111 |
(* general setup *) |
68154 | 112 |
|
68201 | 113 |
fun setup_presentation f = |
114 |
Theory.setup (Thy_Info.add_presentation (fn context => fn thy => |
|
115 |
if Options.bool (#options context) "export_theory" then f context thy else ())); |
|
68154 | 116 |
|
70990 | 117 |
fun export_body thy name body = |
70994 | 118 |
if XML.is_empty_body body then () |
70992
e7dfc505de1b
more direct output of XML material -- bypass Buffer.T;
wenzelm
parents:
70991
diff
changeset
|
119 |
else Export.export thy (Path.binding0 (Path.make ["theory", name])) body; |
68165 | 120 |
|
68154 | 121 |
|
68201 | 122 |
(* presentation *) |
123 |
||
71249 | 124 |
val _ = setup_presentation (fn context => fn thy => |
68201 | 125 |
let |
68900
1145b25c53de
more robust: parents are strict in Export_Theory.read_theory and thus approximate "commit" of exports;
wenzelm
parents:
68864
diff
changeset
|
126 |
val parents = Theory.parents_of thy; |
68264 | 127 |
val rep_tsig = Type.rep_tsig (Sign.tsig_of thy); |
128 |
||
69003 | 129 |
val thy_ctxt = Proof_Context.init_global thy; |
68997 | 130 |
|
71249 | 131 |
val pos_properties = Thy_Info.adjust_pos_properties context; |
132 |
||
68264 | 133 |
|
71218 | 134 |
(* spec rules *) |
135 |
||
136 |
fun spec_rule_content {pos, name, rough_classification, terms, rules} = |
|
137 |
let |
|
138 |
val spec = |
|
139 |
terms @ map Thm.plain_prop_of rules |
|
140 |
|> Term_Subst.zero_var_indexes_list |
|
141 |
|> map Logic.unvarify_global; |
|
142 |
in |
|
71249 | 143 |
{props = pos_properties pos, |
71218 | 144 |
name = name, |
145 |
rough_classification = rough_classification, |
|
146 |
typargs = rev (fold Term.add_tfrees spec []), |
|
147 |
args = rev (fold Term.add_frees spec []), |
|
148 |
terms = map (fn t => (t, Term.type_of t)) (take (length terms) spec), |
|
149 |
rules = drop (length terms) spec} |
|
150 |
end; |
|
151 |
||
152 |
||
68201 | 153 |
(* entities *) |
68154 | 154 |
|
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
155 |
fun make_entity_markup name xname pos serial = |
71249 | 156 |
let val props = pos_properties pos @ Markup.serial_properties serial; |
68997 | 157 |
in (Markup.entityN, (Markup.nameN, name) :: (Markup.xnameN, xname) :: props) end; |
68154 | 158 |
|
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
159 |
fun entity_markup space name = |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
160 |
let |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
161 |
val xname = Name_Space.extern_shortest thy_ctxt space name; |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
162 |
val {serial, pos, ...} = Name_Space.the_entry space name; |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
163 |
in make_entity_markup name xname pos serial end; |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
164 |
|
68201 | 165 |
fun export_entities export_name export get_space decls = |
70601
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
166 |
let |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
167 |
val parent_spaces = map get_space parents; |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
168 |
val space = get_space thy; |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
169 |
in |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
170 |
(decls, []) |-> fold (fn (name, decl) => |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
171 |
if exists (fn space => Name_Space.declared space name) parent_spaces then I |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
172 |
else |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
173 |
(case export name decl of |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
174 |
NONE => I |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
175 |
| SOME body => |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
176 |
cons (#serial (Name_Space.the_entry space name), |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
177 |
XML.Elem (entity_markup space name, body)))) |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
178 |
|> sort (int_ord o apply2 #1) |> map #2 |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
179 |
|> export_body thy export_name |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
180 |
end; |
68165 | 181 |
|
182 |
||
68201 | 183 |
(* types *) |
68165 | 184 |
|
68201 | 185 |
val encode_type = |
186 |
let open XML.Encode Term_XML.Encode |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
187 |
in triple encode_syntax (list string) (option typ) end; |
68165 | 188 |
|
69003 | 189 |
fun export_type c (Type.LogicalType n) = |
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
190 |
SOME (encode_type (get_syntax_type thy_ctxt c, Name.invent Name.context Name.aT n, NONE)) |
69003 | 191 |
| export_type c (Type.Abbreviation (args, U, false)) = |
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
192 |
SOME (encode_type (get_syntax_type thy_ctxt c, args, SOME U)) |
69003 | 193 |
| export_type _ _ = NONE; |
68165 | 194 |
|
68201 | 195 |
val _ = |
69003 | 196 |
export_entities "types" export_type Sign.type_space |
68264 | 197 |
(Name_Space.dest_table (#types rep_tsig)); |
68201 | 198 |
|
68173 | 199 |
|
68201 | 200 |
(* consts *) |
201 |
||
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70605
diff
changeset
|
202 |
val consts = Sign.consts_of thy; |
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70605
diff
changeset
|
203 |
val encode_term = Term_XML.Encode.term consts; |
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70605
diff
changeset
|
204 |
|
68201 | 205 |
val encode_const = |
71222
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
wenzelm
parents:
71218
diff
changeset
|
206 |
let open XML.Encode Term_XML.Encode |
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
wenzelm
parents:
71218
diff
changeset
|
207 |
in pair encode_syntax (pair (list string) (pair typ (pair (option encode_term) bool))) end; |
68165 | 208 |
|
68201 | 209 |
fun export_const c (T, abbrev) = |
210 |
let |
|
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
211 |
val syntax = get_syntax_const thy_ctxt c; |
69992
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
212 |
val U = Logic.unvarifyT_global T; |
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
213 |
val U0 = Type.strip_sorts U; |
70529 | 214 |
val abbrev' = abbrev |
215 |
|> Option.map (Proofterm.standard_vars_term Name.context #> map_types Type.strip_sorts); |
|
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70605
diff
changeset
|
216 |
val args = map (#1 o dest_TFree) (Consts.typargs consts (c, U0)); |
69992
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents:
69988
diff
changeset
|
217 |
val propositional = Object_Logic.is_propositional thy_ctxt (Term.body_type U0); |
71222
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
wenzelm
parents:
71218
diff
changeset
|
218 |
in encode_const (syntax, (args, (U0, (abbrev', propositional)))) end; |
68165 | 219 |
|
68201 | 220 |
val _ = |
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
221 |
export_entities "consts" (SOME oo export_const) Sign.const_space |
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70605
diff
changeset
|
222 |
(#constants (Consts.dest consts)); |
68201 | 223 |
|
68208 | 224 |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
225 |
(* axioms *) |
68208 | 226 |
|
70534
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
227 |
fun standard_prop used extra_shyps raw_prop raw_proof = |
68727 | 228 |
let |
70541
f3fbc7f3559d
more careful treatment of hidden type variable names: smash before zero_var_indexes to get standard enumeration;
wenzelm
parents:
70540
diff
changeset
|
229 |
val (prop, proof) = Proofterm.standard_vars used (raw_prop, raw_proof); |
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
230 |
val args = rev (add_frees used prop []); |
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
231 |
val typargs = rev (add_tfrees used prop []); |
70534
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
232 |
val used_typargs = fold (Name.declare o #1) typargs used; |
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
233 |
val sorts = Name.invent used_typargs Name.aT (length extra_shyps) ~~ extra_shyps; |
70541
f3fbc7f3559d
more careful treatment of hidden type variable names: smash before zero_var_indexes to get standard enumeration;
wenzelm
parents:
70540
diff
changeset
|
234 |
in ((sorts @ typargs, args, prop), proof) end; |
70534
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
235 |
|
71202 | 236 |
fun standard_prop_of thm = |
237 |
standard_prop Name.context (Thm.extra_shyps thm) (Thm.full_prop_of thm); |
|
238 |
||
70534
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
239 |
val encode_prop = |
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
240 |
let open XML.Encode Term_XML.Encode |
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70605
diff
changeset
|
241 |
in triple (list (pair string sort)) (list (pair string typ)) encode_term end; |
70534
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
242 |
|
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
243 |
fun encode_axiom used prop = |
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
244 |
encode_prop (#1 (standard_prop used [] prop NONE)); |
68208 | 245 |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
246 |
val _ = |
70923
98d9b78b7f47
clarified axiom_table: uniform space (e.g. like consts), e.g. relevant for export of HOL-ex.Join_Theory;
wenzelm
parents:
70920
diff
changeset
|
247 |
export_entities "axioms" (K (SOME o encode_axiom Name.context)) |
98d9b78b7f47
clarified axiom_table: uniform space (e.g. like consts), e.g. relevant for export of HOL-ex.Join_Theory;
wenzelm
parents:
70920
diff
changeset
|
248 |
Theory.axiom_space (Theory.all_axioms_of thy); |
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
249 |
|
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
250 |
|
70914
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
70909
diff
changeset
|
251 |
(* theorems and proof terms *) |
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
70909
diff
changeset
|
252 |
|
70895
2a318149b01b
proof boxes based on proof digest (not proof term): thus it works with prune_proofs;
wenzelm
parents:
70892
diff
changeset
|
253 |
val clean_thm = Thm.check_hyps (Context.Theory thy) #> Thm.strip_shyps; |
71660
4269db8981b8
avoid vacous type variable, due to "potentially redundant" shyps in Thm.unconstrainT;
wenzelm
parents:
71249
diff
changeset
|
254 |
val prep_thm = clean_thm #> Thm.unconstrainT #> Thm.strip_shyps; |
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
255 |
|
70892
aadb5c23af24
clarified proof_boxes (requires prune_proofs=false);
wenzelm
parents:
70884
diff
changeset
|
256 |
val lookup_thm_id = Global_Theory.lookup_thm_id thy; |
aadb5c23af24
clarified proof_boxes (requires prune_proofs=false);
wenzelm
parents:
70884
diff
changeset
|
257 |
|
70915
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
258 |
fun expand_name thm_id (header: Proofterm.thm_header) = |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
259 |
if #serial header = #serial thm_id then "" |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
260 |
else |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
261 |
(case lookup_thm_id (Proofterm.thm_header_id header) of |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
262 |
NONE => "" |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
263 |
| SOME thm_name => Thm_Name.print thm_name); |
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
264 |
|
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
265 |
fun entity_markup_thm (serial, (name, i)) = |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
266 |
let |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
267 |
val space = Facts.space_of (Global_Theory.facts_of thy); |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
268 |
val xname = Name_Space.extern_shortest thy_ctxt space name; |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
269 |
val {pos, ...} = Name_Space.the_entry space name; |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
270 |
in make_entity_markup (Thm_Name.print (name, i)) (Thm_Name.print (xname, i)) pos serial end; |
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
271 |
|
70915
bd4d37edfee4
clarified expand_proof/expand_name: allow more detailed control via thm_header;
wenzelm
parents:
70914
diff
changeset
|
272 |
fun encode_thm thm_id raw_thm = |
70597 | 273 |
let |
70605 | 274 |
val deps = map (Thm_Name.print o #2) (Thm_Deps.thm_deps thy [raw_thm]); |
71202 | 275 |
val thm = prep_thm raw_thm; |
70914
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
70909
diff
changeset
|
276 |
|
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
70909
diff
changeset
|
277 |
val proof0 = |
70983 | 278 |
if Proofterm.export_standard_enabled () then |
71088 | 279 |
Proof_Syntax.standard_proof_of |
280 |
{full = true, expand_name = SOME o expand_name thm_id} thm |
|
70914
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
70909
diff
changeset
|
281 |
else if Proofterm.export_enabled () then Thm.reconstruct_proof_of thm |
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
70909
diff
changeset
|
282 |
else MinProof; |
71202 | 283 |
val (prop, SOME proof) = standard_prop_of thm (SOME proof0); |
71018
d32ed8927a42
more robust expose_proofs corresponding to register_proofs/consolidate_theory;
wenzelm
parents:
71015
diff
changeset
|
284 |
val _ = Thm.expose_proofs thy [thm]; |
70597 | 285 |
in |
71015
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70994
diff
changeset
|
286 |
(prop, deps, proof) |> |
70843
cc987440d776
more compact XML: separate environment for free variables;
wenzelm
parents:
70829
diff
changeset
|
287 |
let |
cc987440d776
more compact XML: separate environment for free variables;
wenzelm
parents:
70829
diff
changeset
|
288 |
open XML.Encode Term_XML.Encode; |
cc987440d776
more compact XML: separate environment for free variables;
wenzelm
parents:
70829
diff
changeset
|
289 |
val encode_proof = Proofterm.encode_standard_proof consts; |
71015
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents:
70994
diff
changeset
|
290 |
in triple encode_prop (list string) encode_proof end |
70597 | 291 |
end; |
68208 | 292 |
|
70992
e7dfc505de1b
more direct output of XML material -- bypass Buffer.T;
wenzelm
parents:
70991
diff
changeset
|
293 |
fun export_thm (thm_id, thm_name) = |
70601
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
294 |
let |
70904 | 295 |
val markup = entity_markup_thm (#serial thm_id, thm_name); |
70914
05c4c6a99b3f
option to export standardized proof terms (not scalable);
wenzelm
parents:
70909
diff
changeset
|
296 |
val thm = Global_Theory.get_thm_name thy (thm_name, Position.none); |
70992
e7dfc505de1b
more direct output of XML material -- bypass Buffer.T;
wenzelm
parents:
70991
diff
changeset
|
297 |
in XML.Elem (markup, encode_thm thm_id thm) end; |
70579
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents:
70541
diff
changeset
|
298 |
|
70992
e7dfc505de1b
more direct output of XML material -- bypass Buffer.T;
wenzelm
parents:
70991
diff
changeset
|
299 |
val _ = export_body thy "thms" (map export_thm (Global_Theory.dest_thm_names thy)); |
68232 | 300 |
|
68264 | 301 |
|
302 |
(* type classes *) |
|
303 |
||
304 |
val encode_class = |
|
305 |
let open XML.Encode Term_XML.Encode |
|
70534
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
306 |
in pair (list (pair string typ)) (list (encode_axiom Name.context)) end; |
68264 | 307 |
|
308 |
fun export_class name = |
|
309 |
(case try (Axclass.get_info thy) name of |
|
310 |
NONE => ([], []) |
|
70534
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents:
70529
diff
changeset
|
311 |
| SOME {params, axioms, ...} => (params, map (Thm.plain_prop_of o clean_thm) axioms)) |
68264 | 312 |
|> encode_class |> SOME; |
313 |
||
314 |
val _ = |
|
315 |
export_entities "classes" (fn name => fn () => export_class name) |
|
316 |
Sign.class_space (map (rpair ()) (Graph.keys (Sorts.classes_of (#2 (#classes rep_tsig))))); |
|
317 |
||
68295 | 318 |
|
319 |
(* sort algebra *) |
|
320 |
||
70386 | 321 |
local |
322 |
val prop = encode_axiom Name.context o Logic.varify_global; |
|
68295 | 323 |
|
70386 | 324 |
val encode_classrel = |
325 |
let open XML.Encode |
|
326 |
in list (pair prop (pair string string)) end; |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
70015
diff
changeset
|
327 |
|
70386 | 328 |
val encode_arities = |
329 |
let open XML.Encode Term_XML.Encode |
|
330 |
in list (pair prop (triple string (list sort) string)) end; |
|
331 |
in |
|
332 |
val export_classrel = |
|
333 |
maps (fn (c, cs) => map (pair c) cs) #> map (`Logic.mk_classrel) #> encode_classrel; |
|
68295 | 334 |
|
70386 | 335 |
val export_arities = map (`Logic.mk_arity) #> encode_arities; |
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
70015
diff
changeset
|
336 |
|
70386 | 337 |
val {classrel, arities} = |
338 |
Sorts.dest_algebra (map (#2 o #classes o Type.rep_tsig o Sign.tsig_of) parents) |
|
339 |
(#2 (#classes rep_tsig)); |
|
340 |
end; |
|
70384
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
70015
diff
changeset
|
341 |
|
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
70015
diff
changeset
|
342 |
val _ = if null classrel then () else export_body thy "classrel" (export_classrel classrel); |
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents:
70015
diff
changeset
|
343 |
val _ = if null arities then () else export_body thy "arities" (export_arities arities); |
68295 | 344 |
|
68862 | 345 |
|
346 |
(* locales *) |
|
347 |
||
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
348 |
fun encode_locale used = |
69076 | 349 |
let open XML.Encode Term_XML.Encode in |
69077
11529ae45786
more approximative prefix syntax, including binder;
wenzelm
parents:
69076
diff
changeset
|
350 |
triple (list (pair string sort)) (list (pair (pair string typ) encode_syntax)) |
69076 | 351 |
(list (encode_axiom used)) |
352 |
end; |
|
69023
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents:
69019
diff
changeset
|
353 |
|
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
354 |
fun export_locale loc = |
68864 | 355 |
let |
69034 | 356 |
val {typargs, args, axioms} = locale_content thy loc; |
69076 | 357 |
val used = fold Name.declare (map #1 typargs @ map (#1 o #1) args) Name.context; |
69027 | 358 |
in encode_locale used (typargs, args, axioms) end |
359 |
handle ERROR msg => |
|
360 |
cat_error msg ("The error(s) above occurred in locale " ^ |
|
361 |
quote (Locale.markup_name thy_ctxt loc)); |
|
68862 | 362 |
|
363 |
val _ = |
|
69029
aec64b88e708
clarified locale content: proper args with types for interpretation/axioms and typargs derived from the result;
wenzelm
parents:
69028
diff
changeset
|
364 |
export_entities "locales" (fn loc => fn () => SOME (export_locale loc)) |
69087
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
365 |
Locale.locale_space (get_locales thy); |
68862 | 366 |
|
68900
1145b25c53de
more robust: parents are strict in Export_Theory.read_theory and thus approximate "commit" of exports;
wenzelm
parents:
68864
diff
changeset
|
367 |
|
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
368 |
(* locale dependencies *) |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
369 |
|
69087
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
370 |
fun encode_locale_dependency (dep: Locale.locale_dependency, subst) = |
06017b2c4552
suppress aux. locales from command 'experiment' -- avoid crash of theory Dict_Construction.Test_Dict_Construction (AFP);
wenzelm
parents:
69086
diff
changeset
|
371 |
(#source dep, (#target dep, (#prefix dep, subst))) |> |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
372 |
let |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
373 |
open XML.Encode Term_XML.Encode; |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
374 |
val encode_subst = |
70784
799437173553
Term_XML.Encode/Decode.term uses Const "typargs";
wenzelm
parents:
70605
diff
changeset
|
375 |
pair (list (pair (pair string sort) typ)) (list (pair (pair string typ) (term consts))); |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
376 |
in pair string (pair string (pair (list (pair string bool)) encode_subst)) end; |
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
377 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
378 |
val _ = |
70601
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
379 |
get_dependencies parents thy |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
380 |
|> map_index (fn (i, dep) => |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
381 |
let |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
382 |
val xname = string_of_int (i + 1); |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
383 |
val name = Long_Name.implode [Context.theory_name thy, xname]; |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
384 |
val markup = make_entity_markup name xname (#pos (#1 dep)) (#serial (#1 dep)); |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
385 |
val body = encode_locale_dependency dep; |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
386 |
in XML.Elem (markup, body) end) |
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
387 |
|> export_body thy "locale_dependencies"; |
69069
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
388 |
|
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents:
69034
diff
changeset
|
389 |
|
70920 | 390 |
(* constdefs *) |
391 |
||
392 |
val constdefs = |
|
393 |
Defs.dest_constdefs (map Theory.defs_of (Theory.parents_of thy)) (Theory.defs_of thy) |
|
394 |
|> sort_by #1; |
|
395 |
||
396 |
val encode_constdefs = |
|
397 |
let open XML.Encode |
|
398 |
in list (pair string string) end; |
|
399 |
||
400 |
val _ = |
|
401 |
if null constdefs then () else export_body thy "constdefs" (encode_constdefs constdefs); |
|
402 |
||
403 |
||
71202 | 404 |
(* spec rules *) |
405 |
||
71208
5e0050eb64f2
clarified export of spec rules: more like locale;
wenzelm
parents:
71207
diff
changeset
|
406 |
val encode_specs = |
5e0050eb64f2
clarified export of spec rules: more like locale;
wenzelm
parents:
71207
diff
changeset
|
407 |
let open XML.Encode Term_XML.Encode in |
5e0050eb64f2
clarified export of spec rules: more like locale;
wenzelm
parents:
71207
diff
changeset
|
408 |
list (fn {props, name, rough_classification, typargs, args, terms, rules} => |
5e0050eb64f2
clarified export of spec rules: more like locale;
wenzelm
parents:
71207
diff
changeset
|
409 |
pair properties (pair string (pair Spec_Rules.encode_rough_classification |
5e0050eb64f2
clarified export of spec rules: more like locale;
wenzelm
parents:
71207
diff
changeset
|
410 |
(pair (list (pair string sort)) (pair (list (pair string typ)) |
71211 | 411 |
(pair (list (pair encode_term typ)) (list encode_term)))))) |
71208
5e0050eb64f2
clarified export of spec rules: more like locale;
wenzelm
parents:
71207
diff
changeset
|
412 |
(props, (name, (rough_classification, (typargs, (args, (terms, rules))))))) |
71202 | 413 |
end; |
414 |
||
415 |
val _ = |
|
416 |
(case Spec_Rules.dest_theory thy of |
|
417 |
[] => () |
|
71211 | 418 |
| spec_rules => export_body thy "spec_rules" (encode_specs (map spec_rule_content spec_rules))); |
71202 | 419 |
|
420 |
||
68900
1145b25c53de
more robust: parents are strict in Export_Theory.read_theory and thus approximate "commit" of exports;
wenzelm
parents:
68864
diff
changeset
|
421 |
(* parents *) |
1145b25c53de
more robust: parents are strict in Export_Theory.read_theory and thus approximate "commit" of exports;
wenzelm
parents:
68864
diff
changeset
|
422 |
|
1145b25c53de
more robust: parents are strict in Export_Theory.read_theory and thus approximate "commit" of exports;
wenzelm
parents:
68864
diff
changeset
|
423 |
val _ = |
70601
79831e40e2be
more scalable: avoid huge intermediate XML elems;
wenzelm
parents:
70597
diff
changeset
|
424 |
Export.export thy \<^path_binding>\<open>theory/parents\<close> |
70991
f9f7c34b7dd4
more scalable protocol_message: use XML.body directly (Output.output hook is not required);
wenzelm
parents:
70990
diff
changeset
|
425 |
(XML.Encode.string (cat_lines (map Context.theory_long_name parents))); |
68900
1145b25c53de
more robust: parents are strict in Export_Theory.read_theory and thus approximate "commit" of exports;
wenzelm
parents:
68864
diff
changeset
|
426 |
|
68295 | 427 |
in () end); |
68165 | 428 |
|
429 |
end; |