src/Tools/isac/xmlsrc/datatypes.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Sat, 15 Aug 2015 16:03:53 +0200
changeset 59162 6a69fb432973
parent 59161 49efc0b16e24
child 59171 4aa3dfc17a5d
permissions -rw-r--r--
PIDE-phase-2a: changed XML for Tactic, driven from isac-java

cf. https://intra.ist.tugraz.at/hg/isac/rev/3ed5dc655f8e
neuper@37906
     1
(* convert sml-datatypes to xml
neuper@37906
     2
   authors: Walther Neuper 2003
neuper@37906
     3
   (c) due to copyright terms
neuper@37906
     4
neuper@37906
     5
use"xmlsrc/datatypes.sml";
neuper@37906
     6
use"datatypes.sml";
neuper@37906
     7
*)
neuper@37906
     8
neuper@37940
     9
neuper@37906
    10
signature DATATYPES =
neuper@37906
    11
  sig
neuper@37906
    12
    val authors2xml : int -> string -> string list -> xml
neuper@37906
    13
    val calc2xml : int -> thyID * calc -> xml
neuper@37906
    14
    val calcrefs2xml : int -> thyID * calc list -> xml
neuper@37906
    15
    val contthy2xml : int -> contthy -> xml
neuper@37906
    16
    val extref2xml : int -> string -> string -> xml
neuper@37906
    17
    val filterpbl :
neuper@37906
    18
       ''a -> (''a * (Term.term * Term.term)) list -> Term.term list
neuper@37906
    19
    val formula2xml : int -> Term.term -> xml
neuper@37906
    20
    val formulae2xml : int -> Term.term list -> xml
neuper@37906
    21
    val i : int
neuper@37906
    22
    val id2xml : int -> string list -> string
neuper@37906
    23
    val ints2xml : int -> int list -> string
neuper@37906
    24
    val itm_2xml : int -> SpecifyTools.itm_ -> xml
neuper@37906
    25
    val itms2xml :
neuper@37906
    26
       int ->
neuper@37906
    27
       (int * SpecifyTools.vats * bool * string * SpecifyTools.itm_) list ->
neuper@37906
    28
       string
neuper@37906
    29
    val keref2xml : int -> ketype -> kestoreID -> xml
neuper@37906
    30
    val model2xml :
neuper@37906
    31
       int -> SpecifyTools.itm list -> (bool * Term.term) list -> xml
neuper@37906
    32
    val modspec2xml : int -> ocalhd -> xml
neuper@37906
    33
    val pattern2xml :
neuper@37906
    34
       int ->
neuper@37906
    35
       (string * (Term.term * Term.term)) list -> Term.term list -> string
neuper@37906
    36
    val pos'2xml : int -> string * (int list * pos_) -> string
neuper@37906
    37
    val pos'calchead2xml : int -> pos' * ocalhd -> xml
neuper@37906
    38
    val pos_2xml : int -> pos_ -> string
neuper@37906
    39
    val posform2xml : int -> pos' * Term.term -> xml
neuper@37906
    40
    val posformhead2xml : int -> pos' * ptform -> string
neuper@37906
    41
    val posformheads2xml : int -> (pos' * ptform) list -> xml
neuper@37906
    42
    val posforms2xml : int -> (pos' * Term.term) list -> xml
neuper@37906
    43
    val posterms2xml : int -> (pos' * term) list -> xml
neuper@37906
    44
    val precond2xml : int -> bool * Term.term -> xml
neuper@37906
    45
    val preconds2xml : int -> (bool * Term.term) list -> xml
neuper@37906
    46
    val rls2xml : int -> thyID * rls -> xml
neuper@37906
    47
    val rule2xml : int -> guh -> rule -> xml
neuper@37906
    48
    val rules2xml : int -> guh -> rule list -> xml
neuper@37906
    49
    val scr2xml : int -> scr -> xml
neuper@37906
    50
    val spec2xml : int -> spec -> xml
neuper@37906
    51
    val sub2xml : int -> Term.term * Term.term -> xml
neuper@37906
    52
    val subs2xml : int -> subs -> xml
neuper@37906
    53
    val subst2xml : int -> subst -> xml
neuper@37906
    54
    val tac2xml : int -> tac -> xml
neuper@37906
    55
    val tacs2xml : int -> tac list -> xml
neuper@37906
    56
    val theref2xml : int -> thyID -> string -> xstring -> string
neuper@37906
    57
    val thm'2xml : int -> thm' -> xml
neuper@37906
    58
    val thm''2xml : int -> thm -> xml
neuper@37906
    59
    val thmstr2xml : int -> string -> xml
neuper@37906
    60
  end
neuper@37906
    61
neuper@37906
    62
neuper@37906
    63
wneuper@59124
    64
(*------------------------------------------------------------------
neuper@37906
    65
structure datatypes:DATATYPES =
neuper@37940
    66
(*structure datatypes =*)
neuper@37906
    67
struct
wneuper@59124
    68
------------------------------------------------------------------*)
neuper@37906
    69
neuper@37906
    70
(** general types: lists,  **)
neuper@37906
    71
wneuper@59124
    72
fun xml_of_bool b = XML.Elem (("BOOL", []), [XML.Text (bool2str b)])
wneuper@59124
    73
fun xml_to_bool (XML.Elem (("BOOL", []), [XML.Text b])) = string_to_bool b
wneuper@59149
    74
  | xml_to_bool tree = error ("xml_to_bool: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59124
    75
wneuper@59156
    76
fun xml_to_ketype (XML.Elem (("KETYPE", []), [XML.Text str])) = str2ketype str
wneuper@59156
    77
  | xml_to_ketype tree = error ("xml_to_ketype: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59156
    78
neuper@37906
    79
(*.handles string list like 'fun id2xml'.*)
neuper@37906
    80
fun authors2xml j str auts = 
neuper@37906
    81
    let fun autx _ [] = ""
neuper@37906
    82
	  | autx j (s::ss) = (indt j) ^ "<STRING> " ^ s ^ " </STRING>\n" ^ 
neuper@37906
    83
			     (autx j ss)
neuper@37906
    84
    in indt j ^ "<"^str^">\n" ^
neuper@37906
    85
       autx (j + i) auts ^ 
neuper@37906
    86
       indt j ^ "</"^str^">\n" : xml
neuper@37906
    87
    end;
neuper@38031
    88
(* writeln(authors2xml 2 "MATHAUTHORS" []);
neuper@38031
    89
   writeln(authors2xml 2 "MATHAUTHORS" 
neuper@37906
    90
		       ["isac-team 2001", "Richard Lang 2003"]);
neuper@37906
    91
   *)
neuper@37906
    92
neuper@37906
    93
fun id2xml j ids =
neuper@37906
    94
    let fun id2x _ [] = ""
neuper@37906
    95
	  | id2x j (s::ss) = (indt j) ^ "<STRING> " ^ s ^ " </STRING>\n" ^ 
neuper@37906
    96
			     (id2x j ss)
neuper@37906
    97
    in (indt j) ^ "<STRINGLIST>\n" ^ 
neuper@37906
    98
       (id2x (j + indentation) ids) ^ 
neuper@37906
    99
       (indt j) ^ "</STRINGLIST>\n" end;
neuper@38031
   100
(* writeln(id2xml 8 ["linear","univariate","equation"]);
neuper@37906
   101
        <STRINGLIST>
neuper@37906
   102
          <STRING>linear</STRING>
neuper@37906
   103
          <STRING>univariate</STRING>
neuper@37906
   104
          <STRING>equation</STRING>
neuper@37906
   105
        </STRINGLIST>*)
neuper@37906
   106
wneuper@59124
   107
fun xml_of_str str = XML.Elem (("STRING", []), [XML.Text str])
wneuper@59124
   108
fun xml_of_strs strs = XML.Elem (("STRINGLIST", []), map xml_of_str strs)
wneuper@59124
   109
wneuper@59124
   110
fun xml_to_str (XML.Elem (("STRING", []), [XML.Text str])) = str
wneuper@59149
   111
  | xml_to_str tree = error ("xml_to_str: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59124
   112
fun xml_to_strs (XML.Elem (("STRINGLIST", []), strs)) = map xml_to_str strs
wneuper@59148
   113
  | xml_to_strs tree = error ("xml_to_strs: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59124
   114
neuper@37906
   115
fun ints2xml j ids =
neuper@37906
   116
    let fun int2x _ [] = ""
neuper@37906
   117
	  | int2x j (s::ss) = (indt j) ^"<INT> "^ string_of_int s ^" </INT>\n"^
neuper@37906
   118
			     (int2x j ss)
neuper@37906
   119
    in (indt j) ^ "<INTLIST>\n" ^ 
neuper@37906
   120
       (int2x (j + i) ids) ^ 
neuper@37906
   121
       (indt j) ^ "</INTLIST>\n" end;
neuper@38031
   122
(* writeln(ints2xml 3 [1,2,3]);
neuper@37906
   123
   *)
wneuper@59124
   124
fun xml_of_int i = XML.Elem (("INT", []), [XML.Text (string_of_int i)])
wneuper@59124
   125
fun xml_of_ints is = (*xml/datatypes.sml: fun ints2xml*)
wneuper@59124
   126
  XML.Elem (("INTLIST", []), map xml_of_int is)
wneuper@59124
   127
wneuper@59124
   128
fun xml_to_int (XML.Elem (("INT", []), [XML.Text i])) = 
wneuper@59124
   129
      (case int_of_str i of SOME i => i | _ => error "xml_to_int: int_of_str \<Rightarrow> NONE")
wneuper@59149
   130
  | xml_to_int tree = error ("xml_to_int: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59124
   131
fun xml_to_ints (XML.Elem (("INTLIST", []), is)) = map xml_to_int is
wneuper@59149
   132
  | xml_to_ints tree = error ("xml_to_ints: wrong XML.tree \n" ^ xmlstr 0 tree)
neuper@37906
   133
neuper@37906
   134
neuper@37906
   135
(** isac datatypes **)
neuper@37906
   136
neuper@37906
   137
fun pos_2xml j pos_ =
neuper@37906
   138
    (indt j) ^ "<POS> " ^  pos_2str pos_ ^ " </POS>\n";
neuper@37906
   139
neuper@37906
   140
(*.due to specialties of isac/util/parser/XMLParseDigest.java
neuper@37906
   141
   pos' requires different tags.*)
neuper@37906
   142
fun pos'2xml j (tag, (pos, pos_)) =
neuper@37906
   143
    indt     (j) ^ "<" ^ tag ^ ">\n" ^ 
neuper@37906
   144
    ints2xml (j+i) pos ^ 
neuper@37906
   145
    pos_2xml (j+i) pos_ ^ 
neuper@37906
   146
    indt     (j) ^ "</" ^ tag ^ ">\n";
neuper@38031
   147
(* writeln(pos'2xml 3 ("POSITION", ([1,2,3], Pbl)));
neuper@37906
   148
   *)
wneuper@59124
   149
fun xml_of_pos tag (is, pp) = (*xml/datatypes.sml: fun pos'2xml*)
wneuper@59124
   150
  XML.Elem ((tag, []), [
wneuper@59124
   151
    xml_of_ints is,
wneuper@59124
   152
    XML.Elem (("POS", []), [XML.Text (pos_2str pp)])])
wneuper@59124
   153
fun xml_to_pos_ (XML.Elem (("POS", []), [XML.Text pp])) = str2pos_ pp
wneuper@59149
   154
  | xml_to_pos_ tree = error ("xml_to_pos_: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59124
   155
fun xml_to_pos (XML.Elem (("POSITION", []), [is, pp])) = (xml_to_ints is, xml_to_pos_ pp) (*: pos'*)
wneuper@59149
   156
  | xml_to_pos tree = error ("xml_to_pos: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59124
   157
wneuper@59124
   158
fun xml_of_auto (Step i) = 
wneuper@59124
   159
      XML.Elem (("AUTO", []), [XML.Text "Step", XML.Text (string_of_int i)])
wneuper@59124
   160
  | xml_of_auto CompleteModel = XML.Elem (("AUTO", []), [XML.Text "CompleteModel"])
wneuper@59124
   161
  | xml_of_auto CompleteCalcHead = XML.Elem (("AUTO", []), [XML.Text "CompleteCalcHead"])
wneuper@59124
   162
  | xml_of_auto CompleteToSubpbl = XML.Elem (("AUTO", []), [XML.Text "CompleteToSubpbl"])
wneuper@59124
   163
  | xml_of_auto CompleteSubpbl = XML.Elem (("AUTO", []), [XML.Text "CompleteSubpbl"])
wneuper@59124
   164
  | xml_of_auto CompleteCalc = XML.Elem (("AUTO", []), [XML.Text "CompleteCalc"])
wneuper@59124
   165
fun xml_to_auto (XML.Elem (("AUTO", []), [XML.Text "Step", XML.Text i])) = Step (int_of_str i |>the)
wneuper@59124
   166
  | xml_to_auto (XML.Elem (("AUTO", []), [XML.Text "CompleteModel"])) = CompleteModel
wneuper@59124
   167
  | xml_to_auto (XML.Elem (("AUTO", []), [XML.Text "CompleteCalcHead"])) = CompleteCalcHead
wneuper@59124
   168
  | xml_to_auto (XML.Elem (("AUTO", []), [XML.Text "CompleteToSubpbl"])) = CompleteToSubpbl
wneuper@59124
   169
  | xml_to_auto (XML.Elem (("AUTO", []), [XML.Text "CompleteSubpbl"])) = CompleteSubpbl
wneuper@59124
   170
  | xml_to_auto (XML.Elem (("AUTO", []), [XML.Text "CompleteCalc"])) = CompleteCalc
wneuper@59149
   171
  | xml_to_auto tree = error ("xml_to_auto: wrong XML.tree \n" ^ xmlstr 0 tree)
neuper@37906
   172
neuper@37906
   173
fun formula2xml j term = (*TODO.WN050211: use for _all_ <FORMULA>*)
neuper@37906
   174
    indt j ^ "<FORMULA>\n"^
neuper@37906
   175
    term2xml j term ^"\n"^
neuper@37906
   176
    indt j ^ "</FORMULA>\n" : xml;
wneuper@59136
   177
fun xml_of_formula term = 
wneuper@59157
   178
  XML.Elem (("FORMULA", []), [xml_of_term term])
wneuper@59154
   179
fun xml_to_formula 
wneuper@59157
   180
      (XML.Elem (("FORMULA", []), [form])) = xml_to_term form
wneuper@59157
   181
  | xml_to_formula x = raise ERROR ("xml_to_formula wrong arg: " ^ xmlstr 0 x)
wneuper@59154
   182
(* TODO test/Tools/isac/xmlsrc/datatypes.sml*)
wneuper@59136
   183
neuper@37906
   184
fun formulae2xml j [] = ("":xml)
neuper@37906
   185
  | formulae2xml j (r::rs) = formula2xml j r ^ formulae2xml j rs;
neuper@38031
   186
(* writeln(formulae2xml 6 [str2term "1+1=2", str2term "1+1+1=3"]);
neuper@37906
   187
   *)
neuper@37906
   188
neuper@37906
   189
(*WN0502 @see ME/ctree: type asms: illdesigned, thus not used*)
neuper@37906
   190
fun posform2xml j (p:pos', term) =
neuper@37906
   191
    indt j ^     "<POSFORM>\n" ^
neuper@37906
   192
    pos'2xml (j+i) ("POSITION", p) ^
neuper@37906
   193
    indt     (j+i) ^ "<FORMULA>\n"^
neuper@37906
   194
    term2xml (j+i) term ^"\n"^
neuper@37906
   195
    indt     (j+i) ^ "</FORMULA>\n"^
neuper@37906
   196
    indt j ^     "</POSFORM>\n" : xml;
neuper@38031
   197
(* writeln(posform2xml 6 (([1,2],Frm), str2term "1+1=2"));
neuper@37906
   198
   *)
neuper@37906
   199
fun posforms2xml j [] = ("":xml)
neuper@37906
   200
  | posforms2xml j (r::rs) = posform2xml j r ^ posforms2xml j rs;
neuper@38031
   201
(* writeln(posforms2xml 6 [(([1],Res), str2term "1+1=2"),(([2],Res), str2term "1+1+1=3")]);
neuper@37906
   202
   *)
neuper@37906
   203
neuper@37906
   204
fun calcref2xml j (thyID:thyID, (scrop, (rewop, _)):calc) =
neuper@37906
   205
    indt j ^ "<CALCREF>\n" ^
neuper@37906
   206
    indt (j+i) ^ "<STRING> " ^ scrop ^ "</STRING>\n" ^
neuper@37906
   207
    indt (j+i) ^ "<GUH> " ^ cal2guh ("IsacKnowledge", 
neuper@37906
   208
				      thyID) scrop  ^ " </GUH>\n" ^
neuper@37906
   209
    indt j ^ "</CALCREF>\n" : xml;
neuper@37906
   210
fun calcrefs2xml _ (_,[]) = "":xml
neuper@37906
   211
  | calcrefs2xml j (thyID, cal::cs) = 
neuper@37906
   212
    calcref2xml j (thyID, cal) ^ calcrefs2xml j (thyID, cs);
neuper@37906
   213
neuper@37906
   214
fun calc2xml j (thyID:thyID, (scrop, (rewop, _)):calc) =
neuper@37906
   215
    indt j ^ "<CALC>\n" ^
neuper@37906
   216
    indt (j+i) ^ "<STRING>\n" ^ scrop ^ "</STRING>\n" ^
neuper@37906
   217
    indt (j+i) ^ "<GUH>\n" ^ cal2guh ("IsacKnowledge", 
neuper@37906
   218
				      thyID) scrop  ^ "</GUH>\n" ^
neuper@37906
   219
    indt (j+i) ^ "<TERMOP>\n" ^ rewop ^ "</TERMOP>\n" ^
neuper@37906
   220
    indt j ^ "</CALC>\n" : xml;
neuper@37906
   221
neuper@37906
   222
(*.for creating a href for a rule within an rls's rule list;
neuper@37906
   223
   the guh points to the thy of definition of the rule, NOT of use in rls.*)
neuper@37906
   224
fun rule2xml j (thyID:thyID) Erule =
neuper@42407
   225
      error "rule2xml called with 'Erule'"
neuper@42400
   226
  | rule2xml j thyID (Thm (thmDeriv, thm)) =
neuper@42407
   227
      indt j ^ "<RULE>\n" ^
neuper@42407
   228
      indt (j+i) ^ "<TAG> Theorem </TAG>\n" ^
neuper@42407
   229
      indt (j+i) ^ "<STRING> " ^ thmID_of_derivation_name thmDeriv ^ " </STRING>\n" ^
neuper@42407
   230
      indt (j+i) ^ "<GUH> " ^ 
neuper@42407
   231
        thm2guh (thy_containing_thm thmDeriv) (thmID_of_derivation_name thmDeriv) ^ " </GUH>\n" ^
neuper@42407
   232
        indt j ^ "</RULE>\n" : xml
neuper@37906
   233
  | rule2xml j thyID (Calc (termop, _)) = ""
neuper@37906
   234
(*FIXXXXXXXME.WN060714 in rls make Calc : calc -> rule [add scriptop!]
neuper@37906
   235
  see smltest/../datatypes.sml !
neuper@37906
   236
    indt j ^ "<RULE>\n" ^
neuper@37906
   237
    indt (j+i) ^ "<STRING> " ^ termop ^ " </STRING>\n" ^
neuper@37906
   238
    indt (j+i) ^ "<GUH> " ^ cal2guh (thy_containing_cal thyID termop) 
neuper@37906
   239
				    termop ^ " </GUH>\n" ^
neuper@37906
   240
    indt j ^ "</RULE>\n"
neuper@37906
   241
*)
neuper@37906
   242
  | rule2xml j thyID (Cal1 (termop, _)) = ""
neuper@37906
   243
  | rule2xml j thyID (Rls_ rls) =
neuper@42407
   244
      let val rls' = (#id o rep_rls) rls
neuper@42407
   245
      in
neuper@42407
   246
        indt j ^ "<RULE>\n" ^
neuper@42407
   247
        indt (j+i) ^ "<TAG> Ruleset </TAG>\n" ^
neuper@42407
   248
        indt (j+i) ^ "<STRING> " ^ rls' ^ " </STRING>\n" ^
neuper@42407
   249
        indt (j+i) ^ "<GUH> " ^ rls2guh (thy_containing_rls thyID rls') rls' ^ " </GUH>\n" ^
neuper@42407
   250
        indt j ^ "</RULE>\n"
neuper@42407
   251
      end;
neuper@42407
   252
neuper@37906
   253
fun rules2xml j thyID [] = ("":xml)
neuper@37906
   254
  | rules2xml j thyID (r::rs) = rule2xml j thyID r ^ rules2xml j thyID rs;
neuper@37906
   255
neuper@37906
   256
fun filterpbl str =
neuper@37906
   257
  let fun filt [] = []
neuper@37906
   258
        | filt ((s, (t1, t2)) :: ps) = 
neuper@37906
   259
	  if str = s then (t1 $ t2) :: filt ps else filt ps
neuper@37906
   260
  in filt end;
neuper@37906
   261
neuper@37906
   262
(*FIXME.WN040831 model2xml <--?--> pattern2xml*)
neuper@38031
   263
(*WN.25.8.03: pattern2xml different output with TextIO | writeln !!!
neuper@37906
   264
  the version below is for TextIO: terms2xml makes \n !*)
neuper@37906
   265
(* val (j, p, where_) = (i, ppc, where_);
neuper@37906
   266
   *)
neuper@37906
   267
fun pattern2xml j p where_ =
neuper@37906
   268
    (case filterpbl "#Given" p of
neuper@37906
   269
	[] =>  (indt j) ^ "<GIVEN>  </GIVEN>\n"
neuper@37906
   270
(* val gis = filterpbl "#Given" p;
neuper@37906
   271
   *)
neuper@37906
   272
      | gis => (indt j) ^ "<GIVEN>\n" ^ terms2xml' j gis ^
neuper@37906
   273
	       (indt j) ^ "</GIVEN>\n")
neuper@37906
   274
    ^ 
neuper@37906
   275
    (case where_ of
neuper@37906
   276
	 [] =>  (indt j) ^ "<WHERE>  </WHERE>\n"
neuper@37906
   277
       | whs => (indt j) ^ "<WHERE>\n" ^ terms2xml' j whs ^
neuper@37906
   278
		(indt j) ^ "</WHERE>\n")
neuper@37906
   279
    ^ 
neuper@37906
   280
    (case filterpbl "#Find" p of
neuper@37906
   281
	 [] =>  (indt j) ^ "<FIND>  </FIND>\n"
neuper@37906
   282
       | fis => (indt j) ^ "<FIND>\n" ^ terms2xml' j fis ^
neuper@37906
   283
		(indt j) ^ "</FIND>\n")
neuper@37906
   284
    ^ 
neuper@37906
   285
    (case filterpbl "#Relate" p of
neuper@37906
   286
	 [] =>  (indt j) ^ "<RELATE>  </RELATE>\n"
neuper@37906
   287
       | res => (indt j) ^ "<RELATE>\n" ^ terms2xml' j res ^
neuper@37906
   288
		(indt j) ^ "</RELATE>\n");
neuper@37906
   289
(*
neuper@38031
   290
writeln(pattern2xml 3 ((#ppc o get_pbt)
neuper@37906
   291
			 ["squareroot","univariate","equation","test"]) []);
neuper@37906
   292
  *)
neuper@37906
   293
neuper@37906
   294
(*see itm_2item*)
wneuper@59127
   295
fun itm_2xml j (Cor (dts,_)) =
neuper@37906
   296
    (indt j ^"<ITEM status=\"correct\">\n"^    
neuper@37906
   297
    term2xml (j) (comp_dts' dts)^"\n"^    
neuper@37906
   298
    indt j ^"</ITEM>\n"):xml
neuper@37906
   299
  | itm_2xml j (Syn c) =
neuper@37906
   300
    indt j ^"<ITEM status=\"syntaxerror\">\n"^    
neuper@37906
   301
    indt (j) ^c^    
neuper@37906
   302
    indt j ^"</ITEM>\n"
neuper@37906
   303
  | itm_2xml j (Typ c) =
neuper@37906
   304
    indt j ^"<ITEM status=\"typeerror\">\n"^    
neuper@37906
   305
    indt (j) ^c^    
neuper@37906
   306
    indt j ^"</ITEM>\n"
neuper@37906
   307
  (*type item also has 'False of cterm' set in preconds2xml WN 050618*)
neuper@37906
   308
  | itm_2xml j (Inc (dts,_)) = 
neuper@37906
   309
    indt j ^"<ITEM status=\"incomplete\">\n"^    
neuper@37906
   310
    term2xml (j) (comp_dts' dts)^"\n"^    
neuper@37906
   311
    indt j ^"</ITEM>\n"
neuper@37906
   312
  | itm_2xml j (Sup dts) = 
neuper@37906
   313
    indt j ^"<ITEM status=\"superfluous\">\n"^    
neuper@37906
   314
    term2xml (j) (comp_dts' dts)^"\n"^    
neuper@37906
   315
    indt j ^"</ITEM>\n"
neuper@37906
   316
  | itm_2xml j (Mis (d,pid)) =
neuper@37906
   317
    indt j ^"<ITEM status=\"missing\">\n"^    
neuper@37906
   318
    term2xml (j) (d $ pid)^"\n"^    
neuper@37906
   319
    indt j ^"</ITEM>\n";
wneuper@59127
   320
fun xml_of_itm_ (Cor (dts, _)) =
wneuper@59127
   321
    XML.Elem (("ITEM", [("status", "correct")]), [xml_of_term (comp_dts' dts)])
wneuper@59127
   322
  | xml_of_itm_ (Syn c) =
wneuper@59127
   323
    XML.Elem (("ITEM", [("status", "syntaxerror")]), [XML.Text c])
wneuper@59127
   324
  | xml_of_itm_ (Typ c) =
wneuper@59127
   325
    XML.Elem (("ITEM", [("status", "typeerror")]), [XML.Text c])
wneuper@59127
   326
  (*type item also has 'False of cterm' set in preconds2xml WN 050618*)
wneuper@59127
   327
  | xml_of_itm_ (Inc (dts, _)) = 
wneuper@59127
   328
    XML.Elem (("ITEM", [("status", "incomplete")]), [xml_of_term (comp_dts' dts)])
wneuper@59127
   329
  | xml_of_itm_ (Sup dts) = 
wneuper@59127
   330
    XML.Elem (("ITEM", [("status", "superfluous")]), [xml_of_term (comp_dts' dts)])
wneuper@59127
   331
  | xml_of_itm_ (Mis (d, pid)) = 
wneuper@59127
   332
    XML.Elem (("ITEM", [("status", "missing")]), [xml_of_term (d $ pid)])
neuper@37906
   333
neuper@37906
   334
(*see terms2xml' fpr \n*)
neuper@37906
   335
fun itms2xml _ [] = ""
neuper@37906
   336
  | itms2xml j [(_,_,_,_,itm_)] = itm_2xml j itm_
neuper@37906
   337
  | itms2xml j (((_,_,_,_,itm_):itm)::itms) =
neuper@37906
   338
    itm_2xml j itm_ ^ itms2xml j itms;
wneuper@59127
   339
fun xml_of_itms itms =
wneuper@59127
   340
  let 
wneuper@59127
   341
    fun extract (_, _, _, _, itm_) = itm_
wneuper@59127
   342
      | extract _ = error "xml_of_itms.extract: wrong argument" 
wneuper@59127
   343
  in map (xml_of_itm_ o extract) itms end
neuper@37906
   344
neuper@37906
   345
fun precond2xml j (true, term) =
neuper@37906
   346
    (indt j ^"<ITEM status=\"correct\">\n"^
neuper@37906
   347
    term2xml (j) term^"\n"^
neuper@37906
   348
    indt j ^"</ITEM>\n"):xml
neuper@37906
   349
  | precond2xml j (false, term) =
neuper@37906
   350
    indt j ^"<ITEM status=\"false\">\n"^
neuper@37906
   351
    term2xml (j+i) term^"\n"^
neuper@37906
   352
    indt j ^"</ITEM>\n";
wneuper@59127
   353
fun xml_of_precond (status, term) =
wneuper@59127
   354
    XML.Elem (("ITEM", [("status", if status then "correct" else "false")]), [xml_of_term term])
neuper@37906
   355
neuper@37906
   356
fun preconds2xml _ [] = ("":xml)
neuper@37906
   357
  | preconds2xml j (p::ps) = precond2xml j p ^ preconds2xml j ps;
wneuper@59127
   358
fun xml_of_preconds ps = map xml_of_precond ps
neuper@37906
   359
neuper@37906
   360
(*FIXME.WN040831 model2xml <--?--> pattern2xml*)
neuper@37906
   361
fun model2xml j (itms:itm list) where_ =
wneuper@59127
   362
  let fun eq4 str (_,_,_,field,_) = str = field
wneuper@59127
   363
  in  (indt j ^"<MODEL>\n"^
wneuper@59127
   364
    (case filter (eq4 "#Given") itms of
wneuper@59127
   365
         [] =>  (indt (j+i)) ^ "<GIVEN>  </GIVEN>\n"
wneuper@59127
   366
       | gis => (indt (j+i)) ^ "<GIVEN>\n" ^ itms2xml (j+2*i) gis ^
wneuper@59127
   367
          (indt (j+i)) ^ "</GIVEN>\n")
wneuper@59127
   368
    ^
wneuper@59127
   369
    (case where_ of
wneuper@59127
   370
         [] =>  (indt (j+i)) ^ "<WHERE>  </WHERE>\n"
wneuper@59127
   371
       | whs => (indt (j+i)) ^ "<WHERE>\n" ^ preconds2xml (j+2*i) whs ^
wneuper@59127
   372
          (indt (j+i)) ^ "</WHERE>\n")
wneuper@59127
   373
    ^
wneuper@59127
   374
    (case filter (eq4 "#Find") itms of
wneuper@59127
   375
         [] =>  (indt (j+i)) ^ "<FIND>  </FIND>\n"
wneuper@59127
   376
       | fis => (indt (j+i)) ^ "<FIND>\n" ^ itms2xml (j+2*i) fis ^
wneuper@59127
   377
          (indt (j+i)) ^ "</FIND>\n")
wneuper@59127
   378
    ^
wneuper@59127
   379
    (case filter (eq4 "#Relate") itms of
wneuper@59127
   380
         [] =>  (indt (j+i)) ^ "<RELATE>  </RELATE>\n"
wneuper@59127
   381
       | res => (indt (j+i)) ^ "<RELATE>\n" ^ itms2xml (j+2*i) res ^
wneuper@59127
   382
          (indt (j+i)) ^ "</RELATE>\n")^
wneuper@59127
   383
        indt j ^"</MODEL>\n"):xml
wneuper@59127
   384
  end;
neuper@38031
   385
(* writeln(model2xml 3 itms []);
neuper@37906
   386
   *)
wneuper@59127
   387
fun xml_of_model itms where_ =
wneuper@59127
   388
  let
wneuper@59127
   389
    fun eq str (_, _, _,field, _) = str = field
wneuper@59127
   390
  in 
wneuper@59127
   391
    XML.Elem (("MODEL", []), [
wneuper@59127
   392
      XML.Elem (("GIVEN", []), 
wneuper@59127
   393
        filter (eq "#Given") itms |> xml_of_itms),
wneuper@59127
   394
      XML.Elem (("WHERE", []), 
wneuper@59127
   395
        xml_of_preconds where_),
wneuper@59127
   396
      XML.Elem (("FIND", []), 
wneuper@59127
   397
        filter (eq "#Find") itms |> xml_of_itms),
wneuper@59127
   398
      XML.Elem (("RELATE", []), 
wneuper@59127
   399
        filter (eq "#Relate") itms |> xml_of_itms)])
wneuper@59127
   400
  end 
neuper@37906
   401
neuper@37906
   402
fun spec2xml j ((dI,pI,mI):spec) =
neuper@37906
   403
    (indt j ^"<SPECIFICATION>\n"^
neuper@37906
   404
    indt (j+i) ^"<THEORYID> "^ dI ^" </THEORYID>\n"^
neuper@37906
   405
    indt (j+i) ^"<PROBLEMID>\n"^
neuper@37906
   406
    id2xml (j+2*i) pI ^
neuper@37906
   407
    indt (j+i) ^"</PROBLEMID>\n"^
neuper@37906
   408
    indt (j+i) ^"<METHODID>\n"^
neuper@37906
   409
    id2xml (j+2*i) mI ^
neuper@37906
   410
    indt (j+i) ^"</METHODID>\n"^
neuper@37906
   411
    indt j ^"</SPECIFICATION>\n"):xml;
wneuper@59124
   412
fun xml_of_spec (thyID, pblID, metID) =
wneuper@59124
   413
  XML.Elem (("SPECIFICATION", []), [
wneuper@59124
   414
    XML.Elem (("THEORYID", []), [XML.Text thyID]),
wneuper@59124
   415
    XML.Elem (("PROBLEMID", []), [xml_of_strs pblID]),
wneuper@59124
   416
    XML.Elem (("METHODID", []), [xml_of_strs metID])])
wneuper@59124
   417
fun xml_to_spec (XML.Elem (("SPECIFICATION", []), [
wneuper@59124
   418
      XML.Elem (("THEORYID", []), [XML.Text thyID]),
wneuper@59141
   419
      XML.Elem (("PROBLEMID", []), [ps]),
wneuper@59141
   420
      XML.Elem (("METHODID", []), [ms])])) = (thyID, xml_to_strs ps, xml_to_strs ms)
wneuper@59149
   421
  | xml_to_spec tree = error ("xml_to_spec: wrong XML.tree \n" ^ xmlstr 0 tree)
neuper@37906
   422
wneuper@59148
   423
fun xml_of_variant (items, spec) = 
wneuper@59148
   424
  XML.Elem (("VARIANT", []), [xml_of_strs items, xml_of_spec spec])
wneuper@59148
   425
fun xml_to_variant (XML.Elem (("VARIANT", []), [items, spec])) = 
wneuper@59148
   426
    (xml_to_strs items, xml_to_spec spec)
wneuper@59149
   427
  | xml_to_variant tree = error ("xml_to_variant: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59148
   428
wneuper@59141
   429
fun xml_of_fmz [] = xml_of_fmz [e_fmz]
wneuper@59148
   430
  | xml_of_fmz vs = XML.Elem (("FORMALIZATION", []), map xml_of_variant vs)
wneuper@59148
   431
fun xml_to_fmz (XML.Elem (("FORMALIZATION", []), vars)) = map xml_to_variant vars
wneuper@59149
   432
  | xml_to_fmz tree = error ("xml_to_fmz: wrong XML.tree \n" ^ xmlstr 0 tree)
wneuper@59141
   433
neuper@37906
   434
fun modspec2xml j ((b, p_, head, gfr, pre, spec): ocalhd) =
neuper@37906
   435
    (indt j ^"<CALCHEAD status = "^
neuper@37906
   436
     quote (if b then "correct" else "incorrect")^">\n"^
neuper@37906
   437
     indt (j+i) ^"<HEAD>\n"^
neuper@37906
   438
     term2xml (j+i) head^"\n"^
neuper@37906
   439
     indt (j+i) ^"</HEAD>\n"^
neuper@37906
   440
     model2xml (j+i) gfr pre ^
neuper@37906
   441
     indt (j+i) ^"<BELONGSTO> "^(case p_ of Pbl => "Pbl"
neuper@37906
   442
					  | Met => "Met"
neuper@37906
   443
					  | _ => "Und")^" </BELONGSTO>\n"^
neuper@37906
   444
     spec2xml (j+i) spec ^
neuper@37906
   445
     indt j ^"</CALCHEAD>\n"):xml;
wneuper@59135
   446
fun xml_of_modspec ((b, p_, head, gfr, pre, spec): ocalhd) =
wneuper@59129
   447
  XML.Elem (("CALCHEAD", [("status", if b then "correct" else "incorrect")]), [
wneuper@59129
   448
    XML.Elem (("HEAD", []), [xml_of_term head]),
wneuper@59151
   449
    xml_of_model gfr pre,
wneuper@59129
   450
    XML.Elem (("BELONGSTO", []), [
wneuper@59129
   451
      XML.Text (case p_ of Pbl => "Pbl" | Met => "Met" | _ => "Und")]),
wneuper@59129
   452
    xml_of_spec spec])
wneuper@59129
   453
neuper@37906
   454
fun pos'calchead2xml j (p:pos', (b, p_, head, gfr, pre, spec): ocalhd) =
neuper@37906
   455
    (indt j ^"<CALCHEAD status = "^
neuper@37906
   456
     quote (if b then "correct" else "incorrect")^">\n"^
neuper@37906
   457
     pos'2xml (j+i) ("POSITION", p) ^
neuper@37906
   458
     indt (j+i) ^"<HEAD>\n"^
neuper@37906
   459
     term2xml (j+i) head^"\n"^
neuper@37906
   460
     indt (j+i) ^"</HEAD>\n"^
neuper@37906
   461
     model2xml (j+i) gfr pre ^
neuper@37906
   462
     indt (j+i) ^"<BELONGSTO> "^(case p_ of Pbl => "Pbl"
neuper@37906
   463
					  | Met => "Met"
neuper@37906
   464
					  | _ => "Und")^" </BELONGSTO>\n"^
neuper@37906
   465
     spec2xml (j+i) spec ^
neuper@37906
   466
     indt j ^"</CALCHEAD>\n"):xml;
wneuper@59150
   467
fun xml_of_posmodspec ((p: pos', (b, p_, head, gfr, pre, spec): ocalhd)) =
wneuper@59150
   468
  XML.Elem (("CALCHEAD", [("status", if b then "correct" else "incorrect")]), [
wneuper@59150
   469
    xml_of_pos "POSITION" p,
wneuper@59150
   470
    XML.Elem (("HEAD", []), [xml_of_term head]),
wneuper@59151
   471
    xml_of_model gfr pre,
wneuper@59150
   472
    XML.Elem (("BELONGSTO", []), [
wneuper@59150
   473
      XML.Text (case p_ of Pbl => "Pbl" | Met => "Met" | _ => "Und")]),
wneuper@59150
   474
    xml_of_spec spec])
wneuper@59156
   475
fun xml_to_imodel
wneuper@59156
   476
    (XML.Elem (("IMODEL", []), [
wneuper@59156
   477
      XML.Elem (("GIVEN", []), givens),
wneuper@59156
   478
      (*XML.Elem (("WHERE", []), wheres),  ... Where is never input*)
wneuper@59156
   479
      XML.Elem (("FIND", []), finds),
wneuper@59156
   480
      XML.Elem (("RELATE", []), relates)])) =
wneuper@59156
   481
    ([Given (map xml_to_cterm givens), 
wneuper@59156
   482
      Find (map xml_to_cterm finds), 
wneuper@59156
   483
      Relate (map xml_to_cterm relates)]): imodel
wneuper@59156
   484
  | xml_to_imodel x = raise ERROR ("xml_to_imodel: WRONG arg = " ^ xmlstr 0 x)
wneuper@59156
   485
fun xml_to_icalhd
wneuper@59156
   486
    (XML.Elem (("ICALCHEAD", []), [
wneuper@59156
   487
      pos as XML.Elem (("POSITION", []), _),
wneuper@59156
   488
      headln as XML.Elem (("MATHML", []), _),
wneuper@59158
   489
      imodel as XML.Elem (("MATHML", []), _), (* TODO WN150813 ?!?*)
wneuper@59156
   490
      XML.Elem (("POS", []), [XML.Text belongsto]),
wneuper@59156
   491
      spec as XML.Elem (("SPECIFICATION", []), _)])) =
wneuper@59156
   492
    (xml_to_pos pos, xml_to_cterm headln, xml_to_imodel imodel, 
wneuper@59156
   493
    str2pos_ belongsto, xml_to_spec spec): icalhd
wneuper@59156
   494
  | xml_to_icalhd x = raise ERROR ("xml_to_icalhd: WRONG arg = " ^ xmlstr 0 x)
neuper@37906
   495
neuper@37906
   496
fun sub2xml j (id, value) =
neuper@37906
   497
    (indt j ^"<PAIR>\n"^
neuper@37906
   498
     indt j ^"  <VARIABLE>\n"^
neuper@37906
   499
     term2xml (j+i) id ^ "\n" ^
neuper@37906
   500
     indt j ^"  </VARIABLE>\n" ^
neuper@37906
   501
     indt j ^"  <VALUE>\n"^
neuper@37906
   502
     term2xml (j+i) value ^ "\n" ^
neuper@37906
   503
     indt j ^"  </VALUE>\n" ^
neuper@37906
   504
     indt j ^"</PAIR>\n"):xml;
wneuper@59134
   505
fun xml_of_sub (id, value) =
wneuper@59134
   506
  XML.Elem (("PAIR", []), [
wneuper@59134
   507
    XML.Elem (("VARIABLE", []), [xml_of_term id]),
wneuper@59134
   508
    XML.Elem (("VALUE", []), [xml_of_term value])])
wneuper@59155
   509
fun xml_to_sub
wneuper@59155
   510
    (XML.Elem (("PAIR", []), [
wneuper@59155
   511
      XML.Elem (("VARIABLE", []), [id]),
wneuper@59155
   512
      XML.Elem (("VALUE", []), [value])])) = (xml_to_term id, xml_to_term value)
wneuper@59155
   513
  | xml_to_sub x = raise ERROR ("xml_to_sub wrong arg: " ^ xmlstr 0 x)
neuper@37906
   514
fun subs2xml j (subs:subs) =
neuper@37906
   515
    (indt j ^"<SUBSTITUTION>\n"^
neuper@37906
   516
     foldl op^ ("", map (sub2xml (j+i))
neuper@38050
   517
			(subs2subst (assoc_thy "Isac") subs)) ^
neuper@37906
   518
     indt j ^"</SUBSTITUTION>\n"):xml;
wneuper@59134
   519
fun xml_of_subs (subs : subs) =
wneuper@59134
   520
  XML.Elem (("SUBSTITUTION", []), map xml_of_sub (subs2subst (assoc_thy "Isac") subs))
wneuper@59155
   521
fun xml_to_subs
wneuper@59155
   522
    (XML.Elem (("SUBSTITUTION", []), 
wneuper@59155
   523
      subs)) = (subst2subs (map xml_to_sub subs) : subs)
wneuper@59155
   524
  | xml_to_subs x = raise ERROR ("xml_to_subs wrong arg: " ^ xmlstr 0 x)
wneuper@59159
   525
fun xml_of_sube (sube : sube) =
wneuper@59159
   526
  XML.Elem (("SUBSTITUTION", []), map xml_of_sub (sube2subst (assoc_thy "Isac") sube))
wneuper@59159
   527
fun xml_to_sube
wneuper@59159
   528
    (XML.Elem (("SUBSTITUTION", []), 
wneuper@59159
   529
      xml_var_val_pairs)) = subst2sube (map xml_to_sub xml_var_val_pairs)
wneuper@59159
   530
  | xml_to_sube x = raise ERROR ("xml_to_sube wrong arg: " ^ xmlstr 0 x)
wneuper@59134
   531
neuper@37906
   532
fun subst2xml j (subst:subst) =
neuper@37906
   533
    (indt j ^"<SUBSTITUTION>\n"^
neuper@37906
   534
     foldl op^ ("", map (sub2xml (j+i)) subst) ^
neuper@37906
   535
     indt j ^"</SUBSTITUTION>\n"):xml;
neuper@37906
   536
(* val subst = [(str2term "bdv", str2term "x")];
neuper@38031
   537
   writeln(subst2xml 0 subst);
neuper@37906
   538
   *)
neuper@37906
   539
neuper@37906
   540
(* val (j, str) = ((j+i), form);
neuper@37906
   541
   *)
neuper@37906
   542
fun thmstr2xml j str = ((((term2xml j) o str2term) str)^"\n"):xml;
neuper@37906
   543
neuper@37906
   544
(* val (j, ((ID, form):thm')) = ((j+i), thm');
neuper@37906
   545
   *)
neuper@37906
   546
fun thm'2xml j ((ID, form):thm') =
neuper@37906
   547
    (indt j ^"<THEOREM>\n"^
neuper@37906
   548
    indt (j+i) ^"<ID> "^ID^" </ID>\n"^
neuper@37906
   549
    indt (j+i) ^"<FORMULA>\n"^
neuper@37906
   550
    thmstr2xml (j+i) form^
neuper@37906
   551
    indt (j+i) ^"</FORMULA>\n"^
neuper@37906
   552
    indt j ^"</THEOREM>\n"):xml;
wneuper@59134
   553
fun xml_of_thm' ((ID, form) : thm') =
wneuper@59134
   554
  XML.Elem (("THEOREM", []), [
wneuper@59134
   555
    XML.Elem (("ID", []), [XML.Text ID]),
wneuper@59158
   556
    XML.Elem (("FORMULA", []), [
wneuper@59158
   557
      XML.Text form])])           (* repair for MathML: use term instead String *)
wneuper@59155
   558
fun xml_to_thm'
wneuper@59155
   559
    (XML.Elem (("THEOREM", []), [
wneuper@59155
   560
      XML.Elem (("ID", []), [XML.Text ID]),
wneuper@59158
   561
      XML.Elem (("FORMULA", []), [(* repair for MathML: use term instead String *)
wneuper@59158
   562
        XML.Text form])])) = ((ID, form) : thm')
wneuper@59155
   563
  | xml_to_thm' x = raise ERROR ("xml_of_thm' wrong arg:" ^ xmlstr 0 x)
neuper@37906
   564
neuper@37906
   565
(*WN060627 scope of thy's not considered ?!?*)
neuper@55490
   566
fun thm''2xml j (thm : thm) =
neuper@55490
   567
    indt j ^ "<THEOREM>\n" ^
neuper@55490
   568
    indt (j+i) ^ "<ID> " ^ thmID_of_derivation_name' thm ^ " </ID>\n"^
neuper@55489
   569
    term2xml j (prop_of thm) ^ "\n" ^
neuper@55490
   570
    indt j ^ "</THEOREM>\n" : xml;
wneuper@59134
   571
fun xml_of_thm (thm : thm) =
wneuper@59134
   572
  XML.Elem (("THEOREM", []), [
wneuper@59134
   573
    XML.Elem (("ID", []), [XML.Text (thmID_of_derivation_name' thm)]),
wneuper@59134
   574
    xml_of_term (prop_of thm)])
neuper@37906
   575
neuper@37906
   576
fun scr2xml j EmptyScr =
neuper@37906
   577
    indt j ^"<SCRIPT>  </SCRIPT>\n" : xml
neuper@48763
   578
  | scr2xml j (Prog term) =
neuper@37906
   579
    if term = e_term 
neuper@37906
   580
    then indt j ^"<SCRIPT>  </SCRIPT>\n"
neuper@37906
   581
    else indt j ^"<SCRIPT>\n"^ 
neuper@38050
   582
	 term2xml j (inst_abs (assoc_thy "Isac") term) ^ "\n" ^
neuper@37906
   583
	 indt j ^"</SCRIPT>\n"
neuper@37906
   584
  | scr2xml j (Rfuns _) =
neuper@37906
   585
    indt j ^"<REVERSREWRITE> reverse rewrite functions </REVERSREWRITE>\n";
wneuper@59133
   586
fun xml_of_src EmptyScr =
wneuper@59133
   587
    XML.Elem (("SCRIPT", []), [XML.Text "empty_script"])
wneuper@59133
   588
  | xml_of_src (Prog term) =
wneuper@59133
   589
    XML.Elem (("SCRIPT", []), [
wneuper@59133
   590
      if term = e_term then xml_of_src EmptyScr 
wneuper@59133
   591
      else XML.Elem (("SCRIPT", []), [xml_of_term (inst_abs (assoc_thy "Isac") term)])])
wneuper@59133
   592
  | xml_of_src (Rfuns _) =
wneuper@59133
   593
    XML.Elem (("REVERSREWRITE", []), [XML.Text "reverse rewrite functions"])
neuper@37906
   594
neuper@37906
   595
fun prepa12xml j (terms, term) =
neuper@37906
   596
    indt j ^"<PREPAT>\n"^
neuper@37906
   597
    indt (j+i) ^"<PRECONDS>\n"^
neuper@37906
   598
    terms2xml (j+2*i) terms ^
neuper@37906
   599
    indt (j+i) ^"</PRECONDS>\n"^
neuper@37906
   600
    indt (j+i) ^"<PATTERN>\n"^
neuper@37906
   601
    term2xml (j+2*i) term ^
neuper@37906
   602
    indt (j+i) ^"</PATTERN>\n"^
neuper@37906
   603
    indt j ^"</PREPAT>\n" : xml;
neuper@37906
   604
neuper@37906
   605
fun prepat2xml j [] = ""
neuper@37906
   606
  | prepat2xml j (p::ps) = prepa12xml j p ^ prepat2xml j ps : xml;
neuper@37906
   607
neuper@37906
   608
(* val (j, (thyID, seqrls, {id, preconds, rew_ord=(ord,_), erls,
neuper@37906
   609
			    srls, calc, rules, scr})) = 
neuper@37906
   610
	   (j, (thyID, "Seq", data));
neuper@37906
   611
   *)
neuper@37906
   612
fun rls2xm j (thyID, seqrls, {id, preconds, rew_ord=(ord,_), erls,
neuper@42451
   613
		      srls, calc, rules, errpatts, scr}) =
neuper@37906
   614
    indt j ^"<RULESET>\n"^
neuper@37906
   615
    indt (j+i) ^"<ID> "^ id ^" </ID>\n"^
neuper@37906
   616
    indt (j+i) ^"<TYPE> "^ seqrls ^" </TYPE>\n"^
neuper@37906
   617
    indt (j+i) ^"<RULES>\n" ^
neuper@37906
   618
    rules2xml (j+2*i) thyID rules ^
neuper@37906
   619
    indt (j+i) ^"</RULES>\n" ^
neuper@37906
   620
    indt (j+i) ^"<PRECONDS> " ^
neuper@37906
   621
    terms2xml' (j+2*i) preconds ^
neuper@37906
   622
    indt (j+i) ^"</PRECONDS>\n" ^
neuper@37906
   623
    indt (j+i) ^"<ORDER>\n" ^
neuper@37906
   624
    indt (j+2*i) ^ "<STRING> " ^ ord ^ " </STRING>\n" ^
neuper@37906
   625
(*WN060714 thy_isac_*-ord-*.xml not yet generated ................
neuper@37906
   626
    indt (j+2*i) ^ "<GUH> " ^ ord2guh ("IsacKnowledge", 
neuper@37906
   627
				      thyID) ord ^ " </GUH>\n" ^
neuper@37906
   628
..................................................................*)
neuper@37906
   629
    indt (j+i) ^"</ORDER>\n" ^
neuper@37906
   630
    indt (j+i) ^"<ERLS>\n" ^
neuper@37906
   631
    indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
neuper@37906
   632
    indt (j+2*i) ^ "<STRING> " ^ id_rls erls ^ " </STRING>\n" ^
neuper@37906
   633
    indt (j+2*i) ^ "<GUH> " ^ rls2guh ("IsacKnowledge", thyID) 
neuper@37906
   634
				     (id_rls erls) ^ " </GUH>\n" ^
neuper@37906
   635
    indt (j+i) ^"</ERLS>\n" ^
neuper@37906
   636
    indt (j+i) ^"<SRLS>\n" ^
neuper@37906
   637
    indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
neuper@37906
   638
    indt (j+2*i) ^ "<STRING> " ^ id_rls erls ^ " </STRING>\n" ^
neuper@37906
   639
    indt (j+2*i) ^ "<GUH> " ^ rls2guh ("IsacKnowledge", thyID) 
neuper@37906
   640
				     (id_rls srls) ^ " </GUH>\n" ^
neuper@37906
   641
    indt (j+i) ^"</SRLS>\n" ^
neuper@37906
   642
    calcrefs2xml (j+i) (thyID, calc) ^
neuper@37906
   643
    scr2xml (j+i) scr ^
neuper@37906
   644
    indt j ^"</RULESET>\n" : xml;
neuper@37906
   645
neuper@37906
   646
fun rls2xml j (thyID, Erls) = rls2xml j (thyID, e_rls)
neuper@37906
   647
  | rls2xml j (thyID, Rls data) = rls2xm j (thyID, "Rls", data)
neuper@37906
   648
  | rls2xml j (thyID, Seq data) = rls2xm j (thyID, "Seq", data)
neuper@42451
   649
  | rls2xml j (thyID, Rrls {id, prepat, rew_ord=(ord,_), erls, calc, errpatts, scr}) = 
neuper@37906
   650
    indt j ^"<RULESET>\n"^
neuper@37906
   651
    indt (j+i) ^"<ID> "^ id ^" </ID>\n"^
neuper@37906
   652
    indt (j+i) ^"<TYPE> Rrls </TYPE>\n"^
neuper@37906
   653
    prepat2xml (j+i) prepat ^
neuper@37906
   654
    indt (j+i) ^"<ORDER> " ^
neuper@37906
   655
    indt (j+2*i) ^ "<TAG> Rewrite order </TAG>\n" ^
neuper@37906
   656
    indt (j+2*i) ^ "<STRING> " ^ ord ^ " </STRING>\n" ^
neuper@37906
   657
(*WN060714 thy_isac_*-ord-*.xml not yet generated ................
neuper@37906
   658
    indt (j+2*i) ^ "<GUH> " ^ ord2guh ("IsacKnowledge", 
neuper@37906
   659
				      thyID) ord ^ " </GUH>\n" ^
neuper@37906
   660
.................................................................*)
neuper@37906
   661
    indt (j+i) ^"</ORDER>\n" ^
neuper@37906
   662
    indt (j+i) ^"<ERLS> " ^
neuper@37906
   663
    indt (j+2*i) ^ "<TAG> Ruleset </TAG>\n" ^
neuper@37906
   664
    indt (j+2*i) ^ "<STRING> " ^ id_rls erls ^ " </STRING>\n" ^
neuper@55490
   665
    indt (j+2*i) ^ "<GUH> " ^ rls2guh ("IsacKnowledge", thyID) (id_rls erls) ^ " </GUH>\n" ^
neuper@37906
   666
    indt (j+i) ^"</ERLS>\n" ^
neuper@37906
   667
    calcrefs2xml (j+i) (thyID, calc) ^
neuper@37906
   668
    indt (j+i) ^"<SCRIPT>\n"^ 
neuper@37906
   669
    scr2xml (j+2*i) scr ^
neuper@37906
   670
    indt (j+i) ^" </SCRIPT>\n"^
neuper@37906
   671
    indt j ^"</RULESET>\n" : xml;
neuper@37906
   672
neuper@37906
   673
(*.convert a tactic into xml-format
neuper@37906
   674
   ATTENTION: WN060513 detected faulty 'cterm2xml's with 'string's as args.*)
neuper@37906
   675
fun tac2xml j (Subproblem (dI, pI)) =
neuper@37906
   676
    (indt j ^"<SUBPROBLEMTACTIC name=\"Subproblem\">\n"^
neuper@37906
   677
    indt (j+i) ^"<THEORY> "^ dI ^" </THEORY>\n"^
neuper@37906
   678
    indt (j+i) ^"<PROBLEM>\n"^
neuper@37906
   679
    id2xml (j+2*i) pI^
neuper@37906
   680
    indt (j+i) ^"</PROBLEM>\n"^
neuper@37906
   681
    indt j ^"</SUBPROBLEMTACTIC>\n"):xml
neuper@37906
   682
  | tac2xml j Model_Problem =
neuper@37906
   683
    (indt j ^"<STRINGLISTTACTIC name=\"Model_Problem\">"^
neuper@37906
   684
    indt j ^"</STRINGLISTTACTIC>\n"):xml
neuper@37906
   685
  | tac2xml j (Refine_Tacitly pI) =
neuper@37906
   686
    (indt j ^"<STRINGLISTTACTIC name=\"Refine_Tacitly\">\n"^
neuper@37906
   687
    id2xml (j+i) pI^
neuper@37906
   688
    indt j ^"</STRINGLISTTACTIC>\n"):xml
neuper@37906
   689
neuper@37906
   690
  | tac2xml j (Add_Given ct) =
neuper@37906
   691
    (indt j ^"<SIMPLETACTIC name=\"Add_Given\">\n"^
neuper@37906
   692
    cterm2xml (j+i) ct^
neuper@37906
   693
    indt j ^"</SIMPLETACTIC>\n"):xml
neuper@37906
   694
  | tac2xml j (Add_Find ct) =
neuper@37906
   695
    (indt j ^"<SIMPLETACTIC name=\"Add_Find\">\n"^
neuper@37906
   696
    cterm2xml (j+i) ct^
neuper@37906
   697
    indt j ^"</SIMPLETACTIC>\n"):xml
neuper@37906
   698
  | tac2xml j (Add_Relation ct) =
neuper@37906
   699
    (indt j ^"<SIMPLETACTIC name=\"Add_Relation\">\n"^
neuper@37906
   700
    cterm2xml (j+i) ct^
neuper@37906
   701
    indt j ^"</SIMPLETACTIC>\n"):xml
neuper@37906
   702
neuper@37906
   703
  | tac2xml j (Specify_Theory ct) =
neuper@37906
   704
    (indt j ^"<SIMPLETACTIC name=\"Specify_Theory\">\n"^
neuper@37906
   705
    cterm2xml (j+i) ct^(*WN060513 Specify_Theory = fn : domID -> tac
neuper@37906
   706
and domID is a string, not a cterm *)
neuper@37906
   707
    indt j ^"</SIMPLETACTIC>\n"):xml
neuper@37906
   708
  | tac2xml j (Specify_Problem ct) =
neuper@37906
   709
    (indt j ^"<STRINGLISTTACTIC name=\"Specify_Problem\">\n"^
neuper@37906
   710
    id2xml (j+i) ct^
neuper@37906
   711
    indt j ^"</STRINGLISTTACTIC>\n"):xml
neuper@37906
   712
  | tac2xml j (Specify_Method ct) =
neuper@37906
   713
    (indt j ^"<STRINGLISTTACTIC name=\"Specify_Method\">\n"^
neuper@37906
   714
    id2xml (j+i) ct^
neuper@37906
   715
    indt j ^"</STRINGLISTTACTIC>\n"):xml
neuper@37906
   716
  | tac2xml j (Apply_Method mI) =
neuper@37906
   717
    (indt j ^"<STRINGLISTTACTIC name=\"Apply_Method\">\n"^
neuper@37906
   718
    id2xml (j+i) mI^
neuper@37906
   719
    indt j ^"</STRINGLISTTACTIC>\n"):xml
neuper@37906
   720
neuper@37906
   721
  | tac2xml j (Take ct) =
neuper@37906
   722
    (indt j ^"<SIMPLETACTIC name=\"Take\">\n"^
neuper@37906
   723
    cterm2xml (j+i) ct^
neuper@37906
   724
    indt j ^"</SIMPLETACTIC>\n"):xml
neuper@37906
   725
  | tac2xml j (Calculate opstr) =
neuper@37906
   726
    (indt j ^"<SIMPLETACTIC name=\"Calculate\">\n"^
neuper@37906
   727
    cterm2xml (j+i) opstr^(*WN060513 Calculate = fn : string -> tac
neuper@37906
   728
			'string', _NOT_ 'cterm' ..flaw from RG*)
neuper@37906
   729
    indt j ^"</SIMPLETACTIC>\n"):xml
neuper@37906
   730
(* val (j, Rewrite thm') = (i, tac);
neuper@37906
   731
   *)
neuper@37906
   732
  | tac2xml j (Rewrite thm') =
neuper@37906
   733
    (indt j ^"<REWRITETACTIC name=\"Rewrite\">\n"^
neuper@37906
   734
    thm'2xml (j+i) thm'^
neuper@37906
   735
    indt j ^"</REWRITETACTIC>\n"):xml
neuper@38031
   736
(* writeln (tac2xml 2 (Rewrite ("all_left",
neuper@37906
   737
				"~ ?b =!= 0 ==> (?a = ?b) = (?a - ?b = 0)")));
neuper@37906
   738
   val (j, (Rewrite_Inst (subs, thm'))) = (i, tac);
neuper@37906
   739
   *)
neuper@37906
   740
  | tac2xml j (Rewrite_Inst (subs, thm')) =
neuper@37906
   741
    (indt j ^"<REWRITEINSTTACTIC name=\"Rewrite_Inst\">\n"^
neuper@37906
   742
    subs2xml (j+i) subs^
neuper@37906
   743
    thm'2xml (j+i) thm'^
neuper@37906
   744
    indt j ^"</REWRITEINSTTACTIC>\n"):xml
neuper@38031
   745
(* writeln (tac2xml 2 (Rewrite_Inst
neuper@37906
   746
			   (["(bdv,x)"],
neuper@37906
   747
			    ("all_left",
neuper@37906
   748
			     "~ ?b =!= 0 ==> (?a = ?b) = (?a - ?b = 0)"))));
neuper@37906
   749
   *)
neuper@37906
   750
  | tac2xml j (Rewrite_Set rls') =
neuper@37906
   751
    (indt j ^"<REWRITESETTACTIC name=\"Rewrite_Set\">\n"^
neuper@37906
   752
    indt (j+i) ^"<RULESET> "^ rls' ^" </RULESET>\n"^
neuper@37906
   753
    indt j ^"</REWRITESETTACTIC>\n"):xml
neuper@37906
   754
  | tac2xml j (Rewrite_Set_Inst (subs, rls')) =
neuper@37906
   755
    (indt j ^"<REWRITESETINSTTACTIC name=\"Rewrite_Set_Inst\">\n"^
neuper@37906
   756
    indt (j+i) ^"<RULESET> "^ rls' ^" </RULESET>\n"^
neuper@37906
   757
    subs2xml (j+i) subs^
neuper@37906
   758
    indt j ^"</REWRITESETINSTTACTIC>\n"):xml
neuper@37906
   759
neuper@37906
   760
  | tac2xml j (Or_to_List) =
neuper@37940
   761
    (indt j ^"<STRINGLISTTACTIC name=\"Or_to_List\"> </STRINGLISTTACTIC>\n"):xml
neuper@37906
   762
  | tac2xml j (Check_elementwise ct) =
neuper@37906
   763
    (indt j ^"<SIMPLETACTIC name=\"Check_elementwise\">\n"^
neuper@37906
   764
    cterm2xml (j+i) ct ^ "\n"^
neuper@37906
   765
    indt j ^"</SIMPLETACTIC>\n"):xml
neuper@37906
   766
  (*WN0605 quick and dirty: cterms is _NOT_ a stringlist like pblID...*)
neuper@37906
   767
  | tac2xml j (Substitute cterms) =
neuper@37906
   768
    (indt j ^"<STRINGLISTTACTIC name=\"Substitute\">\n"^
neuper@37906
   769
    (*cterms2xml (j+i) cterms^  ....should be WN060514: TODO TERMLISTTACTIC?*)
neuper@37906
   770
    id2xml (j+i) cterms^
neuper@37906
   771
    indt j ^"</STRINGLISTTACTIC>\n"):xml
neuper@37906
   772
  | tac2xml j (Check_Postcond pI) =
neuper@37906
   773
    (indt j ^"<STRINGLISTTACTIC name=\"Check_Postcond\">\n"^
neuper@37906
   774
    id2xml (j+i) pI^
neuper@37906
   775
    indt j ^"</STRINGLISTTACTIC>\n"):xml
neuper@38031
   776
  | tac2xml j tac = error ("tac2xml: not impl. for "^tac2str tac);
wneuper@59134
   777
fun xml_of_tac (Subproblem (dI, pI)) =
wneuper@59134
   778
    XML.Elem (("SUBPROBLEMTACTIC", [("name", "Subproblem")]), [
wneuper@59134
   779
      XML.Elem (("THEORY", []), [XML.Text dI]),
wneuper@59134
   780
      XML.Elem (("PROBLEM", []), [xml_of_strs pI])])
wneuper@59162
   781
  | xml_of_tac (Substitute cterms) =
wneuper@59162
   782
    (*Substitute: sube -> tac; e_sube: cterm' list; UNCLEAR HOW TO INPUT ON FRONTEND*)
wneuper@59162
   783
    XML.Elem (("STRINGLISTTACTIC", [("name", "Substitute")]), [xml_of_sube cterms])
wneuper@59160
   784
    (*----- Rewrite* -----------------------------------------------------*)
wneuper@59134
   785
  | xml_of_tac (Rewrite thm') =
wneuper@59134
   786
    XML.Elem (("REWRITETACTIC", [("name", "Rewrite")]), [xml_of_thm' thm'])
wneuper@59134
   787
  | xml_of_tac (Rewrite_Inst (subs, thm')) =
wneuper@59134
   788
    XML.Elem (("REWRITEINSTTACTIC", [("name", "Rewrite_Inst")]), (
wneuper@59134
   789
      xml_of_subs subs ::
wneuper@59134
   790
      xml_of_thm' thm' :: []))
wneuper@59134
   791
  | xml_of_tac (Rewrite_Set rls') =
wneuper@59134
   792
    XML.Elem (("REWRITESETTACTIC", [("name", "Rewrite_Set")]), [XML.Text rls'])
wneuper@59134
   793
  | xml_of_tac (Rewrite_Set_Inst (subs, rls')) =
wneuper@59161
   794
    XML.Elem (("REWRITESETINSTTACTIC", [("name", "Rewrite_Set_Inst")]), ([
wneuper@59161
   795
      xml_of_subs subs,
wneuper@59161
   796
      XML.Elem (("RULESET", []), [XML.Text rls'])]))
wneuper@59161
   797
    (*----- FORMTACTIC ---------------------------------------------------*)
wneuper@59160
   798
  | xml_of_tac (Add_Find ct) =
wneuper@59161
   799
    XML.Elem (("FORMTACTIC", [("name", "Add_Find")]), [xml_of_cterm ct])
wneuper@59160
   800
  | xml_of_tac (Add_Given ct) =
wneuper@59161
   801
    XML.Elem (("FORMTACTIC", [("name", "Add_Given")]), [xml_of_cterm ct])
wneuper@59160
   802
  | xml_of_tac (Add_Relation ct) =
wneuper@59161
   803
    XML.Elem (("FORMTACTIC", [("name", "Add_Relation")]), [xml_of_cterm ct])
wneuper@59134
   804
  | xml_of_tac (Check_elementwise ct) =
wneuper@59161
   805
    XML.Elem (("FORMTACTIC", [("name", "Check_elementwise")]), [xml_of_cterm ct])
wneuper@59160
   806
  | xml_of_tac (Take ct) =
wneuper@59161
   807
    XML.Elem (("FORMTACTIC", [("name", "Take")]), [xml_of_cterm ct])
wneuper@59160
   808
    (*----- SIMPLETACTIC -------------------------------------------------*)
wneuper@59160
   809
  | xml_of_tac (Calculate opstr) =
wneuper@59160
   810
    XML.Elem (("SIMPLETACTIC", [("name", "Calculate")]), [XML.Text opstr])
wneuper@59160
   811
  | xml_of_tac (Or_to_List) =
wneuper@59160
   812
    XML.Elem (("SIMPLETACTIC", [("name", "Or_to_List")]), [(*//////////*)])
wneuper@59160
   813
  | xml_of_tac (Specify_Theory ct) =
wneuper@59160
   814
    XML.Elem (("SIMPLETACTIC", [("name", "Specify_Theory")]), [XML.Text ct])
wneuper@59160
   815
    (*----- STRINGLISTTACTIC ---------------------------------------------*)
wneuper@59160
   816
  | xml_of_tac (Apply_Method mI) =
wneuper@59160
   817
    XML.Elem (("STRINGLISTTACTIC", [("name", "Apply_Method")]), [xml_of_strs mI])
wneuper@59160
   818
  | xml_of_tac (Check_Postcond pI) =
wneuper@59160
   819
    XML.Elem (("STRINGLISTTACTIC", [("name", "Check_Postcond")]), [xml_of_strs pI])
wneuper@59160
   820
  | xml_of_tac Model_Problem =
wneuper@59160
   821
    XML.Elem (("STRINGLISTTACTIC", [("name", "Model_Problem")]), [])
wneuper@59160
   822
  | xml_of_tac (Refine_Tacitly pI) =
wneuper@59160
   823
    XML.Elem (("STRINGLISTTACTIC", [("name", "Refine_Tacitly")]), [xml_of_strs pI])
wneuper@59160
   824
  | xml_of_tac (Specify_Method ct) =
wneuper@59160
   825
    XML.Elem (("STRINGLISTTACTIC", [("name", "Specify_Method")]), [xml_of_strs ct])
wneuper@59160
   826
  | xml_of_tac (Specify_Problem ct) =
wneuper@59160
   827
    XML.Elem (("STRINGLISTTACTIC", [("name", "Specify_Problem")]), [xml_of_strs ct])
wneuper@59134
   828
  | xml_of_tac tac = error ("xml_of_tac: not impl. for " ^ tac2str tac);
wneuper@59160
   829
wneuper@59155
   830
fun xml_to_tac 
wneuper@59155
   831
    (XML.Elem (("SUBPROBLEMTACTIC", [("name", "Subproblem")]), [
wneuper@59155
   832
      XML.Elem (("THEORY", []), [XML.Text dI]),
wneuper@59155
   833
      XML.Elem (("PROBLEM", []), [pI])])) = Subproblem (dI, xml_to_strs pI)
wneuper@59162
   834
  | xml_to_tac
wneuper@59162
   835
    (*Substitute: sube -> tac; e_sube: cterm' list; UNCLEAR HOW TO INPUT ON FRONTEND*)
wneuper@59162
   836
    (XML.Elem (("STRINGLISTTACTIC", [
wneuper@59162
   837
      ("name", "Substitute")]), [cterms])) = Substitute (xml_to_sube cterms)
wneuper@59160
   838
    (*----- Rewrite* -----------------------------------------------------*)
wneuper@59155
   839
  | xml_to_tac
wneuper@59155
   840
    (XML.Elem (("REWRITETACTIC", [
wneuper@59155
   841
      ("name", "Rewrite")]), [thm'])) = Rewrite (xml_to_thm' thm')
wneuper@59155
   842
  | xml_to_tac
wneuper@59155
   843
    (XML.Elem (("REWRITEINSTTACTIC", [
wneuper@59155
   844
      ("name", "Rewrite_Inst")]), [
wneuper@59155
   845
        subs, thm'])) = Rewrite_Inst (xml_to_subs subs, xml_to_thm' thm')
wneuper@59155
   846
  | xml_to_tac
wneuper@59155
   847
    (XML.Elem (("REWRITESETTACTIC", [
wneuper@59155
   848
      ("name", "Rewrite_Set")]), [XML.Text rls'])) = Rewrite_Set (rls')
wneuper@59155
   849
  | xml_to_tac
wneuper@59155
   850
    (XML.Elem (("REWRITESETINSTTACTIC", [
wneuper@59155
   851
      ("name", "Rewrite_Set_Inst")]), [
wneuper@59161
   852
        subs,
wneuper@59161
   853
        XML.Elem (("RULESET", []), [XML.Text rls'])])) = Rewrite_Set_Inst (xml_to_subs subs, rls')
wneuper@59161
   854
    (*----- FORMTACTIC ---------------------------------------------------*)
wneuper@59160
   855
  | xml_to_tac
wneuper@59161
   856
    (XML.Elem (("FORMTACTIC", [
wneuper@59160
   857
      ("name", "Add_Find")]), [ct])) =  Add_Find (xml_to_cterm ct)
wneuper@59160
   858
  | xml_to_tac
wneuper@59161
   859
    (XML.Elem (("FORMTACTIC", [
wneuper@59160
   860
      ("name", "Add_Given")]), [ct])) = Add_Given (xml_to_cterm ct)
wneuper@59160
   861
  | xml_to_tac
wneuper@59161
   862
    (XML.Elem (("FORMTACTIC", [
wneuper@59160
   863
      ("name", "Add_Relation")]), [ct])) = Add_Relation (xml_to_cterm ct)
wneuper@59160
   864
  | xml_to_tac
wneuper@59161
   865
    (XML.Elem (("FORMTACTIC", [
wneuper@59160
   866
      ("name", "Take")]), [ct])) = Take (xml_to_cterm ct)
wneuper@59160
   867
  | xml_to_tac
wneuper@59161
   868
    (XML.Elem (("FORMTACTIC", [
wneuper@59160
   869
      ("name", "Check_elementwise")]), [ct])) = Check_elementwise (xml_to_cterm ct)
wneuper@59160
   870
    (*----- SIMPLETACTIC -------------------------------------------------*)
wneuper@59160
   871
  | xml_to_tac
wneuper@59160
   872
    (XML.Elem (("SIMPLETACTIC", [
wneuper@59160
   873
      ("name", "Calculate")]), [XML.Text opstr])) = Calculate opstr
wneuper@59155
   874
  | xml_to_tac
wneuper@59158
   875
    (XML.Elem (("SIMPLETACTIC", [("name", "Or_to_List")]), [])) = Or_to_List
wneuper@59155
   876
  | xml_to_tac
wneuper@59160
   877
    (XML.Elem (("SIMPLETACTIC", [
wneuper@59160
   878
      ("name", "Specify_Theory")]), [XML.Text ct])) = Specify_Theory ct
wneuper@59160
   879
    (*----- STRINGLISTTACTIC ---------------------------------------------*)
wneuper@59160
   880
  | xml_to_tac
wneuper@59160
   881
    (XML.Elem (("STRINGLISTTACTIC", [
wneuper@59160
   882
      ("name", "Apply_Method")]), [mI])) = Apply_Method (xml_to_strs  mI)
wneuper@59160
   883
  | xml_to_tac
wneuper@59160
   884
    (XML.Elem (("STRINGLISTTACTIC", [
wneuper@59160
   885
      ("name", "Check_Postcond")]), [pI])) = Check_Postcond (xml_to_strs pI)
wneuper@59160
   886
  | xml_to_tac
wneuper@59160
   887
    (XML.Elem (("STRINGLISTTACTIC", [
wneuper@59160
   888
      ("name", "Model_Problem")]), [])) = Model_Problem 
wneuper@59160
   889
  | xml_to_tac
wneuper@59160
   890
    (XML.Elem (("STRINGLISTTACTIC", [
wneuper@59160
   891
      ("name", "Refine_Tacitly")]), [pI])) = Refine_Tacitly (xml_to_strs pI)
wneuper@59160
   892
  | xml_to_tac
wneuper@59160
   893
    (XML.Elem (("STRINGLISTTACTIC", [
wneuper@59160
   894
      ("name", "Specify_Method")]), [ct])) = Specify_Method (xml_to_strs ct)
wneuper@59160
   895
  | xml_to_tac
wneuper@59160
   896
    (XML.Elem (("STRINGLISTTACTIC", [
wneuper@59160
   897
      ("name", "Specify_Problem")]), [ct])) = Specify_Problem (xml_to_strs ct)
wneuper@59155
   898
  | xml_to_tac x = raise ERROR ("xml_to_tac: not impl. for " ^ xmlstr 0 x);
neuper@37906
   899
neuper@37906
   900
fun tacs2xml j [] = "":xml
neuper@37906
   901
  | tacs2xml j (t::ts) = tac2xml j t ^ tacs2xml j ts;
neuper@37906
   902
neuper@37906
   903
fun posformhead2xml j (p:pos', Form f) =
neuper@37906
   904
    indt j ^"<CALCFORMULA>\n"^
neuper@37906
   905
    pos'2xml (j+i) ("POSITION", p) ^
neuper@37906
   906
    indt (j+i) ^"<FORMULA>\n"^
neuper@37906
   907
    term2xml (j+i) f^"\n"^
neuper@37906
   908
    indt (j+i) ^"</FORMULA>\n"^
neuper@37906
   909
    indt j ^"</CALCFORMULA>\n"
neuper@37906
   910
  | posformhead2xml j (p, ModSpec c) =
neuper@37906
   911
    pos'calchead2xml (j) (p, c);
neuper@37906
   912
neuper@37906
   913
fun posformheads2xml j [] = ("":xml)
neuper@37906
   914
  | posformheads2xml j (r::rs) = posformhead2xml j r ^ posformheads2xml j rs;
neuper@37906
   915
neuper@48763
   916
val e_pblterm = (term_of o the o (parse @{theory Script})) 
neuper@37906
   917
		    ("Problem (" ^ e_domID ^ "," ^ strs2str' e_pblID ^ ")");
neuper@37906
   918
neuper@37906
   919
(*WN051224 minimal adaption to exporting Formulae _only_ by getFormulaeFromTo*)
neuper@37906
   920
fun posterm2xml j (p:pos', t) =
neuper@37906
   921
    indt j ^"<CALCFORMULA>\n"^
neuper@37906
   922
    pos'2xml (j+i) ("POSITION", p) ^
neuper@37906
   923
    indt (j+i) ^"<FORMULA>\n"^
neuper@37906
   924
    (if t = e_pblterm (*headline in pbl is e_ <- _root_pbl for CAS-command*)
neuper@37906
   925
     then cterm2xml (j+i) "________________________________________________" 
neuper@37906
   926
     else term2xml (j+i) t)^"\n" ^
neuper@37906
   927
    indt (j+i) ^"</FORMULA>\n"^
neuper@37906
   928
    indt j ^"</CALCFORMULA>\n";
wneuper@59127
   929
fun xml_of_posterm ((p : pos'), t) = 
wneuper@59127
   930
  XML.Elem (("CALCFORMULA", []),
wneuper@59127
   931
    [xml_of_pos "POSITION" p,
wneuper@59127
   932
    XML.Elem (("FORMULA", []), [
wneuper@59127
   933
      if t = e_pblterm (*headline in pbl is e_ <- _root_pbl for CAS-command*)
wneuper@59127
   934
      then xml_of_cterm "________________________________________________"
wneuper@59127
   935
      else xml_of_term t])])
neuper@37906
   936
neuper@37906
   937
fun posterms2xml j [] = ("":xml)
neuper@37906
   938
  | posterms2xml j (r::rs) = posterm2xml j r ^ posterms2xml j rs;
neuper@37906
   939
neuper@37906
   940
fun  asm_val2xml j (asm, vl) = 
neuper@37906
   941
    indt j ^ "<ASMEVALUATED>\n" ^
neuper@37906
   942
    indt (j+i) ^ "<ASM>\n" ^
neuper@37906
   943
    term2xml (j+i) asm ^ "\n" ^
neuper@37906
   944
    indt (j+i) ^ "</ASM>\n" ^
neuper@37906
   945
    indt (j+i) ^ "<VALUE>\n" ^
neuper@37906
   946
    term2xml (j+i) vl ^ "\n" ^
neuper@37906
   947
    indt (j+i) ^ "</VALUE>\n" ^
neuper@37906
   948
    indt j ^ "</ASMEVALUATED>\n" : xml;
wneuper@59133
   949
fun xml_of_asm_val (asm, vl) =
wneuper@59133
   950
  XML.Elem (("ASMEVALUATED", []),[
wneuper@59133
   951
    XML.Elem (("ASM", []), [xml_of_term asm]),
wneuper@59133
   952
    XML.Elem (("VALUE", []), [xml_of_term vl])])
neuper@37906
   953
neuper@37906
   954
fun asm_vals2xml j [] = ("":xml)
neuper@37906
   955
  | asm_vals2xml j (asm_val::avs) = asm_val2xml j asm_val ^
neuper@37906
   956
				    asm_vals2xml j avs;
neuper@37906
   957
neuper@37906
   958
(*.a reference to an element in the theory hierarchy; 
neuper@37906
   959
   compare 'fun keref2xml'.*)
neuper@37906
   960
(* val (j, thyID, typ, xstring) = 
neuper@37906
   961
       (i+i, snd (thy_containing_rls thy' prls'), "Rulesets", prls');
neuper@37906
   962
   *)
neuper@37906
   963
fun theref2xml j (thyID:thyID) typ (xstring:xstring) =
neuper@37906
   964
    let val guh = theID2guh ["IsacKnowledge", thyID, typ, xstring]
neuper@40836
   965
	val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
neuper@37906
   966
    in indt j ^ "<KESTOREREF>\n" ^
neuper@37906
   967
       indt (j+i) ^ "<TAG> " ^ typ' ^ " </TAG>\n" ^
neuper@37906
   968
       indt (j+i) ^ "<ID> " ^ xstring ^ " </ID>\n" ^
neuper@37906
   969
       indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
neuper@37906
   970
       indt j ^ "</KESTOREREF>\n" : xml
neuper@37906
   971
    end;
wneuper@59133
   972
fun xml_of_theref (thyid : thyID) typ (xstring : xstring) =
wneuper@59133
   973
  let 
wneuper@59133
   974
    val guh = theID2guh ["IsacKnowledge", thyid, typ, xstring]
wneuper@59133
   975
    val typ' = (implode o (drop_last_n 1) o Symbol.explode) typ
wneuper@59133
   976
  in 
wneuper@59133
   977
    XML.Elem (("KESTOREREF", []),[
wneuper@59133
   978
      XML.Elem (("TAG", []), [XML.Text typ']),
wneuper@59133
   979
      XML.Elem (("ID", []), [XML.Text xstring]),
wneuper@59133
   980
      XML.Elem (("GUH", []), [XML.Text guh])])
wneuper@59133
   981
  end
neuper@37906
   982
(*.a reference to an element in the kestore EXCEPT theory hierarchy; 
neuper@37906
   983
   compare 'fun theref2xml'.*)
neuper@37906
   984
(* val (j, typ, kestoreID) = (i+i, Met_, hd met);
neuper@37906
   985
   *)
neuper@37906
   986
fun keref2xml j typ (kestoreID:kestoreID) =
neuper@37906
   987
    let val id = strs2str' kestoreID
neuper@37906
   988
	val guh = kestoreID2guh typ kestoreID
neuper@37906
   989
    in indt j ^ "<KESTOREREF>\n" ^
neuper@37906
   990
       indt (j+i) ^ "<TAG> " ^ ketype2str' typ ^ "</TAG>\n" ^
neuper@37906
   991
       indt (j+i) ^ "<ID> " ^ id ^ " </ID>\n" ^
neuper@37906
   992
       indt (j+i) ^ "<GUH> " ^ guh ^ " </GUH>\n" ^
neuper@37906
   993
       indt j ^ "</KESTOREREF>\n" : xml
neuper@37906
   994
    end;
neuper@37906
   995
neuper@37906
   996
(*url to a source external to isac*)
neuper@37906
   997
fun extref2xml j linktext url =
neuper@37906
   998
    indt j ^ "<EXTREF>\n" ^
neuper@37906
   999
    indt (j+i) ^ "<TEXT> " ^ linktext ^ " </TEXT>\n" ^
neuper@37906
  1000
    indt (j+i) ^ "<URL> " ^ url ^ " </URL>\n" ^
neuper@37906
  1001
    indt j ^ "</EXTREF>\n" : xml;
neuper@37906
  1002
neuper@37906
  1003
(* val (ContThmInst{thyID, thm, bdvs, thminst, applto, applat, reword,
neuper@37906
  1004
		    asms, lhs, rhs, result, resasms, asmrls}) =
neuper@37906
  1005
       (context_thy (pt,pos) tac);
neuper@38031
  1006
writeln (contthy2xml 2 (context_thy (pt,pos) tac));
neuper@37906
  1007
   *)
neuper@37906
  1008
fun contthy2xml j EContThy =
neuper@38031
  1009
    error "contthy2xml called with EContThy"
neuper@37906
  1010
  | contthy2xml j (ContThm {thyID, thm, applto, applat, reword, 
neuper@37906
  1011
				 asms,lhs, rhs, result, resasms, asmrls}) =
neuper@37906
  1012
    indt j ^ "<GUH> " ^ thm ^ " </GUH>\n" ^
neuper@37940
  1013
neuper@37906
  1014
    indt j ^ "<APPLTO>\n" ^
neuper@37906
  1015
    term2xml j applto ^ "\n" ^
neuper@37906
  1016
    indt j ^ "</APPLTO>\n" ^
neuper@37906
  1017
    indt j ^ "<APPLAT>\n" ^
neuper@37906
  1018
    term2xml j applat ^ "\n" ^
neuper@37906
  1019
    indt j ^ "</APPLAT>\n" ^
neuper@37906
  1020
    indt j ^ "<ORDER>\n" ^ (*should be a theref2xml*)
neuper@37906
  1021
    indt (j+i) ^"<ID> " ^ reword ^ " </ID>\n" ^
neuper@37906
  1022
    indt j ^ "</ORDER>\n" ^
neuper@37906
  1023
    indt j ^ "<ASMSEVAL>\n" ^
neuper@37906
  1024
    asm_vals2xml (j+i) asms ^
neuper@37906
  1025
    indt j ^ "</ASMSEVAL>\n" ^
neuper@37906
  1026
    indt j ^ "<LHS>\n" ^
neuper@37906
  1027
    term2xml j (fst lhs) ^ "\n" ^
neuper@37906
  1028
    indt j ^ "</LHS>\n" ^
neuper@37906
  1029
    indt j ^ "<LHSINST>\n" ^
neuper@37906
  1030
    term2xml j (snd lhs) ^ "\n" ^
neuper@37906
  1031
    indt j ^ "</LHSINST>\n" ^
neuper@37906
  1032
    indt j ^ "<RHS>\n" ^
neuper@37906
  1033
    term2xml j (fst rhs) ^ "\n" ^
neuper@37906
  1034
    indt j ^ "</RHS>\n" ^
neuper@37906
  1035
    indt j ^ "<RHSINST>\n" ^
neuper@37906
  1036
    term2xml j (snd rhs) ^ "\n" ^
neuper@37906
  1037
    indt j ^ "</RHSINST>\n" ^
neuper@37906
  1038
    indt j ^ "<RESULT>\n" ^
neuper@37906
  1039
    term2xml j result ^ "\n" ^
neuper@37906
  1040
    indt j ^ "</RESULT>\n" ^
neuper@37906
  1041
    indt j ^ "<ASSUMPTIONS>\n" ^
neuper@37906
  1042
    terms2xml' j resasms ^
neuper@37906
  1043
    indt j ^ "</ASSUMPTIONS>\n" ^
neuper@37906
  1044
    indt j ^ "<EVALRLS>\n" ^
neuper@37906
  1045
    theref2xml j thyID "Rulesets" asmrls ^
neuper@37906
  1046
    indt j ^ "</EVALRLS>\n"
neuper@37906
  1047
  | contthy2xml j (ContThmInst{thyID, thm, bdvs, thminst, applto, applat, 
neuper@37906
  1048
				    reword, asms, lhs, rhs, result, resasms, 
neuper@37906
  1049
				    asmrls}) =
neuper@37906
  1050
    indt j ^ "<GUH> " ^ thm ^ " </GUH>\n" ^
neuper@37906
  1051
    indt j ^ "<SUBSLIST>\n" ^ (*should be an environment = substitution*)
neuper@37906
  1052
    indt (j+i) ^ "<MATHML>\n" ^
neuper@37906
  1053
    indt (j+2*i) ^ "<ISA> " ^ subst2str' bdvs ^ " </ISA>\n" ^
neuper@37906
  1054
    indt (j+i) ^ "</MATHML>\n" ^
neuper@37906
  1055
    indt j ^ "</SUBSLIST>\n" ^
neuper@37906
  1056
    indt j ^ "<INSTANTIATED>\n" ^
neuper@37906
  1057
    term2xml j thminst ^ "\n" ^
neuper@37906
  1058
    indt j ^ "</INSTANTIATED>\n" ^
neuper@37906
  1059
    indt j ^ "<APPLTO>\n" ^
neuper@37906
  1060
    term2xml j applto ^ "\n" ^
neuper@37906
  1061
    indt j ^ "</APPLTO>\n" ^
neuper@37906
  1062
    indt j ^ "<APPLAT>\n" ^
neuper@37906
  1063
    term2xml j applat ^ "\n" ^
neuper@37906
  1064
    indt j ^ "</APPLAT>\n" ^
neuper@37906
  1065
    indt j ^ "<ORDER>\n" ^ (*should be a theref2xml*)
neuper@37906
  1066
    indt (j+i) ^"<ID> " ^ reword ^ " </ID>\n" ^
neuper@37906
  1067
    indt j ^ "</ORDER>\n" ^
neuper@37906
  1068
    indt j ^ "<ASMSEVAL>\n" ^
neuper@37906
  1069
    asm_vals2xml (j+i) asms ^
neuper@37906
  1070
    indt j ^ "</ASMSEVAL>\n" ^
neuper@37906
  1071
    indt j ^ "<LHS>\n" ^
neuper@37906
  1072
    term2xml j (fst lhs) ^ "\n" ^
neuper@37906
  1073
    indt j ^ "</LHS>\n" ^
neuper@37906
  1074
    indt j ^ "<LHSINST>\n" ^
neuper@37906
  1075
    term2xml j (snd lhs) ^ "\n" ^
neuper@37906
  1076
    indt j ^ "</LHSINST>\n" ^
neuper@37906
  1077
    indt j ^ "<RHS>\n" ^
neuper@37906
  1078
    term2xml j (fst rhs) ^ "\n" ^
neuper@37906
  1079
    indt j ^ "</RHS>\n" ^
neuper@37906
  1080
    indt j ^ "<RHSINST>\n" ^
neuper@37906
  1081
    term2xml j (snd rhs) ^ "\n" ^
neuper@37906
  1082
    indt j ^ "</RHSINST>\n" ^
neuper@37906
  1083
    indt j ^ "<RESULT>\n" ^
neuper@37906
  1084
    term2xml j result ^ "\n" ^
neuper@37906
  1085
    indt j ^ "</RESULT>\n" ^
neuper@37906
  1086
    indt j ^ "<ASSUMPTOIONS>\n" ^
neuper@37906
  1087
    terms2xml' j resasms ^
neuper@37906
  1088
    indt j ^ "</ASSUMPTOIONS>\n" ^
neuper@37906
  1089
    indt j ^ "<EVALRLS>\n" ^
neuper@37906
  1090
    theref2xml j thyID "Rulesets" asmrls ^
neuper@37906
  1091
    indt j ^ "</EVALRLS>\n"
neuper@37906
  1092
neuper@37906
  1093
  | contthy2xml j (ContRls {thyID, rls, applto, result, asms}) =
neuper@37906
  1094
    indt j ^ "<GUH> " ^ rls ^ " </GUH>\n" ^
neuper@37906
  1095
    indt j ^ "<APPLTO>\n" ^
neuper@37906
  1096
    term2xml j applto ^ "\n" ^
neuper@37906
  1097
    indt j ^ "</APPLTO>\n" ^
neuper@37906
  1098
    indt j ^ "<RESULT>\n" ^
neuper@37906
  1099
    term2xml j result ^ "\n" ^
neuper@37906
  1100
    indt j ^ "</RESULT>\n" ^
neuper@37906
  1101
    indt j ^ "<ASSUMPTOIONS>\n" ^
neuper@37906
  1102
    terms2xml' j asms ^
neuper@37906
  1103
    indt j ^ "</ASSUMPTOIONS>\n"
neuper@37906
  1104
neuper@37906
  1105
  | contthy2xml j (ContRlsInst {thyID, rls, bdvs, applto, result, asms}) =
neuper@37906
  1106
    indt j ^ "<GUH> " ^ rls ^ " </GUH>\n" ^
neuper@37906
  1107
    indt j ^ "<SUBSLIST>\n" ^ (*should be an environment = substitution*)
neuper@37906
  1108
    indt (j+i) ^ "<MATHML>\n" ^
neuper@37906
  1109
    indt (j+2*i) ^ "<ISA> " ^ subst2str' bdvs ^ " </ISA>\n" ^
neuper@37906
  1110
    indt (j+i) ^ "</MATHML>\n" ^
neuper@37906
  1111
    indt j ^ "</SUBSLIST>\n" ^
neuper@37906
  1112
    indt j ^ "<APPLTO>\n" ^
neuper@37906
  1113
    term2xml j applto ^ "\n" ^
neuper@37906
  1114
    indt j ^ "</APPLTO>\n" ^
neuper@37906
  1115
    indt j ^ "<RESULT>\n" ^
neuper@37906
  1116
    term2xml j result ^ "\n" ^
neuper@37906
  1117
    indt j ^ "</RESULT>\n" ^
neuper@37906
  1118
    indt j ^ "<ASSUMPTOIONS>\n" ^
neuper@37906
  1119
    terms2xml' j asms ^
neuper@37906
  1120
    indt j ^ "</ASSUMPTOIONS>\n"
neuper@37906
  1121
neuper@37906
  1122
  | contthy2xml j (ContNOrew {thyID, thm_rls, applto}) =
neuper@37906
  1123
    indt j ^ "<GUH> " ^ thm_rls ^ " </GUH>\n" ^
neuper@37906
  1124
    indt j ^ "<APPLTO>\n" ^
neuper@37906
  1125
    term2xml j applto ^ "\n" ^
neuper@37906
  1126
    indt j ^ "</APPLTO>\n"
neuper@37906
  1127
neuper@37906
  1128
  | contthy2xml j (ContNOrewInst{thyID, thm_rls, bdvs, thminst, applto}) =
neuper@37906
  1129
    indt j ^ "<GUH> " ^ thm_rls ^ " </GUH>\n" ^
neuper@37906
  1130
    indt j ^ "<SUBSLIST>\n" ^ (*should be an environment = substitution*)
neuper@37906
  1131
    indt (j+i) ^ "<MATHML>\n" ^
neuper@37906
  1132
    indt (j+2*i) ^ "<ISA> " ^ subst2str' bdvs ^ " </ISA>\n" ^
neuper@37906
  1133
    indt (j+i) ^ "</MATHML>\n" ^
neuper@37906
  1134
    indt j ^ "</SUBSLIST>\n" ^
neuper@37906
  1135
    indt j ^ "<INSTANTIATED>\n" ^
neuper@37906
  1136
    term2xml j thminst ^ "\n" ^
neuper@37906
  1137
    indt j ^ "</INSTANTIATED>\n" ^
neuper@37906
  1138
    indt j ^ "<APPLTO>\n" ^
neuper@37906
  1139
    term2xml j applto ^ "\n" ^
neuper@37906
  1140
    indt j ^ "</APPLTO>\n" : xml;
wneuper@59133
  1141
fun xml_of_contthy EContThy =
wneuper@59133
  1142
    error "contthy2xml called with EContThy"
wneuper@59133
  1143
wneuper@59133
  1144
  | xml_of_contthy (ContThm {thyID, thm, applto, applat, reword, 
wneuper@59133
  1145
				asms,lhs, rhs, result, resasms, asmrls}) =
wneuper@59133
  1146
    [XML.Elem (("GUH", []), [XML.Text thm]),
wneuper@59133
  1147
    XML.Elem (("APPLTO", []), [xml_of_term applto]),
wneuper@59133
  1148
    XML.Elem (("APPLAT", []), [xml_of_term applat]),
wneuper@59133
  1149
    XML.Elem (("ORDER", []), [ (* should be a theref2xml *)
wneuper@59133
  1150
      XML.Elem (("ID", []), [XML.Text reword])]),
wneuper@59133
  1151
    XML.Elem (("ASMSEVAL", []), map xml_of_asm_val asms),
wneuper@59133
  1152
    XML.Elem (("LHS", []), [xml_of_term (fst lhs)]),
wneuper@59133
  1153
    XML.Elem (("LHSINST", []), [xml_of_term (snd lhs)]),
wneuper@59133
  1154
    XML.Elem (("RHS", []), [xml_of_term (fst rhs)]),
wneuper@59133
  1155
    XML.Elem (("RHSINST", []), [xml_of_term (snd rhs)]),
wneuper@59133
  1156
    XML.Elem (("RESULT", []), [xml_of_term result]),
wneuper@59133
  1157
    XML.Elem (("ASSUMPTIONS", []), map xml_of_term resasms),
wneuper@59133
  1158
    XML.Elem (("EVALRLS", []), [xml_of_theref thyID "Rulesets" asmrls])]
wneuper@59133
  1159
wneuper@59133
  1160
  | xml_of_contthy (ContThmInst {thyID, thm, bdvs, thminst, applto, applat, 
wneuper@59133
  1161
				reword, asms, lhs, rhs, result, resasms, asmrls}) =
wneuper@59133
  1162
    [XML.Elem (("GUH", []), [XML.Text thm]),
wneuper@59133
  1163
    XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
wneuper@59133
  1164
      xml_of_cterm (subst2str' bdvs)]),
wneuper@59133
  1165
    XML.Elem (("INSTANTIATED", []), [xml_of_term thminst]),
wneuper@59133
  1166
    XML.Elem (("APPLTO", []), [xml_of_term applto]),
wneuper@59133
  1167
    XML.Elem (("APPLAT", []), [xml_of_term applat]),
wneuper@59133
  1168
    XML.Elem (("ORDER", []), [ (* should be a theref2xml *)
wneuper@59133
  1169
      XML.Elem (("ID", []), [XML.Text reword])]),
wneuper@59133
  1170
    XML.Elem (("ASMSEVAL", []), map xml_of_asm_val asms),
wneuper@59133
  1171
    XML.Elem (("LHS", []), [xml_of_term (fst lhs)]),
wneuper@59133
  1172
    XML.Elem (("LHSINST", []), [xml_of_term (snd lhs)]),
wneuper@59133
  1173
    XML.Elem (("RHS", []), [xml_of_term (fst rhs)]),
wneuper@59133
  1174
    XML.Elem (("RHSINST", []), [xml_of_term (snd rhs)]),
wneuper@59133
  1175
    XML.Elem (("RESULT", []), [xml_of_term result]),
wneuper@59133
  1176
    XML.Elem (("ASSUMPTIONS", []), map xml_of_term resasms),
wneuper@59133
  1177
    XML.Elem (("EVALRLS", []), [xml_of_theref thyID "Rulesets" asmrls])]
wneuper@59133
  1178
wneuper@59133
  1179
  | xml_of_contthy (ContRls {thyID = _, rls, applto, result, asms}) =
wneuper@59133
  1180
    [XML.Elem (("GUH", []), [XML.Text rls]),
wneuper@59133
  1181
    XML.Elem (("APPLTO", []), [xml_of_term applto]),
wneuper@59133
  1182
    XML.Elem (("RESULT", []), [xml_of_term result]),
wneuper@59133
  1183
    XML.Elem (("ASSUMPTIONS", []), map xml_of_term asms)]
wneuper@59133
  1184
wneuper@59133
  1185
  | xml_of_contthy (ContRlsInst {thyID = _, rls, bdvs, applto, result, asms}) =
wneuper@59133
  1186
    [XML.Elem (("GUH", []), [XML.Text rls]),
wneuper@59133
  1187
    XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
wneuper@59133
  1188
      xml_of_cterm (subst2str' bdvs)]),
wneuper@59133
  1189
    XML.Elem (("INSTANTIATED", []), [xml_of_cterm (subst2str' bdvs)]),
wneuper@59133
  1190
    XML.Elem (("APPLTO", []), [xml_of_term applto]),
wneuper@59133
  1191
    XML.Elem (("RESULT", []), [xml_of_term result]),
wneuper@59133
  1192
    XML.Elem (("ASSUMPTIONS", []), map xml_of_term asms)]
wneuper@59133
  1193
wneuper@59133
  1194
  | xml_of_contthy (ContNOrew {thyID = _, thm_rls, applto}) =
wneuper@59133
  1195
    [XML.Elem (("GUH", []), [XML.Text thm_rls]),
wneuper@59133
  1196
    XML.Elem (("APPLTO", []), [xml_of_term applto])]
wneuper@59133
  1197
wneuper@59133
  1198
  | xml_of_contthy (ContNOrewInst{thyID = _, thm_rls, bdvs, thminst, applto}) =
wneuper@59133
  1199
    [XML.Elem (("GUH", []), [XML.Text thm_rls]),
wneuper@59133
  1200
    XML.Elem (("SUBSLIST", []), [ (* should be an environment = substitution *)
wneuper@59133
  1201
      xml_of_cterm (subst2str' bdvs)]),
wneuper@59133
  1202
    XML.Elem (("INSTANTIATED", []), [xml_of_term thminst]),
wneuper@59133
  1203
    XML.Elem (("APPLTO", []), [xml_of_term applto])]
neuper@37906
  1204
wneuper@59156
  1205
fun xml_of_calcchanged calcid tag old del new = (*TODO: make analogous to xml_to_calcchanged*)
wneuper@59131
  1206
  XML.Elem ((tag, []),[
wneuper@59131
  1207
    XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
wneuper@59131
  1208
    XML.Elem (("CALCCHANGED", []), [
wneuper@59131
  1209
      xml_of_pos "UNCHANGED" old,
wneuper@59131
  1210
      xml_of_pos "DELETED" del,
wneuper@59131
  1211
      xml_of_pos "GENERATED" new])])
wneuper@59156
  1212
fun xml_to_calcchanged (XML.Elem (("CALCCHANGED", []), [old, del, new])) = 
wneuper@59156
  1213
      (xml_to_pos old, xml_to_pos del, xml_to_pos new)
wneuper@59156
  1214
  | xml_to_calcchanged x = raise ERROR ("xml_to_calcchanged: WRONG arg = " ^ xmlstr 0 x)
wneuper@59124
  1215
(*------------------------------------------------------------------
neuper@37906
  1216
end
neuper@37906
  1217
open datatypes;
wneuper@59124
  1218
------------------------------------------------------------------*)
neuper@37940
  1219
neuper@37940
  1220