| author | wenzelm | 
| Tue, 03 Dec 2019 16:40:04 +0100 | |
| changeset 71222 | 2bc39c80a95d | 
| parent 71211 | 7d522732b7f2 | 
| child 71248 | adf5e53d2b2b | 
| permissions | -rw-r--r-- | 
| 68171 | 1  | 
/* Title: Pure/Thy/export_theory.scala  | 
2  | 
Author: Makarius  | 
|
3  | 
||
4  | 
Export foundational theory content.  | 
|
5  | 
*/  | 
|
6  | 
||
7  | 
package isabelle  | 
|
8  | 
||
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  | 
|
| 68171 | 13  | 
object Export_Theory  | 
14  | 
{
 | 
|
| 68206 | 15  | 
/** session content **/  | 
16  | 
||
| 70789 | 17  | 
sealed case class Session(name: String, theory_graph: Graph[String, Option[Theory]])  | 
| 68206 | 18  | 
  {
 | 
19  | 
override def toString: String = name  | 
|
20  | 
||
| 70789 | 21  | 
def theory(theory_name: String): Option[Theory] =  | 
| 68206 | 22  | 
if (theory_graph.defined(theory_name)) theory_graph.get_node(theory_name)  | 
| 70789 | 23  | 
else None  | 
| 68206 | 24  | 
|
25  | 
def theories: List[Theory] =  | 
|
| 70789 | 26  | 
theory_graph.topological_order.flatMap(theory(_))  | 
| 68206 | 27  | 
}  | 
28  | 
||
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
29  | 
def read_session(  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
30  | 
store: Sessions.Store,  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
31  | 
sessions_structure: Sessions.Structure,  | 
| 68209 | 32  | 
session_name: String,  | 
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
33  | 
progress: Progress = No_Progress,  | 
| 68206 | 34  | 
types: Boolean = true,  | 
| 68264 | 35  | 
consts: Boolean = true,  | 
36  | 
axioms: Boolean = true,  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
37  | 
thms: Boolean = true,  | 
| 68264 | 38  | 
classes: Boolean = true,  | 
| 68862 | 39  | 
locales: Boolean = true,  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
40  | 
locale_dependencies: Boolean = true,  | 
| 68295 | 41  | 
classrel: Boolean = true,  | 
42  | 
arities: Boolean = true,  | 
|
| 70920 | 43  | 
constdefs: Boolean = true,  | 
| 68862 | 44  | 
typedefs: Boolean = true,  | 
| 71202 | 45  | 
spec_rules: Boolean = true,  | 
| 68267 | 46  | 
cache: Term.Cache = Term.make_cache()): Session =  | 
| 68206 | 47  | 
  {
 | 
48  | 
val thys =  | 
|
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
49  | 
sessions_structure.build_requirements(List(session_name)).flatMap(session =>  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
50  | 
using(store.open_database(session))(db =>  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
51  | 
        {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
52  | 
          db.transaction {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
53  | 
for (theory <- Export.read_theory_names(db, session))  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
54  | 
            yield {
 | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
55  | 
              progress.echo("Reading theory " + theory)
 | 
| 70891 | 56  | 
read_theory(Export.Provider.database(db, session, theory),  | 
57  | 
session, theory, types = types, consts = consts,  | 
|
58  | 
axioms = axioms, thms = thms, classes = classes, locales = locales,  | 
|
59  | 
locale_dependencies = locale_dependencies, classrel = classrel, arities = arities,  | 
|
| 71202 | 60  | 
constdefs = constdefs, typedefs = typedefs,  | 
61  | 
spec_rules = spec_rules, cache = Some(cache))  | 
|
| 
70790
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
62  | 
}  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
63  | 
}  | 
| 
 
73514ccad7a6
clarified signature: read full session requirements;
 
wenzelm 
parents: 
70789 
diff
changeset
 | 
64  | 
}))  | 
| 68206 | 65  | 
|
66  | 
val graph0 =  | 
|
| 70890 | 67  | 
      (Graph.string[Option[Theory]] /: thys) {
 | 
68  | 
case (g, thy) => g.default_node(thy.name, Some(thy)) }  | 
|
| 68206 | 69  | 
val graph1 =  | 
70  | 
      (graph0 /: thys) { case (g0, thy) =>
 | 
|
71  | 
        (g0 /: thy.parents) { case (g1, parent) =>
 | 
|
| 70789 | 72  | 
g1.default_node(parent, None).add_edge_acyclic(parent, thy.name) } }  | 
| 68206 | 73  | 
|
74  | 
Session(session_name, graph1)  | 
|
75  | 
}  | 
|
76  | 
||
77  | 
||
78  | 
||
| 68203 | 79  | 
/** theory content **/  | 
80  | 
||
| 68346 | 81  | 
val export_prefix: String = "theory/"  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
82  | 
val export_prefix_proofs: String = "proofs/"  | 
| 68346 | 83  | 
|
| 68208 | 84  | 
sealed case class Theory(name: String, parents: List[String],  | 
85  | 
types: List[Type],  | 
|
86  | 
consts: List[Const],  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
87  | 
axioms: List[Axiom],  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
88  | 
thms: List[Thm],  | 
| 68264 | 89  | 
classes: List[Class],  | 
| 68862 | 90  | 
locales: List[Locale],  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
91  | 
locale_dependencies: List[Locale_Dependency],  | 
| 68295 | 92  | 
classrel: List[Classrel],  | 
| 68862 | 93  | 
arities: List[Arity],  | 
| 70920 | 94  | 
constdefs: List[Constdef],  | 
| 71202 | 95  | 
typedefs: List[Typedef],  | 
96  | 
spec_rules: List[Spec_Rule])  | 
|
| 68206 | 97  | 
  {
 | 
98  | 
override def toString: String = name  | 
|
| 68267 | 99  | 
|
| 70789 | 100  | 
def entity_iterator: Iterator[Entity] =  | 
101  | 
types.iterator.map(_.entity) ++  | 
|
102  | 
consts.iterator.map(_.entity) ++  | 
|
103  | 
axioms.iterator.map(_.entity) ++  | 
|
104  | 
thms.iterator.map(_.entity) ++  | 
|
105  | 
classes.iterator.map(_.entity) ++  | 
|
106  | 
locales.iterator.map(_.entity) ++  | 
|
107  | 
locale_dependencies.iterator.map(_.entity)  | 
|
| 68711 | 108  | 
|
| 68267 | 109  | 
def cache(cache: Term.Cache): Theory =  | 
110  | 
Theory(cache.string(name),  | 
|
111  | 
parents.map(cache.string(_)),  | 
|
112  | 
types.map(_.cache(cache)),  | 
|
113  | 
consts.map(_.cache(cache)),  | 
|
114  | 
axioms.map(_.cache(cache)),  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
115  | 
thms.map(_.cache(cache)),  | 
| 68267 | 116  | 
classes.map(_.cache(cache)),  | 
| 68862 | 117  | 
locales.map(_.cache(cache)),  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
118  | 
locale_dependencies.map(_.cache(cache)),  | 
| 68295 | 119  | 
classrel.map(_.cache(cache)),  | 
| 68862 | 120  | 
arities.map(_.cache(cache)),  | 
| 70920 | 121  | 
constdefs.map(_.cache(cache)),  | 
| 71202 | 122  | 
typedefs.map(_.cache(cache)),  | 
123  | 
spec_rules.map(_.cache(cache)))  | 
|
| 68206 | 124  | 
}  | 
125  | 
||
| 68418 | 126  | 
def read_theory(provider: Export.Provider, session_name: String, theory_name: String,  | 
| 68203 | 127  | 
types: Boolean = true,  | 
| 68208 | 128  | 
consts: Boolean = true,  | 
| 68232 | 129  | 
axioms: Boolean = true,  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
130  | 
thms: Boolean = true,  | 
| 68264 | 131  | 
classes: Boolean = true,  | 
| 68862 | 132  | 
locales: Boolean = true,  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
133  | 
locale_dependencies: Boolean = true,  | 
| 68295 | 134  | 
classrel: Boolean = true,  | 
135  | 
arities: Boolean = true,  | 
|
| 70920 | 136  | 
constdefs: Boolean = true,  | 
| 68862 | 137  | 
typedefs: Boolean = true,  | 
| 71202 | 138  | 
spec_rules: Boolean = true,  | 
| 68267 | 139  | 
cache: Option[Term.Cache] = None): Theory =  | 
| 68203 | 140  | 
  {
 | 
| 68206 | 141  | 
val parents =  | 
| 70891 | 142  | 
if (theory_name == Thy_Header.PURE) Nil  | 
143  | 
      else {
 | 
|
144  | 
        provider(export_prefix + "parents") match {
 | 
|
145  | 
case Some(entry) => split_lines(entry.uncompressed().text)  | 
|
146  | 
case None =>  | 
|
147  | 
            error("Missing theory export in session " + quote(session_name) + ": " +
 | 
|
148  | 
quote(theory_name))  | 
|
149  | 
}  | 
|
| 68206 | 150  | 
}  | 
| 68267 | 151  | 
val theory =  | 
152  | 
Theory(theory_name, parents,  | 
|
| 68418 | 153  | 
if (types) read_types(provider) else Nil,  | 
154  | 
if (consts) read_consts(provider) else Nil,  | 
|
155  | 
if (axioms) read_axioms(provider) else Nil,  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
156  | 
if (thms) read_thms(provider) else Nil,  | 
| 68418 | 157  | 
if (classes) read_classes(provider) else Nil,  | 
| 68862 | 158  | 
if (locales) read_locales(provider) else Nil,  | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
159  | 
if (locale_dependencies) read_locale_dependencies(provider) else Nil,  | 
| 68418 | 160  | 
if (classrel) read_classrel(provider) else Nil,  | 
| 68862 | 161  | 
if (arities) read_arities(provider) else Nil,  | 
| 70920 | 162  | 
if (constdefs) read_constdefs(provider) else Nil,  | 
| 71202 | 163  | 
if (typedefs) read_typedefs(provider) else Nil,  | 
164  | 
if (spec_rules) read_spec_rules(provider) else Nil)  | 
|
| 68267 | 165  | 
if (cache.isDefined) theory.cache(cache.get) else theory  | 
| 68203 | 166  | 
}  | 
167  | 
||
| 70883 | 168  | 
def read_pure[A](store: Sessions.Store, read: (Export.Provider, String, String) => A): A =  | 
| 68710 | 169  | 
  {
 | 
170  | 
val session_name = Thy_Header.PURE  | 
|
171  | 
val theory_name = Thy_Header.PURE  | 
|
172  | 
||
173  | 
using(store.open_database(session_name))(db =>  | 
|
174  | 
    {
 | 
|
175  | 
      db.transaction {
 | 
|
| 70883 | 176  | 
read(Export.Provider.database(db, session_name, theory_name), session_name, theory_name)  | 
| 68710 | 177  | 
}  | 
178  | 
})  | 
|
179  | 
}  | 
|
180  | 
||
| 70883 | 181  | 
def read_pure_theory(store: Sessions.Store, cache: Option[Term.Cache] = None): Theory =  | 
182  | 
read_pure(store, read_theory(_, _, _, cache = cache))  | 
|
183  | 
||
| 
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
 | 
184  | 
def read_pure_proof(  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
185  | 
store: Sessions.Store, id: Thm_Id, cache: Option[Term.Cache] = None): Option[Proof] =  | 
| 70884 | 186  | 
read_pure(store, (provider, _, _) => read_proof(provider, id, cache = cache))  | 
| 70883 | 187  | 
|
| 68203 | 188  | 
|
| 68171 | 189  | 
/* entities */  | 
190  | 
||
| 68714 | 191  | 
object Kind extends Enumeration  | 
| 68171 | 192  | 
  {
 | 
| 68714 | 193  | 
    val TYPE = Value("type")
 | 
194  | 
    val CONST = Value("const")
 | 
|
195  | 
    val AXIOM = Value("axiom")
 | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
196  | 
    val THM = Value("thm")
 | 
| 70882 | 197  | 
    val PROOF = Value("proof")
 | 
| 68714 | 198  | 
    val CLASS = Value("class")
 | 
| 68862 | 199  | 
    val LOCALE = Value("locale")
 | 
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
200  | 
    val LOCALE_DEPENDENCY = Value("locale_dependency")
 | 
| 70913 | 201  | 
    val DOCUMENT_HEADING = Value("document_heading")
 | 
202  | 
    val DOCUMENT_TEXT = Value("document_text")
 | 
|
203  | 
    val PROOF_TEXT = Value("proof_text")
 | 
|
| 68714 | 204  | 
}  | 
205  | 
||
| 68835 | 206  | 
sealed case class Entity(  | 
| 68997 | 207  | 
kind: Kind.Value, name: String, xname: String, pos: Position.T, id: Option[Long], serial: Long)  | 
| 68714 | 208  | 
  {
 | 
| 68718 | 209  | 
override def toString: String = kind.toString + " " + quote(name)  | 
| 68267 | 210  | 
|
211  | 
def cache(cache: Term.Cache): Entity =  | 
|
| 68997 | 212  | 
Entity(kind, cache.string(name), cache.string(xname), cache.position(pos), id, serial)  | 
| 68171 | 213  | 
}  | 
214  | 
||
| 68714 | 215  | 
def decode_entity(kind: Kind.Value, tree: XML.Tree): (Entity, XML.Body) =  | 
| 68171 | 216  | 
  {
 | 
217  | 
def err(): Nothing = throw new XML.XML_Body(List(tree))  | 
|
218  | 
||
219  | 
    tree match {
 | 
|
220  | 
case XML.Elem(Markup(Markup.ENTITY, props), body) =>  | 
|
221  | 
val name = Markup.Name.unapply(props) getOrElse err()  | 
|
| 68997 | 222  | 
val xname = Markup.XName.unapply(props) getOrElse err()  | 
| 
68830
 
44ec6fdaacf8
retain original id, which is command_id/exec_id for PIDE;
 
wenzelm 
parents: 
68726 
diff
changeset
 | 
223  | 
        val pos = props.filter({ case (a, _) => Markup.POSITION_PROPERTIES(a) && a != Markup.ID })
 | 
| 68835 | 224  | 
val id = Position.Id.unapply(props)  | 
| 68171 | 225  | 
val serial = Markup.Serial.unapply(props) getOrElse err()  | 
| 68997 | 226  | 
(Entity(kind, name, xname, pos, id, serial), body)  | 
| 68171 | 227  | 
case _ => err()  | 
228  | 
}  | 
|
229  | 
}  | 
|
230  | 
||
231  | 
||
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
232  | 
/* approximative syntax */  | 
| 69003 | 233  | 
|
234  | 
object Assoc extends Enumeration  | 
|
235  | 
  {
 | 
|
236  | 
val NO_ASSOC, LEFT_ASSOC, RIGHT_ASSOC = Value  | 
|
237  | 
}  | 
|
238  | 
||
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
239  | 
sealed abstract class Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
240  | 
case object No_Syntax extends Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
241  | 
case class Prefix(delim: String) extends Syntax  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
242  | 
case class Infix(assoc: Assoc.Value, delim: String, pri: Int) extends Syntax  | 
| 69003 | 243  | 
|
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
244  | 
def decode_syntax: XML.Decode.T[Syntax] =  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
245  | 
XML.Decode.variant(List(  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
246  | 
      { case (Nil, Nil) => No_Syntax },
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
247  | 
      { case (List(delim), Nil) => Prefix(delim) },
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
248  | 
      { case (Nil, body) =>
 | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
249  | 
import XML.Decode._  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
250  | 
val (ass, delim, pri) = triple(int, string, int)(body)  | 
| 
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
251  | 
Infix(Assoc(ass), delim, pri) }))  | 
| 69003 | 252  | 
|
253  | 
||
| 68171 | 254  | 
/* types */  | 
255  | 
||
| 69003 | 256  | 
sealed case class Type(  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
257  | 
entity: Entity, syntax: Syntax, args: List[String], abbrev: Option[Term.Typ])  | 
| 68267 | 258  | 
  {
 | 
259  | 
def cache(cache: Term.Cache): Type =  | 
|
260  | 
Type(entity.cache(cache),  | 
|
| 69003 | 261  | 
syntax,  | 
| 68267 | 262  | 
args.map(cache.string(_)),  | 
263  | 
abbrev.map(cache.typ(_)))  | 
|
264  | 
}  | 
|
| 68171 | 265  | 
|
| 68418 | 266  | 
def read_types(provider: Export.Provider): List[Type] =  | 
267  | 
provider.uncompressed_yxml(export_prefix + "types").map((tree: XML.Tree) =>  | 
|
268  | 
      {
 | 
|
| 68714 | 269  | 
val (entity, body) = decode_entity(Kind.TYPE, tree)  | 
| 69003 | 270  | 
val (syntax, args, abbrev) =  | 
| 68203 | 271  | 
        {
 | 
| 68418 | 272  | 
import XML.Decode._  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
273  | 
triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body)  | 
| 68418 | 274  | 
}  | 
| 69003 | 275  | 
Type(entity, syntax, args, abbrev)  | 
| 68418 | 276  | 
})  | 
| 68171 | 277  | 
|
278  | 
||
279  | 
/* consts */  | 
|
280  | 
||
| 68173 | 281  | 
sealed case class Const(  | 
| 69003 | 282  | 
entity: Entity,  | 
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
283  | 
syntax: Syntax,  | 
| 69003 | 284  | 
typargs: List[String],  | 
285  | 
typ: Term.Typ,  | 
|
| 69988 | 286  | 
abbrev: Option[Term.Term],  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
287  | 
propositional: Boolean)  | 
| 68267 | 288  | 
  {
 | 
289  | 
def cache(cache: Term.Cache): Const =  | 
|
290  | 
Const(entity.cache(cache),  | 
|
| 69003 | 291  | 
syntax,  | 
| 68267 | 292  | 
typargs.map(cache.string(_)),  | 
293  | 
cache.typ(typ),  | 
|
| 69988 | 294  | 
abbrev.map(cache.term(_)),  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
295  | 
propositional)  | 
| 68267 | 296  | 
}  | 
| 68171 | 297  | 
|
| 68418 | 298  | 
def read_consts(provider: Export.Provider): List[Const] =  | 
299  | 
provider.uncompressed_yxml(export_prefix + "consts").map((tree: XML.Tree) =>  | 
|
300  | 
      {
 | 
|
| 68714 | 301  | 
val (entity, body) = decode_entity(Kind.CONST, tree)  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
302  | 
val (syntax, (typargs, (typ, (abbrev, propositional)))) =  | 
| 68203 | 303  | 
        {
 | 
| 68418 | 304  | 
import XML.Decode._  | 
| 
69992
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
305  | 
pair(decode_syntax,  | 
| 
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
306  | 
pair(list(string),  | 
| 
 
bd3c10813cc4
more informative Spec_Rules.Equational, notably primrec argument types;
 
wenzelm 
parents: 
69988 
diff
changeset
 | 
307  | 
pair(Term_XML.Decode.typ,  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
308  | 
pair(option(Term_XML.Decode.term), bool))))(body)  | 
| 68418 | 309  | 
}  | 
| 
71222
 
2bc39c80a95d
clarified export of consts: recursion is accessible via spec_rules;
 
wenzelm 
parents: 
71211 
diff
changeset
 | 
310  | 
Const(entity, syntax, typargs, typ, abbrev, propositional)  | 
| 68418 | 311  | 
})  | 
| 68208 | 312  | 
|
313  | 
||
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
314  | 
/* axioms */  | 
| 68232 | 315  | 
|
| 68726 | 316  | 
sealed case class Prop(  | 
317  | 
typargs: List[(String, Term.Sort)],  | 
|
318  | 
args: List[(String, Term.Typ)],  | 
|
319  | 
term: Term.Term)  | 
|
| 68232 | 320  | 
  {
 | 
| 68726 | 321  | 
def cache(cache: Term.Cache): Prop =  | 
322  | 
Prop(  | 
|
323  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
|
324  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
|
325  | 
cache.term(term))  | 
|
| 68232 | 326  | 
}  | 
| 68208 | 327  | 
|
| 68726 | 328  | 
def decode_prop(body: XML.Body): Prop =  | 
| 68267 | 329  | 
  {
 | 
| 68726 | 330  | 
val (typargs, args, t) =  | 
331  | 
    {
 | 
|
332  | 
import XML.Decode._  | 
|
333  | 
import Term_XML.Decode._  | 
|
334  | 
triple(list(pair(string, sort)), list(pair(string, typ)), term)(body)  | 
|
335  | 
}  | 
|
336  | 
Prop(typargs, args, t)  | 
|
| 68267 | 337  | 
}  | 
| 68208 | 338  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
339  | 
sealed case class Axiom(entity: Entity, prop: Prop)  | 
| 
70534
 
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
 
wenzelm 
parents: 
70384 
diff
changeset
 | 
340  | 
  {
 | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
341  | 
def cache(cache: Term.Cache): Axiom =  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
342  | 
Axiom(entity.cache(cache), 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
 | 
343  | 
}  | 
| 
 
fb876ebbf5a7
export facts with reconstructed proof term (if possible), but its PThm boxes need to be collected separately;
 
wenzelm 
parents: 
70384 
diff
changeset
 | 
344  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
345  | 
def read_axioms(provider: Export.Provider): List[Axiom] =  | 
| 68418 | 346  | 
provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) =>  | 
347  | 
      {
 | 
|
| 68714 | 348  | 
val (entity, body) = decode_entity(Kind.AXIOM, tree)  | 
| 68726 | 349  | 
val prop = decode_prop(body)  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
350  | 
Axiom(entity, prop)  | 
| 68418 | 351  | 
})  | 
| 68232 | 352  | 
|
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
353  | 
|
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
354  | 
/* theorems */  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
355  | 
|
| 70884 | 356  | 
sealed case class Thm_Id(serial: Long, theory_name: String)  | 
357  | 
  {
 | 
|
358  | 
def pure: Boolean = theory_name == Thy_Header.PURE  | 
|
359  | 
}  | 
|
360  | 
||
361  | 
sealed case class Thm(  | 
|
362  | 
entity: Entity,  | 
|
363  | 
prop: Prop,  | 
|
364  | 
deps: List[String],  | 
|
| 70896 | 365  | 
proof: Term.Proof)  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
366  | 
  {
 | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
367  | 
def cache(cache: Term.Cache): Thm =  | 
| 70884 | 368  | 
Thm(  | 
369  | 
entity.cache(cache),  | 
|
370  | 
prop.cache(cache),  | 
|
371  | 
deps.map(cache.string _),  | 
|
| 70896 | 372  | 
cache.proof(proof))  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
373  | 
}  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
374  | 
|
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
375  | 
def read_thms(provider: Export.Provider): List[Thm] =  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
376  | 
provider.uncompressed_yxml(export_prefix + "thms").map((tree: XML.Tree) =>  | 
| 68418 | 377  | 
      {
 | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
378  | 
val (entity, body) = decode_entity(Kind.THM, tree)  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
379  | 
val (prop, deps, prf) =  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
380  | 
        {
 | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
381  | 
import XML.Decode._  | 
| 
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
382  | 
import Term_XML.Decode._  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
383  | 
triple(decode_prop, list(string), proof)(body)  | 
| 
70579
 
5a8e3e4b3760
clarified export of axioms and theorems (identified derivations instead of projected facts);
 
wenzelm 
parents: 
70539 
diff
changeset
 | 
384  | 
}  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
385  | 
Thm(entity, prop, deps, prf)  | 
| 68418 | 386  | 
})  | 
| 68264 | 387  | 
|
| 70881 | 388  | 
sealed case class Proof(  | 
389  | 
typargs: List[(String, Term.Sort)],  | 
|
390  | 
args: List[(String, Term.Typ)],  | 
|
391  | 
term: Term.Term,  | 
|
392  | 
proof: Term.Proof)  | 
|
393  | 
  {
 | 
|
| 70883 | 394  | 
def prop: Prop = Prop(typargs, args, term)  | 
395  | 
||
| 70881 | 396  | 
def cache(cache: Term.Cache): Proof =  | 
397  | 
Proof(  | 
|
398  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
|
399  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
|
400  | 
cache.term(term),  | 
|
401  | 
cache.proof(proof))  | 
|
402  | 
}  | 
|
403  | 
||
| 
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
 | 
404  | 
def read_proof(  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
405  | 
provider: Export.Provider, id: Thm_Id, cache: Option[Term.Cache] = None): Option[Proof] =  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
406  | 
  {
 | 
| 
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
 | 
407  | 
    for { entry <- provider.focus(id.theory_name)(export_prefix_proofs + id.serial) }
 | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
408  | 
    yield {
 | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
409  | 
val body = entry.uncompressed_yxml()  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
410  | 
val (typargs, (args, (prop_body, proof_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
 | 
411  | 
      {
 | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
412  | 
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
 | 
413  | 
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
 | 
414  | 
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
 | 
415  | 
}  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
416  | 
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
 | 
417  | 
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
 | 
418  | 
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
 | 
419  | 
|
| 
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
 | 
420  | 
val result = Proof(typargs, args, prop, proof)  | 
| 
 
5f6dea6a7a4c
clarified signature: support partial read_proof to accommodate proof term normalization vs. approximative proof_boxes as upper bound;
 
wenzelm 
parents: 
70896 
diff
changeset
 | 
421  | 
cache.map(result.cache(_)) getOrElse result  | 
| 
70843
 
cc987440d776
more compact XML: separate environment for free variables;
 
wenzelm 
parents: 
70790 
diff
changeset
 | 
422  | 
}  | 
| 
70539
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
423  | 
}  | 
| 
 
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
 
wenzelm 
parents: 
70534 
diff
changeset
 | 
424  | 
|
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
425  | 
def read_proof_boxes(  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
426  | 
store: Sessions.Store,  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
427  | 
provider: Export.Provider,  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
428  | 
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
 | 
429  | 
suppress: Thm_Id => Boolean = _ => false,  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
430  | 
cache: Option[Term.Cache] = None): List[(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
 | 
431  | 
  {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
432  | 
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
 | 
433  | 
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
 | 
434  | 
|
| 71016 | 435  | 
def boxes(context: Option[(Long, Term.Proof)], prf: Term.Proof)  | 
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
436  | 
    {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
437  | 
      prf match {
 | 
| 71016 | 438  | 
case Term.Abst(_, _, p) => boxes(context, p)  | 
439  | 
case Term.AbsP(_, _, p) => boxes(context, p)  | 
|
440  | 
case Term.Appt(p, _) => boxes(context, p)  | 
|
441  | 
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
 | 
442  | 
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
 | 
443  | 
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
 | 
444  | 
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
 | 
445  | 
          if (!suppress(id)) {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
446  | 
val read =  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
447  | 
if (id.pure) Export_Theory.read_pure_proof(store, id, cache = cache)  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
448  | 
else Export_Theory.read_proof(provider, id, cache = cache)  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
449  | 
            read match {
 | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
450  | 
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
 | 
451  | 
result += (thm.serial -> (id -> p))  | 
| 71016 | 452  | 
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
 | 
453  | 
case None =>  | 
| 71016 | 454  | 
                error("Missing proof " + thm.serial + " (theory " + quote (thm.theory_name) + ")" +
 | 
455  | 
                  (context match {
 | 
|
456  | 
case None => ""  | 
|
457  | 
case Some((i, p)) => " in proof " + i + ":\n" + p  | 
|
458  | 
}))  | 
|
| 
71015
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
459  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
460  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
461  | 
case _ =>  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
462  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
463  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
464  | 
|
| 71016 | 465  | 
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
 | 
466  | 
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
 | 
467  | 
}  | 
| 
 
bb49abc2ecbb
determine proof boxes from exported proof (NB: thm_boxes is not sufficient due to OfClass proofs);
 
wenzelm 
parents: 
70920 
diff
changeset
 | 
468  | 
|
| 68264 | 469  | 
|
470  | 
/* type classes */  | 
|
471  | 
||
472  | 
sealed case class Class(  | 
|
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
473  | 
entity: Entity, params: List[(String, Term.Typ)], axioms: List[Prop])  | 
| 68267 | 474  | 
  {
 | 
475  | 
def cache(cache: Term.Cache): Class =  | 
|
476  | 
Class(entity.cache(cache),  | 
|
477  | 
        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
 | 
478  | 
axioms.map(_.cache(cache)))  | 
| 68267 | 479  | 
}  | 
| 68264 | 480  | 
|
| 68418 | 481  | 
def read_classes(provider: Export.Provider): List[Class] =  | 
482  | 
provider.uncompressed_yxml(export_prefix + "classes").map((tree: XML.Tree) =>  | 
|
483  | 
      {
 | 
|
| 68714 | 484  | 
val (entity, body) = decode_entity(Kind.CLASS, tree)  | 
| 68418 | 485  | 
val (params, axioms) =  | 
| 68264 | 486  | 
        {
 | 
| 68418 | 487  | 
import XML.Decode._  | 
488  | 
import Term_XML.Decode._  | 
|
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
489  | 
pair(list(pair(string, typ)), list(decode_prop))(body)  | 
| 68418 | 490  | 
}  | 
491  | 
Class(entity, params, axioms)  | 
|
492  | 
})  | 
|
| 68264 | 493  | 
|
494  | 
||
| 68862 | 495  | 
/* locales */  | 
496  | 
||
497  | 
sealed case class Locale(  | 
|
| 69019 | 498  | 
entity: Entity,  | 
499  | 
typargs: List[(String, Term.Sort)],  | 
|
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
500  | 
args: List[((String, Term.Typ), Syntax)],  | 
| 
69023
 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 
wenzelm 
parents: 
69019 
diff
changeset
 | 
501  | 
axioms: List[Prop])  | 
| 68862 | 502  | 
  {
 | 
503  | 
def cache(cache: Term.Cache): Locale =  | 
|
504  | 
Locale(entity.cache(cache),  | 
|
| 68864 | 505  | 
        typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
| 69076 | 506  | 
        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
 | 
507  | 
axioms.map(_.cache(cache)))  | 
| 68862 | 508  | 
}  | 
509  | 
||
510  | 
def read_locales(provider: Export.Provider): List[Locale] =  | 
|
511  | 
provider.uncompressed_yxml(export_prefix + "locales").map((tree: XML.Tree) =>  | 
|
512  | 
      {
 | 
|
513  | 
val (entity, body) = decode_entity(Kind.LOCALE, tree)  | 
|
| 69019 | 514  | 
val (typargs, args, axioms) =  | 
| 68862 | 515  | 
        {
 | 
516  | 
import XML.Decode._  | 
|
517  | 
import Term_XML.Decode._  | 
|
| 
69077
 
11529ae45786
more approximative prefix syntax, including binder;
 
wenzelm 
parents: 
69076 
diff
changeset
 | 
518  | 
triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)),  | 
| 69076 | 519  | 
list(decode_prop))(body)  | 
| 68862 | 520  | 
}  | 
| 69019 | 521  | 
Locale(entity, typargs, args, axioms)  | 
| 68862 | 522  | 
})  | 
523  | 
||
524  | 
||
| 
69069
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
525  | 
/* locale dependencies */  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
526  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
527  | 
sealed case class Locale_Dependency(  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
528  | 
entity: Entity,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
529  | 
source: String,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
530  | 
target: String,  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
531  | 
prefix: List[(String, Boolean)],  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
532  | 
subst_types: List[((String, Term.Sort), Term.Typ)],  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
533  | 
subst_terms: List[((String, Term.Typ), Term.Term)])  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
534  | 
  {
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
535  | 
def cache(cache: Term.Cache): Locale_Dependency =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
536  | 
Locale_Dependency(entity.cache(cache),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
537  | 
cache.string(source),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
538  | 
cache.string(target),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
539  | 
        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
 | 
540  | 
        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
 | 
541  | 
        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
 | 
542  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
543  | 
def is_inclusion: Boolean =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
544  | 
subst_types.isEmpty && subst_terms.isEmpty  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
545  | 
}  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
546  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
547  | 
def read_locale_dependencies(provider: Export.Provider): List[Locale_Dependency] =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
548  | 
provider.uncompressed_yxml(export_prefix + "locale_dependencies").map((tree: XML.Tree) =>  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
549  | 
      {
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
550  | 
val (entity, body) = decode_entity(Kind.LOCALE_DEPENDENCY, tree)  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
551  | 
val (source, (target, (prefix, (subst_types, subst_terms)))) =  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
552  | 
        {
 | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
553  | 
import XML.Decode._  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
554  | 
import Term_XML.Decode._  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
555  | 
pair(string, pair(string, pair(list(pair(string, bool)),  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
556  | 
pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body)  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
557  | 
}  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
558  | 
Locale_Dependency(entity, source, target, prefix, subst_types, subst_terms)  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
559  | 
})  | 
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
560  | 
|
| 
 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 
wenzelm 
parents: 
69023 
diff
changeset
 | 
561  | 
|
| 68295 | 562  | 
/* sort algebra */  | 
563  | 
||
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
564  | 
sealed case class Classrel(class1: String, class2: String, prop: Prop)  | 
| 68295 | 565  | 
  {
 | 
566  | 
def cache(cache: Term.Cache): Classrel =  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
567  | 
Classrel(cache.string(class1), cache.string(class2), prop.cache(cache))  | 
| 68295 | 568  | 
}  | 
569  | 
||
| 68418 | 570  | 
def read_classrel(provider: Export.Provider): List[Classrel] =  | 
571  | 
  {
 | 
|
572  | 
val body = provider.uncompressed_yxml(export_prefix + "classrel")  | 
|
573  | 
val classrel =  | 
|
574  | 
    {
 | 
|
575  | 
import XML.Decode._  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
576  | 
list(pair(decode_prop, pair(string, string)))(body)  | 
| 68418 | 577  | 
}  | 
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
578  | 
for ((prop, (c1, c2)) <- classrel) yield Classrel(c1, c2, prop)  | 
| 68418 | 579  | 
}  | 
| 68295 | 580  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
581  | 
sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String, prop: Prop)  | 
| 68295 | 582  | 
  {
 | 
583  | 
def cache(cache: Term.Cache): Arity =  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
584  | 
Arity(cache.string(type_name), domain.map(cache.sort(_)), cache.string(codomain),  | 
| 
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
585  | 
prop.cache(cache))  | 
| 68295 | 586  | 
}  | 
587  | 
||
| 68418 | 588  | 
def read_arities(provider: Export.Provider): List[Arity] =  | 
589  | 
  {
 | 
|
590  | 
val body = provider.uncompressed_yxml(export_prefix + "arities")  | 
|
591  | 
val arities =  | 
|
592  | 
    {
 | 
|
593  | 
import XML.Decode._  | 
|
594  | 
import Term_XML.Decode._  | 
|
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
595  | 
list(pair(decode_prop, triple(string, list(sort), string)))(body)  | 
| 68418 | 596  | 
}  | 
| 
70384
 
8ce08b154aa1
clarified export of sort algebra: avoid logical operations in Isabelle/Scala;
 
wenzelm 
parents: 
69996 
diff
changeset
 | 
597  | 
for ((prop, (a, b, c)) <- arities) yield Arity(a, b, c, prop)  | 
| 68418 | 598  | 
}  | 
| 68295 | 599  | 
|
600  | 
||
| 70920 | 601  | 
/* Pure constdefs */  | 
602  | 
||
603  | 
sealed case class Constdef(name: String, axiom_name: String)  | 
|
604  | 
  {
 | 
|
605  | 
def cache(cache: Term.Cache): Constdef =  | 
|
606  | 
Constdef(cache.string(name), cache.string(axiom_name))  | 
|
607  | 
}  | 
|
608  | 
||
609  | 
def read_constdefs(provider: Export.Provider): List[Constdef] =  | 
|
610  | 
  {
 | 
|
611  | 
val body = provider.uncompressed_yxml(export_prefix + "constdefs")  | 
|
612  | 
val constdefs =  | 
|
613  | 
    {
 | 
|
614  | 
import XML.Decode._  | 
|
615  | 
list(pair(string, string))(body)  | 
|
616  | 
}  | 
|
617  | 
for ((name, axiom_name) <- constdefs) yield Constdef(name, axiom_name)  | 
|
618  | 
}  | 
|
619  | 
||
620  | 
||
| 68264 | 621  | 
/* HOL typedefs */  | 
622  | 
||
623  | 
sealed case class Typedef(name: String,  | 
|
624  | 
rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String)  | 
|
| 68267 | 625  | 
  {
 | 
626  | 
def cache(cache: Term.Cache): Typedef =  | 
|
627  | 
Typedef(cache.string(name),  | 
|
628  | 
cache.typ(rep_type),  | 
|
629  | 
cache.typ(abs_type),  | 
|
630  | 
cache.string(rep_name),  | 
|
631  | 
cache.string(abs_name),  | 
|
632  | 
cache.string(axiom_name))  | 
|
633  | 
}  | 
|
| 68264 | 634  | 
|
| 68418 | 635  | 
def read_typedefs(provider: Export.Provider): List[Typedef] =  | 
636  | 
  {
 | 
|
637  | 
val body = provider.uncompressed_yxml(export_prefix + "typedefs")  | 
|
638  | 
val typedefs =  | 
|
639  | 
    {
 | 
|
640  | 
import XML.Decode._  | 
|
641  | 
import Term_XML.Decode._  | 
|
642  | 
list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body)  | 
|
643  | 
}  | 
|
644  | 
    for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs }
 | 
|
645  | 
yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name)  | 
|
646  | 
}  | 
|
| 71202 | 647  | 
|
648  | 
||
649  | 
/* Pure spec rules */  | 
|
650  | 
||
651  | 
sealed abstract class Recursion  | 
|
652  | 
  {
 | 
|
653  | 
def cache(cache: Term.Cache): Recursion =  | 
|
654  | 
      this match {
 | 
|
655  | 
case Primrec(types) => Primrec(types.map(cache.string))  | 
|
656  | 
case Primcorec(types) => Primcorec(types.map(cache.string))  | 
|
657  | 
case _ => this  | 
|
658  | 
}  | 
|
659  | 
}  | 
|
660  | 
case class Primrec(types: List[String]) extends Recursion  | 
|
661  | 
case object Recdef extends Recursion  | 
|
662  | 
case class Primcorec(types: List[String]) extends Recursion  | 
|
663  | 
case object Corec extends Recursion  | 
|
664  | 
case object Unknown_Recursion extends Recursion  | 
|
665  | 
||
666  | 
val decode_recursion: XML.Decode.T[Recursion] =  | 
|
667  | 
  {
 | 
|
668  | 
import XML.Decode._  | 
|
669  | 
variant(List(  | 
|
670  | 
      { case (Nil, a) => Primrec(list(string)(a)) },
 | 
|
671  | 
      { case (Nil, Nil) => Recdef },
 | 
|
672  | 
      { case (Nil, a) => Primcorec(list(string)(a)) },
 | 
|
673  | 
      { case (Nil, Nil) => Corec },
 | 
|
674  | 
      { case (Nil, Nil) => Unknown_Recursion }))
 | 
|
675  | 
}  | 
|
676  | 
||
677  | 
||
678  | 
sealed abstract class Rough_Classification  | 
|
679  | 
  {
 | 
|
680  | 
def is_equational: Boolean = this.isInstanceOf[Equational]  | 
|
681  | 
def is_inductive: Boolean = this == Inductive  | 
|
682  | 
def is_co_inductive: Boolean = this == Co_Inductive  | 
|
683  | 
def is_relational: Boolean = is_inductive || is_co_inductive  | 
|
684  | 
def is_unknown: Boolean = this == Unknown  | 
|
685  | 
||
686  | 
def cache(cache: Term.Cache): Rough_Classification =  | 
|
687  | 
      this match {
 | 
|
688  | 
case Equational(recursion) => Equational(recursion.cache(cache))  | 
|
689  | 
case _ => this  | 
|
690  | 
}  | 
|
691  | 
}  | 
|
692  | 
case class Equational(recursion: Recursion) extends Rough_Classification  | 
|
693  | 
case object Inductive extends Rough_Classification  | 
|
694  | 
case object Co_Inductive extends Rough_Classification  | 
|
695  | 
case object Unknown extends Rough_Classification  | 
|
696  | 
||
697  | 
val decode_rough_classification: XML.Decode.T[Rough_Classification] =  | 
|
698  | 
  {
 | 
|
699  | 
import XML.Decode._  | 
|
700  | 
variant(List(  | 
|
701  | 
      { case (Nil, a) => Equational(decode_recursion(a)) },
 | 
|
702  | 
      { case (Nil, Nil) => Inductive },
 | 
|
703  | 
      { case (Nil, Nil) => Co_Inductive },
 | 
|
704  | 
      { case (Nil, Nil) => Unknown }))
 | 
|
705  | 
}  | 
|
706  | 
||
707  | 
||
708  | 
sealed case class Spec_Rule(  | 
|
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
709  | 
pos: Position.T,  | 
| 71202 | 710  | 
name: String,  | 
711  | 
rough_classification: Rough_Classification,  | 
|
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
712  | 
typargs: List[(String, Term.Sort)],  | 
| 
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
713  | 
args: List[(String, Term.Typ)],  | 
| 71211 | 714  | 
terms: List[(Term.Term, Term.Typ)],  | 
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
715  | 
rules: List[Term.Term])  | 
| 71202 | 716  | 
  {
 | 
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
717  | 
def id: Option[Long] = Position.Id.unapply(pos)  | 
| 
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
718  | 
|
| 71202 | 719  | 
def cache(cache: Term.Cache): Spec_Rule =  | 
720  | 
Spec_Rule(  | 
|
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
721  | 
cache.position(pos),  | 
| 71202 | 722  | 
cache.string(name),  | 
723  | 
rough_classification.cache(cache),  | 
|
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
724  | 
        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
 | 
725  | 
        args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | 
| 71211 | 726  | 
        terms.map({ case (term, typ) => (cache.term(term), cache.typ(typ)) }),
 | 
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
727  | 
rules.map(cache.term(_)))  | 
| 71202 | 728  | 
}  | 
729  | 
||
730  | 
def read_spec_rules(provider: Export.Provider): List[Spec_Rule] =  | 
|
731  | 
  {
 | 
|
732  | 
val body = provider.uncompressed_yxml(export_prefix + "spec_rules")  | 
|
733  | 
val spec_rules =  | 
|
734  | 
    {
 | 
|
735  | 
import XML.Decode._  | 
|
736  | 
import Term_XML.Decode._  | 
|
| 
71207
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
737  | 
list(  | 
| 
 
8af82f3e03c9
formal position for spec rule (not significant for equality);
 
wenzelm 
parents: 
71202 
diff
changeset
 | 
738  | 
pair(properties, pair(string, pair(decode_rough_classification,  | 
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
739  | 
pair(list(pair(string, sort)), pair(list(pair(string, typ)),  | 
| 71211 | 740  | 
pair(list(pair(term, typ)), list(term))))))))(body)  | 
| 71202 | 741  | 
}  | 
| 
71208
 
5e0050eb64f2
clarified export of spec rules: more like locale;
 
wenzelm 
parents: 
71207 
diff
changeset
 | 
742  | 
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
 | 
743  | 
yield Spec_Rule(pos, name, rough_classification, typargs, args, terms, rules)  | 
| 71202 | 744  | 
}  | 
| 68171 | 745  | 
}  |