src/Pure/Thy/export_theory.scala
changeset 68232 4b93573ac5b4
parent 68231 0004e7a9fa10
child 68264 bb9a3be6952a
     1.1 --- a/src/Pure/Thy/export_theory.scala	Sun May 20 15:37:16 2018 +0200
     1.2 +++ b/src/Pure/Thy/export_theory.scala	Sun May 20 16:25:27 2018 +0200
     1.3 @@ -54,17 +54,19 @@
     1.4    sealed case class Theory(name: String, parents: List[String],
     1.5      types: List[Type],
     1.6      consts: List[Const],
     1.7 -    axioms: List[Axiom])
     1.8 +    axioms: List[Axiom],
     1.9 +    facts: List[Fact])
    1.10    {
    1.11      override def toString: String = name
    1.12    }
    1.13  
    1.14 -  def empty_theory(name: String): Theory = Theory(name, Nil, Nil, Nil, Nil)
    1.15 +  def empty_theory(name: String): Theory = Theory(name, Nil, Nil, Nil, Nil, Nil)
    1.16  
    1.17    def read_theory(db: SQL.Database, session_name: String, theory_name: String,
    1.18      types: Boolean = true,
    1.19      consts: Boolean = true,
    1.20 -    axioms: Boolean = true): Theory =
    1.21 +    axioms: Boolean = true,
    1.22 +    facts: Boolean = true): Theory =
    1.23    {
    1.24      val parents =
    1.25        Export.read_entry(db, session_name, theory_name, "theory/parents") match {
    1.26 @@ -76,7 +78,8 @@
    1.27      Theory(theory_name, parents,
    1.28        if (types) read_types(db, session_name, theory_name) else Nil,
    1.29        if (consts) read_consts(db, session_name, theory_name) else Nil,
    1.30 -      if (axioms) read_axioms(db, session_name, theory_name) else Nil)
    1.31 +      if (axioms) read_axioms(db, session_name, theory_name) else Nil,
    1.32 +      if (facts) read_facts(db, session_name, theory_name) else Nil)
    1.33    }
    1.34  
    1.35  
    1.36 @@ -148,7 +151,15 @@
    1.37          })
    1.38  
    1.39  
    1.40 -  /* axioms */
    1.41 +  /* axioms and facts */
    1.42 +
    1.43 +  def decode_props(body: XML.Body):
    1.44 +    (List[(String, Term.Sort)], List[(String, Term.Typ)], List[Term.Term]) =
    1.45 +  {
    1.46 +    import XML.Decode._
    1.47 +    import Term_XML.Decode._
    1.48 +    triple(list(pair(string, sort)), list(pair(string, typ)), list(term))(body)
    1.49 +  }
    1.50  
    1.51    sealed case class Axiom(
    1.52      entity: Entity,
    1.53 @@ -161,12 +172,22 @@
    1.54        (tree: XML.Tree) =>
    1.55          {
    1.56            val (entity, body) = decode_entity(tree)
    1.57 -          val (typargs, args, prop) =
    1.58 -          {
    1.59 -            import XML.Decode._
    1.60 -            import Term_XML.Decode._
    1.61 -            triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)
    1.62 -          }
    1.63 +          val (typargs, args, List(prop)) = decode_props(body)
    1.64            Axiom(entity, typargs, args, prop)
    1.65          })
    1.66 +
    1.67 +  sealed case class Fact(
    1.68 +    entity: Entity,
    1.69 +    typargs: List[(String, Term.Sort)],
    1.70 +    args: List[(String, Term.Typ)],
    1.71 +    props: List[Term.Term])
    1.72 +
    1.73 +  def read_facts(db: SQL.Database, session_name: String, theory_name: String): List[Fact] =
    1.74 +    read_entities(db, session_name, theory_name, "facts",
    1.75 +      (tree: XML.Tree) =>
    1.76 +        {
    1.77 +          val (entity, body) = decode_entity(tree)
    1.78 +          val (typargs, args, props) = decode_props(body)
    1.79 +          Fact(entity, typargs, args, props)
    1.80 +        })
    1.81  }