PIDE-phase 2c CONTINUED: IsaToJava.fetch_proposed_tac_out failed due to wrong XML conversion on SML-side
1 (* interface between isac math engine and java:
2 java -> sml: strings on stdin
3 sml -> java: xml on stdout
5 WN071004 The xml still reflects the insecurity during the first
6 implementation phase, how the communication via stdin/out could
7 correctly relate multiple sml-calculations and java-calculations.
9 Since this insecurity turned out unjustified, the xml can be
10 simplified in several ways:
11 # omit the CALCID; the relation is done by
12 "@@@@@begin@@@@@\n "^string_of_int uI
13 # omit the distinctions APPENDFORMULA, REPLACEFORMULA, ...
14 WN071004 these 2 simplifications are begun with CALCMESSAGE
22 (** add and delete users -----------------------------------------------
23 FIXXME.8.03 addUser: clear code, because only CalcTrees distinguished**)
24 fun adduserOK2xml (cI:calcID) (uI:iterID) =
25 writeln ("@@@@@begin@@@@@\n "^string_of_int uI^" \n" ^
27 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
28 " <USERID> "^string_of_int uI^" </USERID>\n" ^
31 fun adduserOK2xml (calcid : calcID) (userid : iterID) =
32 XML.Elem (("ADDUSER", []),
33 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
34 XML.Elem (("USERID", []), [XML.Text (string_of_int userid)])])
35 fun deluserOK2xml (cI:calcID) (uI:iterID) =
36 writeln ("@@@@@begin@@@@@\n "^string_of_int uI^" \n" ^
38 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
39 " <USERID> "^string_of_int uI^" </USERID>\n" ^
42 (*---------------------------------------------------------------------*)
44 fun calctreeOK2xml (*uI:iterID*) (cI:calcID) =
45 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
47 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
50 fun calctreeOK2xml (calcid : calcID) =
51 XML.Elem (("CALCTREE", []),
52 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)])])
53 fun deconstructcalctreeOK2xml (*uI:userID*) (cI:calcID) =
54 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
56 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
59 fun deconstructcalctreeOK2xml (calcid : calcID) =
60 XML.Elem (("DELCALC", []),
61 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)])])
63 fun iteratorOK2xml (cI:calcID) (p:pos')=
64 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
66 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
67 pos'2xml i ("POSITION", p) ^
70 fun iteratorERROR2xml (cI:calcID) =
71 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
73 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
74 " <ERROR> iteratorERROR2xml: pos does not exist </ERROR>\n" ^
77 fun iteratorOK2xml (calcid : calcID) (p : pos')=
78 XML.Elem (("CALCITERATOR", []),
79 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
80 xml_of_pos "POSITION" p])
81 fun iteratorERROR2xml (calcid : calcID) =
82 XML.Elem (("CALCITERATOR", []),
83 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
84 XML.Elem (("ERROR", []), [XML.Text " iteratorERROR2xml: pos does not exist "])])
86 fun sysERROR2xml (cI:calcID) "" =
87 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
89 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
90 " <ERROR> in kernel </ERROR>\n" ^
93 | sysERROR2xml (cI:calcID) str =
94 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
96 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
97 " <ERROR> "^str^" </ERROR>\n" ^
100 fun sysERROR2xml (calcid : calcID) str =
101 XML.Elem (("SYSERROR", []),
102 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
103 XML.Elem (("ERROR", []), [XML.Text (if str = "" then " ERROR in kernel " else str)])])
105 fun refformulaOK2xml (cI:calcID) p (Form t) =
106 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
108 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
110 pos'2xml (2*i) ("POSITION", p) ^
112 term2xml (2*i) t ^ "\n" ^
114 " </CALCFORMULA>\n" ^
117 | refformulaOK2xml (cI:calcID) p (ModSpec modspec) =
118 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
120 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
121 pos'calchead2xml i (p, modspec)^
124 fun refformulaOK2xml (calcid : calcID) p (Form t) =
125 XML.Elem (("REFFORMULA", []),
126 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
127 XML.Elem (("CALCFORMULA", []), [
128 xml_of_pos "POSITION" p,
129 XML.Elem (("FORMULA", []), [xml_of_term t])])])
130 | refformulaOK2xml (calcid : calcID) p (ModSpec modspec) =
131 XML.Elem (("REFFORMULA", []), [
132 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
133 (*L.Elem (("CALCHEAD*) xml_of_posmodspec (p, modspec)])
135 fun refformulaERROR2xml (cI:calcID) = (*FIXME.WN.29.8.03 unused*)
136 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
138 " <ERROR> object is not a formula </ERROR>\n" ^
142 (* val (cI, tac) = (cI, ta);
144 fun gettacticOK2xml (cI:calcID) tac =
145 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
147 " <CALCID> "^string_of_int cI^" </CALCID>\n"^
151 fun gettacticOK2xml (calcid : calcID) tac =
152 XML.Elem (("GETTACTIC", []),[
153 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
156 fun gettacticERROR2xml (cI:calcID) str =
157 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
159 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
160 " <ERROR> "^str^" </ERROR>\n" ^
163 fun gettacticERROR2xml (calcid : calcID) str =
164 XML.Elem (("GETTACTIC", []),[
165 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
166 XML.Elem (("ERROR", []), [XML.Text str])])
168 fun applicabletacticsOK cI tacs =
169 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
170 "<APPLICABLETACTICS>\n" ^
171 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
175 "</APPLICABLETACTICS>\n" ^
177 fun applicabletacticsOK calcid tacs =
178 XML.Elem (("APPLICABLETACTICS", []), [
179 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
180 XML.Elem (("TACLIST", []), (map xml_of_tac tacs))])
182 fun getasmsOK2xml (cI:calcID) terms =
183 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
184 "<GETASSUMPTIONS>\n" ^
185 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
187 formulae2xml (i+i) terms ^
189 "</GETASSUMPTIONS>\n" ^
191 fun getasmsOK2xml (calcid : calcID) terms =
192 XML.Elem (("ASSUMPTIONS", []), [
193 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
194 XML.Elem (("ASMLIST", []), (map xml_of_formula terms))])
196 (*WN0502 @see ME/ctree: type asms: illdesigned, thus not used*)
197 fun getaccuasmsOK2xml cI asms =
198 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
199 "<GETACCUMULATEDASMS>\n" ^
200 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
202 formulae2xml (i+i) asms^
204 "</GETACCUMULATEDASMS>\n" ^
206 (* getaccuasmsOK2xml 333 [(([1],Res), str2term "1+1=2"),
207 (([2],Res), str2term "1+1+1=3")];
208 getaccuasmsOK2xml 333 [str2term "1+1=2", str2term "1+1+1=3"];
211 fun getintervalOK (cI:calcID) fs =
212 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
213 "<GETELEMENTSFROMTO>\n" ^
214 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
216 posterms2xml (2*i) fs^
218 "</GETELEMENTSFROMTO>\n" ^
220 fun getintervalOK (calcid : calcID) fs =
221 XML.Elem (("GETELEMENTSFROMTO", []),
222 [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
223 XML.Elem (("FORMHEADS", []), map xml_of_posterm fs)])
225 fun matchpbl2xml (cI:calcID) (model_ok, pI, hdl, pbl, pre) =
226 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
228 " <GUH> " ^ pblID2guh pI ^ " </GUH>\n" ^
229 " <STATUS> " ^ (if model_ok
231 else "incorrect") ^ " </STATUS>\n" ^
233 term2xml i hdl ^ "\n" ^
235 model2xml i pbl pre ^
238 fun xml_of_matchpbl (_ : calcID) (model_ok, pI, hdl, pbl, pre) =
239 XML.Elem (("CONTEXTPBL", []),
240 ( (* WN150530: calcid will be required for asynchronous communication *)
241 XML.Elem (("GUH", []), [XML.Text (pblID2guh pI)]) ::
242 XML.Elem (("STATUS", []), [
243 XML.Text ((if model_ok then "correct" else "incorrect"))]) ::
244 XML.Elem (("HEAD", []), [xml_of_term hdl]) ::
245 (xml_of_model pbl pre) :: []))
247 fun matchmet2xml (cI:calcID) (model_ok, pI, scr, pbl, pre) =
248 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
250 " <GUH> " ^ metID2guh pI ^ " </GUH>\n" ^
251 " <STATUS> " ^ (if model_ok
253 else "incorrect") ^ " </STATUS>\n" ^
255 model2xml i pbl pre ^
258 fun xml_of_matchmet (_ : calcID) (model_ok, pI, scr, pbl, pre) =
259 XML.Elem (("CONTEXTMET", []),
260 ( (* WN150530: calcid will be required for asynchronous communication *)
261 XML.Elem (("GUH", []), [XML.Text (pblID2guh pI)]) ::
262 XML.Elem (("STATUS", []), [
263 XML.Text ((if model_ok then "correct" else "incorrect"))]) ::
264 XML.Elem (("HEAD", []), [xml_of_src scr]) ::
265 (xml_of_model pbl pre) :: []))
267 fun tryrefineOK2xml (cI:calcID) (ModSpec modspec) =
268 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
270 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
271 modspec2xml i modspec ^
275 fun appendformulaOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
276 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
277 "<APPENDFORMULA>\n" ^
278 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
280 pos'2xml (2*i) ("UNCHANGED", old) ^
281 pos'2xml (2*i) ("DELETED", del) ^
282 pos'2xml (2*i) ("GENERATED", new) ^
283 " </CALCCHANGED>\n" ^
284 "</APPENDFORMULA>\n" ^
286 fun appendformulaOK2xml (calcid : calcID) (old : pos') (del : pos') (new : pos') =
287 xml_of_calcchanged calcid "APPENDFORMULA" old del new
288 fun appendformulaERROR2xml (cI:calcID) msg =
289 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
290 "<CALCMESSAGE> "^ msg ^" </CALCMESSAGE>\n" ^
292 fun appendformulaERROR2xml (calcid : calcID) e =
293 XML.Elem (("APPENDFORMULA", []), [
294 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
295 XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
297 fun replaceformulaOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
298 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
299 "<REPLACEFORMULA>\n" ^
300 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
302 pos'2xml (2*i) ("UNCHANGED", old) ^
303 pos'2xml (2*i) ("DELETED", del) ^
304 pos'2xml (2*i) ("GENERATED", new) ^
305 " </CALCCHANGED>\n" ^
306 "</REPLACEFORMULA>\n" ^
308 fun replaceformulaOK2xml (calcid : calcID) (old : pos') (del : pos') (new : pos') =
309 xml_of_calcchanged calcid "REPLACEFORMULA" old del new
310 fun replaceformulaERROR2xml (cI:calcID) msg =
311 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
312 "<CALCMESSAGE> "^ msg ^" </CALCMESSAGE>\n" ^
314 fun replaceformulaERROR2xml (calcid : calcID) e =
315 XML.Elem (("REPLACEFORMULA", []), [
316 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
317 XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
319 fun message2xml (cI:calcID) e =
320 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
322 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
323 " <STRING> "^e^" </STRING>\n" ^
326 fun message2xml (calcid : calcID) e =
327 XML.Elem (("MESSAGE", []), [
328 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
329 XML.Elem (("STRING", []), [XML.Text e])])
331 fun setnexttactic2xml (*uI:iterID*) (cI:calcID) e =
332 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
333 "<SETNEXTTACTIC>\n" ^
334 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
335 " <MESSAGE> "^e^" </MESSAGE>\n" ^
336 "</SETNEXTTACTIC>\n" ^
338 fun setnexttactic2xml (calcid : calcID) e =
339 XML.Elem (("SETNEXTTACTIC", []), [
340 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
341 XML.Elem (("MESSAGE", []), [XML.Text e])])
343 fun fetchproposedtacticOK2xml (cI:calcID) tac _ =
344 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
346 " <CALCID> "^string_of_int cI^" </CALCID>\n"^
351 fun fetchproposedtacticOK2xml (cI:calcID) tac (errpatIDs: errpatID list) =
352 writeln ("@@@@@begin@@@@@\n " ^ string_of_int cI ^ " \n" ^
354 " <CALCID> " ^ string_of_int cI ^ " </CALCID>\n" ^
355 " <TACTICERRORPATTERNS>\n" ^
356 id2xml (2*i) errpatIDs ^
358 " </TACTICERRORPATTERNS>\n" ^
361 fun fetchproposedtacticOK2xml (calcid : calcID) tac (errpatIDs : errpatID list) =
362 XML.Elem (("NEXTTAC", []), [
363 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
364 XML.Elem (("TACTICERRORPATTERNS", []), [xml_of_strs errpatIDs]),
367 // java.lang.IllegalArgumentException: fetch_proposed_tac_out wrong arg:
370 * <TACTICERRORPATTERNS>
372 * <STRINGLISTTACTIC name="Apply_Method">
374 * <STRING>Test</STRING>
375 * <STRING>squ-equ-test-subpbl1</STRING>
377 * </STRINGLISTTACTIC>
378 * </TACTICERRORPATTERNS>
382 fun fetchproposedtacticERROR2xml (*uI:userID*) (cI:calcID) e =
383 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
385 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
386 " <ERROR> "^ e ^" </ERROR>\n" ^
389 fun fetchproposedtacticERROR2xml (calcid : calcID) e =
390 XML.Elem (("NEXTTAC", []), [
391 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
392 XML.Elem (("ERROR", []), [XML.Text e])])
394 (*. UNCHANGED: the pos' of the active formula autocalculate has been applied at
395 DELETED: last pos' of the succesional sequence of formulae prob. deleted
396 GENERATED: the pos' of the new active formula
398 fun autocalculateOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
399 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
401 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
403 pos'2xml (2*i) ("UNCHANGED", old) ^
404 pos'2xml (2*i) ("DELETED", del) ^
405 pos'2xml (2*i) ("GENERATED", new) ^
406 " </CALCCHANGED>\n" ^
409 fun autocalculateOK2xml (calcid : calcID) (old : pos') (del : pos') (new : pos') =
410 xml_of_calcchanged calcid "AUTOCALC" old del new
411 fun autocalculateERROR2xml (cI:calcID) e =
412 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
413 (* WN150530: worked without cI ?!? FIXXME*)
414 "<CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
416 fun autocalculateERROR2xml (calcid : calcID) e =
417 XML.Elem (("AUTOCALC", []), [
418 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
419 XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
421 fun interStepsOK (cI:calcID) (old:pos') (del:pos') (new:pos') =
422 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
424 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
426 pos'2xml (2*i) ("UNCHANGED", old) ^
427 pos'2xml (2*i) ("DELETED", del) ^
428 pos'2xml (2*i) ("GENERATED", new) ^
429 " </CALCCHANGED>\n" ^
432 fun interStepsOK (calcid : calcID) (old : pos') (del : pos') (new : pos') =
433 xml_of_calcchanged calcid "INTERSTEPS" old del new
434 fun interStepsERROR (cI:calcID) e =
435 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
436 " <CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
438 fun interStepsERROR (calcid : calcID) e =
439 XML.Elem (("INTERSTEPS", []), [
440 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
441 XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
443 fun calcMessage2xml (cI:calcID) e =
444 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
445 " <CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
448 fun modifycalcheadOK2xml (cI:calcID) (chd as (complete,p_,_,_,_,_):ocalhd) =
449 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
450 "<MODIFYCALCHEAD>\n" ^
451 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
452 " <STATUS> "^(if complete then "complete"
453 else "incomplete")^ "</STATUS>\n"^
455 "</MODIFYCALCHEAD>\n" ^
457 fun modifycalcheadOK2xml (calcid : calcID) (chd as (complete, p_ ,_ ,_ ,_ ,_) : ocalhd) =
458 XML.Elem (("MODIFYCALCHEAD", []), [
459 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
460 XML.Elem (("STATUS", []), [
461 XML.Text (if complete then "complete" else "incomplete")]),
464 fun contextthyOK2xml cI contthy =
465 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
467 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
468 contthy2xml i contthy ^
471 fun contextthyOK2xml calcid contthy =
472 XML.Elem (("CONTEXTTHY", []), [
473 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
474 XML.Elem (("CONTEXTDATA", []), xml_of_contthy contthy)])
476 fun findFillpatterns2xml (cI:calcID) pattIDs =
477 writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
478 "<FINDFILLPATTERNS>\n" ^
479 " <CALCID> "^string_of_int cI^" </CALCID>\n" ^
481 "</FINDFILLPATTERNS>\n" ^
483 fun findFillpatterns2xml (calcid : calcID) pattIDs =
484 XML.Elem (("FINDFILLPATTERNS", []), [
485 XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
486 xml_of_strs pattIDs])