src/Pure/Thy/export_theory.scala
author wenzelm
Sun, 13 May 2018 21:20:28 +0200
changeset 68173 7ed88a534bb6
parent 68172 0f14cf9c632f
child 68203 cda4f24331d5
permissions -rw-r--r--
more uniform types vs. consts;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Thy/export_theory.scala
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     3
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     4
Export foundational theory content.
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     5
*/
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     6
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     7
package isabelle
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     8
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
     9
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    10
object Export_Theory
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    11
{
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    12
  /* entities */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    13
68172
0f14cf9c632f more concise information;
wenzelm
parents: 68171
diff changeset
    14
  sealed case class Entity(name: String, serial: Long, pos: Position.T)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    15
  {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    16
    override def toString: String = name
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    17
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    18
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    19
  def decode_entity(tree: XML.Tree): (Entity, XML.Body) =
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    20
  {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    21
    def err(): Nothing = throw new XML.XML_Body(List(tree))
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    22
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    23
    tree match {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    24
      case XML.Elem(Markup(Markup.ENTITY, props), body) =>
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    25
        val name = Markup.Name.unapply(props) getOrElse err()
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    26
        val serial = Markup.Serial.unapply(props) getOrElse err()
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    27
        val pos = props.filter({ case (a, _) => Markup.POSITION_PROPERTIES(a) })
68172
0f14cf9c632f more concise information;
wenzelm
parents: 68171
diff changeset
    28
        (Entity(name, serial, pos), body)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    29
      case _ => err()
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    30
    }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    31
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    32
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    33
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    34
  /* types */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    35
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    36
  sealed case class Type(entity: Entity, args: List[String], abbrev: Option[Term.Typ])
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    37
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    38
  def decode_type(tree: XML.Tree): Type =
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    39
  {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    40
    val (entity, body) = decode_entity(tree)
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    41
    val (args, abbrev) =
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    42
    {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    43
      import XML.Decode._
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    44
      pair(list(string), option(Term_XML.Decode.typ))(body)
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    45
    }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    46
    Type(entity, args, abbrev)
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    47
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    48
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    49
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    50
  /* consts */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    51
68173
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
    52
  sealed case class Const(
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
    53
    entity: Entity, typargs: List[String], typ: Term.Typ, abbrev: Option[Term.Term])
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    54
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    55
  def decode_const(tree: XML.Tree): Const =
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    56
  {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    57
    val (entity, body) = decode_entity(tree)
68173
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
    58
    val (args, typ, abbrev) =
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    59
    {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    60
      import XML.Decode._
68173
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
    61
      triple(list(string), Term_XML.Decode.typ, option(Term_XML.Decode.term))(body)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    62
    }
68173
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
    63
    Const(entity, args, typ, abbrev)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    64
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
    65
}