src/Tools/isac/xmlsrc/interface-xml.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Thu, 28 May 2015 14:23:18 +0200
changeset 59127 34f296390b60
parent 59126 55c3e6c7b9c4
child 59129 b5770c988153
permissions -rw-r--r--
PIDE: more interactions in frontend interface:

CalcTree, getActiveFormula, moveActiveCalcHead, moveActiveDown,
moveActiveFormula, ...
... all concerning iteratorOK2xml.

We leave the old code until libisabelle is integrated.
     1 (* interface between isac math engine and java:
     2    java -> sml: strings on stdin
     3    sml -> java: xml on stdout
     4 
     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.
     8 
     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
    15 *)
    16 
    17 type iterID = int;
    18 type calcID = int;
    19 
    20 
    21 
    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" ^
    26 	     "<ADDUSER>\n" ^
    27 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    28 	     "  <USERID> "^string_of_int uI^" </USERID>\n" ^
    29 	     "</ADDUSER>\n" ^
    30 	     "@@@@@end@@@@@");
    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" ^
    37 	     "<DELUSER>\n" ^
    38 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    39 	     "  <USERID> "^string_of_int uI^" </USERID>\n" ^
    40 	     "</DELUSER>\n" ^
    41 	     "@@@@@end@@@@@");
    42 (*---------------------------------------------------------------------*)
    43 
    44 fun calctreeOK2xml (*uI:iterID*) (cI:calcID) = 
    45     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
    46 	     "<CALCTREE>\n" ^
    47 	     "   <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    48 	     "</CALCTREE>\n" ^
    49 	     "@@@@@end@@@@@");
    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" ^
    55 	     "<DELCALC>\n" ^
    56 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    57 	     "</DELCALC>\n" ^
    58 	     "@@@@@end@@@@@");
    59 
    60 fun iteratorOK2xml (cI:calcID) (p:pos')= 
    61     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
    62 	     "<CALCITERATOR>\n" ^
    63 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    64 	     pos'2xml i ("POSITION", p) ^
    65 	     "</CALCITERATOR>\n" ^
    66 	     "@@@@@end@@@@@");
    67 fun iteratorERROR2xml (cI:calcID) = 
    68     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
    69 	     "<CALCITERATOR>\n" ^
    70 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    71 	     "  <ERROR> pos does not exist </ERROR>\n" ^
    72 	     "</CALCITERATOR>\n" ^
    73 	     "@@@@@end@@@@@");
    74 fun iteratorOK2xml (calcid : calcID) (p : pos')= 
    75   XML.Elem (("CALCITERATOR", []),
    76     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    77     xml_of_pos "POSITION" p])
    78 fun iteratorERROR2xml  (calcid : calcID) = 
    79   XML.Elem (("CALCITERATOR", []),
    80     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    81     XML.Elem (("ERROR", []), [XML.Text " pos does not exist "])])
    82 
    83 fun sysERROR2xml (cI:calcID) "" = 
    84     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
    85 	     "<SYSERROR>\n" ^
    86 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    87 	     "  <ERROR> in kernel </ERROR>\n" ^
    88 	     "</SYSERROR>\n" ^
    89 	     "@@@@@end@@@@@")
    90   | sysERROR2xml (cI:calcID) str = 
    91     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
    92 	     "<SYSERROR>\n" ^
    93 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    94 	     "  <ERROR> "^str^" </ERROR>\n" ^
    95 	     "</SYSERROR>\n" ^
    96 	     "@@@@@end@@@@@");
    97 fun sysERROR2xmlTODO (calcid : calcID) str =
    98   XML.Elem (("SYSERROR", []),
    99     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   100     XML.Elem (("ERROR", []), [XML.Text (if str = "" then " ERROR in kernel " else str)])])
   101 
   102 fun refformulaOK2xml (cI:calcID) p (Form t) = 
   103     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   104 	     "<REFFORMULA>\n" ^
   105              "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   106 	     "  <CALCFORMULA>\n"^
   107 	     pos'2xml (2*i) ("POSITION", p) ^
   108 	     "    <FORMULA>" ^
   109 	     term2xml (2*i) t ^ "\n" ^
   110 	     "    </FORMULA>\n" ^
   111 	     "  </CALCFORMULA>\n" ^
   112 	     "</REFFORMULA>\n" ^
   113 	     "@@@@@end@@@@@") 
   114   | refformulaOK2xml (cI:calcID) p (ModSpec modspec) =
   115     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   116 	     "<REFFORMULA>\n" ^
   117              "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   118 	     pos'calchead2xml i (p, modspec)^ 
   119 	     "</REFFORMULA>\n" ^
   120 	     "@@@@@end@@@@@"); 
   121 fun refformulaOK2xml (calcid : calcID) p (Form t) = 
   122       XML.Elem (("REFFORMULA", []),
   123         [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   124         XML.Elem (("CALCFORMULA", []), [
   125           xml_of_pos "POSITION" p,
   126           XML.Elem (("FORMULA", []), [xml_of_term t])])])
   127   | refformulaOK2xml (calcid : calcID) p (ModSpec modspec) = 
   128       XML.Elem (("REFFORMULA", []),
   129         [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   130         XML.Elem (("ERROR", []), [XML.Text " pos does not exist "])])
   131 
   132 fun refformulaERROR2xml (cI:calcID) = (*FIXME.WN.29.8.03 unused*)
   133     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   134 	     "<REFFORMULA>\n" ^
   135 	     "   <ERROR> object is not a formula </ERROR>\n" ^
   136 	     "</REFFORMULA>\n" ^
   137 	     "@@@@@end@@@@@");
   138 
   139 (* val (cI, tac) = (cI, ta);
   140    *)
   141 fun gettacticOK2xml (cI:calcID) tac = 
   142     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   143 	     "<GETTACTIC>\n" ^
   144 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n"^
   145 	     tac2xml i tac^
   146 	     "</GETTACTIC>\n" ^
   147 	     "@@@@@end@@@@@");
   148 fun gettacticERROR2xml (cI:calcID) str = 
   149     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   150 	     "<GETTACTIC>\n" ^
   151 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   152 	     "  <ERROR> "^str^" </ERROR>\n" ^
   153 	     "</GETTACTIC>\n" ^
   154 	     "@@@@@end@@@@@");
   155 
   156 fun applicabletacticsOK cI tacs =
   157     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   158 	     "<APPLICABLETACTICS>\n" ^
   159 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   160 	     "  <TACLIST>\n"^
   161 	     tacs2xml (2*i) tacs^
   162 	     "  </TACLIST>\n" ^
   163 	     "</APPLICABLETACTICS>\n" ^
   164 	     "@@@@@end@@@@@");
   165 
   166 fun getasmsOK2xml (cI:calcID) terms = 
   167     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   168 	     "<GETASSUMPTIONS>\n" ^
   169 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   170 	     "  <ASMLIST>\n"^
   171 	     formulae2xml (i+i) terms ^
   172 	     "  </ASMLIST>\n" ^
   173 	     "</GETASSUMPTIONS>\n" ^
   174 	     "@@@@@end@@@@@");
   175 (* getasmsOK2xml 333 [str2term "1+1=2", str2term "1+1+1=3"];
   176    *)
   177 
   178 (*WN0502 @see ME/ctree: type asms: illdesigned, thus not used*)
   179 fun getaccuasmsOK2xml cI asms =
   180     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   181 	     "<GETACCUMULATEDASMS>\n" ^
   182 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   183 	     "  <ASMLIST>\n"^
   184 	     formulae2xml (i+i) asms^
   185 	     "  </ASMLIST>\n" ^
   186 	     "</GETACCUMULATEDASMS>\n" ^
   187 	     "@@@@@end@@@@@");
   188 (* getaccuasmsOK2xml 333 [(([1],Res), str2term "1+1=2"),
   189 			  (([2],Res), str2term "1+1+1=3")];
   190    getaccuasmsOK2xml 333 [str2term "1+1=2", str2term "1+1+1=3"];
   191    *)
   192 
   193 fun getintervalOK (cI:calcID) fs = 
   194     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   195 	     "<GETELEMENTSFROMTO>\n" ^
   196 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   197 	     "  <FORMHEADS>\n"^	     
   198 	     posterms2xml (2*i) fs^
   199 	     "  </FORMHEADS>\n" ^	     
   200 	     "</GETELEMENTSFROMTO>\n" ^
   201 	     "@@@@@end@@@@@");
   202 fun getintervalOK (calcid : calcID) fs = 
   203       XML.Elem (("GETELEMENTSFROMTO", []),
   204         [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   205         XML.Elem (("FORMHEADS", []), map xml_of_posterm fs)])
   206 
   207 fun matchpbl2xml (cI:calcID) (model_ok, pI, hdl, pbl, pre) =
   208     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   209 	     "<CONTEXTPBL>\n" ^
   210 	     "  <GUH> " ^ pblID2guh pI ^ " </GUH>\n" ^
   211 	     "  <STATUS> " ^ (if model_ok 
   212 			     then "correct" 
   213 			     else "incorrect") ^ " </STATUS>\n" ^
   214 	     "  <HEAD>\n" ^
   215 	     term2xml i hdl ^ "\n" ^
   216 	     "  </HEAD>\n" ^
   217 	     model2xml i pbl pre ^
   218 	     "</CONTEXTPBL>\n" ^
   219 	     "@@@@@end@@@@@");
   220 
   221 fun matchmet2xml (cI:calcID) (model_ok, pI, scr, pbl, pre) =
   222     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   223 	     "<CONTEXTMET>\n" ^
   224 	     "  <GUH> " ^ metID2guh pI ^ " </GUH>\n" ^
   225 	     "  <STATUS> " ^ (if model_ok 
   226 			     then "correct" 
   227 			     else "incorrect") ^ " </STATUS>\n" ^
   228 	     scr2xml i scr ^
   229 	     model2xml i pbl pre ^
   230 	     "</CONTEXTMET>\n" ^
   231 	     "@@@@@end@@@@@");
   232 
   233 
   234 fun tryrefineOK2xml (cI:calcID) (ModSpec modspec) =
   235     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   236 	     "<TRYREFINE>\n" ^
   237              "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   238 	     modspec2xml i modspec ^
   239 	     "</TRYREFINE>\n" ^
   240 	     "@@@@@end@@@@@"); 
   241 
   242 fun appendformulaOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
   243     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   244 	     "<APPENDFORMULA>\n" ^
   245 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   246 	     "  <CALCCHANGED>\n" ^
   247 	     pos'2xml (2*i) ("UNCHANGED", old) ^ 
   248 	     pos'2xml (2*i) ("DELETED", del) ^ 
   249 	     pos'2xml (2*i) ("GENERATED", new) ^ 
   250 	     "  </CALCCHANGED>\n" ^
   251 	     "</APPENDFORMULA>\n" ^
   252 	     "@@@@@end@@@@@");
   253 (* appendformulaOK2xml 1 ([2],Frm) ([3],Pbl) ([4],Res);
   254    *)
   255 fun appendformulaERROR2xml (cI:calcID) msg =
   256     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   257 	     "<CALCMESSAGE> "^ msg ^" </CALCMESSAGE>\n" ^
   258 	     "@@@@@end@@@@@");
   259 
   260 fun replaceformulaOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') =
   261     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   262 	     "<REPLACEFORMULA>\n" ^
   263 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   264 	     "  <CALCCHANGED>\n" ^
   265 	     pos'2xml (2*i) ("UNCHANGED", old) ^ 
   266 	     pos'2xml (2*i) ("DELETED", del) ^ 
   267 	     pos'2xml (2*i) ("GENERATED", new) ^ 
   268 	     "  </CALCCHANGED>\n" ^
   269 	     "</REPLACEFORMULA>\n" ^
   270 	     "@@@@@end@@@@@");
   271 fun replaceformulaERROR2xml (cI:calcID) msg =
   272     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   273 	     "<CALCMESSAGE> "^ msg ^" </CALCMESSAGE>\n" ^
   274 	     "@@@@@end@@@@@");
   275 
   276 fun message2xml (cI:calcID) e = 
   277     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   278 	     "<MESSAGE>\n" ^
   279 	     "   <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   280 	     "   <STRING> "^e^" </STRING>\n" ^
   281 	     "</MESSAGE>\n" ^
   282 	     "@@@@@end@@@@@");
   283 
   284 fun setnexttactic2xml (*uI:iterID*) (cI:calcID) e = 
   285     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   286 	     "<SETNEXTTACTIC>\n" ^
   287 	     "   <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   288 	     "   <MESSAGE> "^e^" </MESSAGE>\n" ^
   289 	     "</SETNEXTTACTIC>\n" ^
   290 	     "@@@@@end@@@@@");
   291 
   292 fun fetchproposedtacticOK2xml (cI:calcID) tac _ = 
   293     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   294 	     "<NEXTTAC>\n" ^
   295 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n"^
   296 	     tac2xml i tac^
   297 	     "</NEXTTAC>\n" ^
   298 	     "@@@@@end@@@@@");
   299 (*NEW JAVA*)
   300 fun fetchproposedtacticOK2xml (cI:calcID) tac (errpatIDs: errpatID list) = 
   301     writeln ("@@@@@begin@@@@@\n " ^ string_of_int cI ^ " \n" ^
   302 	     "<NEXTTAC>\n" ^
   303 	     "  <CALCID> " ^ string_of_int cI ^ " </CALCID>\n" ^
   304      "  <TACTICERRORPATTERNS>\n" ^
   305      id2xml (2*i) errpatIDs ^
   306 	     tac2xml (2*i) tac ^
   307 	     "  </TACTICERRORPATTERNS>\n" ^
   308      "</NEXTTAC>\n" ^
   309 	     "@@@@@end@@@@@");
   310 
   311 fun fetchproposedtacticERROR2xml (*uI:userID*) (cI:calcID) e = 
   312     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   313 	     "<NEXTTAC>\n" ^
   314 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   315 	     "  <ERROR> "^ e ^" </ERROR>\n" ^
   316 	     "</NEXTTAC>\n" ^
   317 	     "@@@@@end@@@@@");
   318 
   319 (*. UNCHANGED: the pos' of the active formula autocalculate has been applied at
   320     DELETED:   last pos' of the succesional sequence of formulae prob. deleted
   321     GENERATED: the pos' of the new active formula
   322 .*)
   323 fun autocalculateOK2xml (cI:calcID) (old:pos') (del:pos') (new:pos') = 
   324     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   325 	     "<AUTOCALC>\n" ^
   326 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   327 	     "  <CALCCHANGED>\n" ^
   328 	     pos'2xml (2*i) ("UNCHANGED", old) ^ 
   329 	     pos'2xml (2*i) ("DELETED", del) ^ 
   330 	     pos'2xml (2*i) ("GENERATED", new) ^ 
   331 	     "  </CALCCHANGED>\n" ^
   332 	     "</AUTOCALC>\n" ^
   333 	     "@@@@@end@@@@@");
   334 (* autocalculate2xml 11 22 (Rewrite ("rmult_commute","?m *?n =?n *?m"));
   335    *)
   336 fun autocalculateERROR2xml (cI:calcID) e = 
   337     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   338 	     "<CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
   339 	     "@@@@@end@@@@@");
   340 
   341 fun interStepsOK (cI:calcID) (old:pos') (del:pos') (new:pos') =
   342     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   343 	     "<INTERSTEPS>\n" ^
   344 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   345 	     "  <CALCCHANGED>\n" ^
   346 	     pos'2xml (2*i) ("UNCHANGED", old) ^ 
   347 	     pos'2xml (2*i) ("DELETED", del) ^ 
   348 	     pos'2xml (2*i) ("GENERATED", new) ^ 
   349 	     "  </CALCCHANGED>\n" ^
   350 	     "</INTERSTEPS>\n" ^
   351 	     "@@@@@end@@@@@");
   352 fun interStepsERROR (cI:calcID) e =
   353     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   354 	     "  <CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
   355 	     "@@@@@end@@@@@");
   356 
   357 fun calcMessage2xml (cI:calcID) e =
   358     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   359 	     "  <CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
   360 	     "@@@@@end@@@@@");
   361 
   362 fun modifycalcheadOK2xml (cI:calcID) (chd as (complete,p_,_,_,_,_):ocalhd) =
   363     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   364 	     "<MODIFYCALCHEAD>\n" ^
   365 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   366 	     "  <STATUS> "^(if complete then "complete" 
   367 			    else "incomplete")^ "</STATUS>\n"^
   368 	     modspec2xml i chd^
   369 	     "</MODIFYCALCHEAD>\n" ^
   370 	     "@@@@@end@@@@@");
   371 
   372 (* val (cI, contthy) = (cI, (context_thy (pt,pos) tac));
   373    *)
   374 fun contextthyOK2xml cI contthy = 
   375     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   376 	     "<CONTEXTTHY>\n" ^
   377 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   378 	     contthy2xml i contthy ^
   379 	     "</CONTEXTTHY>\n" ^
   380 	     "@@@@@end@@@@@");
   381 (*
   382 fun contextthyNO2xml guh = 
   383     writeln (datatypes.contextthyNO2xml 0 guh);
   384 *)
   385 
   386 fun findFillpatterns2xml (cI:calcID) pattIDs = 
   387     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   388 	     "<FINDFILLPATTERNS>\n" ^
   389 	     "   <CALCID> "^string_of_int cI^" </CALCID>\n" ^
   390 	     id2xml 3 pattIDs ^
   391 	     "</FINDFILLPATTERNS>\n" ^
   392 	     "@@@@@end@@@@@");
   393