src/Pure/Thy/export_theory.scala
author wenzelm
Fri, 05 Aug 2022 22:49:25 +0200
changeset 75774 efc25bf4b795
parent 75769 4d27b520622a
child 75790 0ab8a9177e41
permissions -rw-r--r--
discontinued Export.Provider in favour of Export.Context and its derivatives; uniform treatment of all sessions, including Pure;
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
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
    10
import scala.collection.immutable.SortedMap
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
    11
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
    12
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
    13
object Export_Theory {
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    14
  /** session content **/
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    15
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
    16
  sealed case class Session(name: String, theory_graph: Graph[String, Option[Theory]]) {
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    17
    override def toString: String = name
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    18
70789
89f6af1b483f clarified signature;
wenzelm
parents: 70597
diff changeset
    19
    def theory(theory_name: String): Option[Theory] =
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    20
      if (theory_graph.defined(theory_name)) theory_graph.get_node(theory_name)
70789
89f6af1b483f clarified signature;
wenzelm
parents: 70597
diff changeset
    21
      else None
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    22
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    23
    def theories: List[Theory] =
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 71251
diff changeset
    24
      theory_graph.topological_order.flatMap(theory)
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    25
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    26
70790
73514ccad7a6 clarified signature: read full session requirements;
wenzelm
parents: 70789
diff changeset
    27
  def read_session(
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    28
    session_context: Export.Session_Context,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71601
diff changeset
    29
    progress: Progress = new Progress,
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    30
    cache: Term.Cache = Term.Cache.make()
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    31
  ): Session = {
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    32
    val thys =
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    33
      for (theory <- session_context.theory_names()) yield {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    34
        progress.echo("Reading theory " + theory)
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    35
        read_theory(session_context.theory(theory), cache = cache)
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    36
      }
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    37
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    38
    val graph0 =
73359
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    39
      thys.foldLeft(Graph.string[Option[Theory]]) {
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    40
        case (g, thy) => g.default_node(thy.name, Some(thy))
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    41
      }
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    42
    val graph1 =
73359
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    43
      thys.foldLeft(graph0) {
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    44
        case (g0, thy) =>
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    45
          thy.parents.foldLeft(g0) {
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    46
            case (g1, parent) => g1.default_node(parent, None).add_edge_acyclic(parent, thy.name)
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    47
          }
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
    48
      }
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    49
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
    50
    Session(session_context.session_name, graph1)
68206
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
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    54
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
    55
  /** theory content **/
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
    56
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
    57
  sealed case class Theory(name: String, parents: List[String],
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    58
    types: List[Entity[Type]],
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    59
    consts: List[Entity[Const]],
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    60
    axioms: List[Entity[Axiom]],
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    61
    thms: List[Entity[Thm]],
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    62
    classes: List[Entity[Class]],
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    63
    locales: List[Entity[Locale]],
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    64
    locale_dependencies: List[Entity[Locale_Dependency]],
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    65
    classrel: List[Classrel],
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    66
    arities: List[Arity],
70920
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
    67
    constdefs: List[Constdef],
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
    68
    typedefs: List[Typedef],
71248
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
    69
    datatypes: List[Datatype],
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
    70
    spec_rules: List[Spec_Rule],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
    71
    others: Map[String, List[Entity[Other]]]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
    72
  ) {
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
    73
    override def toString: String = name
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    74
75726
642ecd97d35c clarified signature;
wenzelm
parents: 75436
diff changeset
    75
    def entity_iterator: Iterator[Entity0] =
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    76
      types.iterator.map(_.no_content) ++
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    77
      consts.iterator.map(_.no_content) ++
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    78
      axioms.iterator.map(_.no_content) ++
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    79
      thms.iterator.map(_.no_content) ++
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    80
      classes.iterator.map(_.no_content) ++
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
    81
      locales.iterator.map(_.no_content) ++
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
    82
      locale_dependencies.iterator.map(_.no_content) ++
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
    83
      (for { (_, xs) <- others; x <- xs.iterator } yield x.no_content)
68711
d1d03b7b6696 tuned signature;
wenzelm
parents: 68710
diff changeset
    84
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    85
    def cache(cache: Term.Cache): Theory =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    86
      Theory(cache.string(name),
73866
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
    87
        parents.map(cache.string),
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    88
        types.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    89
        consts.map(_.cache(cache)),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    90
        axioms.map(_.cache(cache)),
70579
5a8e3e4b3760 clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents: 70539
diff changeset
    91
        thms.map(_.cache(cache)),
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
    92
        classes.map(_.cache(cache)),
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    93
        locales.map(_.cache(cache)),
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
    94
        locale_dependencies.map(_.cache(cache)),
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
    95
        classrel.map(_.cache(cache)),
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
    96
        arities.map(_.cache(cache)),
70920
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
    97
        constdefs.map(_.cache(cache)),
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
    98
        typedefs.map(_.cache(cache)),
71248
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
    99
        datatypes.map(_.cache(cache)),
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   100
        spec_rules.map(_.cache(cache)),
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   101
        (for ((k, xs) <- others.iterator) yield cache.string(k) -> xs.map(_.cache(cache))).toMap)
68206
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   102
  }
dedf1a70d1fa export more theory and session structure;
wenzelm
parents: 68203
diff changeset
   103
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   104
  def read_theory_parents(theory_context: Export.Theory_Context): Option[List[String]] =
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   105
    theory_context.get(Export.THEORY_PARENTS)
75763
8cf14d4ebec4 more uniform exports: proper encoding of empty parents for Pure;
wenzelm
parents: 75753
diff changeset
   106
      .map(entry => Library.trim_split_lines(entry.uncompressed.text))
74688
7e31f7022c7b clarified signature;
wenzelm
parents: 74681
diff changeset
   107
74694
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   108
  def no_theory: Theory =
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   109
    Theory("", Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Map.empty)
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   110
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   111
  def read_theory(
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   112
    theory_context: Export.Theory_Context,
75747
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   113
    permissive: Boolean = false,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   114
    cache: Term.Cache = Term.Cache.none
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   115
  ): Theory = {
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   116
    val session_name = theory_context.session_context.session_name
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   117
    val theory_name = theory_context.theory
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   118
    read_theory_parents(theory_context) match {
75747
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   119
      case None if permissive => no_theory
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   120
      case None =>
74688
7e31f7022c7b clarified signature;
wenzelm
parents: 74681
diff changeset
   121
        error("Missing theory export in session " + quote(session_name) + ": " + quote(theory_name))
75747
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   122
      case Some(parents) =>
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   123
        val theory =
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   124
          Theory(theory_name, parents,
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   125
            read_types(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   126
            read_consts(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   127
            read_axioms(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   128
            read_thms(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   129
            read_classes(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   130
            read_locales(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   131
            read_locale_dependencies(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   132
            read_classrel(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   133
            read_arities(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   134
            read_constdefs(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   135
            read_typedefs(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   136
            read_datatypes(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   137
            read_spec_rules(theory_context),
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   138
            read_others(theory_context))
75747
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   139
        if (cache.no_cache) theory else theory.cache(cache)
8dc9d979bbac clarified signature;
wenzelm
parents: 75746
diff changeset
   140
    }
68203
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   141
  }
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   142
cda4f24331d5 read theory content from session database;
wenzelm
parents: 68173
diff changeset
   143
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   144
  /* entities */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   145
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   146
  object Kind {
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   147
    val TYPE = "type"
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   148
    val CONST = "const"
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   149
    val THM = "thm"
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   150
    val PROOF = "proof"
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   151
    val LOCALE_DEPENDENCY = "locale_dependency"
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   152
    val DOCUMENT_HEADING = "document_heading"
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   153
    val DOCUMENT_TEXT = "document_text"
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   154
    val PROOF_TEXT = "proof_text"
68714
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   155
  }
1d5ab386eaf0 more explicit entity kind;
wenzelm
parents: 68712
diff changeset
   156
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   157
  def export_kind(kind: String): String =
74681
84e5b4339db6 tuned -- eliminate clones stemming from d28a51dd9da6;
wenzelm
parents: 74657
diff changeset
   158
    if (kind == Markup.TYPE_NAME) Kind.TYPE
84e5b4339db6 tuned -- eliminate clones stemming from d28a51dd9da6;
wenzelm
parents: 74657
diff changeset
   159
    else if (kind == Markup.CONSTANT) Kind.CONST
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   160
    else kind
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   161
74694
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   162
  def export_kind_name(kind: String, name: String): String =
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   163
    name + "|" + export_kind(kind)
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   164
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   165
  abstract class Content[T] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   166
    def cache(cache: Term.Cache): T
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   167
  }
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   168
  sealed case class No_Content() extends Content[No_Content] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   169
    def cache(cache: Term.Cache): No_Content = this
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   170
  }
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   171
  sealed case class Entity[A <: Content[A]](
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   172
    kind: String,
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   173
    name: String,
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   174
    xname: String,
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   175
    pos: Position.T,
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   176
    id: Option[Long],
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   177
    serial: Long,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   178
    content: Option[A]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   179
  ) {
74694
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   180
    val kname: String = export_kind_name(kind, name)
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   181
    val range: Symbol.Range = Position.Range.unapply(pos).getOrElse(Text.Range.offside)
2d9d92116fac clarified Theory_Cache: prefer immutable data with Synchronized variable;
wenzelm
parents: 74688
diff changeset
   182
74681
84e5b4339db6 tuned -- eliminate clones stemming from d28a51dd9da6;
wenzelm
parents: 74657
diff changeset
   183
    def export_kind: String = Export_Theory.export_kind(kind)
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   184
    override def toString: String = export_kind + " " + quote(name)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   185
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   186
    def the_content: A =
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   187
      if (content.isDefined) content.get else error("No content for " + toString)
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   188
75726
642ecd97d35c clarified signature;
wenzelm
parents: 75436
diff changeset
   189
    def no_content: Entity0 = copy(content = None)
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   190
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   191
    def cache(cache: Term.Cache): Entity[A] =
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   192
      Entity(
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   193
        cache.string(kind),
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   194
        cache.string(name),
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   195
        cache.string(xname),
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   196
        cache.position(pos),
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   197
        id,
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   198
        serial,
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   199
        content.map(_.cache(cache)))
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   200
  }
75726
642ecd97d35c clarified signature;
wenzelm
parents: 75436
diff changeset
   201
  type Entity0 = Entity[No_Content]
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   202
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   203
  def read_entities[A <: Content[A]](
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   204
    theory_context: Export.Theory_Context,
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   205
    export_name: String,
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   206
    kind: String,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   207
    decode: XML.Decode.T[A]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   208
  ): List[Entity[A]] = {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   209
    def decode_entity(tree: XML.Tree): Entity[A] = {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   210
      def err(): Nothing = throw new XML.XML_Body(List(tree))
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   211
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   212
      tree match {
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   213
        case XML.Elem(Markup(Markup.ENTITY, props), body) =>
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   214
          val name = Markup.Name.unapply(props) getOrElse err()
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   215
          val xname = Markup.XName.unapply(props) getOrElse err()
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   216
          val pos = props.filter(p => Markup.position_property(p) && p._1 != Markup.ID)
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   217
          val id = Position.Id.unapply(props)
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   218
          val serial = Markup.Serial.unapply(props) getOrElse err()
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   219
          val content = if (body.isEmpty) None else Some(decode(body))
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   220
          Entity(kind, name, xname, pos, id, serial, content)
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   221
        case _ => err()
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   222
      }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   223
    }
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   224
    theory_context.uncompressed_yxml(export_name).map(decode_entity)
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   225
  }
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   226
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   227
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   228
  /* approximative syntax */
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   229
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   230
  object Assoc extends Enumeration {
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   231
    val NO_ASSOC, LEFT_ASSOC, RIGHT_ASSOC = Value
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   232
  }
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   233
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   234
  sealed abstract class Syntax
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   235
  case object No_Syntax extends Syntax
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   236
  case class Prefix(delim: String) extends Syntax
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   237
  case class Infix(assoc: Assoc.Value, delim: String, pri: Int) extends Syntax
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   238
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   239
  def decode_syntax: XML.Decode.T[Syntax] =
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   240
    XML.Decode.variant(List(
75436
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   241
      { case (Nil, Nil) => No_Syntax },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   242
      { case (List(delim), Nil) => Prefix(delim) },
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   243
      { case (Nil, body) =>
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   244
          import XML.Decode._
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   245
          val (ass, delim, pri) = triple(int, string, int)(body)
75436
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   246
          Infix(Assoc(ass), delim, pri) }))
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   247
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   248
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   249
  /* types */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   250
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   251
  sealed case class Type(syntax: Syntax, args: List[String], abbrev: Option[Term.Typ])
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   252
  extends Content[Type] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   253
    override def cache(cache: Term.Cache): Type =
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   254
      Type(
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   255
        syntax,
73866
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
   256
        args.map(cache.string),
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
   257
        abbrev.map(cache.typ))
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   258
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   259
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   260
  def read_types(theory_context: Export.Theory_Context): List[Entity[Type]] =
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   261
    read_entities(theory_context, Export.THEORY_PREFIX + "types", Markup.TYPE_NAME,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   262
      { body =>
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   263
        import XML.Decode._
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   264
        val (syntax, args, abbrev) =
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   265
          triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body)
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   266
        Type(syntax, args, abbrev)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   267
      })
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   268
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   269
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   270
  /* consts */
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   271
68173
7ed88a534bb6 more uniform types vs. consts;
wenzelm
parents: 68172
diff changeset
   272
  sealed case class Const(
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   273
    syntax: Syntax,
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   274
    typargs: List[String],
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   275
    typ: Term.Typ,
69988
6fa51a36b7f7 export propositional status of consts;
wenzelm
parents: 69077
diff changeset
   276
    abbrev: Option[Term.Term],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   277
    propositional: Boolean
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   278
  ) extends Content[Const] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   279
    override def cache(cache: Term.Cache): Const =
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   280
      Const(
69003
a015f1d3ba0c export plain infix syntax;
wenzelm
parents: 68997
diff changeset
   281
        syntax,
73866
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
   282
        typargs.map(cache.string),
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   283
        cache.typ(typ),
73866
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
   284
        abbrev.map(cache.term),
71222
2bc39c80a95d clarified export of consts: recursion is accessible via spec_rules;
wenzelm
parents: 71211
diff changeset
   285
        propositional)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   286
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   287
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   288
  def read_consts(theory_context: Export.Theory_Context): List[Entity[Const]] =
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   289
    read_entities(theory_context, Export.THEORY_PREFIX + "consts", Markup.CONSTANT,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   290
      { body =>
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   291
        import XML.Decode._
71222
2bc39c80a95d clarified export of consts: recursion is accessible via spec_rules;
wenzelm
parents: 71211
diff changeset
   292
        val (syntax, (typargs, (typ, (abbrev, propositional)))) =
69992
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   293
          pair(decode_syntax,
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   294
            pair(list(string),
bd3c10813cc4 more informative Spec_Rules.Equational, notably primrec argument types;
wenzelm
parents: 69988
diff changeset
   295
              pair(Term_XML.Decode.typ,
71222
2bc39c80a95d clarified export of consts: recursion is accessible via spec_rules;
wenzelm
parents: 71211
diff changeset
   296
                pair(option(Term_XML.Decode.term), bool))))(body)
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   297
        Const(syntax, typargs, typ, abbrev, propositional)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   298
      })
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   299
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   300
70579
5a8e3e4b3760 clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents: 70539
diff changeset
   301
  /* axioms */
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   302
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   303
  sealed case class Prop(
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   304
    typargs: List[(String, Term.Sort)],
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   305
    args: List[(String, Term.Typ)],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   306
    term: Term.Term
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   307
  ) extends Content[Prop] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   308
    override def cache(cache: Term.Cache): Prop =
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   309
      Prop(
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   310
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   311
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   312
        cache.term(term))
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   313
  }
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   314
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   315
  def decode_prop(body: XML.Body): Prop = {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   316
    val (typargs, args, t) = {
68726
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   317
      import XML.Decode._
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   318
      import Term_XML.Decode._
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   319
      triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   320
    }
782d6b89fb19 more uniform facts: single vs. multi;
wenzelm
parents: 68718
diff changeset
   321
    Prop(typargs, args, t)
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   322
  }
68208
d9f2cf4fc002 more exports;
wenzelm
parents: 68206
diff changeset
   323
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   324
  sealed case class Axiom(prop: Prop) extends Content[Axiom] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   325
    override def cache(cache: Term.Cache): Axiom = Axiom(prop.cache(cache))
70534
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
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   328
  def read_axioms(theory_context: Export.Theory_Context): List[Entity[Axiom]] =
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   329
    read_entities(theory_context, Export.THEORY_PREFIX + "axioms", Markup.AXIOM,
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   330
      body => Axiom(decode_prop(body)))
68232
4b93573ac5b4 export facts;
wenzelm
parents: 68231
diff changeset
   331
70579
5a8e3e4b3760 clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents: 70539
diff changeset
   332
5a8e3e4b3760 clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents: 70539
diff changeset
   333
  /* theorems */
5a8e3e4b3760 clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents: 70539
diff changeset
   334
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   335
  sealed case class Thm_Id(serial: Long, theory_name: String)
70884
84145953b2a5 more support for proof terms;
wenzelm
parents: 70883
diff changeset
   336
84145953b2a5 more support for proof terms;
wenzelm
parents: 70883
diff changeset
   337
  sealed case class Thm(
84145953b2a5 more support for proof terms;
wenzelm
parents: 70883
diff changeset
   338
    prop: Prop,
84145953b2a5 more support for proof terms;
wenzelm
parents: 70883
diff changeset
   339
    deps: List[String],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   340
    proof: Term.Proof)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   341
  extends Content[Thm] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   342
    override def cache(cache: Term.Cache): Thm =
70884
84145953b2a5 more support for proof terms;
wenzelm
parents: 70883
diff changeset
   343
      Thm(
84145953b2a5 more support for proof terms;
wenzelm
parents: 70883
diff changeset
   344
        prop.cache(cache),
73866
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
   345
        deps.map(cache.string),
70896
8017d382a0d7 tuned signature;
wenzelm
parents: 70891
diff changeset
   346
        cache.proof(proof))
70579
5a8e3e4b3760 clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents: 70539
diff changeset
   347
  }
5a8e3e4b3760 clarified export of axioms and theorems (identified derivations instead of projected facts);
wenzelm
parents: 70539
diff changeset
   348
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   349
  def read_thms(theory_context: Export.Theory_Context): List[Entity[Thm]] =
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   350
    read_entities(theory_context, Export.THEORY_PREFIX + "thms", Kind.THM,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   351
      { body =>
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   352
        import XML.Decode._
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   353
        import Term_XML.Decode._
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   354
        val (prop, deps, prf) = triple(decode_prop, list(string), proof)(body)
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   355
        Thm(prop, deps, prf)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   356
      })
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   357
70881
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   358
  sealed case class Proof(
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   359
    typargs: List[(String, Term.Sort)],
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   360
    args: List[(String, Term.Typ)],
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   361
    term: Term.Term,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   362
    proof: Term.Proof
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   363
  ) {
70883
93767b7a8e7b more support for proof terms;
wenzelm
parents: 70882
diff changeset
   364
    def prop: Prop = Prop(typargs, args, term)
93767b7a8e7b more support for proof terms;
wenzelm
parents: 70882
diff changeset
   365
70881
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   366
    def cache(cache: Term.Cache): Proof =
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   367
      Proof(
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   368
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   369
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   370
        cache.term(term),
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   371
        cache.proof(proof))
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   372
  }
80f3a290b35c clarified proof export;
wenzelm
parents: 70843
diff changeset
   373
70899
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   374
  def read_proof(
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   375
    session_context: Export.Session_Context,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   376
    id: Thm_Id,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   377
    cache: Term.Cache = Term.Cache.none
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   378
  ): Option[Proof] = {
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   379
    val theory_context = session_context.theory(id.theory_name)
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   380
    for { entry <- theory_context.get(Export.PROOFS_PREFIX + id.serial) }
70899
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   381
    yield {
72847
9dda93a753b1 clarified signature: provide XZ.Cache where Export.Entry is created;
wenzelm
parents: 72708
diff changeset
   382
      val body = entry.uncompressed_yxml
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   383
      val (typargs, (args, (prop_body, proof_body))) = {
70899
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   384
        import XML.Decode._
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   385
        import Term_XML.Decode._
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   386
        pair(list(pair(string, sort)), pair(list(pair(string, typ)), pair(x => x, x => x)))(body)
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   387
      }
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   388
      val env = args.toMap
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   389
      val prop = Term_XML.Decode.term_env(env)(prop_body)
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   390
      val proof = Term_XML.Decode.proof_env(env)(proof_body)
70843
cc987440d776 more compact XML: separate environment for free variables;
wenzelm
parents: 70790
diff changeset
   391
70899
5f6dea6a7a4c clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
wenzelm
parents: 70896
diff changeset
   392
      val result = Proof(typargs, args, prop, proof)
73024
337e1b135d2f clarified signature --- internal Cache.none;
wenzelm
parents: 72847
diff changeset
   393
      if (cache.no_cache) result else result.cache(cache)
70843
cc987440d776 more compact XML: separate environment for free variables;
wenzelm
parents: 70790
diff changeset
   394
    }
70539
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   395
  }
30b3c58a1933 support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents: 70534
diff changeset
   396
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   397
  def read_proof_boxes(
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   398
    session_context: Export.Session_Context,
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   399
    proof: Term.Proof,
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   400
    suppress: Thm_Id => Boolean = _ => false,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   401
    cache: Term.Cache = Term.Cache.none
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   402
  ): List[(Thm_Id, Proof)] = {
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   403
    var seen = Set.empty[Long]
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   404
    var result = SortedMap.empty[Long, (Thm_Id, Proof)]
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   405
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   406
    def boxes(context: Option[(Long, Term.Proof)], prf: Term.Proof): Unit = {
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   407
      prf match {
71016
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   408
        case Term.Abst(_, _, p) => boxes(context, p)
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   409
        case Term.AbsP(_, _, p) => boxes(context, p)
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   410
        case Term.Appt(p, _) => boxes(context, p)
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   411
        case Term.AppP(p, q) => boxes(context, p); boxes(context, q)
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   412
        case thm: Term.PThm if !seen(thm.serial) =>
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   413
          seen += thm.serial
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   414
          val id = Thm_Id(thm.serial, thm.theory_name)
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   415
          if (!suppress(id)) {
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   416
            Export_Theory.read_proof(session_context, id, cache = cache) match {
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   417
              case Some(p) =>
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   418
                result += (thm.serial -> (id -> p))
71016
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   419
                boxes(Some((thm.serial, p.proof)), p.proof)
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   420
              case None =>
71016
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   421
                error("Missing proof " + thm.serial + " (theory " + quote (thm.theory_name) + ")" +
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   422
                  (context match {
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   423
                    case None => ""
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   424
                    case Some((i, p)) => " in proof " + i + ":\n" + p
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   425
                  }))
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   426
            }
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   427
          }
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   428
        case _ =>
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   429
      }
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   430
    }
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   431
71016
b05d78bfc67c clarified errors;
wenzelm
parents: 71015
diff changeset
   432
    boxes(None, proof)
71015
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   433
    result.iterator.map(_._2).toList
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   434
  }
bb49abc2ecbb determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
wenzelm
parents: 70920
diff changeset
   435
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   436
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   437
  /* type classes */
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   438
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   439
  sealed case class Class(params: List[(String, Term.Typ)], axioms: List[Prop])
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   440
  extends Content[Class] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   441
    override def cache(cache: Term.Cache): Class =
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   442
      Class(
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   443
        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
   444
        axioms.map(_.cache(cache)))
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   445
  }
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   446
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   447
  def read_classes(theory_context: Export.Theory_Context): List[Entity[Class]] =
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   448
    read_entities(theory_context, Export.THEORY_PREFIX + "classes", Markup.CLASS,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   449
      { body =>
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   450
        import XML.Decode._
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   451
        import Term_XML.Decode._
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   452
        val (params, axioms) = pair(list(pair(string, typ)), list(decode_prop))(body)
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   453
        Class(params, axioms)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   454
      })
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   455
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   456
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   457
  /* locales */
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   458
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   459
  sealed case class Locale(
69019
a6ba77af6486 export semi-unfolded locale axioms;
wenzelm
parents: 69003
diff changeset
   460
    typargs: List[(String, Term.Sort)],
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   461
    args: List[((String, Term.Typ), Syntax)],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   462
    axioms: List[Prop]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   463
  ) extends Content[Locale] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   464
    override def cache(cache: Term.Cache): Locale =
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   465
      Locale(
68864
1dacce27bc25 clarified signature: proper typargs;
wenzelm
parents: 68862
diff changeset
   466
        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
   467
        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
   468
        axioms.map(_.cache(cache)))
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   469
  }
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   470
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   471
  def read_locales(theory_context: Export.Theory_Context): List[Entity[Locale]] =
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   472
    read_entities(theory_context, Export.THEORY_PREFIX + "locales", Markup.LOCALE,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   473
      { body =>
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   474
        import XML.Decode._
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   475
        import Term_XML.Decode._
69019
a6ba77af6486 export semi-unfolded locale axioms;
wenzelm
parents: 69003
diff changeset
   476
        val (typargs, args, axioms) =
69077
11529ae45786 more approximative prefix syntax, including binder;
wenzelm
parents: 69076
diff changeset
   477
          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
   478
            list(decode_prop))(body)
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   479
        Locale(typargs, args, axioms)
68862
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   480
      })
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   481
47e9912c53c3 export locale content;
wenzelm
parents: 68835
diff changeset
   482
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   483
  /* locale dependencies */
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   484
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   485
  sealed case class Locale_Dependency(
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   486
    source: String,
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   487
    target: String,
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   488
    prefix: List[(String, Boolean)],
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   489
    subst_types: List[((String, Term.Sort), Term.Typ)],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   490
    subst_terms: List[((String, Term.Typ), Term.Term)]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   491
  ) extends Content[Locale_Dependency] {
74114
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   492
    override def cache(cache: Term.Cache): Locale_Dependency =
700e5bd59c7d clarified export of formal entities: name space info is always present, but content depends on option "export_theory";
wenzelm
parents: 73866
diff changeset
   493
      Locale_Dependency(
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   494
        cache.string(source),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   495
        cache.string(target),
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   496
        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
   497
        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
   498
        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
   499
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   500
    def is_inclusion: Boolean =
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   501
      subst_types.isEmpty && subst_terms.isEmpty
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   502
  }
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   503
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   504
  def read_locale_dependencies(
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   505
    theory_context: Export.Theory_Context
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   506
  ): List[Entity[Locale_Dependency]] = {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   507
    read_entities(theory_context, Export.THEORY_PREFIX + "locale_dependencies",
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   508
      Kind.LOCALE_DEPENDENCY,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   509
      { body =>
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   510
        import XML.Decode._
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   511
        import Term_XML.Decode._
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   512
        val (source, (target, (prefix, (subst_types, subst_terms)))) =
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   513
          pair(string, pair(string, pair(list(pair(string, bool)),
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   514
            pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   515
        Locale_Dependency(source, target, prefix, subst_types, subst_terms)
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   516
      })
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   517
  }
69069
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   518
b9aca3b9619f export locale dependencies, with approx. morphism as type/term substitution;
wenzelm
parents: 69023
diff changeset
   519
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   520
  /* sort algebra */
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   521
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   522
  sealed case class Classrel(class1: String, class2: String, prop: Prop) {
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   523
    def cache(cache: Term.Cache): Classrel =
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   524
      Classrel(cache.string(class1), cache.string(class2), prop.cache(cache))
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   525
  }
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   526
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   527
  def read_classrel(theory_context: Export.Theory_Context): List[Classrel] = {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   528
    val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "classrel")
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   529
    val classrel = {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   530
      import XML.Decode._
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   531
      list(pair(decode_prop, pair(string, string)))(body)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   532
    }
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   533
    for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   534
  }
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   535
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   536
  sealed case class Arity(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   537
    type_name: String,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   538
    domain: List[Term.Sort],
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   539
    codomain: String,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   540
    prop: Prop
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   541
  ) {
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   542
    def cache(cache: Term.Cache): Arity =
73866
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
   543
      Arity(cache.string(type_name), domain.map(cache.sort), cache.string(codomain),
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   544
        prop.cache(cache))
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   545
  }
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   546
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   547
  def read_arities(theory_context: Export.Theory_Context): List[Arity] = {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   548
    val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "arities")
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   549
    val arities = {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   550
      import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   551
      import Term_XML.Decode._
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   552
      list(pair(decode_prop, triple(string, list(sort), string)))(body)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   553
    }
70384
8ce08b154aa1 clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
wenzelm
parents: 69996
diff changeset
   554
    for ((prop, (a, b, c)) <- arities) yield Arity(a, b, c, prop)
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   555
  }
68295
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   556
781a98696638 export sort algebra;
wenzelm
parents: 68267
diff changeset
   557
70920
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   558
  /* Pure constdefs */
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   559
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   560
  sealed case class Constdef(name: String, axiom_name: String) {
70920
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   561
    def cache(cache: Term.Cache): Constdef =
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   562
      Constdef(cache.string(name), cache.string(axiom_name))
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   563
  }
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   564
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   565
  def read_constdefs(theory_context: Export.Theory_Context): List[Constdef] = {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   566
    val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "constdefs")
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   567
    val constdefs = {
70920
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   568
      import XML.Decode._
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   569
      list(pair(string, string))(body)
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   570
    }
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   571
    for ((name, axiom_name) <- constdefs) yield Constdef(name, axiom_name)
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   572
  }
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   573
1e0ad25c94c8 export constdefs according to defs.ML;
wenzelm
parents: 70913
diff changeset
   574
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   575
  /* HOL typedefs */
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   576
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   577
  sealed case class Typedef(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   578
    name: String,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   579
    rep_type: Term.Typ,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   580
    abs_type: Term.Typ,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   581
    rep_name: String,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   582
    abs_name: String,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   583
    axiom_name: String
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   584
  ) {
68267
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   585
    def cache(cache: Term.Cache): Typedef =
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   586
      Typedef(cache.string(name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   587
        cache.typ(rep_type),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   588
        cache.typ(abs_type),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   589
        cache.string(rep_name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   590
        cache.string(abs_name),
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   591
        cache.string(axiom_name))
6a29709906c6 more scalable JVM memory management;
wenzelm
parents: 68264
diff changeset
   592
  }
68264
bb9a3be6952a more exports;
wenzelm
parents: 68232
diff changeset
   593
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   594
  def read_typedefs(theory_context: Export.Theory_Context): List[Typedef] = {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   595
    val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "typedefs")
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   596
    val typedefs = {
68418
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   597
      import XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   598
      import Term_XML.Decode._
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   599
      list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   600
    }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   601
    for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs }
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   602
    yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name)
366e43cddd20 more abstract Export.Provider;
wenzelm
parents: 68346
diff changeset
   603
  }
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   604
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   605
71248
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   606
  /* HOL datatypes */
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   607
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   608
  sealed case class Datatype(
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   609
    pos: Position.T,
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   610
    name: String,
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   611
    co: Boolean,
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   612
    typargs: List[(String, Term.Sort)],
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   613
    typ: Term.Typ,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   614
    constructors: List[(Term.Term, Term.Typ)]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   615
  ) {
71248
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   616
    def id: Option[Long] = Position.Id.unapply(pos)
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   617
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   618
    def cache(cache: Term.Cache): Datatype =
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   619
      Datatype(
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   620
        cache.position(pos),
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   621
        cache.string(name),
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   622
        co,
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   623
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   624
        cache.typ(typ),
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   625
        constructors.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }))
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   626
  }
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   627
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   628
  def read_datatypes(theory_context: Export.Theory_Context): List[Datatype] = {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   629
    val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "datatypes")
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   630
    val datatypes = {
71248
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   631
      import XML.Decode._
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   632
      import Term_XML.Decode._
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   633
      list(pair(properties, pair(string, pair(bool, pair(list(pair(string, sort)),
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   634
            pair(typ, list(pair(term, typ))))))))(body)
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   635
    }
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   636
    for ((pos, (name, (co, (typargs, (typ, constructors))))) <- datatypes)
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   637
      yield Datatype(pos, name, co, typargs, typ, constructors)
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   638
  }
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   639
adf5e53d2b2b export datatypes;
wenzelm
parents: 71222
diff changeset
   640
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   641
  /* Pure spec rules */
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   642
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   643
  sealed abstract class Recursion {
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   644
    def cache(cache: Term.Cache): Recursion =
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   645
      this match {
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   646
        case Primrec(types) => Primrec(types.map(cache.string))
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   647
        case Primcorec(types) => Primcorec(types.map(cache.string))
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   648
        case _ => this
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   649
      }
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   650
  }
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   651
  case class Primrec(types: List[String]) extends Recursion
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   652
  case object Recdef extends Recursion
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   653
  case class Primcorec(types: List[String]) extends Recursion
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   654
  case object Corec extends Recursion
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   655
  case object Unknown_Recursion extends Recursion
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   656
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   657
  val decode_recursion: XML.Decode.T[Recursion] = {
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   658
    import XML.Decode._
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   659
    variant(List(
75436
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   660
      { case (Nil, a) => Primrec(list(string)(a)) },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   661
      { case (Nil, Nil) => Recdef },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   662
      { case (Nil, a) => Primcorec(list(string)(a)) },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   663
      { case (Nil, Nil) => Corec },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   664
      { case (Nil, Nil) => Unknown_Recursion }))
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   665
  }
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   666
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   667
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   668
  sealed abstract class Rough_Classification {
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   669
    def is_equational: Boolean = this.isInstanceOf[Equational]
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   670
    def is_inductive: Boolean = this == Inductive
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   671
    def is_co_inductive: Boolean = this == Co_Inductive
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   672
    def is_relational: Boolean = is_inductive || is_co_inductive
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   673
    def is_unknown: Boolean = this == Unknown
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   674
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   675
    def cache(cache: Term.Cache): Rough_Classification =
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   676
      this match {
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   677
        case Equational(recursion) => Equational(recursion.cache(cache))
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   678
        case _ => this
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   679
      }
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   680
  }
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   681
  case class Equational(recursion: Recursion) extends Rough_Classification
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   682
  case object Inductive extends Rough_Classification
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   683
  case object Co_Inductive extends Rough_Classification
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   684
  case object Unknown extends Rough_Classification
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   685
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   686
  val decode_rough_classification: XML.Decode.T[Rough_Classification] = {
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   687
    import XML.Decode._
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   688
    variant(List(
75436
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   689
      { case (Nil, a) => Equational(decode_recursion(a)) },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   690
      { case (Nil, Nil) => Inductive },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   691
      { case (Nil, Nil) => Co_Inductive },
40630fec3b5d clarified signature;
wenzelm
parents: 75425
diff changeset
   692
      { case (Nil, Nil) => Unknown }))
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   693
  }
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   694
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   695
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   696
  sealed case class Spec_Rule(
71207
8af82f3e03c9 formal position for spec rule (not significant for equality);
wenzelm
parents: 71202
diff changeset
   697
    pos: Position.T,
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   698
    name: String,
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   699
    rough_classification: Rough_Classification,
71208
5e0050eb64f2 clarified export of spec rules: more like locale;
wenzelm
parents: 71207
diff changeset
   700
    typargs: List[(String, Term.Sort)],
5e0050eb64f2 clarified export of spec rules: more like locale;
wenzelm
parents: 71207
diff changeset
   701
    args: List[(String, Term.Typ)],
71211
7d522732b7f2 more informative export;
wenzelm
parents: 71208
diff changeset
   702
    terms: List[(Term.Term, Term.Typ)],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   703
    rules: List[Term.Term]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   704
  ) {
71207
8af82f3e03c9 formal position for spec rule (not significant for equality);
wenzelm
parents: 71202
diff changeset
   705
    def id: Option[Long] = Position.Id.unapply(pos)
8af82f3e03c9 formal position for spec rule (not significant for equality);
wenzelm
parents: 71202
diff changeset
   706
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   707
    def cache(cache: Term.Cache): Spec_Rule =
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   708
      Spec_Rule(
71207
8af82f3e03c9 formal position for spec rule (not significant for equality);
wenzelm
parents: 71202
diff changeset
   709
        cache.position(pos),
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   710
        cache.string(name),
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   711
        rough_classification.cache(cache),
71208
5e0050eb64f2 clarified export of spec rules: more like locale;
wenzelm
parents: 71207
diff changeset
   712
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
5e0050eb64f2 clarified export of spec rules: more like locale;
wenzelm
parents: 71207
diff changeset
   713
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
71211
7d522732b7f2 more informative export;
wenzelm
parents: 71208
diff changeset
   714
        terms.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }),
73866
66bff50bc5f1 tuned --- following hints by IntelliJ;
wenzelm
parents: 73359
diff changeset
   715
        rules.map(cache.term))
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   716
  }
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   717
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   718
  def read_spec_rules(theory_context: Export.Theory_Context): List[Spec_Rule] = {
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   719
    val body = theory_context.uncompressed_yxml(Export.THEORY_PREFIX + "spec_rules")
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   720
    val spec_rules = {
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   721
      import XML.Decode._
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   722
      import Term_XML.Decode._
71207
8af82f3e03c9 formal position for spec rule (not significant for equality);
wenzelm
parents: 71202
diff changeset
   723
      list(
8af82f3e03c9 formal position for spec rule (not significant for equality);
wenzelm
parents: 71202
diff changeset
   724
        pair(properties, pair(string, pair(decode_rough_classification,
71208
5e0050eb64f2 clarified export of spec rules: more like locale;
wenzelm
parents: 71207
diff changeset
   725
          pair(list(pair(string, sort)), pair(list(pair(string, typ)),
71211
7d522732b7f2 more informative export;
wenzelm
parents: 71208
diff changeset
   726
            pair(list(pair(term, typ)), list(term))))))))(body)
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   727
    }
71208
5e0050eb64f2 clarified export of spec rules: more like locale;
wenzelm
parents: 71207
diff changeset
   728
    for ((pos, (name, (rough_classification, (typargs, (args, (terms, rules)))))) <- spec_rules)
5e0050eb64f2 clarified export of spec rules: more like locale;
wenzelm
parents: 71207
diff changeset
   729
      yield Spec_Rule(pos, name, rough_classification, typargs, args, terms, rules)
71202
785610ad6bfa export spec rules;
wenzelm
parents: 71016
diff changeset
   730
  }
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   731
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   732
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   733
  /* other entities */
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   734
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74828
diff changeset
   735
  sealed case class Other() extends Content[Other] {
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   736
    override def cache(cache: Term.Cache): Other = this
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   737
  }
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   738
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   739
  def read_others(theory_context: Export.Theory_Context): Map[String, List[Entity[Other]]] = {
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   740
    val kinds =
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   741
      theory_context.get(Export.THEORY_PREFIX + "other_kinds") match {
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   742
        case Some(entry) => split_lines(entry.uncompressed.text)
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   743
        case None => Nil
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   744
      }
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   745
    val other = Other()
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   746
    def read_other(kind: String): List[Entity[Other]] =
75774
efc25bf4b795 discontinued Export.Provider in favour of Export.Context and its derivatives;
wenzelm
parents: 75769
diff changeset
   747
      read_entities(theory_context, Export.THEORY_PREFIX + "other/" + kind, kind, _ => other)
74261
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   748
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   749
    kinds.map(kind => kind -> read_other(kind)).toMap
d28a51dd9da6 export other entities, e.g. relevant for formal document output;
wenzelm
parents: 74119
diff changeset
   750
  }
68171
13162bb3a677 export foundational theory content in Scala;
wenzelm
parents:
diff changeset
   751
}