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