src/Pure/Thy/export_theory.ML
changeset 68199 f551dd2178ab
parent 68180 112d9624c020
child 68201 dee993b88a7b
equal deleted inserted replaced
68198:6710167e17af 68199:f551dd2178ab
     4 Export foundational theory content.
     4 Export foundational theory content.
     5 *)
     5 *)
     6 
     6 
     7 signature EXPORT_THEORY =
     7 signature EXPORT_THEORY =
     8 sig
     8 sig
     9   val entity_markup: Name_Space.T -> string -> Markup.T
       
    10 end;
     9 end;
    11 
    10 
    12 structure Export_Theory: EXPORT_THEORY =
    11 structure Export_Theory: EXPORT_THEORY =
    13 struct
    12 struct
    14 
    13 
    15 (* name space entries *)
    14 (* name space entries *)
    16 
    15 
    17 fun entity_markup space name =
    16 fun entity_markup adjust_pos space name =
    18   let
    17   let
    19     val {serial, pos, ...} = Name_Space.the_entry space name;
    18     val {serial, pos, ...} = Name_Space.the_entry space name;
    20     val props = Markup.serial_properties serial @ Position.offset_properties_of pos;
    19     val props = Markup.serial_properties serial @ Position.offset_properties_of (adjust_pos pos);
    21   in (Markup.entityN, (Markup.nameN, name) :: props) end;
    20   in (Markup.entityN, (Markup.nameN, name) :: props) end;
    22 
    21 
    23 fun export_decls export_decl parents thy space decls =
    22 fun export_decls export_decl parents thy adjust_pos space decls =
    24   (decls, []) |-> fold (fn (name, decl) =>
    23   (decls, []) |-> fold (fn (name, decl) =>
    25     if exists (fn space => Name_Space.declared space name) parents then I
    24     if exists (fn space => Name_Space.declared space name) parents then I
    26     else
    25     else
    27       (case export_decl thy name decl of
    26       (case export_decl thy name decl of
    28         NONE => I
    27         NONE => I
    29       | SOME body => cons (name, XML.Elem (entity_markup space name, body))))
    28       | SOME body => cons (name, XML.Elem (entity_markup adjust_pos space name, body))))
    30   |> sort_by #1 |> map #2;
    29   |> sort_by #1 |> map #2;
    31 
    30 
    32 
    31 
    33 (* present *)
    32 (* present *)
    34 
    33 
    35 fun present get_space get_decls export name thy =
    34 fun present get_space get_decls export name adjust_pos thy =
    36   if Options.default_bool "export_theory" then
    35   if Options.default_bool "export_theory" then
    37     (case export (map get_space (Theory.parents_of thy)) thy (get_space thy) (get_decls thy) of
    36     (case
       
    37       export (map get_space (Theory.parents_of thy)) thy adjust_pos (get_space thy) (get_decls thy)
       
    38      of
    38       [] => ()
    39       [] => ()
    39     | body => Export.export thy ("theory/" ^ name) [YXML.string_of_body body])
    40     | body => Export.export thy ("theory/" ^ name) [YXML.string_of_body body])
    40   else ();
    41   else ();
    41 
    42 
    42 fun present_decls get_space get_decls =
    43 fun present_decls get_space get_decls =
    43   present get_space get_decls o export_decls;
    44   present get_space get_decls o export_decls;
    44 
    45 
    45 fun setup_presentation f = Theory.setup (Thy_Info.add_presentation (K f));
    46 val setup_presentation = Theory.setup o Thy_Info.add_presentation;
    46 
    47 
    47 
    48 
    48 (* types *)
    49 (* types *)
    49 
    50 
    50 local
    51 local
    60   | export_type (Type.Abbreviation (args, U, false)) = SOME (encode_type (args, SOME U))
    61   | export_type (Type.Abbreviation (args, U, false)) = SOME (encode_type (args, SOME U))
    61   | export_type _ = NONE;
    62   | export_type _ = NONE;
    62 
    63 
    63 in
    64 in
    64 
    65 
    65 val _ = setup_presentation (present_types (K (K export_type)) "types");
    66 val _ = setup_presentation (present_types (K (K export_type)) "types" o #adjust_pos);
    66 
    67 
    67 end;
    68 end;
    68 
    69 
    69 
    70 
    70 (* consts *)
    71 (* consts *)
    85     val args = map (#1 o dest_TFree) (Consts.typargs (Sign.consts_of thy) (c, T'));
    86     val args = map (#1 o dest_TFree) (Consts.typargs (Sign.consts_of thy) (c, T'));
    86   in SOME (encode_const (args, T', abbrev')) end;
    87   in SOME (encode_const (args, T', abbrev')) end;
    87 
    88 
    88 in
    89 in
    89 
    90 
    90 val _ = setup_presentation (present_consts export_const "consts");
    91 val _ = setup_presentation (present_consts export_const "consts" o #adjust_pos);
    91 
    92 
    92 end;
    93 end;
    93 
    94 
    94 end;
    95 end;