src/Pure/Thy/export_theory.ML
changeset 70915 bd4d37edfee4
parent 70914 05c4c6a99b3f
child 70917 693e811b91bb
equal deleted inserted replaced
70914:05c4c6a99b3f 70915:bd4d37edfee4
   261           val dep_boxes =
   261           val dep_boxes =
   262             thm |> Thm_Deps.proof_boxes (fn thm_id' =>
   262             thm |> Thm_Deps.proof_boxes (fn thm_id' =>
   263               if #serial thm_id = #serial thm_id' then false else is_some (lookup_thm_id thm_id'));
   263               if #serial thm_id = #serial thm_id' then false else is_some (lookup_thm_id thm_id'));
   264         in dep_boxes @ [thm_id] end;
   264         in dep_boxes @ [thm_id] end;
   265 
   265 
       
   266     fun expand_name thm_id (header: Proofterm.thm_header) =
       
   267       if #serial header = #serial thm_id then ""
       
   268       else
       
   269         (case lookup_thm_id (Proofterm.thm_header_id header) of
       
   270           NONE => ""
       
   271         | SOME thm_name => Thm_Name.print thm_name);
       
   272 
   266     fun entity_markup_thm (serial, (name, i)) =
   273     fun entity_markup_thm (serial, (name, i)) =
   267       let
   274       let
   268         val space = Facts.space_of (Global_Theory.facts_of thy);
   275         val space = Facts.space_of (Global_Theory.facts_of thy);
   269         val xname = Name_Space.extern_shortest thy_ctxt space name;
   276         val xname = Name_Space.extern_shortest thy_ctxt space name;
   270         val {pos, ...} = Name_Space.the_entry space name;
   277         val {pos, ...} = Name_Space.the_entry space name;
   271       in make_entity_markup (Thm_Name.print (name, i)) (Thm_Name.print (xname, i)) pos serial end;
   278       in make_entity_markup (Thm_Name.print (name, i)) (Thm_Name.print (xname, i)) pos serial end;
   272 
   279 
   273     fun encode_thm (thm_id, thm_name) raw_thm =
   280     fun encode_thm thm_id raw_thm =
   274       let
   281       let
   275         val deps = map (Thm_Name.print o #2) (Thm_Deps.thm_deps thy [raw_thm]);
   282         val deps = map (Thm_Name.print o #2) (Thm_Deps.thm_deps thy [raw_thm]);
   276         val thm = Thm.unconstrainT (clean_thm raw_thm);
   283         val thm = Thm.unconstrainT (clean_thm raw_thm);
   277         val boxes = proof_boxes_of thm thm_id;
   284         val boxes = proof_boxes_of thm thm_id;
   278 
   285 
   279         val proof0 =
   286         val proof0 =
   280           if export_standard_proofs
   287           if export_standard_proofs then
   281           then Thm.standard_proof_of {full = true, expand = [Thm_Name.flatten thm_name]} thm
   288             Thm.standard_proof_of {full = true, expand_name = SOME o expand_name thm_id} thm
   282           else if Proofterm.export_enabled () then Thm.reconstruct_proof_of thm
   289           else if Proofterm.export_enabled () then Thm.reconstruct_proof_of thm
   283           else MinProof;
   290           else MinProof;
   284         val (prop, SOME proof) =
   291         val (prop, SOME proof) =
   285           standard_prop Name.context (Thm.extra_shyps thm) (Thm.full_prop_of thm) (SOME proof0);
   292           standard_prop Name.context (Thm.extra_shyps thm) (Thm.full_prop_of thm) (SOME proof0);
   286         val _ = Proofterm.commit_proof proof;
   293         val _ = Proofterm.commit_proof proof;
   295 
   302 
   296     fun buffer_export_thm (thm_id, thm_name) =
   303     fun buffer_export_thm (thm_id, thm_name) =
   297       let
   304       let
   298         val markup = entity_markup_thm (#serial thm_id, thm_name);
   305         val markup = entity_markup_thm (#serial thm_id, thm_name);
   299         val thm = Global_Theory.get_thm_name thy (thm_name, Position.none);
   306         val thm = Global_Theory.get_thm_name thy (thm_name, Position.none);
   300         val body = encode_thm (thm_id, thm_name) thm;
   307         val body = encode_thm thm_id thm;
   301       in YXML.buffer (XML.Elem (markup, body)) end;
   308       in YXML.buffer (XML.Elem (markup, body)) end;
   302 
   309 
   303     val _ =
   310     val _ =
   304       Buffer.empty
   311       Buffer.empty
   305       |> fold buffer_export_thm (Global_Theory.dest_thm_names thy)
   312       |> fold buffer_export_thm (Global_Theory.dest_thm_names thy)