src/Tools/isac/xmlsrc/interface-xml.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Thu, 15 Mar 2018 10:17:44 +0100
changeset 59405 49d7d410b83c
parent 59276 56dc790071cb
child 59416 229e5c9cf78b
permissions -rw-r--r--
separate structure Celem: CALC_ELEMENT, all but Knowledge/
     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 (**FIXXME.8.03 addUser: clear code, because only CalcTrees distinguished**)
    18 fun adduserOK2xml (calcid : Celem.calcID) (userid : Celem.iterID) =
    19   XML.Elem (("ADDUSER", []),
    20     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    21     XML.Elem (("USERID", []), [XML.Text (string_of_int userid)])])
    22 
    23 fun calctreeOK2xml (calcid : Celem.calcID) = 
    24   XML.Elem (("CALCTREE", []),
    25     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)])])    
    26 fun deconstructcalctreeOK2xml (calcid : Celem.calcID) = 
    27   XML.Elem (("DELCALC", []),
    28     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)])])    
    29 
    30 fun iteratorOK2xml (calcid : Celem.calcID) (p : Ctree.pos')= 
    31   XML.Elem (("CALCITERATOR", []),
    32     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    33     xml_of_pos "POSITION" p])
    34 fun iteratorERROR2xml  (calcid : Celem.calcID) = 
    35   XML.Elem (("CALCITERATOR", []),
    36     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    37     XML.Elem (("ERROR", []), [XML.Text " iteratorERROR2xml: pos does not exist "])])
    38 
    39 fun sysERROR2xml (calcid : Celem.calcID) str =
    40   XML.Elem (("SYSERROR", []),
    41     [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    42     XML.Elem (("ERROR", []), [XML.Text (if str = "" then " ERROR in kernel " else str)])])
    43 
    44 fun refformulaOK2xml (calcid : Celem.calcID) p (Ctree.Form t) = 
    45       XML.Elem (("REFFORMULA", []),
    46         [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    47         XML.Elem (("CALCFORMULA", []), [
    48           xml_of_pos "POSITION" p,
    49           xml_of_term_NEW t])])
    50   | refformulaOK2xml (calcid : Celem.calcID) p (Ctree.ModSpec modspec) = 
    51       XML.Elem (("REFFORMULA", []), [
    52         XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    53         (*L.Elem (("CALCHEAD*) xml_of_posmodspec (p, modspec)])
    54 
    55 fun gettacticOK2xml (calcid : Celem.calcID) tac = 
    56   XML.Elem (("GETTACTIC", []),[
    57     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    58     xml_of_tac tac])
    59 
    60 fun gettacticERROR2xml (calcid : Celem.calcID) str = 
    61   XML.Elem (("GETTACTIC", []),[
    62     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    63     XML.Elem (("ERROR", []), [XML.Text  str])])
    64 
    65 fun applicabletacticsOK calcid tacs =
    66   XML.Elem (("APPLICABLETACTICS", []), [
    67     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    68     XML.Elem (("TACLIST", []), (map xml_of_tac tacs))])
    69 
    70 fun getasmsOK2xml (calcid : Celem.calcID) terms = 
    71   XML.Elem (("ASSUMPTIONS", []), [
    72     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
    73     XML.Elem (("ASMLIST", []), (map xml_of_term_NEW terms))])
    74 
    75 (*WN0502 getaccuasmsOK2xml @see ME/ctree: type asms: illdesigned, thus not used*)
    76 fun formula2xml j term = (*TODO.WN050211: use for _all_ <FORMULA>*)
    77     indt j ^ "<FORMULA>\n"^
    78     term2xml j term ^"\n"^
    79     indt j ^ "</FORMULA>\n" : Celem.xml;
    80 fun formulae2xml j [] = ("": Celem.xml)
    81   | formulae2xml j (r::rs) = formula2xml j r ^ formulae2xml j rs;
    82 (* writeln(formulae2xml 6 [str2term "1+1=2", str2term "1+1+1=3"]);
    83    *)
    84 fun getaccuasmsOK2xml cI asms =
    85     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
    86 	     "<GETACCUMULATEDASMS>\n" ^
    87 	     "  <CALCID> "^string_of_int cI^" </CALCID>\n" ^
    88 	     "  <ASMLIST>\n"^
    89 	     formulae2xml (i+i) asms^
    90 	     "  </ASMLIST>\n" ^
    91 	     "</GETACCUMULATEDASMS>\n" ^
    92 	     "@@@@@end@@@@@");
    93 (* getaccuasmsOK2xml 333 [(([1],Res), str2term "1+1=2"),
    94 			  (([2],Res), str2term "1+1+1=3")];
    95    getaccuasmsOK2xml 333 [str2term "1+1=2", str2term "1+1+1=3"];
    96    *)
    97 
    98 fun getintervalOK (calcid : Celem.calcID) fs = 
    99       XML.Elem (("GETELEMENTSFROMTO", []),
   100         [XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   101         XML.Elem (("FORMHEADS", []), map xml_of_posterm fs)])
   102 
   103 fun appendformulaOK2xml (calcid : Celem.calcID) (old : Ctree.pos') (del : Ctree.pos') (new : Ctree.pos') = 
   104   xml_of_calcchanged calcid "APPENDFORMULA" old del new
   105 fun appendformulaERROR2xml (calcid : Celem.calcID) e = 
   106   XML.Elem (("APPENDFORMULA", []), [
   107     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   108     XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
   109 
   110 fun replaceformulaOK2xml (calcid : Celem.calcID) (old : Ctree.pos') (del : Ctree.pos') (new : Ctree.pos') = 
   111   xml_of_calcchanged calcid "REPLACEFORMULA" old del new
   112 fun replaceformulaERROR2xml (calcid : Celem.calcID) e = 
   113   XML.Elem (("REPLACEFORMULA", []), [
   114     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   115     XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
   116 
   117 fun message2xml (calcid : Celem.calcID) e = 
   118   XML.Elem (("MESSAGE", []), [
   119     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   120     XML.Elem (("STRING", []), [XML.Text e])])
   121 
   122 fun setnexttactic2xml (calcid : Celem.calcID) e = 
   123   XML.Elem (("SETNEXTTACTIC", []), [
   124     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   125     XML.Elem (("MESSAGE", []), [XML.Text e])])
   126 
   127 fun fetchproposedtacticOK2xml (calcid : Celem.calcID) tac (errpatIDs : Celem.errpatID list) = 
   128   XML.Elem (("NEXTTAC", []), [
   129     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   130     XML.Elem (("TACTICERRORPATTERNS", []), [xml_of_strs errpatIDs]),
   131     xml_of_tac tac])
   132 
   133 fun fetchproposedtacticERROR2xml (calcid : Celem.calcID) e = 
   134   XML.Elem (("NEXTTAC", []), [
   135     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   136     XML.Elem (("ERROR", []), [XML.Text e])])
   137 
   138 (*. UNCHANGED: the pos' of the active formula autocalculate has been applied at
   139     DELETED:   last pos' of the succesional sequence of formulae prob. deleted
   140     GENERATED: the pos' of the new active formula
   141 .*)
   142 fun autocalculateOK2xml (calcid : Celem.calcID) (old : Ctree.pos') (del : Ctree.pos') (new : Ctree.pos') = 
   143   xml_of_calcchanged calcid "AUTOCALC" old del new
   144 fun autocalculateERROR2xml (calcid : Celem.calcID) e = 
   145   XML.Elem (("AUTOCALC", []), [
   146     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   147     XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
   148 
   149 fun interStepsOK (calcid : Celem.calcID) (old : Ctree.pos') (del : Ctree.pos') (new : Ctree.pos') =
   150    xml_of_calcchanged calcid "INTERSTEPS" old del new
   151 fun interStepsERROR (calcid : Celem.calcID) e = 
   152   XML.Elem (("INTERSTEPS", []), [
   153     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   154     XML.Elem (("CALCMESSAGE", []), [XML.Text e])])
   155 
   156 fun calcMessage2xml (cI: Celem.calcID) e =
   157     writeln ("@@@@@begin@@@@@\n "^string_of_int cI^" \n" ^
   158 	     "  <CALCMESSAGE> "^ e ^" </CALCMESSAGE>\n" ^
   159 	     "@@@@@end@@@@@");
   160 
   161 fun modifycalcheadOK2xml (calcid : Celem.calcID) (chd as (complete, p_ ,_ ,_ ,_ ,_) : Ctree.ocalhd) =
   162   XML.Elem (("MODIFYCALCHEAD", []), [
   163     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   164     XML.Elem (("STATUS", []), [
   165       XML.Text (if complete then "complete" else "incomplete")]),
   166     xml_of_modspec chd])
   167 
   168 fun contextthyOK2xml calcid contthy = 
   169   XML.Elem (("CONTEXTTHY", []), [
   170     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   171     xml_of_contthy contthy])
   172 
   173 fun contextpblOK2xml calcid contpbl = 
   174   XML.Elem (("CONTEXTPBL", []), [
   175     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   176     xml_of_matchpbl contpbl])
   177 fun contextmetOK2xml calcid contmet = 
   178   XML.Elem (("CONTEXTMET", []), [
   179     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   180     xml_of_matchmet contmet])
   181 
   182 fun findFillpatterns2xml (calcid : Celem.calcID) pattIDs = 
   183   XML.Elem (("FINDFILLPATTERNS", []), [
   184     XML.Elem (("CALCID", []), [XML.Text (string_of_int calcid)]),
   185     xml_of_strs pattIDs])
   186