src/Tools/isac/xmlsrc/datatypes.sml
changeset 59405 49d7d410b83c
parent 59393 4274a44ec183
child 59408 0b11cdcb1bea
equal deleted inserted replaced
59404:6a2753b8d70c 59405:49d7d410b83c
     3    (c) due to copyright terms
     3    (c) due to copyright terms
     4 *)
     4 *)
     5 
     5 
     6 signature DATATYPES = (*TODO: redo with xml_of/to *)
     6 signature DATATYPES = (*TODO: redo with xml_of/to *)
     7   sig
     7   sig
     8     val authors2xml : int -> string -> string list -> xml
     8     val authors2xml : int -> string -> string list -> Celem.xml
     9     val calc2xml : int -> thyID * calc -> xml
     9     val calc2xml : int -> Celem.thyID * Celem.calc -> Celem.xml
    10     val calcrefs2xml : int -> thyID * calc list -> xml
    10     val calcrefs2xml : int -> Celem.thyID * Celem.calc list -> Celem.xml
    11     val contthy2xml : int -> Rtools.contthy -> xml
    11     val contthy2xml : int -> Rtools.contthy -> Celem.xml
    12     val extref2xml : int -> string -> string -> xml
    12     val extref2xml : int -> string -> string -> Celem.xml
    13     val filterpbl :
    13     val filterpbl :
    14        ''a -> (''a * (Term.term * Term.term)) list -> Term.term list
    14        ''a -> (''a * (Term.term * Term.term)) list -> Term.term list
    15     val formula2xml : int -> Term.term -> xml
    15     val formula2xml : int -> Term.term -> Celem.xml
    16     val formulae2xml : int -> Term.term list -> xml
    16     val formulae2xml : int -> Term.term list -> Celem.xml
    17     val i : int
    17     val i : int
    18     val id2xml : int -> string list -> string
    18     val id2xml : int -> string list -> string
    19     val ints2xml : int -> int list -> string
    19     val ints2xml : int -> int list -> string
    20     val itm_2xml : int -> Model.itm_ -> xml
    20     val itm_2xml : int -> Model.itm_ -> Celem.xml
    21     val itms2xml : int -> (int * Model.vats * bool * string * Model.itm_) list ->
    21     val itms2xml : int -> (int * Model.vats * bool * string * Model.itm_) list ->
    22       string
    22       string
    23     val keref2xml : int -> ketype -> kestoreID -> xml
    23     val keref2xml : int -> Celem.ketype -> Celem.kestoreID -> Celem.xml
    24     val model2xml :
    24     val model2xml :
    25        int -> Model.itm list -> (bool * Term.term) list -> xml
    25        int -> Model.itm list -> (bool * Term.term) list -> Celem.xml
    26     val modspec2xml : int -> Ctree.ocalhd -> xml
    26     val modspec2xml : int -> Ctree.ocalhd -> Celem.xml
    27     val pattern2xml :
    27     val pattern2xml :
    28        int ->
    28        int ->
    29        (string * (Term.term * Term.term)) list -> Term.term list -> string
    29        (string * (Term.term * Term.term)) list -> Term.term list -> string
    30     val pos'2xml : int -> string * (int list * Ctree.pos_) -> string
    30     val pos'2xml : int -> string * (int list * Ctree.pos_) -> string
    31     val pos'calchead2xml : int -> Ctree.pos' * Ctree.ocalhd -> xml
    31     val pos'calchead2xml : int -> Ctree.pos' * Ctree.ocalhd -> Celem.xml
    32     val pos_2xml : int -> Ctree.pos_ -> string
    32     val pos_2xml : int -> Ctree.pos_ -> string
    33     val posform2xml : int -> Ctree.pos' * Term.term -> xml
    33     val posform2xml : int -> Ctree.pos' * Term.term -> Celem.xml
    34     val posformhead2xml : int -> Ctree.pos' * Ctree.ptform -> string
    34     val posformhead2xml : int -> Ctree.pos' * Ctree.ptform -> string
    35     val posformheads2xml : int -> (Ctree.pos' * Ctree.ptform) list -> xml
    35     val posformheads2xml : int -> (Ctree.pos' * Ctree.ptform) list -> Celem.xml
    36     val posforms2xml : int -> (Ctree.pos' * Term.term) list -> xml
    36     val posforms2xml : int -> (Ctree.pos' * Term.term) list -> Celem.xml
    37     val posterms2xml : int -> (Ctree.pos' * term) list -> xml
    37     val posterms2xml : int -> (Ctree.pos' * term) list -> Celem.xml
    38     val precond2xml : int -> bool * Term.term -> xml
    38     val precond2xml : int -> bool * Term.term -> Celem.xml
    39     val preconds2xml : int -> (bool * Term.term) list -> xml
    39     val preconds2xml : int -> (bool * Term.term) list -> Celem.xml
    40     val rls2xml : int -> thyID * rls -> xml
    40     val rls2xml : int -> Celem.thyID * rls -> Celem.xml
    41     val rule2xml : int -> guh -> rule -> xml
    41     val rule2xml : int -> Celem.guh -> rule -> Celem.xml
    42     val rules2xml : int -> guh -> rule list -> xml
    42     val rules2xml : int -> Celem.guh -> rule list -> Celem.xml
    43     val scr2xml : int -> scr -> xml
    43     val scr2xml : int -> Celem.scr -> Celem.xml
    44     val spec2xml : int -> spec -> xml
    44     val spec2xml : int -> Celem.spec -> Celem.xml
    45     val sub2xml : int -> Term.term * Term.term -> xml
    45     val sub2xml : int -> Term.term * Term.term -> Celem.xml
    46     val subs2xml : int -> Selem.subs -> xml
    46     val subs2xml : int -> Selem.subs -> Celem.xml
    47     val subst2xml : int -> subst -> xml
    47     val subst2xml : int -> Celem.subst -> Celem.xml
    48     val tac2xml : int -> Tac.tac -> xml
    48     val tac2xml : int -> Tac.tac -> Celem.xml
    49     val tacs2xml : int -> Tac.tac list -> xml
    49     val tacs2xml : int -> Tac.tac list -> Celem.xml
    50     val theref2xml : int -> thyID -> string -> xstring -> string
    50     val theref2xml : int -> Celem.thyID -> string -> xstring -> string
    51     val thm'2xml : int -> thm' -> xml
    51     val thm'2xml : int -> Celem.thm' -> Celem.xml
    52     val thm''2xml : int -> thm -> xml
    52     val thm''2xml : int -> thm -> Celem.xml
    53     val thmstr2xml : int -> string -> xml
    53     val thmstr2xml : int -> string -> Celem.xml
    54   end
    54   end
    55 
    55 
    56 (*------------------------------------------------------------------
    56 (*------------------------------------------------------------------
    57 structure datatypes:DATATYPES =
    57 structure datatypes:DATATYPES =
    58 (*structure datatypes =*)
    58 (*structure datatypes =*)
    75         <STRINGLIST>
    75         <STRINGLIST>
    76           <STRING>linear</STRING>
    76           <STRING>linear</STRING>
    77           <STRING>univariate</STRING>
    77           <STRING>univariate</STRING>
    78           <STRING>equation</STRING>
    78           <STRING>equation</STRING>
    79         </STRINGLIST>*)
    79         </STRINGLIST>*)
    80 fun calc2xml j (thyID:thyID, (scrop, (rewop, _)):calc) =
    80 fun calc2xml j (thyID, (scrop, (rewop, _))) =
    81     indt j ^ "<CALC>\n" ^
    81     indt j ^ "<CALC>\n" ^
    82     indt (j+i) ^ "<STRING>\n" ^ scrop ^ "</STRING>\n" ^
    82     indt (j+i) ^ "<STRING>\n" ^ scrop ^ "</STRING>\n" ^
    83     indt (j+i) ^ "<GUH>\n" ^ cal2guh ("IsacKnowledge", 
    83     indt (j+i) ^ "<GUH>\n" ^ Celem.cal2guh ("IsacKnowledge", 
    84 				      thyID) scrop  ^ "</GUH>\n" ^
    84 				      thyID) scrop  ^ "</GUH>\n" ^
    85     indt (j+i) ^ "<TERMOP>\n" ^ rewop ^ "</TERMOP>\n" ^
    85     indt (j+i) ^ "<TERMOP>\n" ^ rewop ^ "</TERMOP>\n" ^
    86     indt j ^ "</CALC>\n" : xml;
    86     indt j ^ "</CALC>\n";
    87 (*replace by 'fun calc2xml' as developed for thy in 0607*)
    87 (*replace by 'fun calc2xml' as developed for thy in 0607*)
    88 fun calc2xmlOLD _ ((scr_op, (isa_op, _)):calc) =
    88 fun calc2xmlOLD _ (scr_op, (isa_op, _)) =
    89     indt i ^ "<CALCULATE> (" ^ scr_op ^ ", (" ^ isa_op ^ ")) </CALCULATE>\n";
    89     indt i ^ "<CALCULATE> (" ^ scr_op ^ ", (" ^ isa_op ^ ")) </CALCULATE>\n";
    90 fun calcs2xmlOLD _ [] = ("":xml) (*TODO replace with 'strs2xml'*)
    90 fun calcs2xmlOLD _ [] = "" (*TODO replace with 'strs2xml'*)
    91   | calcs2xmlOLD j (r::rs) = calc2xmlOLD j r ^ calcs2xmlOLD j rs;
    91   | calcs2xmlOLD j (r::rs) = calc2xmlOLD j r ^ calcs2xmlOLD j rs;
    92 
    92 
    93 (*.for creating a href for a rule within an rls's rule list;
    93 (*.for creating a href for a rule within an rls's rule list;
    94    the guh points to the thy of definition of the rule, NOT of use in rls.*)
    94    the guh points to the thy of definition of the rule, NOT of use in rls.*)
    95 fun rule2xml _ (_ : thyID) Erule =
    95 fun rule2xml _ _  Celem.Erule =
    96       error "rule2xml called with 'Erule'"
    96       error "rule2xml called with 'Erule'"
    97   | rule2xml j _ (Thm (thmDeriv, _)) =
    97   | rule2xml j _ (Celem.Thm (thmDeriv, _)) =
    98       indt j ^ "<RULE>\n" ^
    98       indt j ^ "<RULE>\n" ^
    99       indt (j+i) ^ "<TAG> Theorem </TAG>\n" ^
    99       indt (j+i) ^ "<TAG> Theorem </TAG>\n" ^
   100       indt (j+i) ^ "<STRING> " ^ thmID_of_derivation_name thmDeriv ^ " </STRING>\n" ^
   100       indt (j+i) ^ "<STRING> " ^ Celem.thmID_of_derivation_name thmDeriv ^ " </STRING>\n" ^
   101       indt (j+i) ^ "<GUH> " ^ 
   101       indt (j+i) ^ "<GUH> " ^ 
   102         thm2guh (Rtools.thy_containing_thm thmDeriv) (thmID_of_derivation_name thmDeriv) ^ " </GUH>\n" ^
   102         Celem.thm2guh (Rtools.thy_containing_thm thmDeriv) (Celem.thmID_of_derivation_name thmDeriv) ^ " </GUH>\n" ^
   103         indt j ^ "</RULE>\n" : xml
   103         indt j ^ "</RULE>\n"
   104   | rule2xml _ _ (Calc (_(*termop*), _)) = ""
   104   | rule2xml _ _ (Celem.Calc (_(*termop*), _)) = ""
   105 (*FIXXXXXXXME.WN060714 in rls make Calc : calc -> rule [add scriptop!]
   105 (*FIXXXXXXXME.WN060714 in rls make Calc : calc -> rule [add scriptop!]
   106   see smltest/../datatypes.sml !
   106   see smltest/../datatypes.sml !
   107     indt j ^ "<RULE>\n" ^
   107     indt j ^ "<RULE>\n" ^
   108     indt (j+i) ^ "<STRING> " ^ termop ^ " </STRING>\n" ^
   108     indt (j+i) ^ "<STRING> " ^ termop ^ " </STRING>\n" ^
   109     indt (j+i) ^ "<GUH> " ^ cal2guh (thy_containing_cal thyID termop) 
   109     indt (j+i) ^ "<GUH> " ^ cal2guh (thy_containing_cal thyID termop) 
   110 				    termop ^ " </GUH>\n" ^
   110 				    termop ^ " </GUH>\n" ^
   111     indt j ^ "</RULE>\n"
   111     indt j ^ "</RULE>\n"
   112 *)
   112 *)
   113   | rule2xml _ _ (Cal1 (_(*termop*), _)) = ""
   113   | rule2xml _ _ (Celem.Cal1 (_(*termop*), _)) = ""
   114   | rule2xml j thyID (Rls_ rls) =
   114   | rule2xml j thyID (Celem.Rls_ rls) =
   115       let val rls' = (#id o rep_rls) rls
   115       let val rls' = (#id o Celem.rep_rls) rls
   116       in
   116       in
   117         indt j ^ "<RULE>\n" ^
   117         indt j ^ "<RULE>\n" ^
   118         indt (j+i) ^ "<TAG> Ruleset </TAG>\n" ^
   118         indt (j+i) ^ "<TAG> Ruleset </TAG>\n" ^
   119         indt (j+i) ^ "<STRING> " ^ rls' ^ " </STRING>\n" ^
   119         indt (j+i) ^ "<STRING> " ^ rls' ^ " </STRING>\n" ^
   120         indt (j+i) ^ "<GUH> " ^ rls2guh (Rtools.thy_containing_rls thyID rls') rls' ^ " </GUH>\n" ^
   120         indt (j+i) ^ "<GUH> " ^ Celem.rls2guh (Rtools.thy_containing_rls thyID rls') rls' ^ " </GUH>\n" ^
   121         indt j ^ "</RULE>\n"
   121         indt j ^ "</RULE>\n"
   122       end;
   122       end;
   123 fun rules2xml _ _ [] = ("":xml)                    
   123 fun rules2xml _ _ [] = ""
   124   | rules2xml j thyID (r::rs) = rule2xml j thyID r ^ rules2xml j thyID rs;
   124   | rules2xml j thyID (r::rs) = rule2xml j thyID r ^ rules2xml j thyID rs;
   125 
   125 
   126 fun filterpbl str =
   126 fun filterpbl str =
   127   let fun filt [] = []
   127   let fun filt [] = []
   128         | filt ((s, (t1, t2)) :: ps) = 
   128         | filt ((s, (t1, t2)) :: ps) = 
   158 (*url to a source external to isac*)
   158 (*url to a source external to isac*)
   159 fun extref2xml j linktext url =
   159 fun extref2xml j linktext url =
   160     indt j ^ "<EXTREF>\n" ^
   160     indt j ^ "<EXTREF>\n" ^
   161     indt (j+i) ^ "<TEXT> " ^ linktext ^ " </TEXT>\n" ^
   161     indt (j+i) ^ "<TEXT> " ^ linktext ^ " </TEXT>\n" ^
   162     indt (j+i) ^ "<URL> " ^ url ^ " </URL>\n" ^
   162     indt (j+i) ^ "<URL> " ^ url ^ " </URL>\n" ^
   163     indt j ^ "</EXTREF>\n" : xml;
   163     indt j ^ "</EXTREF>\n";
   164 fun theref2xml j (thyID:thyID) typ (xstring:xstring) =
   164 fun theref2xml j thyID typ xstring =
   165     let val guh = theID2guh ["IsacKnowledge", thyID, typ, xstring]
   165     let val guh = Celem.theID2guh ["IsacKnowledge", thyID, typ, xstring]
   166 	val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
   166 	val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
   167     in indt j ^ "<KESTOREREF>\n" ^
   167     in indt j ^ "<KESTOREREF>\n" ^
   168        indt (j+i) ^ "<TAG> " ^ typ' ^ " </TAG>\n" ^
   168        indt (j+i) ^ "<TAG> " ^ typ' ^ " </TAG>\n" ^
   169        indt (j+i) ^ "<ID> " ^ xstring ^ " </ID>\n" ^
   169        indt (j+i) ^ "<ID> " ^ xstring ^ " </ID>\n" ^
   170        indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
   170        indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
   171        indt j ^ "</KESTOREREF>\n" : xml
   171        indt j ^ "</KESTOREREF>\n"
   172     end;
   172     end;
   173 fun keref2xml j typ (kestoreID:kestoreID) =
   173 fun keref2xml j typ kestoreID =
   174     let val id = strs2str' kestoreID
   174     let val id = strs2str' kestoreID
   175 	val guh = Specify.kestoreID2guh typ kestoreID
   175 	val guh = Specify.kestoreID2guh typ kestoreID
   176     in indt j ^ "<KESTOREREF>\n" ^
   176     in indt j ^ "<KESTOREREF>\n" ^
   177        indt (j+i) ^ "<TAG> " ^ ketype2str' typ ^ "</TAG>\n" ^
   177        indt (j+i) ^ "<TAG> " ^ Celem.ketype2str' typ ^ "</TAG>\n" ^
   178        indt (j+i) ^ "<ID> " ^ id ^ " </ID>\n" ^
   178        indt (j+i) ^ "<ID> " ^ id ^ " </ID>\n" ^
   179        indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
   179        indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
   180        indt j ^ "</KESTOREREF>\n" : xml
   180        indt j ^ "</KESTOREREF>\n"
   181     end;
   181     end;
   182 fun authors2xml j str auts = 
   182 fun authors2xml j str auts = 
   183     let fun autx _ [] = ""
   183     let fun autx _ [] = ""
   184 	  | autx j (s::ss) = (indt j) ^ "<STRING> " ^ s ^ " </STRING>\n" ^ 
   184 	  | autx j (s::ss) = (indt j) ^ "<STRING> " ^ s ^ " </STRING>\n" ^ 
   185 			     (autx j ss)
   185 			     (autx j ss)
   186     in indt j ^ "<"^str^">\n" ^
   186     in indt j ^ "<"^str^">\n" ^
   187        autx (j + i) auts ^ 
   187        autx (j + i) auts ^ 
   188        indt j ^ "</"^str^">\n" : xml
   188        indt j ^ "</"^str^">\n"
   189     end;
   189     end;
   190 (* writeln(authors2xml 2 "MATHAUTHORS" []);
   190 (* writeln(authors2xml 2 "MATHAUTHORS" []);
   191    writeln(authors2xml 2 "MATHAUTHORS" 
   191    writeln(authors2xml 2 "MATHAUTHORS" 
   192 		       ["isac-team 2001", "Richard Lang 2003"]);
   192 		       ["isac-team 2001", "Richard Lang 2003"]);
   193    *)
   193    *)
   194 fun scr2xml j EmptyScr =
   194 fun scr2xml j EmptyScr =
   195     indt j ^"<SCRIPT>  </SCRIPT>\n" : xml
   195     indt j ^"<SCRIPT>  </SCRIPT>\n"
   196   | scr2xml j (Prog term) =
   196   | scr2xml j (Celem.Prog term) =
   197     if term = e_term 
   197     if term = Celem.e_term 
   198     then indt j ^"<SCRIPT>  </SCRIPT>\n"
   198     then indt j ^"<SCRIPT>  </SCRIPT>\n"
   199     else indt j ^"<SCRIPT>\n"^ 
   199     else indt j ^"<SCRIPT>\n"^ 
   200 	 term2xml j (TermC.inst_abs term) ^ "\n" ^
   200 	 term2xml j (TermC.inst_abs term) ^ "\n" ^
   201 	 indt j ^"</SCRIPT>\n"
   201 	 indt j ^"</SCRIPT>\n"
   202   | scr2xml j (Rfuns _) =
   202   | scr2xml j (Celem.Rfuns _) =
   203     indt j ^"<REVERSREWRITE> reverse rewrite functions </REVERSREWRITE>\n";
   203     indt j ^"<REVERSREWRITE> reverse rewrite functions </REVERSREWRITE>\n";
   204 
   204 
   205 fun calcref2xml j (thyID:thyID, (scrop, (_(*rewop*), _)):calc) =
   205 fun calcref2xml j (thyID, (scrop, (_(*rewop*), _))) =
   206     indt j ^ "<CALCREF>\n" ^
   206     indt j ^ "<CALCREF>\n" ^
   207     indt (j+i) ^ "<STRING> " ^ scrop ^ "</STRING>\n" ^
   207     indt (j+i) ^ "<STRING> " ^ scrop ^ "</STRING>\n" ^
   208     indt (j+i) ^ "<GUH> " ^ cal2guh ("IsacKnowledge", 
   208     indt (j+i) ^ "<GUH> " ^ Celem.cal2guh ("IsacKnowledge", 
   209 				      thyID) scrop  ^ " </GUH>\n" ^
   209 				      thyID) scrop  ^ " </GUH>\n" ^
   210     indt j ^ "</CALCREF>\n" : xml;
   210     indt j ^ "</CALCREF>\n";
   211 fun calcrefs2xml _ (_,[]) = "":xml
   211 fun calcrefs2xml _ (_,[]) = ""
   212   | calcrefs2xml j (thyID, cal::cs) = 
   212   | calcrefs2xml j (thyID, cal::cs) = 
   213     calcref2xml j (thyID, cal) ^ calcrefs2xml j (thyID, cs);
   213     calcref2xml j (thyID, cal) ^ calcrefs2xml j (thyID, cs);
   214 
   214 
   215 fun prepa12xml j (terms, term) =
   215 fun prepa12xml j (terms, term) =
   216     indt j ^"<PREPAT>\n"^
   216     indt j ^"<PREPAT>\n"^
   218     terms2xml (j+2*i) terms ^
   218     terms2xml (j+2*i) terms ^
   219     indt (j+i) ^"</PRECONDS>\n"^
   219     indt (j+i) ^"</PRECONDS>\n"^
   220     indt (j+i) ^"<PATTERN>\n"^
   220     indt (j+i) ^"<PATTERN>\n"^
   221     term2xml (j+2*i) term ^
   221     term2xml (j+2*i) term ^
   222     indt (j+i) ^"</PATTERN>\n"^
   222     indt (j+i) ^"</PATTERN>\n"^
   223     indt j ^"</PREPAT>\n" : xml;
   223     indt j ^"</PREPAT>\n";
   224 fun prepat2xml _ [] = ""
   224 fun prepat2xml _ [] = ""
   225   | prepat2xml j (p::ps) = prepa12xml j p ^ prepat2xml j ps : xml;
   225   | prepat2xml j (p::ps) = prepa12xml j p ^ prepat2xml j ps;
   226 
   226 
   227 fun rls2xm j (thyID, seqrls, {id, preconds, rew_ord=(ord,_), erls,
   227 fun rls2xm j (thyID, seqrls, {id, preconds, rew_ord=(ord,_), erls,
   228 		      srls, calc, rules, errpatts, scr}) =
   228 		      srls, calc, rules, errpatts, scr}) =
   229     indt j ^"<RULESET>\n"^
   229     indt j ^"<RULESET>\n"^
   230     indt (j+i) ^"<ID> "^ id ^" </ID>\n"^
   230     indt (j+i) ^"<ID> "^ id ^" </ID>\n"^
   242 				      thyID) ord ^ " </GUH>\n" ^
   242 				      thyID) ord ^ " </GUH>\n" ^
   243 ..................................................................*)
   243 ..................................................................*)
   244     indt (j+i) ^"</ORDER>\n" ^
   244     indt (j+i) ^"</ORDER>\n" ^
   245     indt (j+i) ^"<ERLS>\n" ^
   245     indt (j+i) ^"<ERLS>\n" ^
   246     indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
   246     indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
   247     indt (j+2*i) ^ "<STRING> " ^ id_rls erls ^ " </STRING>\n" ^
   247     indt (j+2*i) ^ "<STRING> " ^ Celem.id_rls erls ^ " </STRING>\n" ^
   248     indt (j+2*i) ^ "<GUH> " ^ rls2guh ("IsacKnowledge", thyID) 
   248     indt (j+2*i) ^ "<GUH> " ^ Celem.rls2guh ("IsacKnowledge", thyID) 
   249 				     (id_rls erls) ^ " </GUH>\n" ^
   249 				     (Celem.id_rls erls) ^ " </GUH>\n" ^
   250     indt (j+i) ^"</ERLS>\n" ^
   250     indt (j+i) ^"</ERLS>\n" ^
   251     indt (j+i) ^"<SRLS>\n" ^
   251     indt (j+i) ^"<SRLS>\n" ^
   252     indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
   252     indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
   253     indt (j+2*i) ^ "<STRING> " ^ id_rls erls ^ " </STRING>\n" ^
   253     indt (j+2*i) ^ "<STRING> " ^ Celem.id_rls erls ^ " </STRING>\n" ^
   254     indt (j+2*i) ^ "<GUH> " ^ rls2guh ("IsacKnowledge", thyID) 
   254     indt (j+2*i) ^ "<GUH> " ^ Celem.rls2guh ("IsacKnowledge", thyID) 
   255 				     (id_rls srls) ^ " </GUH>\n" ^
   255 				     (Celem.id_rls srls) ^ " </GUH>\n" ^
   256     indt (j+i) ^"</SRLS>\n" ^
   256     indt (j+i) ^"</SRLS>\n" ^
   257     calcrefs2xml (j+i) (thyID, calc) ^
   257     calcrefs2xml (j+i) (thyID, calc) ^
   258     scr2xml (j+i) scr ^
   258     scr2xml (j+i) scr ^
   259     indt j ^"</RULESET>\n" : xml;
   259     indt j ^"</RULESET>\n";
   260 fun rls2xml j (thyID, Erls) = rls2xml j (thyID, e_rls)
   260 fun rls2xml j (thyID, Celem.Erls) = rls2xml j (thyID, Celem.e_rls)
   261   | rls2xml j (thyID, Rls data) = rls2xm j (thyID, "Rls", data)
   261   | rls2xml j (thyID, Celem.Rls data) = rls2xm j (thyID, "Rls", data)
   262   | rls2xml j (thyID, Seq data) = rls2xm j (thyID, "Seq", data)
   262   | rls2xml j (thyID, Celem.Seq data) = rls2xm j (thyID, "Seq", data)
   263   | rls2xml j (thyID, Rrls {id, prepat, rew_ord=(ord,_), erls, calc, errpatts, scr}) = 
   263   | rls2xml j (thyID, Celem.Rrls {id, prepat, rew_ord=(ord,_), erls, calc, errpatts, scr}) = 
   264     indt j ^"<RULESET>\n"^
   264     indt j ^"<RULESET>\n"^
   265     indt (j+i) ^"<ID> "^ id ^" </ID>\n"^
   265     indt (j+i) ^"<ID> "^ id ^" </ID>\n"^
   266     indt (j+i) ^"<TYPE> Rrls </TYPE>\n"^
   266     indt (j+i) ^"<TYPE> Rrls </TYPE>\n"^
   267     prepat2xml (j+i) prepat ^
   267     prepat2xml (j+i) prepat ^
   268     indt (j+i) ^"<ORDER> " ^
   268     indt (j+i) ^"<ORDER> " ^
   273 				      thyID) ord ^ " </GUH>\n" ^
   273 				      thyID) ord ^ " </GUH>\n" ^
   274 .................................................................*)
   274 .................................................................*)
   275     indt (j+i) ^"</ORDER>\n" ^
   275     indt (j+i) ^"</ORDER>\n" ^
   276     indt (j+i) ^"<ERLS> " ^
   276     indt (j+i) ^"<ERLS> " ^
   277     indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
   277     indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
   278     indt (j+2*i) ^ "<STRING> " ^ id_rls erls ^ " </STRING>\n" ^
   278     indt (j+2*i) ^ "<STRING> " ^ Celem.id_rls erls ^ " </STRING>\n" ^
   279     indt (j+2*i) ^ "<GUH> " ^ rls2guh ("IsacKnowledge", thyID) (id_rls erls) ^ " </GUH>\n" ^
   279     indt (j+2*i) ^ "<GUH> " ^ Celem.rls2guh ("IsacKnowledge", thyID) (Celem.id_rls erls) ^ " </GUH>\n" ^
   280     indt (j+i) ^"</ERLS>\n" ^
   280     indt (j+i) ^"</ERLS>\n" ^
   281     calcrefs2xml (j+i) (thyID, calc) ^
   281     calcrefs2xml (j+i) (thyID, calc) ^
   282     indt (j+i) ^"<SCRIPT>\n"^ 
   282     indt (j+i) ^"<SCRIPT>\n"^ 
   283     scr2xml (j+2*i) scr ^
   283     scr2xml (j+2*i) scr ^
   284     indt (j+i) ^" </SCRIPT>\n"^
   284     indt (j+i) ^" </SCRIPT>\n"^
   285     indt j ^"</RULESET>\n" : xml;
   285     indt j ^"</RULESET>\n";
   286 
   286 
   287 (*** convert sml-datatypes to xml for libisabelle ***)
   287 (*** convert sml-datatypes to xml for libisabelle ***)
   288 
   288 
   289 (** general types: lists,  **)
   289 (** general types: lists,  **)
   290 
   290 
   291 fun xml_of_bool b = XML.Elem (("BOOL", []), [XML.Text (bool2str b)])
   291 fun xml_of_bool b = XML.Elem (("BOOL", []), [XML.Text (bool2str b)])
   292 fun xml_to_bool (XML.Elem (("BOOL", []), [XML.Text b])) = string_to_bool b
   292 fun xml_to_bool (XML.Elem (("BOOL", []), [XML.Text b])) = string_to_bool b
   293   | xml_to_bool tree = raise ERROR ("xml_to_bool: wrong XML.tree \n" ^ xmlstr 0 tree)
   293   | xml_to_bool tree = raise ERROR ("xml_to_bool: wrong XML.tree \n" ^ xmlstr 0 tree)
   294 
   294 
   295 fun xml_to_ketype (XML.Elem (("KETYPE", []), [XML.Text str])) = str2ketype' str
   295 fun xml_to_ketype (XML.Elem (("KETYPE", []), [XML.Text str])) = Celem.str2ketype' str
   296   | xml_to_ketype tree = raise ERROR ("xml_to_ketype: wrong XML.tree \n" ^ xmlstr 0 tree)
   296   | xml_to_ketype tree = raise ERROR ("xml_to_ketype: wrong XML.tree \n" ^ xmlstr 0 tree)
   297 
   297 
   298 fun xml_of_str str = XML.Elem (("STRING", []), [XML.Text str])
   298 fun xml_of_str str = XML.Elem (("STRING", []), [XML.Text str])
   299 fun xml_of_strs strs = XML.Elem (("STRINGLIST", []), map xml_of_str strs)
   299 fun xml_of_strs strs = XML.Elem (("STRINGLIST", []), map xml_of_str strs)
   300 
   300 
   437       pos as XML.Elem ((   "POSITION", []), _),
   437       pos as XML.Elem ((   "POSITION", []), _),
   438       XML.Elem ((          "HEAD", []), [form]),
   438       XML.Elem ((          "HEAD", []), [form]),
   439       imodel as XML.Elem (("MATHML", []), _), (* TODO WN150813 ?!?*)
   439       imodel as XML.Elem (("MATHML", []), _), (* TODO WN150813 ?!?*)
   440       XML.Elem ((          "POS", []), [XML.Text belongsto]),
   440       XML.Elem ((          "POS", []), [XML.Text belongsto]),
   441       spec as XML.Elem ((  "SPECIFICATION", []), _)])) =
   441       spec as XML.Elem ((  "SPECIFICATION", []), _)])) =
   442     (xml_to_pos pos, xml_to_term_NEW form |> term2str, xml_to_imodel imodel, 
   442     (xml_to_pos pos, xml_to_term_NEW form |> Celem.term2str, xml_to_imodel imodel, 
   443     Ctree.str2pos_ belongsto, xml_to_spec spec) : Inform.icalhd
   443     Ctree.str2pos_ belongsto, xml_to_spec spec) : Inform.icalhd
   444   | xml_to_icalhd x = raise ERROR ("xml_to_icalhd: WRONG arg = " ^ xmlstr 0 x)
   444   | xml_to_icalhd x = raise ERROR ("xml_to_icalhd: WRONG arg = " ^ xmlstr 0 x)
   445 
   445 
   446 fun xml_of_sub (id, value) =
   446 fun xml_of_sub (id, value) =
   447   XML.Elem (("PAIR", []), [
   447   XML.Elem (("PAIR", []), [
   451     (XML.Elem (("PAIR", []), [
   451     (XML.Elem (("PAIR", []), [
   452       XML.Elem (("VARIABLE", []), [id]),
   452       XML.Elem (("VARIABLE", []), [id]),
   453       XML.Elem (("VALUE", []), [value])])) = (xml_to_term id, xml_to_term value)
   453       XML.Elem (("VALUE", []), [value])])) = (xml_to_term id, xml_to_term value)
   454   | xml_to_sub x = raise ERROR ("xml_to_sub wrong arg: " ^ xmlstr 0 x)
   454   | xml_to_sub x = raise ERROR ("xml_to_sub wrong arg: " ^ xmlstr 0 x)
   455 fun xml_of_subs (subs : Selem.subs) =
   455 fun xml_of_subs (subs : Selem.subs) =
   456   XML.Elem (("SUBSTITUTION", []), map xml_of_sub (Selem.subs2subst (assoc_thy "Isac") subs))
   456   XML.Elem (("SUBSTITUTION", []), map xml_of_sub (Selem.subs2subst (Celem.assoc_thy "Isac") subs))
   457 fun xml_to_subs
   457 fun xml_to_subs
   458     (XML.Elem (("SUBSTITUTION", []), 
   458     (XML.Elem (("SUBSTITUTION", []), 
   459       subs)) = Selem.subst2subs (map xml_to_sub subs)
   459       subs)) = Selem.subst2subs (map xml_to_sub subs)
   460   | xml_to_subs x = raise ERROR ("xml_to_subs wrong arg: " ^ xmlstr 0 x)
   460   | xml_to_subs x = raise ERROR ("xml_to_subs wrong arg: " ^ xmlstr 0 x)
   461 fun xml_of_sube sube =
   461 fun xml_of_sube sube =
   462   XML.Elem (("SUBSTITUTION", []), map xml_of_sub (Selem.sube2subst (assoc_thy "Isac") sube))
   462   XML.Elem (("SUBSTITUTION", []), map xml_of_sub (Selem.sube2subst (Celem.assoc_thy "Isac") sube))
   463 fun xml_to_sube
   463 fun xml_to_sube
   464     (XML.Elem (("SUBSTITUTION", []), 
   464     (XML.Elem (("SUBSTITUTION", []), 
   465       xml_var_val_pairs)) = Selem.subst2sube (map xml_to_sub xml_var_val_pairs)
   465       xml_var_val_pairs)) = Selem.subst2sube (map xml_to_sub xml_var_val_pairs)
   466   | xml_to_sube x = raise ERROR ("xml_to_sube wrong arg: " ^ xmlstr 0 x)
   466   | xml_to_sube x = raise ERROR ("xml_to_sube wrong arg: " ^ xmlstr 0 x)
   467 
   467 
   468 fun thm''2xml j (thm : thm) =
   468 fun thm''2xml j (thm : thm) =
   469     indt j ^ "<THEOREM>\n" ^
   469     indt j ^ "<THEOREM>\n" ^
   470     indt (j+i) ^ "<ID> " ^ thmID_of_derivation_name' thm ^ " </ID>\n"^
   470     indt (j+i) ^ "<ID> " ^ Celem.thmID_of_derivation_name' thm ^ " </ID>\n"^
   471     term2xml j (Thm.prop_of thm) ^ "\n" ^
   471     term2xml j (Thm.prop_of thm) ^ "\n" ^
   472     indt j ^ "</THEOREM>\n" : xml;
   472     indt j ^ "</THEOREM>\n";
   473 fun xml_of_thm' ((ID, form) : thm') =
   473 fun xml_of_thm' (ID, form) =
   474   XML.Elem (("THEOREM", []), [
   474   XML.Elem (("THEOREM", []), [
   475     XML.Elem (("ID", []), [XML.Text ID]),
   475     XML.Elem (("ID", []), [XML.Text ID]),
   476     XML.Elem (("FORMULA", []), [
   476     XML.Elem (("FORMULA", []), [
   477       XML.Text form])])           (* repair for MathML: use term instead String *)
   477       XML.Text form])])           (* repair for MathML: use term instead String *)
   478 (* at the front-end theorems can be shown by their term, so term is transported isac-java <--- ME *)
   478 (* at the front-end theorems can be shown by their term, so term is transported isac-java <--- ME *)
   479 fun xml_of_thm'' ((ID, thm) : thm'') =
   479 fun xml_of_thm'' (ID, thm) =
   480 (*---xml_of_thm''------------------------------------------thm'_to_thm''--------------
   480 (*---xml_of_thm''------------------------------------------thm'_to_thm''--------------
   481   XML.Elem (("THEOREM", []), [
   481   XML.Elem (("THEOREM", []), [
   482     XML.Elem (("ID", []), [XML.Text ID]),
   482     XML.Elem (("ID", []), [XML.Text ID]),
   483     xml_of_term_NEW term])
   483     xml_of_term_NEW term])
   484 -----xml_of_thm''------------------------------------------thm'_to_thm''------------*)
   484 -----xml_of_thm''------------------------------------------thm'_to_thm''------------*)
   485   XML.Elem (("THEOREM", []), [
   485   XML.Elem (("THEOREM", []), [
   486     XML.Elem (("ID", []), [XML.Text ID]),
   486     XML.Elem (("ID", []), [XML.Text ID]),
   487     XML.Elem (("FORMULA", []), [
   487     XML.Elem (("FORMULA", []), [
   488       XML.Text ((term2str o Thm.prop_of) thm)])])           (* repair for MathML: use term instead String *)
   488       XML.Text ((Celem.term2str o Thm.prop_of) thm)])])           (* repair for MathML: use term instead String *)
   489 
   489 
   490 fun xml_to_thm'
   490 fun xml_to_thm'
   491     (XML.Elem (("THEOREM", []), [
   491     (XML.Elem (("THEOREM", []), [
   492       XML.Elem (("ID", []), [XML.Text ID]),
   492       XML.Elem (("ID", []), [XML.Text ID]),
   493       XML.Elem (("FORMULA", []), [XML.Text "NO_ad_hoc_thm_FROM_FRONTEND = True"])])) =
   493       XML.Elem (("FORMULA", []), [XML.Text "NO_ad_hoc_thm_FROM_FRONTEND = True"])])) =
   494     ((ID, "NO_ad_hoc_thm_FROM_GUI = True") : thm')
   494     (ID, "NO_ad_hoc_thm_FROM_GUI = True")
   495   | xml_to_thm' x = raise ERROR ("xml_of_thm' wrong arg:\n" ^ xmlstr 0 x)
   495   | xml_to_thm' x = raise ERROR ("xml_of_thm' wrong arg:\n" ^ xmlstr 0 x)
   496 (* at the front-end theorems are identified only by their name, so NO isac-java \<longrightarrow> ME *)
   496 (* at the front-end theorems are identified only by their name, so NO isac-java \<longrightarrow> ME *)
   497 fun xml_to_thm''
   497 fun xml_to_thm''
   498 (*---xml_of_thm''------------------------------------------thm'_to_thm''--------------
   498 (*---xml_of_thm''------------------------------------------thm'_to_thm''--------------
   499     (XML.Elem (("THEOREM", []), [
   499     (XML.Elem (("THEOREM", []), [
   503   | xml_to_thm'' x = raise ERROR ("xml_to_thm'' wrong arg:\n" ^ xmlstr 0 x)
   503   | xml_to_thm'' x = raise ERROR ("xml_to_thm'' wrong arg:\n" ^ xmlstr 0 x)
   504 -----xml_of_thm''------------------------------------------thm'_to_thm''------------*)
   504 -----xml_of_thm''------------------------------------------thm'_to_thm''------------*)
   505     (XML.Elem (("THEOREM", []), [
   505     (XML.Elem (("THEOREM", []), [
   506       XML.Elem (("ID", []), [XML.Text ID]),
   506       XML.Elem (("ID", []), [XML.Text ID]),
   507       XML.Elem (("FORMULA", []), [
   507       XML.Elem (("FORMULA", []), [
   508         XML.Text term])])) = (ID, Rewrite.assoc_thm'' (Isac ()) ID) : thm''
   508         XML.Text term])])) = (ID, Rewrite.assoc_thm'' (Celem.Isac ()) ID)
   509   | xml_to_thm'' x = raise ERROR ("xml_of_thm' wrong arg:" ^ xmlstr 0 x)
   509   | xml_to_thm'' x = raise ERROR ("xml_of_thm' wrong arg:" ^ xmlstr 0 x)
   510 
   510 
   511 fun xml_of_src EmptyScr =
   511 fun xml_of_src EmptyScr =
   512     XML.Elem (("NOCODE", []), [XML.Text "empty"])
   512     XML.Elem (("NOCODE", []), [XML.Text "empty"])
   513   | xml_of_src (Prog term) =
   513   | xml_of_src (Celem.Prog term) =
   514     XML.Elem (("CODE", []), [
   514     XML.Elem (("CODE", []), [
   515       if term = e_term then xml_of_src EmptyScr
   515       if term = Celem.e_term then xml_of_src Celem.EmptyScr
   516       else xml_of_term (TermC.inst_abs term)])
   516       else xml_of_term (TermC.inst_abs term)])
   517   | xml_of_src (Rfuns _) =
   517   | xml_of_src (Celem.Rfuns _) =
   518     XML.Elem (("NOCODE", []), [XML.Text "reverse rewrite functions"])
   518     XML.Elem (("NOCODE", []), [XML.Text "reverse rewrite functions"])
   519 
   519 
   520 (*.convert a tactic into xml-format .*)
   520 (*.convert a tactic into xml-format .*)
   521 fun xml_of_tac (Tac.Subproblem (dI, pI)) =
   521 fun xml_of_tac (Tac.Subproblem (dI, pI)) =
   522     XML.Elem (("SUBPROBLEMTACTIC", [("name", "Subproblem")]), [
   522     XML.Elem (("SUBPROBLEMTACTIC", [("name", "Subproblem")]), [
   640     (XML.Elem (("STRINGLISTTACTIC", [
   640     (XML.Elem (("STRINGLISTTACTIC", [
   641       ("name", "Specify_Problem")]), [ct])) = Tac.Specify_Problem (xml_to_strs ct)
   641       ("name", "Specify_Problem")]), [ct])) = Tac.Specify_Problem (xml_to_strs ct)
   642   | xml_to_tac x = raise ERROR ("xml_to_tac: not impl. for " ^ xmlstr 0 x);
   642   | xml_to_tac x = raise ERROR ("xml_to_tac: not impl. for " ^ xmlstr 0 x);
   643 
   643 
   644 val e_pblterm = (Thm.term_of o the o (TermC.parse @{theory Script})) 
   644 val e_pblterm = (Thm.term_of o the o (TermC.parse @{theory Script})) 
   645 		    ("Problem (" ^ e_domID ^ "," ^ strs2str' e_pblID ^ ")");
   645 		    ("Problem (" ^ Celem.e_domID ^ "," ^ strs2str' Celem.e_pblID ^ ")");
   646 
   646 
   647 (*WN051224 minimal adaption to exporting Formulae _only_ by getFormulaeFromTo*)
   647 (*WN051224 minimal adaption to exporting Formulae _only_ by getFormulaeFromTo*)
   648 fun xml_of_posterm (p, t) =
   648 fun xml_of_posterm (p, t) =
   649   let val input_request = Free ("________________________________________________", dummyT)
   649   let val input_request = Free ("________________________________________________", dummyT)
   650   in 
   650   in 
   663 (*.a reference to an element in the theory hierarchy; 
   663 (*.a reference to an element in the theory hierarchy; 
   664    compare 'fun keref2xml'.*)
   664    compare 'fun keref2xml'.*)
   665 (* val (j, thyID, typ, xstring) = 
   665 (* val (j, thyID, typ, xstring) = 
   666        (i+i, snd (thy_containing_rls thy' prls'), "Rulesets", prls');
   666        (i+i, snd (thy_containing_rls thy' prls'), "Rulesets", prls');
   667    *)
   667    *)
   668 fun theref2xml j (thyID:thyID) typ (xstring:xstring) =
   668 fun theref2xml j thyID typ xstring =
   669     let val guh = theID2guh ["IsacKnowledge", thyID, typ, xstring]
   669     let val guh = Celem.theID2guh ["IsacKnowledge", thyID, typ, xstring]
   670 	val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
   670 	val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
   671     in indt j ^ "<KESTOREREF>\n" ^
   671     in indt j ^ "<KESTOREREF>\n" ^
   672        indt (j+i) ^ "<TAG> " ^ typ' ^ " </TAG>\n" ^
   672        indt (j+i) ^ "<TAG> " ^ typ' ^ " </TAG>\n" ^
   673        indt (j+i) ^ "<ID> " ^ xstring ^ " </ID>\n" ^
   673        indt (j+i) ^ "<ID> " ^ xstring ^ " </ID>\n" ^
   674        indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
   674        indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
   675        indt j ^ "</KESTOREREF>\n" : xml
   675        indt j ^ "</KESTOREREF>\n"
   676     end;
   676     end;
   677 fun xml_of_theref (thyid : thyID) typ (xstring : xstring) =
   677 fun xml_of_theref thyid typ xstring =
   678   let 
   678   let 
   679     val guh = theID2guh ["IsacKnowledge", thyid, typ, xstring]
   679     val guh = Celem.theID2guh ["IsacKnowledge", thyid, typ, xstring]
   680     val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
   680     val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
   681   in 
   681   in 
   682     XML.Elem (("KESTOREREF", []),[
   682     XML.Elem (("KESTOREREF", []),[
   683       XML.Elem (("TAG", []), [XML.Text typ']),
   683       XML.Elem (("TAG", []), [XML.Text typ']),
   684       XML.Elem (("ID", []), [XML.Text xstring]),
   684       XML.Elem (("ID", []), [XML.Text xstring]),
   708   | xml_of_contthy (Rtools.ContThmInst {thyID, thm, bdvs, thminst, applto, applat, 
   708   | xml_of_contthy (Rtools.ContThmInst {thyID, thm, bdvs, thminst, applto, applat, 
   709 				reword, asms, lhs, rhs, result, resasms, asmrls}) =
   709 				reword, asms, lhs, rhs, result, resasms, asmrls}) =
   710     XML.Elem (("CONTEXTDATA", []), [
   710     XML.Elem (("CONTEXTDATA", []), [
   711       XML.Elem (("GUH", []), [XML.Text thm]),
   711       XML.Elem (("GUH", []), [XML.Text thm]),
   712       XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
   712       XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
   713         xml_of_cterm (subst2str' bdvs)]),
   713         xml_of_cterm (Celem.subst2str' bdvs)]),
   714       XML.Elem (("INSTANTIATED", []), [xml_of_term thminst]),
   714       XML.Elem (("INSTANTIATED", []), [xml_of_term thminst]),
   715       XML.Elem (("APPLTO", []), [xml_of_term applto]),
   715       XML.Elem (("APPLTO", []), [xml_of_term applto]),
   716       XML.Elem (("APPLAT", []), [xml_of_term applat]),
   716       XML.Elem (("APPLAT", []), [xml_of_term applat]),
   717       XML.Elem (("ORDER", []), [ (* should be a theref2xml *)
   717       XML.Elem (("ORDER", []), [ (* should be a theref2xml *)
   718         XML.Elem (("ID", []), [XML.Text reword])]),
   718         XML.Elem (("ID", []), [XML.Text reword])]),
   734 
   734 
   735   | xml_of_contthy (Rtools.ContRlsInst {thyID = _, rls, bdvs, applto, result, asms}) =
   735   | xml_of_contthy (Rtools.ContRlsInst {thyID = _, rls, bdvs, applto, result, asms}) =
   736     XML.Elem (("CONTEXTDATA", []), [
   736     XML.Elem (("CONTEXTDATA", []), [
   737       XML.Elem (("GUH", []), [XML.Text rls]),
   737       XML.Elem (("GUH", []), [XML.Text rls]),
   738       XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
   738       XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
   739         xml_of_cterm (subst2str' bdvs)]),
   739         xml_of_cterm (Celem.subst2str' bdvs)]),
   740       XML.Elem (("INSTANTIATED", []), [xml_of_cterm (subst2str' bdvs)]),
   740       XML.Elem (("INSTANTIATED", []), [xml_of_cterm (Celem.subst2str' bdvs)]),
   741       XML.Elem (("APPLTO", []), [xml_of_term applto]),
   741       XML.Elem (("APPLTO", []), [xml_of_term applto]),
   742       XML.Elem (("RESULT", []), [xml_of_term result]),
   742       XML.Elem (("RESULT", []), [xml_of_term result]),
   743       XML.Elem (("ASSUMPTIONS", []), map xml_of_term asms)])
   743       XML.Elem (("ASSUMPTIONS", []), map xml_of_term asms)])
   744 
   744 
   745   | xml_of_contthy (Rtools.ContNOrew {thyID = _, thm_rls, applto}) =
   745   | xml_of_contthy (Rtools.ContNOrew {thyID = _, thm_rls, applto}) =
   749 
   749 
   750   | xml_of_contthy (Rtools.ContNOrewInst{thyID = _, thm_rls, bdvs, thminst, applto}) =
   750   | xml_of_contthy (Rtools.ContNOrewInst{thyID = _, thm_rls, bdvs, thminst, applto}) =
   751     XML.Elem (("CONTEXTDATA", []), [
   751     XML.Elem (("CONTEXTDATA", []), [
   752       XML.Elem (("GUH", []), [XML.Text thm_rls]),
   752       XML.Elem (("GUH", []), [XML.Text thm_rls]),
   753       XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
   753       XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
   754         xml_of_cterm (subst2str' bdvs)]),
   754         xml_of_cterm (Celem.subst2str' bdvs)]),
   755       XML.Elem (("INSTANTIATED", []), [xml_of_term thminst]),
   755       XML.Elem (("INSTANTIATED", []), [xml_of_term thminst]),
   756       XML.Elem (("APPLTO", []), [xml_of_term applto])])
   756       XML.Elem (("APPLTO", []), [xml_of_term applto])])
   757 
   757 
   758 fun xml_of_matchpbl (model_ok, pI, hdl, pbl, pre) =
   758 fun xml_of_matchpbl (model_ok, pI, hdl, pbl, pre) =
   759   XML.Elem (("CONTEXTDATA", []), [
   759   XML.Elem (("CONTEXTDATA", []), [