src/Pure/Thy/export_theory.ML
changeset 70579 5a8e3e4b3760
parent 70541 f3fbc7f3559d
child 70597 a896257a3f07
equal deleted inserted replaced
70578:7bb2bbb3ccd6 70579:5a8e3e4b3760
   216     val _ =
   216     val _ =
   217       export_entities "consts" (SOME oo export_const) Sign.const_space
   217       export_entities "consts" (SOME oo export_const) Sign.const_space
   218         (#constants (Consts.dest (Sign.consts_of thy)));
   218         (#constants (Consts.dest (Sign.consts_of thy)));
   219 
   219 
   220 
   220 
   221     (* axioms and facts *)
   221     (* axioms *)
   222 
   222 
   223     fun standard_prop used extra_shyps raw_prop raw_proof =
   223     fun standard_prop used extra_shyps raw_prop raw_proof =
   224       let
   224       let
   225         val (prop, proof) = Proofterm.standard_vars used (raw_prop, raw_proof);
   225         val (prop, proof) = Proofterm.standard_vars used (raw_prop, raw_proof);
   226         val args = rev (add_frees used prop []);
   226         val args = rev (add_frees used prop []);
   234       in triple (list (pair string sort)) (list (pair string typ)) term end;
   234       in triple (list (pair string sort)) (list (pair string typ)) term end;
   235 
   235 
   236     fun encode_axiom used prop =
   236     fun encode_axiom used prop =
   237       encode_prop (#1 (standard_prop used [] prop NONE));
   237       encode_prop (#1 (standard_prop used [] prop NONE));
   238 
   238 
       
   239     val _ =
       
   240       export_entities "axioms" (fn _ => fn t => SOME (encode_axiom Name.context t))
       
   241         Theory.axiom_space (Theory.axioms_of thy);
       
   242 
       
   243 
       
   244     (* theorems *)
       
   245 
   239     val clean_thm =
   246     val clean_thm =
   240       Thm.transfer thy
   247       Thm.transfer thy
   241       #> Thm.check_hyps (Context.Theory thy)
   248       #> Thm.check_hyps (Context.Theory thy)
   242       #> Thm.strip_shyps;
   249       #> Thm.strip_shyps;
   243 
   250 
   244     val encode_fact = clean_thm #> (fn thm =>
   251     fun entity_markup_thm (serial, (name, i)) =
       
   252       let
       
   253         val space = Facts.space_of (Global_Theory.facts_of thy);
       
   254         val xname = Name_Space.extern_shortest thy_ctxt space name;
       
   255         val {pos, ...} = Name_Space.the_entry space name;
       
   256       in make_entity_markup (Thm_Name.print (name, i)) (Thm_Name.print (xname, i)) pos serial end;
       
   257 
       
   258     val encode_thm = clean_thm #> (fn thm =>
   245       standard_prop Name.context
   259       standard_prop Name.context
   246         (Thm.extra_shyps thm)
   260         (Thm.extra_shyps thm)
   247         (Thm.full_prop_of thm)
   261         (Thm.full_prop_of thm)
   248         (try Thm.reconstruct_proof_of thm) |>
   262         (try Thm.reconstruct_proof_of thm) |>
   249       let open XML.Encode Term_XML.Encode
   263       let open XML.Encode Term_XML.Encode
   250       in pair encode_prop (option Proofterm.encode_full) end);
   264       in pair encode_prop (option Proofterm.encode_full) end);
   251 
   265 
   252     val _ =
   266     fun export_thms thms =
   253       export_entities "axioms" (fn _ => fn t => SOME (encode_axiom Name.context t))
   267       let val elems =
   254         Theory.axiom_space (Theory.axioms_of thy);
   268         thms |> map (fn (serial, thm_name) =>
   255     val _ =
   269           let
   256       export_entities "facts" (K (SOME o XML.Encode.list encode_fact))
   270             val markup = entity_markup_thm (serial, thm_name);
   257         (Facts.space_of o Global_Theory.facts_of)
   271             val body = encode_thm (Global_Theory.get_thm_name thy (thm_name, Position.none));
   258         (Facts.dest_static true [] (Global_Theory.facts_of thy));
   272           in XML.Elem (markup, body) end)
       
   273       in if null elems then () else export_body thy "thms" elems end;
       
   274 
       
   275     val _ = export_thms (Global_Theory.dest_thm_names thy);
   259 
   276 
   260 
   277 
   261     (* type classes *)
   278     (* type classes *)
   262 
   279 
   263     val encode_class =
   280     val encode_class =