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