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