src/Pure/Thy/export_theory.scala
author wenzelm
Thu, 15 Aug 2019 18:21:12 +0200
changeset 70539 30b3c58a1933
parent 70534 fb876ebbf5a7
child 70579 5a8e3e4b3760
permissions -rw-r--r--
support Export_Theory.read_proof, based on theory_name and serial;
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
{
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    12
  /** session content **/
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    13
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    14
  sealed case class Session(name: String, theory_graph: Graph[String, Theory])
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    15
  {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    16
    override def toString: String = name
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    17
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    18
    def theory(theory_name: String): Theory =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    19
      if (theory_graph.defined(theory_name)) theory_graph.get_node(theory_name)
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    20
      else error("Bad theory " + quote(theory_name))
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    21
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    22
    def theories: List[Theory] =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    23
      theory_graph.topological_order.map(theory_graph.get_node(_))
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    24
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    25
68209
aeffd8f1f079 support Store with options;
wenzelm
parents: 68208
diff changeset
    26
  def read_session(store: Sessions.Store,
aeffd8f1f079 support Store with options;
wenzelm
parents: 68208
diff changeset
    27
    session_name: String,
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    28
    types: Boolean = true,
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    29
    consts: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    30
    axioms: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    31
    facts: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    32
    classes: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    33
    locales: Boolean = true,
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
    34
    locale_dependencies: Boolean = true,
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    35
    classrel: Boolean = true,
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    36
    arities: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    37
    typedefs: Boolean = true,
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    38
    cache: Term.Cache = Term.make_cache()): Session =
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    39
  {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    40
    val thys =
68210
65f79c0ddb0d tuned signature;
wenzelm
parents: 68209
diff changeset
    41
      using(store.open_database(session_name))(db =>
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    42
      {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    43
        db.transaction {
68222
3c1a716e7f59 tuned queries;
wenzelm
parents: 68210
diff changeset
    44
          Export.read_theory_names(db, session_name).map((theory_name: String) =>
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
    45
            read_theory(Export.Provider.database(db, session_name, theory_name),
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
    46
              session_name, theory_name, types = types, consts = consts,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    47
              axioms = axioms, facts = facts, classes = classes, locales = locales,
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
    48
              locale_dependencies = locale_dependencies, classrel = classrel, arities = arities,
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
    49
              typedefs = typedefs, cache = Some(cache)))
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    50
        }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    51
      })
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    52
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    53
    val graph0 =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    54
      (Graph.string[Theory] /: thys) { case (g, thy) => g.new_node(thy.name, thy) }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    55
    val graph1 =
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    56
      (graph0 /: thys) { case (g0, thy) =>
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    57
        (g0 /: thy.parents) { case (g1, parent) =>
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    58
          g1.default_node(parent, empty_theory(parent)).add_edge_acyclic(parent, thy.name) } }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    59
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    60
    Session(session_name, graph1)
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    61
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    62
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    63
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    64
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
    65
  /** theory content **/
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
    66
68346
b44010800a19 tuned signature;
wenzelm
parents: 68295
diff changeset
    67
  val export_prefix: String = "theory/"
70539
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
    68
  val export_prefix_proofs: String = "proofs/"
68346
b44010800a19 tuned signature;
wenzelm
parents: 68295
diff changeset
    69
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
    70
  sealed case class Theory(name: String, parents: List[String],
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
    71
    types: List[Type],
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
    72
    consts: List[Const],
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
    73
    axioms: List[Fact_Single],
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
    74
    facts: List[Fact_Multi],
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
    75
    classes: List[Class],
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    76
    locales: List[Locale],
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
    77
    locale_dependencies: List[Locale_Dependency],
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    78
    classrel: List[Classrel],
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    79
    arities: List[Arity],
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    80
    typedefs: List[Typedef])
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    81
  {
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    82
    override def toString: String = name
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    83
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    84
    lazy val entities: Set[Long] =
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    85
      Set.empty[Long] ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    86
        types.iterator.map(_.entity.serial) ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    87
        consts.iterator.map(_.entity.serial) ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    88
        axioms.iterator.map(_.entity.serial) ++
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    89
        facts.iterator.map(_.entity.serial) ++
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    90
        classes.iterator.map(_.entity.serial) ++
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
    91
        locales.iterator.map(_.entity.serial) ++
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
    92
        locale_dependencies.iterator.map(_.entity.serial)
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    93
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    94
    def cache(cache: Term.Cache): Theory =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    95
      Theory(cache.string(name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    96
        parents.map(cache.string(_)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    97
        types.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    98
        consts.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    99
        axioms.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   100
        facts.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   101
        classes.map(_.cache(cache)),
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   102
        locales.map(_.cache(cache)),
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   103
        locale_dependencies.map(_.cache(cache)),
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   104
        classrel.map(_.cache(cache)),
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   105
        arities.map(_.cache(cache)),
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   106
        typedefs.map(_.cache(cache)))
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   107
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   108
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   109
  def empty_theory(name: String): Theory =
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   110
    Theory(name, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil)
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   111
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   112
  def read_theory(provider: Export.Provider, session_name: String, theory_name: String,
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   113
    types: Boolean = true,
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   114
    consts: Boolean = true,
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   115
    axioms: Boolean = true,
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   116
    facts: Boolean = true,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   117
    classes: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   118
    locales: Boolean = true,
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   119
    locale_dependencies: Boolean = true,
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   120
    classrel: Boolean = true,
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   121
    arities: Boolean = true,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   122
    typedefs: Boolean = true,
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   123
    cache: Option[Term.Cache] = None): Theory =
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   124
  {
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   125
    val parents =
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   126
      provider(export_prefix + "parents") match {
68231
0004e7a9fa10 clarified encoding;
wenzelm
parents: 68222
diff changeset
   127
        case Some(entry) => split_lines(entry.uncompressed().text)
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   128
        case None =>
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   129
          error("Missing theory export in session " + quote(session_name) + ": " +
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   130
            quote(theory_name))
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   131
      }
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   132
    val theory =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   133
      Theory(theory_name, parents,
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   134
        if (types) read_types(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   135
        if (consts) read_consts(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   136
        if (axioms) read_axioms(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   137
        if (facts) read_facts(provider) else Nil,
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   138
        if (classes) read_classes(provider) else Nil,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   139
        if (locales) read_locales(provider) else Nil,
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   140
        if (locale_dependencies) read_locale_dependencies(provider) else Nil,
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   141
        if (classrel) read_classrel(provider) else Nil,
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   142
        if (arities) read_arities(provider) else Nil,
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   143
        if (typedefs) read_typedefs(provider) else Nil)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   144
    if (cache.isDefined) theory.cache(cache.get) else theory
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   145
  }
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   146
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
   147
  def read_pure_theory(store: Sessions.Store, cache: Option[Term.Cache] = None): Theory =
68710
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   148
  {
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   149
    val session_name = Thy_Header.PURE
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   150
    val theory_name = Thy_Header.PURE
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   151
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   152
    using(store.open_database(session_name))(db =>
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   153
    {
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   154
      db.transaction {
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   155
        read_theory(Export.Provider.database(db, session_name, theory_name),
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
   156
          session_name, theory_name, cache = cache)
68710
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   157
      }
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   158
    })
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   159
  }
3db37e950118 always export Pure theory;
wenzelm
parents: 68418
diff changeset
   160
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   161
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   162
  /* entities */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   163
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   164
  object Kind extends Enumeration
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   165
  {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   166
    val TYPE = Value("type")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   167
    val CONST = Value("const")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   168
    val AXIOM = Value("axiom")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   169
    val FACT = Value("fact")
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   170
    val CLASS = Value("class")
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   171
    val LOCALE = Value("locale")
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   172
    val LOCALE_DEPENDENCY = Value("locale_dependency")
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   173
  }
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   174
68835
2e59da922630 more robust: Pure entities may lack id;
wenzelm
parents: 68830
diff changeset
   175
  sealed case class Entity(
68997
4278947ba336 more exports;
wenzelm
parents: 68864
diff changeset
   176
    kind: Kind.Value, name: String, xname: String, pos: Position.T, id: Option[Long], serial: Long)
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   177
  {
68718
ce18a3924864 tuned output;
wenzelm
parents: 68717
diff changeset
   178
    override def toString: String = kind.toString + " " + quote(name)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   179
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   180
    def cache(cache: Term.Cache): Entity =
68997
4278947ba336 more exports;
wenzelm
parents: 68864
diff changeset
   181
      Entity(kind, cache.string(name), cache.string(xname), cache.position(pos), id, serial)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   182
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   183
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   184
  def decode_entity(kind: Kind.Value, tree: XML.Tree): (Entity, XML.Body) =
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   185
  {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   186
    def err(): Nothing = throw new XML.XML_Body(List(tree))
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   187
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   188
    tree match {
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   189
      case XML.Elem(Markup(Markup.ENTITY, props), body) =>
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   190
        val name = Markup.Name.unapply(props) getOrElse err()
68997
4278947ba336 more exports;
wenzelm
parents: 68864
diff changeset
   191
        val xname = Markup.XName.unapply(props) getOrElse err()
68830
44ec6fdaacf8 retain original id, which is command_id/exec_id for PIDE;
wenzelm
parents: 68726
diff changeset
   192
        val pos = props.filter({ case (a, _) => Markup.POSITION_PROPERTIES(a) && a != Markup.ID })
68835
2e59da922630 more robust: Pure entities may lack id;
wenzelm
parents: 68830
diff changeset
   193
        val id = Position.Id.unapply(props)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   194
        val serial = Markup.Serial.unapply(props) getOrElse err()
68997
4278947ba336 more exports;
wenzelm
parents: 68864
diff changeset
   195
        (Entity(kind, name, xname, pos, id, serial), body)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   196
      case _ => err()
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   197
    }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   198
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   199
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   200
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   201
  /* approximative syntax */
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   202
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   203
  object Assoc extends Enumeration
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   204
  {
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   205
    val NO_ASSOC, LEFT_ASSOC, RIGHT_ASSOC = Value
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   206
  }
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   207
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   208
  sealed abstract class Syntax
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   209
  case object No_Syntax extends Syntax
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   210
  case class Prefix(delim: String) extends Syntax
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   211
  case class Infix(assoc: Assoc.Value, delim: String, pri: Int) extends Syntax
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   212
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   213
  def decode_syntax: XML.Decode.T[Syntax] =
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   214
    XML.Decode.variant(List(
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   215
      { case (Nil, Nil) => No_Syntax },
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   216
      { case (List(delim), Nil) => Prefix(delim) },
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   217
      { case (Nil, body) =>
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   218
          import XML.Decode._
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   219
          val (ass, delim, pri) = triple(int, string, int)(body)
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   220
          Infix(Assoc(ass), delim, pri) }))
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   221
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   222
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   223
  /* types */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   224
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   225
  sealed case class Type(
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   226
    entity: Entity, syntax: Syntax, args: List[String], abbrev: Option[Term.Typ])
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   227
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   228
    def cache(cache: Term.Cache): Type =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   229
      Type(entity.cache(cache),
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   230
        syntax,
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   231
        args.map(cache.string(_)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   232
        abbrev.map(cache.typ(_)))
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   233
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   234
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   235
  def read_types(provider: Export.Provider): List[Type] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   236
    provider.uncompressed_yxml(export_prefix + "types").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   237
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   238
        val (entity, body) = decode_entity(Kind.TYPE, tree)
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   239
        val (syntax, args, abbrev) =
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   240
        {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   241
          import XML.Decode._
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   242
          triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   243
        }
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   244
        Type(entity, syntax, args, abbrev)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   245
      })
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   246
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   247
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   248
  /* consts */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   249
68173
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
   250
  sealed case class Const(
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   251
    entity: Entity,
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   252
    syntax: Syntax,
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   253
    typargs: List[String],
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   254
    typ: Term.Typ,
69988
6fa51a36b7f7 export propositional status of consts;
wenzelm
parents: 69077
diff changeset
   255
    abbrev: Option[Term.Term],
69992
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   256
    propositional: Boolean,
69996
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   257
    primrec_types: List[String],
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   258
    corecursive: Boolean)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   259
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   260
    def cache(cache: Term.Cache): Const =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   261
      Const(entity.cache(cache),
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   262
        syntax,
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   263
        typargs.map(cache.string(_)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   264
        cache.typ(typ),
69988
6fa51a36b7f7 export propositional status of consts;
wenzelm
parents: 69077
diff changeset
   265
        abbrev.map(cache.term(_)),
69992
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   266
        propositional,
69996
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   267
        primrec_types.map(cache.string(_)),
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   268
        corecursive)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   269
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   270
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   271
  def read_consts(provider: Export.Provider): List[Const] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   272
    provider.uncompressed_yxml(export_prefix + "consts").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   273
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   274
        val (entity, body) = decode_entity(Kind.CONST, tree)
69996
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   275
        val (syntax, (args, (typ, (abbrev, (propositional, (primrec_types, corecursive)))))) =
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   276
        {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   277
          import XML.Decode._
69992
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   278
          pair(decode_syntax,
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   279
            pair(list(string),
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   280
              pair(Term_XML.Decode.typ,
69996
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   281
                pair(option(Term_XML.Decode.term), pair(bool,
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   282
                  pair(list(string), bool))))))(body)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   283
        }
69996
8f2d3a27aff0 more informative Spec_Rules.Equational: support corecursion;
wenzelm
parents: 69992
diff changeset
   284
        Const(entity, syntax, args, typ, abbrev, propositional, primrec_types, corecursive)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   285
      })
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   286
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   287
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   288
  /* axioms and facts */
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   289
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   290
  sealed case class Prop(
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   291
    typargs: List[(String, Term.Sort)],
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   292
    args: List[(String, Term.Typ)],
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   293
    term: Term.Term)
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   294
  {
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   295
    def cache(cache: Term.Cache): Prop =
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   296
      Prop(
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   297
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   298
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   299
        cache.term(term))
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   300
  }
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   301
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   302
  def decode_prop(body: XML.Body): Prop =
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   303
  {
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   304
    val (typargs, args, t) =
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   305
    {
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   306
      import XML.Decode._
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   307
      import Term_XML.Decode._
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   308
      triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   309
    }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   310
    Prop(typargs, args, t)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   311
  }
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   312
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   313
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   314
  sealed case class Fact(prop: Prop, proof: Option[Term.Proof])
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   315
  {
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   316
    def cache(cache: Term.Cache): Fact =
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   317
      Fact(prop.cache(cache), proof.map(cache.proof _))
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   318
  }
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   319
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   320
  def decode_fact(body: XML.Body): Fact =
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   321
  {
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   322
    val (prop, proof) =
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   323
    {
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   324
      import XML.Decode._
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   325
      pair(decode_prop _, option(Term_XML.Decode.proof))(body)
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   326
    }
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   327
    Fact(prop, proof)
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   328
  }
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   329
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   330
  sealed case class Fact_Single(entity: Entity, fact: Fact)
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   331
  {
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   332
    def cache(cache: Term.Cache): Fact_Single =
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   333
      Fact_Single(entity.cache(cache), fact.cache(cache))
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   334
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   335
    def prop: Prop = fact.prop
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   336
    def proof: Option[Term.Proof] = fact.proof
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   337
  }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   338
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   339
  sealed case class Fact_Multi(entity: Entity, facts: List[Fact])
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   340
  {
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   341
    def cache(cache: Term.Cache): Fact_Multi =
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   342
      Fact_Multi(entity.cache(cache), facts.map(_.cache(cache)))
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   343
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   344
    def props: List[Prop] = facts.map(_.prop)
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   345
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   346
    def split: List[Fact_Single] =
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   347
      facts match {
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   348
        case List(fact) => List(Fact_Single(entity, fact))
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   349
        case _ =>
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   350
          for ((fact, i) <- facts.zipWithIndex)
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   351
          yield Fact_Single(entity.copy(name = entity.name + "(" + (i + 1) + ")"), fact)
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   352
      }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   353
  }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   354
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   355
  def read_axioms(provider: Export.Provider): List[Fact_Single] =
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   356
    provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   357
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   358
        val (entity, body) = decode_entity(Kind.AXIOM, tree)
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   359
        val prop = decode_prop(body)
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   360
        Fact_Single(entity, Fact(prop, None))
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   361
      })
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   362
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   363
  def read_facts(provider: Export.Provider): List[Fact_Multi] =
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   364
    provider.uncompressed_yxml(export_prefix + "facts").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   365
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   366
        val (entity, body) = decode_entity(Kind.FACT, tree)
70534
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   367
        val facts = XML.Decode.list(decode_fact)(body)
fb876ebbf5a7 export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
wenzelm
parents: 70384
diff changeset
   368
        Fact_Multi(entity, facts)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   369
      })
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   370
70539
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   371
  def read_proof(
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   372
    provider: Export.Provider,
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   373
    theory_name: String,
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   374
    serial: Long,
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   375
    cache: Option[Term.Cache] = None): (Term.Term, Term.Proof) =
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   376
  {
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   377
    val body = provider.focus(theory_name).uncompressed_yxml(export_prefix_proofs + serial)
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   378
    if (body.isEmpty) error("Bad proof export " + serial)
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   379
    val (prop, proof) = XML.Decode.pair(Term_XML.Decode.term, Term_XML.Decode.proof)(body)
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   380
    cache match {
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   381
      case None => (prop, proof)
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   382
      case Some(cache) => (cache.term(prop), cache.proof(proof))
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   383
    }
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   384
  }
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   385
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   386
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   387
  /* type classes */
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   388
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   389
  sealed case class Class(
69023
cef000855cf4 clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents: 69019
diff changeset
   390
    entity: Entity, params: List[(String, Term.Typ)], axioms: List[Prop])
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   391
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   392
    def cache(cache: Term.Cache): Class =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   393
      Class(entity.cache(cache),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   394
        params.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
69023
cef000855cf4 clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents: 69019
diff changeset
   395
        axioms.map(_.cache(cache)))
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   396
  }
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   397
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   398
  def read_classes(provider: Export.Provider): List[Class] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   399
    provider.uncompressed_yxml(export_prefix + "classes").map((tree: XML.Tree) =>
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   400
      {
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   401
        val (entity, body) = decode_entity(Kind.CLASS, tree)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   402
        val (params, axioms) =
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   403
        {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   404
          import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   405
          import Term_XML.Decode._
69023
cef000855cf4 clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents: 69019
diff changeset
   406
          pair(list(pair(string, typ)), list(decode_prop))(body)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   407
        }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   408
        Class(entity, params, axioms)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   409
      })
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   410
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   411
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   412
  /* locales */
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   413
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   414
  sealed case class Locale(
69019
a6ba77af6486 export semi-unfolded locale axioms;
wenzelm
parents: 69003
diff changeset
   415
    entity: Entity,
a6ba77af6486 export semi-unfolded locale axioms;
wenzelm
parents: 69003
diff changeset
   416
    typargs: List[(String, Term.Sort)],
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   417
    args: List[((String, Term.Typ), Syntax)],
69023
cef000855cf4 clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents: 69019
diff changeset
   418
    axioms: List[Prop])
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   419
  {
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   420
    def cache(cache: Term.Cache): Locale =
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   421
      Locale(entity.cache(cache),
68864
1dacce27bc25 clarified signature: proper typargs;
wenzelm
parents: 68862
diff changeset
   422
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
69076
90cce2f79e77 proper syntax for locale vs. class parameters;
wenzelm
parents: 69069
diff changeset
   423
        args.map({ case ((name, typ), syntax) => ((cache.string(name), cache.typ(typ)), syntax) }),
69023
cef000855cf4 clarified standardization of variables, with proper treatment of local variables;
wenzelm
parents: 69019
diff changeset
   424
        axioms.map(_.cache(cache)))
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   425
  }
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   426
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   427
  def read_locales(provider: Export.Provider): List[Locale] =
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   428
    provider.uncompressed_yxml(export_prefix + "locales").map((tree: XML.Tree) =>
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   429
      {
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   430
        val (entity, body) = decode_entity(Kind.LOCALE, tree)
69019
a6ba77af6486 export semi-unfolded locale axioms;
wenzelm
parents: 69003
diff changeset
   431
        val (typargs, args, axioms) =
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   432
        {
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   433
          import XML.Decode._
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   434
          import Term_XML.Decode._
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   435
          triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)),
69076
90cce2f79e77 proper syntax for locale vs. class parameters;
wenzelm
parents: 69069
diff changeset
   436
            list(decode_prop))(body)
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   437
        }
69019
a6ba77af6486 export semi-unfolded locale axioms;
wenzelm
parents: 69003
diff changeset
   438
        Locale(entity, typargs, args, axioms)
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   439
      })
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   440
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   441
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   442
  /* locale dependencies */
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   443
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   444
  sealed case class Locale_Dependency(
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   445
    entity: Entity,
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   446
    source: String,
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   447
    target: String,
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   448
    prefix: List[(String, Boolean)],
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   449
    subst_types: List[((String, Term.Sort), Term.Typ)],
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   450
    subst_terms: List[((String, Term.Typ), Term.Term)])
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   451
  {
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   452
    def cache(cache: Term.Cache): Locale_Dependency =
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   453
      Locale_Dependency(entity.cache(cache),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   454
        cache.string(source),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   455
        cache.string(target),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   456
        prefix.map({ case (name, mandatory) => (cache.string(name), mandatory) }),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   457
        subst_types.map({ case ((a, s), ty) => ((cache.string(a), cache.sort(s)), cache.typ(ty)) }),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   458
        subst_terms.map({ case ((x, ty), t) => ((cache.string(x), cache.typ(ty)), cache.term(t)) }))
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   459
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   460
    def is_inclusion: Boolean =
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   461
      subst_types.isEmpty && subst_terms.isEmpty
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   462
  }
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   463
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   464
  def read_locale_dependencies(provider: Export.Provider): List[Locale_Dependency] =
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   465
    provider.uncompressed_yxml(export_prefix + "locale_dependencies").map((tree: XML.Tree) =>
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   466
      {
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   467
        val (entity, body) = decode_entity(Kind.LOCALE_DEPENDENCY, tree)
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   468
        val (source, (target, (prefix, (subst_types, subst_terms)))) =
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   469
        {
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   470
          import XML.Decode._
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   471
          import Term_XML.Decode._
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   472
          pair(string, pair(string, pair(list(pair(string, bool)),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   473
            pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body)
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   474
        }
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   475
        Locale_Dependency(entity, source, target, prefix, subst_types, subst_terms)
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   476
      })
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   477
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   478
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   479
  /* sort algebra */
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   480
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   481
  sealed case class Classrel(class1: String, class2: String, prop: Prop)
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   482
  {
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   483
    def cache(cache: Term.Cache): Classrel =
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   484
      Classrel(cache.string(class1), cache.string(class2), prop.cache(cache))
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   485
  }
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   486
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   487
  def read_classrel(provider: Export.Provider): List[Classrel] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   488
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   489
    val body = provider.uncompressed_yxml(export_prefix + "classrel")
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   490
    val classrel =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   491
    {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   492
      import XML.Decode._
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   493
      list(pair(decode_prop, pair(string, string)))(body)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   494
    }
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   495
    for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   496
  }
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   497
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   498
  sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String, prop: Prop)
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   499
  {
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   500
    def cache(cache: Term.Cache): Arity =
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   501
      Arity(cache.string(type_name), domain.map(cache.sort(_)), cache.string(codomain),
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   502
        prop.cache(cache))
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   503
  }
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   504
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   505
  def read_arities(provider: Export.Provider): List[Arity] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   506
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   507
    val body = provider.uncompressed_yxml(export_prefix + "arities")
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   508
    val arities =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   509
    {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   510
      import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   511
      import Term_XML.Decode._
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   512
      list(pair(decode_prop, triple(string, list(sort), string)))(body)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   513
    }
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   514
    for ((prop, (a, b, c)) <- arities) yield Arity(a, b, c, prop)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   515
  }
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   516
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   517
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   518
  /* HOL typedefs */
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   519
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   520
  sealed case class Typedef(name: String,
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   521
    rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   522
  {
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   523
    def cache(cache: Term.Cache): Typedef =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   524
      Typedef(cache.string(name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   525
        cache.typ(rep_type),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   526
        cache.typ(abs_type),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   527
        cache.string(rep_name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   528
        cache.string(abs_name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   529
        cache.string(axiom_name))
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   530
  }
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   531
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   532
  def read_typedefs(provider: Export.Provider): List[Typedef] =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   533
  {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   534
    val body = provider.uncompressed_yxml(export_prefix + "typedefs")
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   535
    val typedefs =
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   536
    {
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   537
      import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   538
      import Term_XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   539
      list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   540
    }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   541
    for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   542
    yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   543
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   544
}