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