isac-java/src/java/isac/bridge/xml/DataTypes.scala
author mmahringer <s1520454056@students.fh-hagenberg.at>
Wed, 24 May 2017 13:58:32 +0200
changeset 5120 18fe76f55082
parent 5070 0eff8e522ebb
child 5130 c0abc49ba2db
permissions -rw-r--r--
Integrate mawen Editor into ISAC

Note: integration is minimaly invasive:
* String representation of formulas can stay as before (set by Editor properties)
* formula transports Asts also from the other direction (frontend to backend)
* backend in the bridge is not yet implemented
wneuper@4757
     1
/* 
wneuper@4757
     2
 * @author Walther Neuper
wneuper@4757
     3
 * Copyright (c) due to license terms
wneuper@4757
     4
 * Created on Jul 14, 2015
wneuper@4757
     5
 * Institute for Softwaretechnology, Graz University of Technology, Austria.
wneuper@4757
     6
 * 
wneuper@4757
     7
 * When ConvertXML.scala was not recognized switiching "Scala Nature" 
wneuper@4757
     8
 * off and on again helped.
wneuper@4757
     9
 */
wneuper@4757
    10
wneuper@4757
    11
package isac.bridge.xml
wneuper@4757
    12
wneuper@4759
    13
import isac.bridge.CChanged
wneuper@4788
    14
import isac.bridge.CEvent
wneuper@4788
    15
import isac.bridge.CMessage
wneuper@4932
    16
import isac.gui.mawen.scalaterm.Util
wneuper@5070
    17
import isac.gui.mawen.syntax.Syntax_Phases
wneuper@4759
    18
import isac.util.Formalization
wneuper@4759
    19
import isac.util.formulae.CalcFormula
wneuper@4759
    20
import isac.util.formulae.CalcHead
wneuper@4759
    21
import isac.util.formulae.CalcHeadSimpleID
wneuper@4825
    22
import isac.util.formulae.ContextMethod
wneuper@4825
    23
import isac.util.formulae.ContextProblem
wneuper@4789
    24
import isac.util.formulae.ContextTheory
wneuper@4759
    25
import isac.util.formulae.Formula
wneuper@4789
    26
import isac.util.formulae.FormulaPair
wneuper@4759
    27
import isac.util.formulae.HierarchyKey
wneuper@4789
    28
import isac.util.formulae.KEStoreKey
wneuper@4759
    29
import isac.util.formulae.ModelItem
wneuper@4759
    30
import isac.util.formulae.ModelItemList
wneuper@4759
    31
import isac.util.formulae.Model
wneuper@4757
    32
import isac.util.formulae.Position
wneuper@4789
    33
import isac.util.formulae.Reference
wneuper@4758
    34
import isac.util.formulae.Specification
wneuper@4810
    35
import isac.util.tactics.TermTactic
wneuper@4771
    36
import isac.util.tactics.Rewrite
wneuper@4771
    37
import isac.util.tactics.RewriteInst
wneuper@4771
    38
import isac.util.tactics.RewriteSet
wneuper@4771
    39
import isac.util.tactics.RewriteSetInst
wneuper@4771
    40
import isac.util.tactics.SimpleTactic
wneuper@4771
    41
import isac.util.tactics.StringListTactic
wneuper@4771
    42
import isac.util.tactics.SubProblemTactic
wneuper@4771
    43
import isac.util.tactics.SubstituteTactic
wneuper@4771
    44
import isac.util.tactics.Tactic
wneuper@4771
    45
import isac.util.tactics.Theorem
wneuper@4892
    46
import isac.util.Variant
wneuper@4757
    47
wneuper@4848
    48
import edu.tum.cs.isabelle.api.XML
wneuper@4853
    49
import edu.tum.cs.isabelle.pure._  // for Term
wneuper@4853
    50
import edu.tum.cs.isabelle._       // for Codec
wneuper@4848
    51
wneuper@4757
    52
import java.util.ArrayList
wneuper@4757
    53
import java.util.Vector
wneuper@4757
    54
import java.math.BigInteger
wneuper@4757
    55
import scala.math.BigInt
wneuper@4757
    56
import scala.collection.JavaConverters._
wneuper@4757
    57
wneuper@4758
    58
/**
wneuper@4758
    59
 * conversion XML <--> Java-objects in isac-java used by libisabelle;
wneuper@4758
    60
 * analogous to isabisac/src/Tools/isac/xmlsrc/datatypes.sml.
wneuper@4758
    61
 */
wneuper@4757
    62
object DataTypes {
wneuper@4758
    63
  
wneuper@4759
    64
  /** 
wneuper@4759
    65
   *  auxiliary methods, both directions
wneuper@4759
    66
   **/
wneuper@4757
    67
wneuper@4757
    68
  def xml_of_int (i: scala.math.BigInt): XML.Tree = {
wneuper@4848
    69
    XML.Elem(("INT", Nil), List(XML.Text(i.toString)))
wneuper@4757
    70
  }  
wneuper@4757
    71
  def xml_to_int (t: XML.Tree): scala.math.BigInt = t match {
wneuper@4848
    72
    case XML.Elem(("INT", Nil), List(XML.Text(i))) => BigInt(i)
wneuper@4757
    73
    case _ => throw new IllegalArgumentException("xml_to_int exn")
wneuper@4757
    74
  }
wneuper@4758
    75
  def xml_of_ints (is: List[scala.math.BigInt]): XML.Tree = {
wneuper@4848
    76
    XML.Elem(("INTLIST", Nil), is map xml_of_int)
wneuper@4757
    77
  }
wneuper@4758
    78
  def xml_to_ints (t: XML.Tree): List[scala.math.BigInt] = t match {
wneuper@4848
    79
    case XML.Elem(("INTLIST", Nil), is) => is map xml_to_int
wneuper@4757
    80
    case _ => throw new IllegalArgumentException("xml_to_ints exn")
wneuper@4757
    81
  }
wneuper@4757
    82
  def xml_of_pos (ints: List[scala.math.BigInt], kind: String ): XML.Tree = {
wneuper@4848
    83
    XML.Elem(("POSITION", Nil), List(
wneuper@4757
    84
      xml_of_ints(ints),
wneuper@4848
    85
      XML.Elem(("POS", Nil), List(XML.Text(kind)))))
wneuper@4757
    86
  }
wneuper@4757
    87
  def xml_to_pos (t: XML.Tree): (List[scala.math.BigInt], String) = t match {
wneuper@4848
    88
    case XML.Elem(("POSITION", Nil), List(
wneuper@4848
    89
        is, XML.Elem(("POS", Nil), List(XML.Text(kind))))) => (xml_to_ints(is), kind)
wneuper@4757
    90
    case _ => throw new IllegalArgumentException("xml_to_pos exn")
wneuper@4757
    91
  } 
wneuper@4758
    92
  def xml_to_VectorString (t: XML.Tree): Vector[java.lang.String] = t match {
wneuper@4848
    93
    case XML.Elem(("STRINGLIST", Nil), is) => {
wneuper@4758
    94
      val v = new java.util.Vector[java.lang.String];
wneuper@4759
    95
      is.foreach { 
wneuper@4848
    96
        case (XML.Elem(("STRING", Nil), List(XML.Text(str)))) 
wneuper@4759
    97
          => v.add(str)
wneuper@4759
    98
        case _ => throw new IllegalArgumentException("xml_to_VectorString 1 wrong arg: " + t)
wneuper@4759
    99
      }
wneuper@4758
   100
      v
wneuper@4758
   101
    }
wneuper@4759
   102
    case _ => throw new IllegalArgumentException("xml_to_VectorString 2 wrong arg: " + t)
wneuper@4758
   103
  }
wneuper@4771
   104
  def  xml_of_VectorString(strs: Vector[java.lang.String]): XML.Tree = {
wneuper@4848
   105
    XML.Elem(("STRINGLIST", Nil), 
wneuper@4771
   106
      strs.asScala.toList map xml_of_str)  
wneuper@4771
   107
  }
wneuper@4787
   108
  def xml_to_VectorTactic (t: XML.Tree): Vector[Tactic] = t match {
wneuper@4848
   109
    case XML.Elem(("TACLIST", Nil), tacs_xml) => {
wneuper@4787
   110
      val v = new java.util.Vector[Tactic];
wneuper@4787
   111
      tacs_xml.foreach { tac_xml => v.add(xml_to_Tactic(tac_xml)) }
wneuper@4787
   112
      v
wneuper@4787
   113
    }
wneuper@4787
   114
    case _ => throw new IllegalArgumentException("xml_to_VectorTactic wrong arg: " + t)
wneuper@4787
   115
  }
wneuper@4787
   116
  
wneuper@4758
   117
  // Note: java.int-->scala.BigInt not done here, because "int" is unknown in Scala.
wneuper@4758
   118
  def Integer_to_BigInt (i: java.lang.Integer): scala.math.BigInt = {
wneuper@4771
   119
    new scala.math.BigInt(new BigInteger(i.toString)) //TODO: improve conversion ?
wneuper@4758
   120
  }
wneuper@4758
   121
  // UNUSED conversion scala.math.BigInt --> java.lang.Integer
wneuper@4758
   122
  def BigInt_to_Integer (i: scala.math.BigInt): java.lang.Integer = {
wneuper@4771
   123
    new java.lang.Integer(i.toString) //TODO: improve conversion ?
wneuper@4758
   124
  }
wneuper@4757
   125
  def xml_of_str (s: String): XML.Tree = {
wneuper@4848
   126
    XML.Elem(("STRING", Nil), List(XML.Text(s)))
wneuper@4757
   127
  }  
wneuper@4757
   128
  def xml_to_str (t: XML.Tree): String = t match {
wneuper@4848
   129
    case XML.Elem(("STRING", Nil), List(XML.Text(s))) => s
wneuper@4757
   130
    case _ => throw new IllegalArgumentException("xml_to_str exn")
wneuper@4757
   131
  }
wneuper@4757
   132
  def xml_of_strs (ss: List[String]): XML.Tree = {
wneuper@4848
   133
    XML.Elem(("STRINGLIST", Nil), ss map xml_of_str)
wneuper@4757
   134
  }
wneuper@4757
   135
  def xml_to_strs (t: XML.Tree): List[String] = t match {
wneuper@4848
   136
    case XML.Elem(("STRINGLIST", Nil), ss) => ss map xml_to_str
wneuper@4757
   137
    case _ => throw new IllegalArgumentException("xml_to_strs exn")
wneuper@4757
   138
  } 
wneuper@4757
   139
  def xml_of_spec (thy: String, pbl: ArrayList[String], met: ArrayList[String]): XML.Tree = {
wneuper@4848
   140
    XML.Elem(("SPECIFICATION", Nil), List(
wneuper@4848
   141
      XML.Elem(("THEORYID", Nil), List(XML.Text(thy))),
wneuper@4848
   142
      XML.Elem(("PROBLEMID", Nil), List(xml_of_strs(pbl.asScala.toList))),
wneuper@4848
   143
      XML.Elem(("METHODID", Nil), List(xml_of_strs(met.asScala.toList)))))
wneuper@4757
   144
  }
wneuper@4757
   145
  def xml_to_spec (t: XML.Tree) = t match {
wneuper@4848
   146
    case XML.Elem(("SPECIFICATION", Nil), List(
wneuper@4848
   147
      XML.Elem(("THEORYID", Nil), List(XML.Text(thy))),
wneuper@4848
   148
      XML.Elem(("PROBLEMID", Nil), List(pbl)),
wneuper@4848
   149
      XML.Elem(("METHODID", Nil), List(met)))) => 
wneuper@4759
   150
        (thy, DataTypes.xml_to_strs(pbl), xml_to_strs(met))
wneuper@4757
   151
    case _ => throw new IllegalArgumentException("xml_to_spec exn")
wneuper@4757
   152
  } 
wneuper@4759
   153
  def xml_to_VectorInteger (t: XML.Tree): Vector[java.lang.Integer] = t match {
wneuper@4848
   154
    case XML.Elem(("INTLIST", Nil), is) => {
wneuper@4759
   155
      val v = new java.util.Vector[java.lang.Integer];
wneuper@4759
   156
      is.foreach { 
wneuper@4848
   157
        case (XML.Elem(("INT", Nil), List(XML.Text(i)))) 
wneuper@4759
   158
          => v.add(new java.lang.Integer(i)) 
wneuper@4759
   159
        case _ => throw new IllegalArgumentException("xml_to_VectorInteger 1 wrong arg: " + t)
wneuper@4759
   160
      }
wneuper@4759
   161
      v
wneuper@4759
   162
    }
wneuper@4759
   163
    case _ => throw new IllegalArgumentException("xml_to_VectorInteger 2 wrong arg: " + t)
wneuper@4759
   164
  }
wneuper@4759
   165
  def sListToVectorCalcFormula (forms: List[CalcFormula]): Vector[CalcFormula] = {
wneuper@4759
   166
      val v = new java.util.Vector[CalcFormula];
wneuper@4759
   167
      forms.foreach { form => v.add(form) }
wneuper@4759
   168
      v
wneuper@4759
   169
  }
wneuper@4787
   170
  def sListToVectorFormula (forms: List[Formula]): Vector[Formula] = {
wneuper@4787
   171
      val v = new java.util.Vector[Formula];
wneuper@4787
   172
      forms.foreach { form => v.add(form) }
wneuper@4787
   173
      v
wneuper@4787
   174
  }
wneuper@4789
   175
  def sListToVectorFormulaPair (forms: List[FormulaPair]): Vector[FormulaPair] = {
wneuper@4789
   176
      val v = new java.util.Vector[FormulaPair];
wneuper@4789
   177
      forms.foreach { form => v.add(form) }
wneuper@4789
   178
      v
wneuper@4789
   179
  }
wneuper@4759
   180
  def xml_to_String (t: XML.Tree): java.lang.String = t match {
wneuper@4759
   181
    case XML.Text(str) => str
wneuper@4789
   182
    case _ => throw new IllegalArgumentException("xml_to_String wrong arg: " + t)
wneuper@4759
   183
    }
wneuper@4789
   184
  def xml_of_term (str: String): XML.Tree = {
wneuper@4848
   185
    XML.Elem(("MATHML", Nil), List(
wneuper@4848
   186
        XML.Elem(("ISA", Nil), List(XML.Text(str)))))
wneuper@4771
   187
  }
wneuper@4789
   188
  def xml_to_term (t: XML.Tree): java.lang.String = t match {
wneuper@4789
   189
    case
wneuper@4848
   190
      XML.Elem(("MATHML", Nil), List(
wneuper@4848
   191
          XML.Elem(("ISA", Nil), List(XML.Text(str)))))
wneuper@4789
   192
      => str
wneuper@4789
   193
    case _ => throw new IllegalArgumentException("xml_to_term wrong arg: " + t)
wneuper@4789
   194
  }
wneuper@4932
   195
  def xml_of_Term (t: Term): XML.Tree =
wneuper@4932
   196
    XML.Elem(("MATHML", Nil), List(
wneuper@4932
   197
      XML.Elem(("ISA", Nil), List(XML.Text(Util.string_of(t)))),
wneuper@4932
   198
      XML.Elem(("TERM", Nil), List(Codec[Term].encode(t)))))
wneuper@4932
   199
      
wneuper@4842
   200
  def xml_to_prog (t: XML.Tree): java.lang.String = t match {
wneuper@4842
   201
    case
wneuper@4848
   202
      XML.Elem(("NOCODE", Nil), List(XML.Text(str)))
wneuper@4842
   203
      => str
wneuper@4842
   204
    case
wneuper@4848
   205
      XML.Elem(("CODE", Nil), List(term_xml))
wneuper@4842
   206
      => xml_to_term(term_xml)
wneuper@4842
   207
    case _ => throw new IllegalArgumentException("xml_to_prog wrong arg: " + t)
wneuper@4842
   208
  }
wneuper@4771
   209
  
wneuper@4759
   210
  /** 
wneuper@4759
   211
   *  conversion XML <--> Java-objects in isac-java used by libisabelle 
wneuper@4759
   212
   **/
wneuper@4758
   213
  
wneuper@4781
   214
   // <--ISA carries a "status" computed by Math_Engine
wneuper@4781
   215
   def xml_to_ModelItem(t: XML.Tree): isac.util.formulae.ModelItem = t match {
wneuper@4759
   216
    case
wneuper@4848
   217
      XML.Elem(("ITEM", List(("status", status))), List(
wneuper@4848
   218
        XML.Elem(("MATHML", Nil), List(
wneuper@4848
   219
          XML.Elem(("ISA", Nil), List(XML.Text(form_isa)))))))
wneuper@4759
   220
      => new ModelItem(status, form_isa)
wneuper@4759
   221
    case _ => throw new IllegalArgumentException("xml_to_ModelItem wrong arg: " + t)
wneuper@4759
   222
  }
wneuper@4781
   223
   // -->ISA carries NO "status" coming from user.
wneuper@4770
   224
  def xml_of_ModelItem(item: ModelItem): XML.Tree = {
wneuper@4848
   225
    XML.Elem(("ITEM", Nil), List(
wneuper@4848
   226
      XML.Elem(("MATHML", Nil), List(
wneuper@4848
   227
        XML.Elem(("ISA", Nil), List(XML.Text(item.getFormula.toSMLString)))))))
wneuper@4770
   228
  }
wneuper@4759
   229
  def sList2jVectorModelItem(ilist: List[ModelItem]): Vector[ModelItem] = {
wneuper@4771
   230
    val ivect = new Vector[ModelItem]
wneuper@4759
   231
    for (n <- 0 to ilist.size - 1) ivect.add(ilist(n))
wneuper@4759
   232
    ivect
wneuper@4759
   233
  }
wneuper@4759
   234
  //for test on console:
wneuper@4759
   235
  def sList2jVector(ilist: List[Integer]): Vector[Integer] = {
wneuper@4771
   236
    val ivect = new Vector[Integer]
wneuper@4759
   237
    for (n <- 0 to ilist.size - 1) ivect.add(ilist(n))
wneuper@4759
   238
    ivect
wneuper@4759
   239
  }
wneuper@4759
   240
  def xml_to_VectorModelItem(t: XML.Tree): java.util.Vector[ModelItem] = t match {
wneuper@4759
   241
    case
wneuper@4848
   242
      XML.Elem(("GIVEN", Nil), list_xml)
wneuper@4759
   243
      => sList2jVectorModelItem(list_xml map xml_to_ModelItem)
wneuper@4759
   244
    case
wneuper@4848
   245
      XML.Elem(("WHERE", Nil), list_xml)
wneuper@4759
   246
      => sList2jVectorModelItem(list_xml map xml_to_ModelItem)
wneuper@4759
   247
    case
wneuper@4848
   248
      XML.Elem(("FIND", Nil), list_xml)
wneuper@4759
   249
      => sList2jVectorModelItem(list_xml map xml_to_ModelItem)
wneuper@4759
   250
    case
wneuper@4848
   251
      XML.Elem(("RELATE", Nil), list_xml)
wneuper@4759
   252
      => sList2jVectorModelItem(list_xml map xml_to_ModelItem)
wneuper@4759
   253
    case _ => throw new IllegalArgumentException("xml_to_VectorModelItem wrong arg: " + t)
wneuper@4759
   254
  }
wneuper@4759
   255
  def xml_to_Model(t: XML.Tree): Model = t match {
wneuper@4759
   256
    case
wneuper@4848
   257
      XML.Elem(("MODEL", Nil), List(xml_given, xml_where, xml_find, xml_relate))
wneuper@4759
   258
      => new Model(
wneuper@4759
   259
          new ModelItemList(xml_to_VectorModelItem(xml_given)),
wneuper@4759
   260
          new ModelItemList(xml_to_VectorModelItem(xml_where)),
wneuper@4759
   261
          new ModelItemList(xml_to_VectorModelItem(xml_find)),
wneuper@4759
   262
          new ModelItemList(xml_to_VectorModelItem(xml_relate)))
wneuper@4759
   263
    case _ => throw new IllegalArgumentException("xml_to_Model wrong arg: " + t)
wneuper@4759
   264
  }
wneuper@4781
   265
  // 
wneuper@4781
   266
  // status (coming from user) is irrelevant: status is computed by Math_Engine
wneuper@4781
   267
  def xml_of_Item(item: ModelItem): XML.Tree = {
wneuper@4848
   268
    XML.Elem(("ITEM", Nil), List(
wneuper@4781
   269
      xml_of_term(item.getFormula.toString)))
wneuper@4781
   270
  }
wneuper@4781
   271
  def xml_of_items(tag: String, items: java.util.Vector[ModelItem]): XML.Tree = {
wneuper@4781
   272
    var xml: List[XML.Tree] = List()
wneuper@4781
   273
    for (n <- 0 to items.size - 1) { ((xml_of_Item(items.elementAt(n))) :: xml) }
wneuper@4848
   274
    XML.Elem((tag, Nil), xml.reverse)
wneuper@4781
   275
  }
wneuper@4781
   276
  // status (coming from user) is irrelevant: status is computed by Math_Engine
wneuper@4781
   277
  def xml_of_Model(model: Model): XML.Tree = {
wneuper@4848
   278
    XML.Elem(("MODEL", Nil), List(
wneuper@4781
   279
      xml_of_items("GIVEN", model.getGiven.getItems),
wneuper@4781
   280
      // xml_where, is never input by user
wneuper@4781
   281
      xml_of_items("FIND", model.getFind.getItems),
wneuper@4781
   282
      xml_of_items("RELATE", model.getRelate.getItems)
wneuper@4781
   283
      ))
wneuper@4781
   284
  }
wneuper@4759
   285
wneuper@4759
   286
  def xml_to_Specification(t: XML.Tree): isac.util.formulae.Specification = t match {
wneuper@4759
   287
    case
wneuper@4848
   288
      XML.Elem(("SPECIFICATION", Nil), List(
wneuper@4848
   289
        XML.Elem(("THEORYID", Nil), List(xml_thy)),
wneuper@4848
   290
        XML.Elem(("PROBLEMID", Nil), List(xml_pbl)),
wneuper@4848
   291
        XML.Elem(("METHODID", Nil), List(xml_met))))
wneuper@4771
   292
      => { val thy_key = new CalcHeadSimpleID
wneuper@4759
   293
             thy_key.setID(DataTypes.xml_to_String(xml_thy))
wneuper@4771
   294
           val pbl_key = new HierarchyKey
wneuper@4771
   295
             pbl_key.setID(xml_to_VectorString(xml_pbl))
wneuper@4771
   296
           val met_key = new HierarchyKey
wneuper@4771
   297
             met_key.setID(xml_to_VectorString(xml_met))
wneuper@4759
   298
           new Specification(thy_key, pbl_key, met_key) 
wneuper@4759
   299
        }
wneuper@4759
   300
    case _ => throw new IllegalArgumentException("xml_to_Specification wrong arg: " + t)
wneuper@4759
   301
  }
wneuper@4759
   302
  
wneuper@4759
   303
  def xml_to_CalcHead(t: XML.Tree): CalcHead = t match {
wneuper@4759
   304
    case
wneuper@4848
   305
        XML.Elem(("CALCHEAD", List(("status", status))), List(
wneuper@4759
   306
          xml_pos, xml_head, xml_model,
wneuper@4848
   307
          XML.Elem(("BELONGSTO", Nil), List(XML.Text(pbl_met))),
wneuper@4759
   308
          xml_spec))
wneuper@4928
   309
      => {
wneuper@4928
   310
        println("1a xml_to_CalcHead "+xml_head);
wneuper@4928
   311
        println("1b xml_to_CalcHead "+DataTypes.xml_to_Head(xml_head));
wneuper@4787
   312
        new CalcHead(DataTypes.xml_to_Position(xml_pos), 
wneuper@4928
   313
          DataTypes.xml_to_Head(xml_head), xml_to_Model(xml_model),
wneuper@4759
   314
          pbl_met, xml_to_Specification(xml_spec), status)
wneuper@4759
   315
      }
wneuper@4759
   316
    case _ => throw new IllegalArgumentException("xml_to_CalcHead wrong arg: " + t)
wneuper@4759
   317
  }
wneuper@4770
   318
  def xml_of_CalcHead(chead: CalcHead):  XML.Tree = {
wneuper@4848
   319
    XML.Elem(("CALCHEAD", List(("status", chead.getStatusString))), List(
wneuper@4771
   320
      xml_of_Position(chead.getPosition), 
wneuper@4928
   321
      xml_of_Head(chead.getHeadLine),
wneuper@4781
   322
      xml_of_Model(chead.getModel),
wneuper@4848
   323
      XML.Elem(("BELONGSTO", Nil), List(XML.Text(chead.getBelongsTo))),
wneuper@4771
   324
      xml_of_Specification(chead.getSpecification)))
wneuper@4770
   325
  }
wneuper@4787
   326
  def xml_to_Formula(t: XML.Tree): isac.util.formulae.Formula = t match {
wneuper@4759
   327
    case
wneuper@4848
   328
      XML.Elem(("FORMULA", Nil), List(
wneuper@4848
   329
        XML.Elem(("MATHML", Nil), List(
wneuper@4848
   330
          XML.Elem(("ISA", Nil), List(XML.Text(form_isa)))))))
wneuper@4787
   331
      =>  new Formula(form_isa)
wneuper@4928
   332
    case _ => throw new IllegalArgumentException("xml_to_Formula wrong arg: " + t)
wneuper@4928
   333
  }
wneuper@4928
   334
  def xml_to_Head(t: XML.Tree): isac.util.formulae.Formula = t match {
wneuper@4759
   335
    case
wneuper@4928
   336
      XML.Elem(("HEAD", Nil), List(form_xml)) => {
wneuper@4928
   337
      println("2a xml_to_Head "+"found HEAD");
wneuper@4928
   338
      xml_to_Formula_NEW(form_xml)
wneuper@4928
   339
    }
wneuper@4928
   340
    case _ => {
wneuper@4928
   341
      println("2b xml_to_Head "+"Exception");
wneuper@4928
   342
      throw new IllegalArgumentException("xml_to_Formula wrong arg: " + t)
wneuper@4928
   343
    }
wneuper@4759
   344
  }
wneuper@4853
   345
  def xml_to_Formula_NEW(t: XML.Tree): isac.util.formulae.Formula = t match {
wneuper@4853
   346
    case
wneuper@4928
   347
        XML.Elem(("FORMULA", Nil), List(
wneuper@4853
   348
          XML.Elem(("ISA", Nil), List(XML.Text(str))),
wneuper@4855
   349
          XML.Elem(("TERM", Nil), List(term))))
wneuper@5070
   350
      => new Formula(str, Syntax_Phases.term_to_ast(Codec[Term].decode(term).right.get))
wneuper@4855
   351
      // TODO: catch exn which might be thrown by "right.get"
wneuper@4853
   352
    case _ => throw new IllegalArgumentException("xml_to_Formula_NEW wrong arg: " + t)
wneuper@4853
   353
  }
wneuper@4884
   354
  /* 
wneuper@4884
   355
   * WN160512 presently there is no transport of Terms from the GUI to the MathEngine
wneuper@4884
   356
   * and it is questionable whether such transport will be implemented at all.
wneuper@4884
   357
   * So this method might take a String as argument (and send no TERM), like xml_of_Formula.
wneuper@4884
   358
   */
wneuper@4916
   359
  def xml_of_Formula_UNUSED(form: Formula): XML.Tree = {
wneuper@4884
   360
    XML.Elem(("MATHML", Nil), List(
wneuper@4884
   361
      XML.Elem(("ISA", Nil), List(XML.Text("TODO form.getString() OR form.toSMLString()"))),
wneuper@5070
   362
      XML.Elem(("TERM", Nil), List(Codec[Term].encode(Syntax_Phases.ast_to_term(form.getTerm))))))
wneuper@4884
   363
  }
s1520454056@5120
   364
 /* TODO we plan to send both, String and Term to Isabelle_Isac.
s1520454056@5120
   365
   * In a later phase of development Isabelle_Isac will decide whether to use
s1520454056@5120
   366
   * either String or Term (after conversion from Ast). 
s1520454056@5120
   367
   */
wneuper@4916
   368
  def xml_of_Formula_NEW(form: Formula): XML.Tree = {
wneuper@4916
   369
    XML.Elem(("FORMULA", Nil), List(
s1520454056@5120
   370
      XML.Elem(("ISA", Nil), List(XML.Text(form.toString)))//,
s1520454056@5120
   371
      //XML.Elem(("TERM", Nil), List(Codec[Term].encode(Syntax_Phases.ast_to_term(form.getTerm))))
s1520454056@5120
   372
      ))
wneuper@4916
   373
  }
wneuper@4787
   374
  def xml_of_Formula(form_isa: Formula): XML.Tree = {
wneuper@4848
   375
    XML.Elem(("FORMULA", Nil), List(
wneuper@4848
   376
      XML.Elem(("MATHML", Nil), List(
wneuper@4848
   377
        XML.Elem(("ISA", Nil), List(XML.Text(form_isa.toString)))))))
wneuper@4767
   378
  }
wneuper@4928
   379
  def xml_of_Head(head_isa: Formula): XML.Tree = {
wneuper@4928
   380
    XML.Elem(("HEAD", Nil), List(xml_of_Formula_NEW(head_isa)))
wneuper@4767
   381
  }
wneuper@4759
   382
  def xml_to_CalcFormula(t: XML.Tree): CalcFormula = t match {
wneuper@4759
   383
    case
wneuper@4848
   384
      XML.Elem(("CALCFORMULA", Nil), List(pos, form))
wneuper@4933
   385
      => new CalcFormula(xml_to_Position(pos), xml_to_Formula_NEW(form))
wneuper@4759
   386
    case _ => throw new IllegalArgumentException("xml_to_CalcFormula wrong arg: " + t)
wneuper@4759
   387
  }
wneuper@4767
   388
  def xml_of_CalcFormula(calc_form: CalcFormula): XML.Tree = {
wneuper@4848
   389
    XML.Elem(("CALCFORMULA", Nil), List(
wneuper@4771
   390
      xml_of_Position(calc_form.getPosition), 
wneuper@4771
   391
      xml_of_Formula(calc_form.getFormula)))
wneuper@4767
   392
  }
wneuper@4758
   393
  def xml_of_Formalization(fmz: Formalization): XML.Tree = {
wneuper@4892
   394
    if (fmz.getVariants.size == 0) { //..from <NEW> on GUI, then Isabelle/Isac expects.. 
wneuper@4892
   395
      XML.Elem(("FORMALIZATION", Nil), List(
wneuper@4892
   396
        XML.Elem(("VARIANT", Nil), List(
wneuper@4892
   397
          XML.Elem(("STRINGLIST", Nil), Nil), 
wneuper@4892
   398
          XML.Elem(("SPECIFICATION", Nil), List(
wneuper@4892
   399
            XML.Elem(("THEORYID", Nil), List(XML.Text("e_domID"))),
wneuper@4892
   400
            XML.Elem(("PROBLEMID", Nil), List(
wneuper@4892
   401
              XML.Elem(("STRINGLIST", Nil), List(
wneuper@4892
   402
                XML.Elem(("STRING", Nil), List(XML.Text("e_pblID"))))))),
wneuper@4892
   403
            XML.Elem(("METHODID", Nil), List(
wneuper@4892
   404
              XML.Elem(("STRINGLIST", Nil), List(
wneuper@4892
   405
                XML.Elem(("STRING", Nil), List(XML.Text("e_metID")))))))))))))
wneuper@4892
   406
    } else {
wneuper@4892
   407
      XML.Elem(("FORMALIZATION", Nil), fmz.getVariants.asScala.toList map xml_of_Variant)
wneuper@4892
   408
    }
wneuper@4758
   409
  }
wneuper@4758
   410
  def xml_of_Position(pos: Position): XML.Tree = {
wneuper@4771
   411
    val is: List[Integer] = pos.getIntList.asInstanceOf[Vector[Integer]].asScala.toList
wneuper@4771
   412
    xml_of_pos(is map Integer_to_BigInt, pos.getKind)
wneuper@4758
   413
  }
wneuper@4759
   414
  def xml_to_Position(t: XML.Tree): Position = t match {
wneuper@4759
   415
    case
wneuper@4848
   416
      XML.Elem(("POSITION", Nil), List(
wneuper@4848
   417
        ints, XML.Elem(("POS", Nil), List(XML.Text(kind)))))
wneuper@4759
   418
      => new Position(xml_to_VectorInteger(ints), kind)
wneuper@4759
   419
    case _ => throw new IllegalArgumentException("xml_to_Position wrong arg: " + t)
wneuper@4759
   420
  }
wneuper@4758
   421
  def xml_of_Specification(spec: Specification): XML.Tree = {
wneuper@4848
   422
    XML.Elem(("SPECIFICATION", Nil), List(
wneuper@4848
   423
      XML.Elem(("THEORYID", Nil), List(XML.Text(spec.getTheory.getID))),
wneuper@4848
   424
      XML.Elem(("PROBLEMID", Nil), List(
wneuper@4771
   425
        DataTypes.xml_of_strs(spec.getProblem.getID.asScala.toList))),
wneuper@4848
   426
      XML.Elem(("METHODID", Nil), List(
wneuper@4771
   427
        DataTypes.xml_of_strs(spec.getMethod.getID.asScala.toList)))))
wneuper@4758
   428
  }
wneuper@4848
   429
  def xml_of_Variant(vat: isac.util.Variant): XML.Tree = {
wneuper@4848
   430
    XML.Elem(("VARIANT", Nil), List(
wneuper@4771
   431
      DataTypes.xml_of_strs(vat.getIsaStrings.asScala.toList),
wneuper@4771
   432
      xml_of_Specification(vat.getSpecification)))
wneuper@4758
   433
  }
wneuper@4848
   434
  def xml_of_ContextType(ctxt_typ: isac.wsdialog.IContextProvider.ContextType): XML.Tree = {
wneuper@4848
   435
    XML.Elem(("KETYPE", Nil), List(XML.Text(ctxt_typ.toString)))
wneuper@4771
   436
  }
wneuper@4771
   437
wneuper@4932
   438
  // from isac-java to kernel goes only "ISA", no "TERM"
wneuper@4932
   439
  // repair: replace "FORMULA" by "ISA"
wneuper@4848
   440
  def xml_of_Theorem(thm: Theorem): XML.Tree = {
wneuper@4848
   441
    XML.Elem(("THEOREM", Nil), List(
wneuper@4848
   442
      XML.Elem(("ID", Nil), List(XML.Text(thm.getId))),
wneuper@4848
   443
      XML.Elem(("FORMULA", Nil), List(
wneuper@4771
   444
        XML.Text(thm.getFormula))))) // term instead String for MathML
wneuper@4771
   445
  }
wneuper@4932
   446
  // from isac-java to kernel goes only "ISA", no "TERM"
wneuper@4932
   447
  // repair: replace "FORMULA" by "ISA"
wneuper@4771
   448
  def xml_to_Theorem(t: XML.Tree): Theorem = t match {
wneuper@4771
   449
    case 
wneuper@4848
   450
      XML.Elem(("THEOREM", Nil), List(
wneuper@4848
   451
        XML.Elem(("ID", Nil), List(XML.Text(id))),
wneuper@4848
   452
        XML.Elem(("FORMULA", Nil), List(
wneuper@4771
   453
          XML.Text(form)))))  // term instead String for MathML
wneuper@4771
   454
      => new Theorem(id, form)
wneuper@4771
   455
    case x => throw new IllegalArgumentException("xml_to_Theorem WRONG arg = " + x)
wneuper@4771
   456
  }
wneuper@4771
   457
wneuper@4771
   458
  //----- FOR xml_of_Tactic --------------------------------------------*)
wneuper@4848
   459
  def xml_of_SubProblemTactic(tac: SubProblemTactic): XML.Tree = {
wneuper@4848
   460
    XML.Elem(("SUBPROBLEMTACTIC", List(("name", tac.getName))), List(
wneuper@4848
   461
      XML.Elem(("THEORY", Nil), List(XML.Text(tac.getTheoryID))),
wneuper@4848
   462
      XML.Elem(("PROBLEM", Nil), List(xml_of_VectorString(tac.getProblemID)))))
wneuper@4771
   463
  }
wneuper@4771
   464
  // Substitute see //----- STRINGLISTTACTIC below
wneuper@4771
   465
wneuper@4771
   466
  //----- Rewrite* -----------------------------------------------------*)
wneuper@4848
   467
  def xml_of_Rewrite(tac: Rewrite): XML.Tree = {
wneuper@4848
   468
    XML.Elem(("REWRITETACTIC", List(("name", tac.getName))), List(
wneuper@4771
   469
      xml_of_Theorem(tac.getTheorem)))
wneuper@4771
   470
  }
wneuper@4848
   471
  def xml_of_RewriteInst(tac: RewriteInst): XML.Tree = {
wneuper@4848
   472
    XML.Elem(("REWRITEINSTTACTIC", List(("name", tac.getName))), List(
wneuper@4771
   473
      //this will be generalised at introduction of MathML
wneuper@4848
   474
      XML.Elem(("PAIR", Nil), List(    
wneuper@4848
   475
        XML.Elem(("VARIABLE", Nil), List(    
wneuper@4848
   476
          XML.Elem(("MATHML", Nil), List(    
wneuper@4848
   477
            XML.Elem(("ISA", Nil), List(XML.Text(tac.getVariable))))))),
wneuper@4848
   478
        XML.Elem(("VALUE", Nil), List(    
wneuper@4848
   479
          XML.Elem(("MATHML", Nil), List(    
wneuper@4848
   480
            XML.Elem(("ISA", Nil), List(XML.Text(tac.getValue))))))))),
wneuper@4771
   481
      xml_of_Theorem(tac.getTheorem)))
wneuper@4771
   482
  }
wneuper@4848
   483
  def xml_of_RewriteSet(tac: RewriteSet): XML.Tree = {
wneuper@4848
   484
    XML.Elem(("REWRITESETTACTIC", List(("name", tac.getName))), List(
wneuper@4771
   485
      XML.Text(tac.getRuleSet)))
wneuper@4771
   486
  }
wneuper@4848
   487
  def xml_of_RewriteSetInst(tac: RewriteSetInst): XML.Tree = {
wneuper@4848
   488
    XML.Elem(("REWRITESETINSTTACTIC", List(("name", tac.getName))), List(
wneuper@4771
   489
      //this will be generalised at introduction of MathML
wneuper@4848
   490
      XML.Elem(("PAIR", Nil), List(    
wneuper@4848
   491
        XML.Elem(("VARIABLE", Nil), List(    
wneuper@4848
   492
          XML.Elem(("MATHML", Nil), List(    
wneuper@4848
   493
            XML.Elem(("ISA", Nil), List(XML.Text(tac.getVariable))))))),
wneuper@4848
   494
        XML.Elem(("VALUE", Nil), List(    
wneuper@4848
   495
          XML.Elem(("MATHML", Nil), List(    
wneuper@4848
   496
            XML.Elem(("ISA", Nil), List(XML.Text(tac.getValue))))))))),
wneuper@4771
   497
      XML.Text(tac.getRuleSet)))
wneuper@4770
   498
  }
wneuper@4758
   499
  
wneuper@4771
   500
  //----- FORMTACTIC ---------------------------------------------------*)
wneuper@4848
   501
  def xml_of_TermTactic(formtac: TermTactic): XML.Tree = {
wneuper@4848
   502
    XML.Elem(("FORMTACTIC", List(("name", formtac.getName))), List(
wneuper@4810
   503
      xml_of_term(formtac.getTerm)))
wneuper@4771
   504
  }  
wneuper@4771
   505
  //----- SIMPLETACTIC -------------------------------------------------*)
wneuper@4848
   506
  def xml_of_SimpleTactic(tac: SimpleTactic): XML.Tree = {
wneuper@4848
   507
    XML.Elem(("SIMPLETACTIC", List(("name", tac.getName))), List(
wneuper@4771
   508
      xml_of_term(tac.getArgument)))
wneuper@4771
   509
  }  
wneuper@4771
   510
  //----- STRINGLISTTACTIC ---------------------------------------------*)
wneuper@4771
   511
  def dest_eq(equality: String): (String, String) = {
wneuper@4771
   512
    val pair = equality.split("=")
wneuper@4771
   513
    if (pair.length == 2) (pair(0), pair(1))
wneuper@4771
   514
    else throw new IllegalArgumentException("dest_eq WRONG arg = " + equality)
wneuper@4771
   515
  }
wneuper@4771
   516
  def xml_of_val_var_pair(vv: (String, String)): XML.Tree = {
wneuper@4848
   517
    XML.Elem(("PAIR", Nil), List(    
wneuper@4848
   518
      XML.Elem(("VARIABLE", Nil), List(    
wneuper@4848
   519
        XML.Elem(("MATHML", Nil), List(    
wneuper@4848
   520
          XML.Elem(("ISA", Nil), List(XML.Text(vv._1))))))),
wneuper@4848
   521
      XML.Elem(("VALUE", Nil), List(    
wneuper@4848
   522
        XML.Elem(("MATHML", Nil), List(    
wneuper@4848
   523
          XML.Elem(("ISA", Nil), List(XML.Text(vv._2)))))))))
wneuper@4771
   524
  }
wneuper@4771
   525
  def xml_of_sube(equs: Vector[String]): XML.Tree = {
wneuper@4848
   526
    XML.Elem(("SUBSTITUTION", Nil), 
wneuper@4771
   527
      (equs.asScala.toList map dest_eq) map xml_of_val_var_pair)
wneuper@4771
   528
  }
wneuper@4848
   529
  def xml_of_StringListTactic(strs_tac: StringListTactic): XML.Tree = {
wneuper@4771
   530
    var xml = XML.Text("DUMMY"): XML.Tree
wneuper@4771
   531
    if (strs_tac.getName == "Substitute")
wneuper@4771
   532
      xml = xml_of_VectorString(strs_tac.getStrings)
wneuper@4771
   533
    else
wneuper@4771
   534
      xml = xml_of_VectorString(strs_tac.getStrings)
wneuper@4848
   535
    XML.Elem(("STRINGLISTTACTIC", List(("name", strs_tac.getName))), List(
wneuper@4771
   536
      xml))
wneuper@4771
   537
  }
wneuper@4848
   538
  // def xml_of_Tactic(tac: Tactic): XML.Tree = tac.getClass match {
wneuper@4781
   539
  //   was shifted to DataTypesCompanion.java
wneuper@4771
   540
  def xml_to_Tactic(t: XML.Tree): Tactic = t match {
wneuper@4771
   541
    case
wneuper@4848
   542
      XML.Elem(("SUBPROBLEMTACTIC", List(("name", "Subproblem"))), List(
wneuper@4848
   543
        XML.Elem(("THEORY", Nil), List(XML.Text(thy))),
wneuper@4848
   544
        XML.Elem(("PROBLEM", Nil), List(pbl))))
wneuper@4771
   545
      => new SubProblemTactic("Subproblem", thy, xml_to_VectorString(pbl))
wneuper@4771
   546
    case
wneuper@4848
   547
      XML.Elem(("STRINGLISTTACTIC", List(("name", "Substitute"))), List(
wneuper@4848
   548
          XML.Elem(("PAIR", Nil), List(
wneuper@4848
   549
            XML.Elem(("VARIABLE", Nil), List(
wneuper@4848
   550
              XML.Elem(("MATHML", Nil), List(
wneuper@4848
   551
                XML.Elem(("ISA", Nil), List(XML.Text(variable))))))),
wneuper@4848
   552
            XML.Elem(("VALUE", Nil), List(
wneuper@4848
   553
              XML.Elem(("MATHML", Nil), List(
wneuper@4848
   554
                XML.Elem(("ISA", Nil), List(XML.Text(value)))))))))))
wneuper@4771
   555
      => new SubstituteTactic("Substitute", variable, value)
wneuper@4771
   556
wneuper@4771
   557
    //----- Rewrite* -----------------------------------------------------*)
wneuper@4771
   558
    case
wneuper@4848
   559
      XML.Elem(("REWRITETACTIC", List(("name", "Rewrite"))), List(
wneuper@4771
   560
        thm))
wneuper@4771
   561
      => new Rewrite("Rewrite", xml_to_Theorem(thm))
wneuper@4771
   562
    case // faked until introduction of MathML
wneuper@4848
   563
      XML.Elem(("REWRITEINSTTACTIC", List(("name", "Rewrite_Inst"))), List(
wneuper@4848
   564
        XML.Elem(("SUBSTITUTION", Nil), List(
wneuper@4848
   565
          XML.Elem(("PAIR", Nil), List(
wneuper@4848
   566
            XML.Elem(("VARIABLE", Nil), List(
wneuper@4848
   567
              XML.Elem(("MATHML", Nil), List(
wneuper@4848
   568
                XML.Elem(("ISA", Nil), List(XML.Text(variable))))))),
wneuper@4848
   569
            XML.Elem(("VALUE", Nil), List(
wneuper@4848
   570
              XML.Elem(("MATHML", Nil), List(
wneuper@4848
   571
                XML.Elem(("ISA", Nil), List(XML.Text(value)))))))
wneuper@4771
   572
          )))),
wneuper@4771
   573
        thm))
wneuper@4771
   574
      => new RewriteInst("Rewrite_Inst", variable, value, xml_to_Theorem(thm))
wneuper@4771
   575
    case
wneuper@4848
   576
      XML.Elem(("REWRITESETTACTIC", List(("name", "Rewrite_Set"))), List(
wneuper@4771
   577
        XML.Text(rule_set)))
wneuper@4771
   578
      => new RewriteSet("Rewrite_Set", rule_set)
wneuper@4810
   579
    case // faked Term by String until introduction of MathML
wneuper@4848
   580
      XML.Elem(("REWRITESETINSTTACTIC", List(("name", "Rewrite_Set_Inst"))), List(
wneuper@4848
   581
        XML.Elem(("SUBSTITUTION", Nil), List(
wneuper@4848
   582
          XML.Elem(("PAIR", Nil), List(
wneuper@4848
   583
            XML.Elem(("VARIABLE", Nil), List(
wneuper@4848
   584
              XML.Elem(("MATHML", Nil), List(
wneuper@4848
   585
                XML.Elem(("ISA", Nil), List(XML.Text(variable))))))),
wneuper@4848
   586
            XML.Elem(("VALUE", Nil), List(
wneuper@4848
   587
              XML.Elem(("MATHML", Nil), List(
wneuper@4848
   588
                XML.Elem(("ISA", Nil), List(XML.Text(value))))))))))),
wneuper@4848
   589
        XML.Elem(("RULESET", Nil), List(XML.Text(rule_set)))))  
wneuper@4810
   590
        // ATTENTION: args--vv are shuffled wrt. RewriteInst
wneuper@4771
   591
      => new RewriteSetInst("Rewrite_Set_Inst", rule_set, variable, value)
wneuper@4771
   592
wneuper@4771
   593
    //----- FORMTACTIC ---------------------------------------------------*)
wneuper@4771
   594
    case
wneuper@4848
   595
      XML.Elem(("FORMTACTIC", List(("name", "Add_Find"))), List(
wneuper@4810
   596
        term))
wneuper@4810
   597
      => new TermTactic("Add_Find", xml_to_term(term))
wneuper@4771
   598
    case
wneuper@4848
   599
      XML.Elem(("FORMTACTIC", List(("name", "Add_Given"))), List(
wneuper@4810
   600
        term))
wneuper@4810
   601
      => new TermTactic("Add_Given", xml_to_term(term))
wneuper@4771
   602
    case
wneuper@4848
   603
      XML.Elem(("FORMTACTIC", List(("name", "Add_Relation"))), List(
wneuper@4810
   604
        term))
wneuper@4810
   605
      => new TermTactic("Add_Relation", xml_to_term(term))
wneuper@4771
   606
    case
wneuper@4848
   607
      XML.Elem(("FORMTACTIC", List(("name", "Check_elementwise"))), List(
wneuper@4810
   608
        term))
wneuper@4810
   609
      => new TermTactic("Check_elementwise", xml_to_term(term))
wneuper@4771
   610
    case
wneuper@4848
   611
      XML.Elem(("FORMTACTIC", List(("name", "Take"))), List(
wneuper@4810
   612
        term))
wneuper@4810
   613
      => new TermTactic("Take", xml_to_term(term))
wneuper@4771
   614
wneuper@4771
   615
    //----- SIMPLETACTIC -------------------------------------------------*)
wneuper@4771
   616
    case
wneuper@4848
   617
      XML.Elem(("SIMPLETACTIC", List(("name", "Or_to_List"))), List(
wneuper@4771
   618
        XML.Text(_)))
wneuper@4787
   619
      => new SimpleTactic("Or_to_List", "DUMMY")
wneuper@4771
   620
    case
wneuper@4848
   621
      XML.Elem(("SIMPLETACTIC", List(("name", "Specify_Theory"))), List(
wneuper@4771
   622
        XML.Text(str)))
wneuper@4787
   623
      => new SimpleTactic("Specify_Theory", str)
wneuper@4771
   624
wneuper@4771
   625
    //----- STRINGLISTTACTIC ---------------------------------------------*)
wneuper@4771
   626
    case
wneuper@4848
   627
      XML.Elem(("STRINGLISTTACTIC", List(("name", "Apply_Method"))), List(
wneuper@4771
   628
        strs))
wneuper@4771
   629
      => new StringListTactic("Apply_Method", xml_to_VectorString(strs))
wneuper@4771
   630
    case
wneuper@4848
   631
      XML.Elem(("STRINGLISTTACTIC", List(("name", "Check_Postcond"))), List(
wneuper@4771
   632
        strs))
wneuper@4771
   633
      => new StringListTactic("Check_Postcond", xml_to_VectorString(strs))
wneuper@4771
   634
    case
wneuper@4848
   635
      XML.Elem(("STRINGLISTTACTIC", List(("name", "Model_Problem"))), List(
wneuper@4771
   636
        strs))
wneuper@4771
   637
      => new StringListTactic("Model_Problem", xml_to_VectorString(strs))
wneuper@4771
   638
    case
wneuper@4848
   639
      XML.Elem(("STRINGLISTTACTIC", List(("name", "Refine_Tacitly"))), List(
wneuper@4771
   640
        strs))
wneuper@4771
   641
      => new StringListTactic("Refine_Tacitly", xml_to_VectorString(strs))
wneuper@4771
   642
    case
wneuper@4848
   643
      XML.Elem(("STRINGLISTTACTIC", List(("name", "Specify_Method"))), List(
wneuper@4771
   644
        strs))
wneuper@4771
   645
      => new StringListTactic("Specify_Method", xml_to_VectorString(strs))
wneuper@4771
   646
    case
wneuper@4848
   647
      XML.Elem(("STRINGLISTTACTIC", List(("name", "Specify_Problem"))), List(
wneuper@4771
   648
        strs))
wneuper@4771
   649
      => new StringListTactic("Specify_Problem", xml_to_VectorString(strs))
wneuper@4771
   650
    case x => throw new IllegalArgumentException("xml_to_Tactic WRONG arg = " + x)
wneuper@4771
   651
  }
wneuper@4771
   652
wneuper@4787
   653
  //------- for xml_of_contthy
wneuper@4787
   654
  //--- see Isabelle/Isac:../datatypes.sml
wneuper@4789
   655
  def xml_to_Reference(t: XML.Tree): Reference = t match {
wneuper@4787
   656
    case
wneuper@4848
   657
      XML.Elem(("KESTOREREF", Nil), List(
wneuper@4848
   658
        XML.Elem(("TAG", Nil), List(XML.Text(tag))),
wneuper@4848
   659
        XML.Elem(("ID", Nil), List(XML.Text(xstring))),
wneuper@4848
   660
        XML.Elem(("GUH", Nil), List(XML.Text(guh)))))
wneuper@4789
   661
      => new Reference(tag, xstring, new KEStoreKey(guh))
wneuper@4789
   662
    case t => throw new IllegalArgumentException("xml_to_Reference wrong arg: " + t)
wneuper@4787
   663
  }
wneuper@4757
   664
  
wneuper@4789
   665
  def xml_to_asm_val(t: XML.Tree): FormulaPair = t match {
wneuper@4787
   666
    case
wneuper@4848
   667
      XML.Elem(("ASMEVALUATED", Nil), List(
wneuper@4848
   668
        XML.Elem(("ASM", Nil), List(asm)),
wneuper@4848
   669
        XML.Elem(("VALUE", Nil), List(vl))))
wneuper@4789
   670
      => new FormulaPair(new Formula(xml_to_term(asm)), /*new Formula((xml_to_term(vl)))*/true)
wneuper@4789
   671
    case t => throw new IllegalArgumentException("xml_to_asm_val wrong arg: " + t)
wneuper@4789
   672
  }
wneuper@4825
   673
  def xml_to_ContextTheory(t: XML.Tree): ContextTheory = t match {
wneuper@4789
   674
    //  | xml_of_contthy (ContThm {thyID, thm, applto, applat, reword, 
wneuper@4789
   675
    //        asms,lhs, rhs, result, resasms, asmrls}) =
wneuper@4789
   676
    case
wneuper@4848
   677
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   678
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   679
        XML.Elem(("APPLTO", Nil), List(applto_xml)),
wneuper@4848
   680
        XML.Elem(("APPLAT", Nil), List(applat_xml)),
wneuper@4848
   681
        XML.Elem(("ORDER", Nil), List(
wneuper@4848
   682
          XML.Elem(("ID", Nil), List(XML.Text(reword))))),
wneuper@4848
   683
        XML.Elem(("ASMSEVAL", Nil), asmevs_xml),    //Nil is possible
wneuper@4848
   684
        XML.Elem(("LHS", Nil), List(lhs_xml)),
wneuper@4848
   685
        XML.Elem(("LHSINST", Nil), List(lhsinst_xml)),
wneuper@4848
   686
        XML.Elem(("RHS", Nil), List(rhs_xml)),
wneuper@4848
   687
        XML.Elem(("RHSINST", Nil), List(rhsinst_xml)),
wneuper@4848
   688
        XML.Elem(("RESULT", Nil), List(result_xml)),
wneuper@4848
   689
        XML.Elem(("ASSUMPTIONS", Nil), asms_xml),   //Nil is possible
wneuper@4848
   690
        XML.Elem(("EVALRLS", Nil), List(rlskey_xml))))
wneuper@4832
   691
      => new ContextTheory(new KEStoreKey(guh),
wneuper@4789
   692
          null, null,
wneuper@4789
   693
          new Formula(xml_to_term(applto_xml)), new Formula(xml_to_term(applat_xml)),
wneuper@4789
   694
          reword,
wneuper@4789
   695
          sListToVectorFormulaPair(asmevs_xml map xml_to_asm_val), //WN150820 bug: Boolean form_2
wneuper@4789
   696
          new Formula(xml_to_term(lhs_xml)), new Formula(xml_to_term(lhsinst_xml)),
wneuper@4789
   697
          new Formula(xml_to_term(rhs_xml)), new Formula(xml_to_term(rhsinst_xml)),
wneuper@4789
   698
          new Formula(xml_to_term(result_xml)), "xml_to_ContextTheory: ASSUMPTIONS wrong type",
wneuper@4789
   699
          xml_to_Reference(rlskey_xml))
wneuper@4789
   700
    //  | xml_of_contthy (ContThmInst {thyID, thm, bdvs, thminst, applto, applat, 
wneuper@4789
   701
    //        reword, asms, lhs, rhs, result, resasms, asmrls}) =
wneuper@4789
   702
    case
wneuper@4848
   703
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   704
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   705
        XML.Elem(("SUBSLIST", Nil), List(subst_xml)), // WRONG type
wneuper@4848
   706
        XML.Elem(("INSTANTIATED", Nil), List(thminst_xml)),
wneuper@4848
   707
        XML.Elem(("APPLTO", Nil), List(applto_xml)),
wneuper@4848
   708
        XML.Elem(("APPLAT", Nil), List(applat_xml)),
wneuper@4848
   709
        XML.Elem(("ORDER", Nil), List(
wneuper@4848
   710
          XML.Elem(("ID", Nil), List(XML.Text(reword))))),
wneuper@4848
   711
        XML.Elem(("ASMSEVAL", Nil), asmevs_xml),    //Nil is possible
wneuper@4848
   712
        XML.Elem(("LHS", Nil), List(lhs_xml)),
wneuper@4848
   713
        XML.Elem(("LHSINST", Nil), List(lhsinst_xml)),
wneuper@4848
   714
        XML.Elem(("RHS", Nil), List(rhs_xml)),
wneuper@4848
   715
        XML.Elem(("RHSINST", Nil), List(rhsinst_xml)),
wneuper@4848
   716
        XML.Elem(("RESULT", Nil), List(result_xml)),
wneuper@4848
   717
        XML.Elem(("ASSUMPTIONS", Nil), asms_xml),   //Nil is possible
wneuper@4848
   718
        XML.Elem(("EVALRLS", Nil), List(rlskey_xml))))
wneuper@4832
   719
      => new ContextTheory(new KEStoreKey(guh),
wneuper@4789
   720
          new Formula(xml_to_term(subst_xml)), new Formula(xml_to_term(thminst_xml)),
wneuper@4789
   721
          new Formula(xml_to_term(applto_xml)), new Formula(xml_to_term(applat_xml)),
wneuper@4789
   722
          reword,
wneuper@4789
   723
          sListToVectorFormulaPair(asmevs_xml map xml_to_asm_val),
wneuper@4789
   724
          new Formula(xml_to_term(lhs_xml)), new Formula(xml_to_term(lhsinst_xml)),
wneuper@4789
   725
          new Formula(xml_to_term(rhs_xml)), new Formula(xml_to_term(rhsinst_xml)),
wneuper@4789
   726
          new Formula(xml_to_term(result_xml)), "xml_to_ContextTheory: ASSUMPTIONS wrong type",
wneuper@4789
   727
          xml_to_Reference(rlskey_xml))
wneuper@4789
   728
    //  | xml_of_contthy (ContRls {thyID = _, rls, applto, result, asms}) =
wneuper@4789
   729
    case
wneuper@4848
   730
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   731
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   732
        XML.Elem(("APPLTO", Nil), List(applto_xml)),
wneuper@4848
   733
        XML.Elem(("RESULT", Nil), List(result_xml)),
wneuper@4848
   734
        XML.Elem(("ASSUMPTIONS", Nil), asms_xml)))   //Nil is possible
wneuper@4832
   735
      => new ContextTheory(new KEStoreKey(guh), null, null,
wneuper@4789
   736
          new Formula(xml_to_term(applto_xml)), null,
wneuper@4789
   737
          null,
wneuper@4789
   738
          null,
wneuper@4789
   739
          null, null,
wneuper@4789
   740
          null, null,
wneuper@4789
   741
          new Formula(xml_to_term(result_xml)), "xml_to_ContextTheory: ASSUMPTIONS wrong type",
wneuper@4789
   742
          null)
wneuper@4789
   743
    //  | xml_of_contthy (ContRlsInst {thyID = _, rls, bdvs, applto, result, asms}) =
wneuper@4789
   744
    case
wneuper@4848
   745
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   746
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   747
        XML.Elem(("SUBSLIST", Nil), List(subst_xml)), // WRONG type
wneuper@4848
   748
        XML.Elem(("INSTANTIATED", Nil), List(thminst_xml)),
wneuper@4848
   749
        XML.Elem(("APPLTO", Nil), List(applto_xml)),
wneuper@4848
   750
        XML.Elem(("RESULT", Nil), List(result_xml)),
wneuper@4848
   751
        XML.Elem(("ASSUMPTIONS", Nil), List(asms_xml))))
wneuper@4832
   752
      => new ContextTheory(new KEStoreKey(guh), 
wneuper@4789
   753
          new Formula(xml_to_term(subst_xml)), new Formula(xml_to_term(thminst_xml)),
wneuper@4789
   754
          new Formula(xml_to_term(applto_xml)), null,
wneuper@4789
   755
          null,
wneuper@4789
   756
          null,
wneuper@4789
   757
          null, null,
wneuper@4789
   758
          null, null,
wneuper@4789
   759
          new Formula(xml_to_term(result_xml)), "xml_to_ContextTheory: ASSUMPTIONS wrong type",
wneuper@4789
   760
          null)
wneuper@4789
   761
    //  | xml_of_contthy (ContNOrew {thyID = _, thm_rls, applto}) =
wneuper@4789
   762
    case
wneuper@4848
   763
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   764
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   765
        XML.Elem(("APPLTO", Nil), List(applto_xml))))
wneuper@4832
   766
      => new ContextTheory(new KEStoreKey(guh), null, null,
wneuper@4789
   767
          new Formula(xml_to_term(applto_xml)), null,
wneuper@4789
   768
          null,
wneuper@4789
   769
          null,
wneuper@4789
   770
          null, null,
wneuper@4789
   771
          null, null,
wneuper@4789
   772
          null, null,
wneuper@4789
   773
          null)
wneuper@4789
   774
    //  | xml_of_contthy (ContNOrewInst{thyID = _, thm_rls, bdvs, thminst, applto}) =
wneuper@4789
   775
    case
wneuper@4848
   776
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   777
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   778
        XML.Elem(("SUBSLIST", Nil), List(subst_xml)), // WRONG type
wneuper@4848
   779
        XML.Elem(("INSTANTIATED", Nil), List(thminst_xml)),
wneuper@4848
   780
        XML.Elem(("APPLTO", Nil), List(applto_xml))))
wneuper@4832
   781
      => new ContextTheory(new KEStoreKey(guh), 
wneuper@4789
   782
          new Formula(xml_to_term(subst_xml)), new Formula(xml_to_term(thminst_xml)),
wneuper@4789
   783
          new Formula(xml_to_term(applto_xml)), null,
wneuper@4789
   784
          null,
wneuper@4789
   785
          null,
wneuper@4789
   786
          null, null,
wneuper@4789
   787
          null, null,
wneuper@4789
   788
          null, null,
wneuper@4789
   789
          null)
wneuper@4789
   790
    case _ => throw new IllegalArgumentException("xml_to_ContextTheory wrong arg: " + t)
wneuper@4789
   791
  }
wneuper@4789
   792
wneuper@4825
   793
  def xml_to_ContextProblem(t: XML.Tree): ContextProblem = t match {
wneuper@4825
   794
    case
wneuper@4848
   795
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   796
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   797
        XML.Elem(("STATUS", Nil), List(XML.Text(status))),
wneuper@4848
   798
        XML.Elem(("HEAD", Nil), List(head_xml)),
wneuper@4825
   799
        model_xml))
wneuper@4832
   800
      => new ContextProblem(new KEStoreKey(guh), 
wneuper@4928
   801
          status, xml_to_Formula_NEW(head_xml), xml_to_Model(model_xml))
wneuper@4825
   802
    case _ => throw new IllegalArgumentException("xml_to_ContextProblem wrong arg: " + t)
wneuper@4825
   803
  }
wneuper@4825
   804
wneuper@4825
   805
  def xml_to_ContextMethod(t: XML.Tree): ContextMethod = t match {
wneuper@4825
   806
    case
wneuper@4848
   807
      XML.Elem(("CONTEXTDATA", Nil), List(
wneuper@4848
   808
        XML.Elem(("GUH", Nil), List(XML.Text(guh))),
wneuper@4848
   809
        XML.Elem(("STATUS", Nil), List(XML.Text(status))),
wneuper@4848
   810
        XML.Elem(("PROGRAM", Nil), List(prog_xml)),
wneuper@4825
   811
        model_xml))
wneuper@4832
   812
      => new ContextMethod(new KEStoreKey(guh),
wneuper@4842
   813
          status, new Formula(xml_to_prog(prog_xml)), xml_to_Model(model_xml))
wneuper@4825
   814
    case _ => throw new IllegalArgumentException("xml_to_ContextMethod wrong arg: " + t)
wneuper@4825
   815
  }
wneuper@4825
   816
wneuper@4788
   817
  def xml_to_CEvent(t: XML.Tree): CEvent = t match {
wneuper@4788
   818
    case
wneuper@4848
   819
      XML.Elem(("CALCCHANGED", Nil), List(
wneuper@4848
   820
        XML.Elem(("UNCHANGED", Nil), List(
wneuper@4848
   821
          unc_is, XML.Elem(("POS", Nil), List(XML.Text(unc_kind))))),
wneuper@4848
   822
        XML.Elem(("DELETED", Nil), List(
wneuper@4848
   823
          del_is, XML.Elem(("POS", Nil), List(XML.Text(del_kind))))),
wneuper@4848
   824
        XML.Elem(("GENERATED", Nil), List(
wneuper@4848
   825
          gen_is, XML.Elem(("POS", Nil), List(XML.Text(gen_kind)))))))
wneuper@4788
   826
      => new CChanged(
wneuper@4788
   827
           new Position(DataTypes.xml_to_VectorInteger(unc_is), unc_kind),
wneuper@4788
   828
           new Position(DataTypes.xml_to_VectorInteger(del_is), del_kind), 
wneuper@4788
   829
           new Position(DataTypes.xml_to_VectorInteger(gen_is), gen_kind))
wneuper@4788
   830
    case
wneuper@4848
   831
      XML.Elem(("CALCMESSAGE", Nil), List(XML.Text(msg)))
wneuper@4788
   832
      => new CMessage(msg)
wneuper@4788
   833
    case _ => throw new IllegalArgumentException("xml_to_CChanged wrong arg: " + t)
wneuper@4788
   834
  }
wneuper@4825
   835
  
wneuper@4757
   836
}