50 val _ = setup_presentation (fn {adjust_pos, ...} => fn thy => |
50 val _ = setup_presentation (fn {adjust_pos, ...} => fn thy => |
51 let |
51 let |
52 val parents = Theory.parents_of thy; |
52 val parents = Theory.parents_of thy; |
53 val rep_tsig = Type.rep_tsig (Sign.tsig_of thy); |
53 val rep_tsig = Type.rep_tsig (Sign.tsig_of thy); |
54 |
54 |
55 val ctxt = Proof_Context.init_global thy; |
55 val thy_ctxt = Proof_Context.init_global thy; |
56 |
56 |
57 |
57 |
58 (* entities *) |
58 (* entities *) |
59 |
59 |
60 fun entity_markup space name = |
60 fun entity_markup space name = |
61 let |
61 let |
62 val xname = Name_Space.extern_shortest ctxt space name; |
62 val xname = Name_Space.extern_shortest thy_ctxt space name; |
63 val {serial, pos, ...} = Name_Space.the_entry space name; |
63 val {serial, pos, ...} = Name_Space.the_entry space name; |
64 val props = |
64 val props = |
65 Position.offset_properties_of (adjust_pos pos) @ |
65 Position.offset_properties_of (adjust_pos pos) @ |
66 Position.id_properties_of pos @ |
66 Position.id_properties_of pos @ |
67 Markup.serial_properties serial; |
67 Markup.serial_properties serial; |
84 |> sort (int_ord o apply2 #1) |> map #2 |
84 |> sort (int_ord o apply2 #1) |> map #2 |
85 end; |
85 end; |
86 in if null elems then () else export_body thy export_name elems end; |
86 in if null elems then () else export_body thy export_name elems end; |
87 |
87 |
88 |
88 |
|
89 (* infix syntax *) |
|
90 |
|
91 fun get_infix_const ctxt = Syntax.get_infix (Proof_Context.syn_of ctxt) o Lexicon.mark_const; |
|
92 fun get_infix_type ctxt = Syntax.get_infix (Proof_Context.syn_of ctxt) o Lexicon.mark_type; |
|
93 |
|
94 fun encode_infix {assoc, delim, pri} = |
|
95 let |
|
96 val ass = |
|
97 (case assoc of |
|
98 Syntax_Ext.No_Assoc => 0 |
|
99 | Syntax_Ext.Left_Assoc => 1 |
|
100 | Syntax_Ext.Right_Assoc => 2); |
|
101 open XML.Encode Term_XML.Encode; |
|
102 in triple int string int (ass, delim, pri) end; |
|
103 |
|
104 |
89 (* types *) |
105 (* types *) |
90 |
106 |
91 val encode_type = |
107 val encode_type = |
92 let open XML.Encode Term_XML.Encode |
108 let open XML.Encode Term_XML.Encode |
93 in pair (list string) (option typ) end; |
109 in triple (option encode_infix) (list string) (option typ) end; |
94 |
110 |
95 fun export_type (Type.LogicalType n) = |
111 fun export_type c (Type.LogicalType n) = |
96 SOME (encode_type (Name.invent Name.context Name.aT n, NONE)) |
112 SOME (encode_type (get_infix_type thy_ctxt c, Name.invent Name.context Name.aT n, NONE)) |
97 | export_type (Type.Abbreviation (args, U, false)) = |
113 | export_type c (Type.Abbreviation (args, U, false)) = |
98 SOME (encode_type (args, SOME U)) |
114 SOME (encode_type (get_infix_type thy_ctxt c, args, SOME U)) |
99 | export_type _ = NONE; |
115 | export_type _ _ = NONE; |
100 |
116 |
101 val _ = |
117 val _ = |
102 export_entities "types" (K export_type) Sign.type_space |
118 export_entities "types" export_type Sign.type_space |
103 (Name_Space.dest_table (#types rep_tsig)); |
119 (Name_Space.dest_table (#types rep_tsig)); |
104 |
120 |
105 |
121 |
106 (* consts *) |
122 (* consts *) |
107 |
123 |
108 val encode_const = |
124 val encode_const = |
109 let open XML.Encode Term_XML.Encode |
125 let open XML.Encode Term_XML.Encode in |
110 in triple (list string) typ (option (term o named_bounds)) end; |
126 pair (option encode_infix) (pair (list string) (pair typ (option (term o named_bounds)))) |
|
127 end; |
111 |
128 |
112 fun export_const c (T, abbrev) = |
129 fun export_const c (T, abbrev) = |
113 let |
130 let |
|
131 val syntax = get_infix_const thy_ctxt c; |
114 val T' = T |> Logic.unvarifyT_global |> Type.strip_sorts; |
132 val T' = T |> Logic.unvarifyT_global |> Type.strip_sorts; |
115 val abbrev' = abbrev |> Option.map (Logic.unvarify_global #> map_types Type.strip_sorts); |
133 val abbrev' = abbrev |> Option.map (Logic.unvarify_global #> map_types Type.strip_sorts); |
116 val args = map (#1 o dest_TFree) (Consts.typargs (Sign.consts_of thy) (c, T')); |
134 val args = map (#1 o dest_TFree) (Consts.typargs (Sign.consts_of thy) (c, T')); |
117 in SOME (encode_const (args, T', abbrev')) end; |
135 in SOME (encode_const (syntax, (args, (T', abbrev')))) end; |
118 |
136 |
119 val _ = |
137 val _ = |
120 export_entities "consts" export_const Sign.const_space |
138 export_entities "consts" export_const Sign.const_space |
121 (#constants (Consts.dest (Sign.consts_of thy))); |
139 (#constants (Consts.dest (Sign.consts_of thy))); |
122 |
140 |