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