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