| author | wenzelm | 
| Fri, 30 Nov 2018 14:21:28 +0100 | |
| changeset 69376 | 53194e2a969d | 
| parent 69077 | 11529ae45786 | 
| child 69988 | 6fa51a36b7f7 | 
| 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 | ||
| 10 | object Export_Theory | |
| 11 | {
 | |
| 68206 | 12 | /** session content **/ | 
| 13 | ||
| 14 | sealed case class Session(name: String, theory_graph: Graph[String, Theory]) | |
| 15 |   {
 | |
| 16 | override def toString: String = name | |
| 17 | ||
| 18 | def theory(theory_name: String): Theory = | |
| 19 | if (theory_graph.defined(theory_name)) theory_graph.get_node(theory_name) | |
| 20 |       else error("Bad theory " + quote(theory_name))
 | |
| 21 | ||
| 22 | def theories: List[Theory] = | |
| 23 | theory_graph.topological_order.map(theory_graph.get_node(_)) | |
| 24 | } | |
| 25 | ||
| 68209 | 26 | def read_session(store: Sessions.Store, | 
| 27 | session_name: String, | |
| 68206 | 28 | types: Boolean = true, | 
| 68264 | 29 | consts: Boolean = true, | 
| 30 | axioms: Boolean = true, | |
| 31 | facts: Boolean = true, | |
| 32 | classes: Boolean = true, | |
| 68862 | 33 | locales: Boolean = true, | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 34 | locale_dependencies: Boolean = true, | 
| 68295 | 35 | classrel: Boolean = true, | 
| 36 | arities: Boolean = true, | |
| 68862 | 37 | typedefs: Boolean = true, | 
| 68267 | 38 | cache: Term.Cache = Term.make_cache()): Session = | 
| 68206 | 39 |   {
 | 
| 40 | val thys = | |
| 68210 | 41 | using(store.open_database(session_name))(db => | 
| 68206 | 42 |       {
 | 
| 43 |         db.transaction {
 | |
| 68222 | 44 | Export.read_theory_names(db, session_name).map((theory_name: String) => | 
| 68418 | 45 | read_theory(Export.Provider.database(db, session_name, theory_name), | 
| 46 | session_name, theory_name, types = types, consts = consts, | |
| 68862 | 47 | axioms = axioms, facts = facts, classes = classes, locales = locales, | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 48 | locale_dependencies = locale_dependencies, classrel = classrel, arities = arities, | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 49 | typedefs = typedefs, cache = Some(cache))) | 
| 68206 | 50 | } | 
| 51 | }) | |
| 52 | ||
| 53 | val graph0 = | |
| 54 |       (Graph.string[Theory] /: thys) { case (g, thy) => g.new_node(thy.name, thy) }
 | |
| 55 | val graph1 = | |
| 56 |       (graph0 /: thys) { case (g0, thy) =>
 | |
| 57 |         (g0 /: thy.parents) { case (g1, parent) =>
 | |
| 58 | g1.default_node(parent, empty_theory(parent)).add_edge_acyclic(parent, thy.name) } } | |
| 59 | ||
| 60 | Session(session_name, graph1) | |
| 61 | } | |
| 62 | ||
| 63 | ||
| 64 | ||
| 68203 | 65 | /** theory content **/ | 
| 66 | ||
| 68346 | 67 | val export_prefix: String = "theory/" | 
| 68 | ||
| 68208 | 69 | sealed case class Theory(name: String, parents: List[String], | 
| 70 | types: List[Type], | |
| 71 | consts: List[Const], | |
| 68726 | 72 | axioms: List[Fact_Single], | 
| 73 | facts: List[Fact_Multi], | |
| 68264 | 74 | classes: List[Class], | 
| 68862 | 75 | locales: List[Locale], | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 76 | locale_dependencies: List[Locale_Dependency], | 
| 68295 | 77 | classrel: List[Classrel], | 
| 68862 | 78 | arities: List[Arity], | 
| 79 | typedefs: List[Typedef]) | |
| 68206 | 80 |   {
 | 
| 81 | override def toString: String = name | |
| 68267 | 82 | |
| 68711 | 83 | lazy val entities: Set[Long] = | 
| 84 | Set.empty[Long] ++ | |
| 85 | types.iterator.map(_.entity.serial) ++ | |
| 86 | consts.iterator.map(_.entity.serial) ++ | |
| 87 | axioms.iterator.map(_.entity.serial) ++ | |
| 88 | facts.iterator.map(_.entity.serial) ++ | |
| 68862 | 89 | classes.iterator.map(_.entity.serial) ++ | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 90 | locales.iterator.map(_.entity.serial) ++ | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 91 | locale_dependencies.iterator.map(_.entity.serial) | 
| 68711 | 92 | |
| 68267 | 93 | def cache(cache: Term.Cache): Theory = | 
| 94 | Theory(cache.string(name), | |
| 95 | parents.map(cache.string(_)), | |
| 96 | types.map(_.cache(cache)), | |
| 97 | consts.map(_.cache(cache)), | |
| 98 | axioms.map(_.cache(cache)), | |
| 99 | facts.map(_.cache(cache)), | |
| 100 | classes.map(_.cache(cache)), | |
| 68862 | 101 | locales.map(_.cache(cache)), | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 102 | locale_dependencies.map(_.cache(cache)), | 
| 68295 | 103 | classrel.map(_.cache(cache)), | 
| 68862 | 104 | arities.map(_.cache(cache)), | 
| 105 | typedefs.map(_.cache(cache))) | |
| 68206 | 106 | } | 
| 107 | ||
| 68295 | 108 | def empty_theory(name: String): Theory = | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 109 | Theory(name, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil, Nil) | 
| 68203 | 110 | |
| 68418 | 111 | def read_theory(provider: Export.Provider, session_name: String, theory_name: String, | 
| 68203 | 112 | types: Boolean = true, | 
| 68208 | 113 | consts: Boolean = true, | 
| 68232 | 114 | axioms: Boolean = true, | 
| 68264 | 115 | facts: Boolean = true, | 
| 116 | classes: Boolean = true, | |
| 68862 | 117 | locales: Boolean = true, | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 118 | locale_dependencies: Boolean = true, | 
| 68295 | 119 | classrel: Boolean = true, | 
| 120 | arities: Boolean = true, | |
| 68862 | 121 | typedefs: Boolean = true, | 
| 68267 | 122 | cache: Option[Term.Cache] = None): Theory = | 
| 68203 | 123 |   {
 | 
| 68206 | 124 | val parents = | 
| 68418 | 125 |       provider(export_prefix + "parents") match {
 | 
| 68231 | 126 | case Some(entry) => split_lines(entry.uncompressed().text) | 
| 68206 | 127 | case None => | 
| 128 |           error("Missing theory export in session " + quote(session_name) + ": " +
 | |
| 129 | quote(theory_name)) | |
| 130 | } | |
| 68267 | 131 | val theory = | 
| 132 | Theory(theory_name, parents, | |
| 68418 | 133 | if (types) read_types(provider) else Nil, | 
| 134 | if (consts) read_consts(provider) else Nil, | |
| 135 | if (axioms) read_axioms(provider) else Nil, | |
| 136 | if (facts) read_facts(provider) else Nil, | |
| 137 | if (classes) read_classes(provider) else Nil, | |
| 68862 | 138 | if (locales) read_locales(provider) else Nil, | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 139 | if (locale_dependencies) read_locale_dependencies(provider) else Nil, | 
| 68418 | 140 | if (classrel) read_classrel(provider) else Nil, | 
| 68862 | 141 | if (arities) read_arities(provider) else Nil, | 
| 142 | if (typedefs) read_typedefs(provider) else Nil) | |
| 68267 | 143 | if (cache.isDefined) theory.cache(cache.get) else theory | 
| 68203 | 144 | } | 
| 145 | ||
| 68711 | 146 | def read_pure_theory(store: Sessions.Store, cache: Option[Term.Cache] = None): Theory = | 
| 68710 | 147 |   {
 | 
| 148 | val session_name = Thy_Header.PURE | |
| 149 | val theory_name = Thy_Header.PURE | |
| 150 | ||
| 151 | using(store.open_database(session_name))(db => | |
| 152 |     {
 | |
| 153 |       db.transaction {
 | |
| 154 | read_theory(Export.Provider.database(db, session_name, theory_name), | |
| 68711 | 155 | session_name, theory_name, cache = cache) | 
| 68710 | 156 | } | 
| 157 | }) | |
| 158 | } | |
| 159 | ||
| 68203 | 160 | |
| 68171 | 161 | /* entities */ | 
| 162 | ||
| 68714 | 163 | object Kind extends Enumeration | 
| 68171 | 164 |   {
 | 
| 68714 | 165 |     val TYPE = Value("type")
 | 
| 166 |     val CONST = Value("const")
 | |
| 167 |     val AXIOM = Value("axiom")
 | |
| 168 |     val FACT = Value("fact")
 | |
| 169 |     val CLASS = Value("class")
 | |
| 68862 | 170 |     val LOCALE = Value("locale")
 | 
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 171 |     val LOCALE_DEPENDENCY = Value("locale_dependency")
 | 
| 68714 | 172 | } | 
| 173 | ||
| 68835 | 174 | sealed case class Entity( | 
| 68997 | 175 | kind: Kind.Value, name: String, xname: String, pos: Position.T, id: Option[Long], serial: Long) | 
| 68714 | 176 |   {
 | 
| 68718 | 177 | override def toString: String = kind.toString + " " + quote(name) | 
| 68267 | 178 | |
| 179 | def cache(cache: Term.Cache): Entity = | |
| 68997 | 180 | Entity(kind, cache.string(name), cache.string(xname), cache.position(pos), id, serial) | 
| 68171 | 181 | } | 
| 182 | ||
| 68714 | 183 | def decode_entity(kind: Kind.Value, tree: XML.Tree): (Entity, XML.Body) = | 
| 68171 | 184 |   {
 | 
| 185 | def err(): Nothing = throw new XML.XML_Body(List(tree)) | |
| 186 | ||
| 187 |     tree match {
 | |
| 188 | case XML.Elem(Markup(Markup.ENTITY, props), body) => | |
| 189 | val name = Markup.Name.unapply(props) getOrElse err() | |
| 68997 | 190 | val xname = Markup.XName.unapply(props) getOrElse err() | 
| 68830 
44ec6fdaacf8
retain original id, which is command_id/exec_id for PIDE;
 wenzelm parents: 
68726diff
changeset | 191 |         val pos = props.filter({ case (a, _) => Markup.POSITION_PROPERTIES(a) && a != Markup.ID })
 | 
| 68835 | 192 | val id = Position.Id.unapply(props) | 
| 68171 | 193 | val serial = Markup.Serial.unapply(props) getOrElse err() | 
| 68997 | 194 | (Entity(kind, name, xname, pos, id, serial), body) | 
| 68171 | 195 | case _ => err() | 
| 196 | } | |
| 197 | } | |
| 198 | ||
| 199 | ||
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 200 | /* approximative syntax */ | 
| 69003 | 201 | |
| 202 | object Assoc extends Enumeration | |
| 203 |   {
 | |
| 204 | val NO_ASSOC, LEFT_ASSOC, RIGHT_ASSOC = Value | |
| 205 | } | |
| 206 | ||
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 207 | sealed abstract class Syntax | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 208 | case object No_Syntax extends Syntax | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 209 | case class Prefix(delim: String) extends Syntax | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 210 | case class Infix(assoc: Assoc.Value, delim: String, pri: Int) extends Syntax | 
| 69003 | 211 | |
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 212 | def decode_syntax: XML.Decode.T[Syntax] = | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 213 | XML.Decode.variant(List( | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 214 |       { case (Nil, Nil) => No_Syntax },
 | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 215 |       { case (List(delim), Nil) => Prefix(delim) },
 | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 216 |       { case (Nil, body) =>
 | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 217 | import XML.Decode._ | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 218 | val (ass, delim, pri) = triple(int, string, int)(body) | 
| 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 219 | Infix(Assoc(ass), delim, pri) })) | 
| 69003 | 220 | |
| 221 | ||
| 68171 | 222 | /* types */ | 
| 223 | ||
| 69003 | 224 | sealed case class Type( | 
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 225 | entity: Entity, syntax: Syntax, args: List[String], abbrev: Option[Term.Typ]) | 
| 68267 | 226 |   {
 | 
| 227 | def cache(cache: Term.Cache): Type = | |
| 228 | Type(entity.cache(cache), | |
| 69003 | 229 | syntax, | 
| 68267 | 230 | args.map(cache.string(_)), | 
| 231 | abbrev.map(cache.typ(_))) | |
| 232 | } | |
| 68171 | 233 | |
| 68418 | 234 | def read_types(provider: Export.Provider): List[Type] = | 
| 235 | provider.uncompressed_yxml(export_prefix + "types").map((tree: XML.Tree) => | |
| 236 |       {
 | |
| 68714 | 237 | val (entity, body) = decode_entity(Kind.TYPE, tree) | 
| 69003 | 238 | val (syntax, args, abbrev) = | 
| 68203 | 239 |         {
 | 
| 68418 | 240 | import XML.Decode._ | 
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 241 | triple(decode_syntax, list(string), option(Term_XML.Decode.typ))(body) | 
| 68418 | 242 | } | 
| 69003 | 243 | Type(entity, syntax, args, abbrev) | 
| 68418 | 244 | }) | 
| 68171 | 245 | |
| 246 | ||
| 247 | /* consts */ | |
| 248 | ||
| 68173 | 249 | sealed case class Const( | 
| 69003 | 250 | entity: Entity, | 
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 251 | syntax: Syntax, | 
| 69003 | 252 | typargs: List[String], | 
| 253 | typ: Term.Typ, | |
| 254 | abbrev: Option[Term.Term]) | |
| 68267 | 255 |   {
 | 
| 256 | def cache(cache: Term.Cache): Const = | |
| 257 | Const(entity.cache(cache), | |
| 69003 | 258 | syntax, | 
| 68267 | 259 | typargs.map(cache.string(_)), | 
| 260 | cache.typ(typ), | |
| 261 | abbrev.map(cache.term(_))) | |
| 262 | } | |
| 68171 | 263 | |
| 68418 | 264 | def read_consts(provider: Export.Provider): List[Const] = | 
| 265 | provider.uncompressed_yxml(export_prefix + "consts").map((tree: XML.Tree) => | |
| 266 |       {
 | |
| 68714 | 267 | val (entity, body) = decode_entity(Kind.CONST, tree) | 
| 69003 | 268 | val (syntax, (args, (typ, abbrev))) = | 
| 68203 | 269 |         {
 | 
| 68418 | 270 | import XML.Decode._ | 
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 271 | pair(decode_syntax, pair(list(string), | 
| 69003 | 272 | pair(Term_XML.Decode.typ, option(Term_XML.Decode.term))))(body) | 
| 68418 | 273 | } | 
| 69003 | 274 | Const(entity, syntax, args, typ, abbrev) | 
| 68418 | 275 | }) | 
| 68208 | 276 | |
| 277 | ||
| 68726 | 278 | /* facts */ | 
| 68232 | 279 | |
| 68726 | 280 | sealed case class Prop( | 
| 281 | typargs: List[(String, Term.Sort)], | |
| 282 | args: List[(String, Term.Typ)], | |
| 283 | term: Term.Term) | |
| 68232 | 284 |   {
 | 
| 68726 | 285 | def cache(cache: Term.Cache): Prop = | 
| 286 | Prop( | |
| 287 |         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | |
| 288 |         args.map({ case (name, typ) => (cache.string(name), cache.typ(typ)) }),
 | |
| 289 | cache.term(term)) | |
| 68232 | 290 | } | 
| 68208 | 291 | |
| 68726 | 292 | def decode_prop(body: XML.Body): Prop = | 
| 68267 | 293 |   {
 | 
| 68726 | 294 | val (typargs, args, t) = | 
| 295 |     {
 | |
| 296 | import XML.Decode._ | |
| 297 | import Term_XML.Decode._ | |
| 298 | triple(list(pair(string, sort)), list(pair(string, typ)), term)(body) | |
| 299 | } | |
| 300 | Prop(typargs, args, t) | |
| 68267 | 301 | } | 
| 68208 | 302 | |
| 68726 | 303 | sealed case class Fact_Single(entity: Entity, prop: Prop) | 
| 304 |   {
 | |
| 305 | def cache(cache: Term.Cache): Fact_Single = | |
| 306 | Fact_Single(entity.cache(cache), prop.cache(cache)) | |
| 307 | } | |
| 308 | ||
| 309 | sealed case class Fact_Multi(entity: Entity, props: List[Prop]) | |
| 310 |   {
 | |
| 311 | def cache(cache: Term.Cache): Fact_Multi = | |
| 312 | Fact_Multi(entity.cache(cache), props.map(_.cache(cache))) | |
| 313 | ||
| 314 | def split: List[Fact_Single] = | |
| 315 |       props match {
 | |
| 316 | case List(prop) => List(Fact_Single(entity, prop)) | |
| 317 | case _ => | |
| 318 | for ((prop, i) <- props.zipWithIndex) | |
| 319 |           yield Fact_Single(entity.copy(name = entity.name + "(" + (i + 1) + ")"), prop)
 | |
| 320 | } | |
| 321 | } | |
| 322 | ||
| 323 | def read_axioms(provider: Export.Provider): List[Fact_Single] = | |
| 68418 | 324 | provider.uncompressed_yxml(export_prefix + "axioms").map((tree: XML.Tree) => | 
| 325 |       {
 | |
| 68714 | 326 | val (entity, body) = decode_entity(Kind.AXIOM, tree) | 
| 68726 | 327 | val prop = decode_prop(body) | 
| 328 | Fact_Single(entity, prop) | |
| 68418 | 329 | }) | 
| 68232 | 330 | |
| 68726 | 331 | def read_facts(provider: Export.Provider): List[Fact_Multi] = | 
| 68418 | 332 | provider.uncompressed_yxml(export_prefix + "facts").map((tree: XML.Tree) => | 
| 333 |       {
 | |
| 68714 | 334 | val (entity, body) = decode_entity(Kind.FACT, tree) | 
| 68726 | 335 | val props = XML.Decode.list(decode_prop)(body) | 
| 336 | Fact_Multi(entity, props) | |
| 68418 | 337 | }) | 
| 68264 | 338 | |
| 339 | ||
| 340 | /* type classes */ | |
| 341 | ||
| 342 | sealed case class Class( | |
| 69023 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 wenzelm parents: 
69019diff
changeset | 343 | entity: Entity, params: List[(String, Term.Typ)], axioms: List[Prop]) | 
| 68267 | 344 |   {
 | 
| 345 | def cache(cache: Term.Cache): Class = | |
| 346 | Class(entity.cache(cache), | |
| 347 |         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: 
69019diff
changeset | 348 | axioms.map(_.cache(cache))) | 
| 68267 | 349 | } | 
| 68264 | 350 | |
| 68418 | 351 | def read_classes(provider: Export.Provider): List[Class] = | 
| 352 | provider.uncompressed_yxml(export_prefix + "classes").map((tree: XML.Tree) => | |
| 353 |       {
 | |
| 68714 | 354 | val (entity, body) = decode_entity(Kind.CLASS, tree) | 
| 68418 | 355 | val (params, axioms) = | 
| 68264 | 356 |         {
 | 
| 68418 | 357 | import XML.Decode._ | 
| 358 | import Term_XML.Decode._ | |
| 69023 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 wenzelm parents: 
69019diff
changeset | 359 | pair(list(pair(string, typ)), list(decode_prop))(body) | 
| 68418 | 360 | } | 
| 361 | Class(entity, params, axioms) | |
| 362 | }) | |
| 68264 | 363 | |
| 364 | ||
| 68862 | 365 | /* locales */ | 
| 366 | ||
| 367 | sealed case class Locale( | |
| 69019 | 368 | entity: Entity, | 
| 369 | typargs: List[(String, Term.Sort)], | |
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 370 | args: List[((String, Term.Typ), Syntax)], | 
| 69023 
cef000855cf4
clarified standardization of variables, with proper treatment of local variables;
 wenzelm parents: 
69019diff
changeset | 371 | axioms: List[Prop]) | 
| 68862 | 372 |   {
 | 
| 373 | def cache(cache: Term.Cache): Locale = | |
| 374 | Locale(entity.cache(cache), | |
| 68864 | 375 |         typargs.map({ case (name, sort) => (cache.string(name), cache.sort(sort)) }),
 | 
| 69076 | 376 |         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: 
69019diff
changeset | 377 | axioms.map(_.cache(cache))) | 
| 68862 | 378 | } | 
| 379 | ||
| 380 | def read_locales(provider: Export.Provider): List[Locale] = | |
| 381 | provider.uncompressed_yxml(export_prefix + "locales").map((tree: XML.Tree) => | |
| 382 |       {
 | |
| 383 | val (entity, body) = decode_entity(Kind.LOCALE, tree) | |
| 69019 | 384 | val (typargs, args, axioms) = | 
| 68862 | 385 |         {
 | 
| 386 | import XML.Decode._ | |
| 387 | import Term_XML.Decode._ | |
| 69077 
11529ae45786
more approximative prefix syntax, including binder;
 wenzelm parents: 
69076diff
changeset | 388 | triple(list(pair(string, sort)), list(pair(pair(string, typ), decode_syntax)), | 
| 69076 | 389 | list(decode_prop))(body) | 
| 68862 | 390 | } | 
| 69019 | 391 | Locale(entity, typargs, args, axioms) | 
| 68862 | 392 | }) | 
| 393 | ||
| 394 | ||
| 69069 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 395 | /* locale dependencies */ | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 396 | |
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 397 | sealed case class Locale_Dependency( | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 398 | entity: Entity, | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 399 | source: String, | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 400 | target: String, | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 401 | prefix: List[(String, Boolean)], | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 402 | subst_types: List[((String, Term.Sort), Term.Typ)], | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 403 | subst_terms: List[((String, Term.Typ), Term.Term)]) | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 404 |   {
 | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 405 | def cache(cache: Term.Cache): Locale_Dependency = | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 406 | Locale_Dependency(entity.cache(cache), | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 407 | cache.string(source), | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 408 | cache.string(target), | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 409 |         prefix.map({ case (name, mandatory) => (cache.string(name), mandatory) }),
 | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 410 |         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: 
69023diff
changeset | 411 |         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: 
69023diff
changeset | 412 | |
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 413 | def is_inclusion: Boolean = | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 414 | subst_types.isEmpty && subst_terms.isEmpty | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 415 | } | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 416 | |
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 417 | def read_locale_dependencies(provider: Export.Provider): List[Locale_Dependency] = | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 418 | provider.uncompressed_yxml(export_prefix + "locale_dependencies").map((tree: XML.Tree) => | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 419 |       {
 | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 420 | val (entity, body) = decode_entity(Kind.LOCALE_DEPENDENCY, tree) | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 421 | val (source, (target, (prefix, (subst_types, subst_terms)))) = | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 422 |         {
 | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 423 | import XML.Decode._ | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 424 | import Term_XML.Decode._ | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 425 | pair(string, pair(string, pair(list(pair(string, bool)), | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 426 | pair(list(pair(pair(string, sort), typ)), list(pair(pair(string, typ), term))))))(body) | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 427 | } | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 428 | Locale_Dependency(entity, source, target, prefix, subst_types, subst_terms) | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 429 | }) | 
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 430 | |
| 
b9aca3b9619f
export locale dependencies, with approx. morphism as type/term substitution;
 wenzelm parents: 
69023diff
changeset | 431 | |
| 68295 | 432 | /* sort algebra */ | 
| 433 | ||
| 434 | sealed case class Classrel(class_name: String, super_names: List[String]) | |
| 435 |   {
 | |
| 436 | def cache(cache: Term.Cache): Classrel = | |
| 437 | Classrel(cache.string(class_name), super_names.map(cache.string(_))) | |
| 438 | } | |
| 439 | ||
| 68418 | 440 | def read_classrel(provider: Export.Provider): List[Classrel] = | 
| 441 |   {
 | |
| 442 | val body = provider.uncompressed_yxml(export_prefix + "classrel") | |
| 443 | val classrel = | |
| 444 |     {
 | |
| 445 | import XML.Decode._ | |
| 446 | list(pair(string, list(string)))(body) | |
| 447 | } | |
| 448 | for ((c, cs) <- classrel) yield Classrel(c, cs) | |
| 449 | } | |
| 68295 | 450 | |
| 451 | sealed case class Arity(type_name: String, domain: List[Term.Sort], codomain: String) | |
| 452 |   {
 | |
| 453 | def cache(cache: Term.Cache): Arity = | |
| 454 | Arity(cache.string(type_name), domain.map(cache.sort(_)), cache.string(codomain)) | |
| 455 | } | |
| 456 | ||
| 68418 | 457 | def read_arities(provider: Export.Provider): List[Arity] = | 
| 458 |   {
 | |
| 459 | val body = provider.uncompressed_yxml(export_prefix + "arities") | |
| 460 | val arities = | |
| 461 |     {
 | |
| 462 | import XML.Decode._ | |
| 463 | import Term_XML.Decode._ | |
| 464 | list(triple(string, list(sort), string))(body) | |
| 465 | } | |
| 466 | for ((a, b, c) <- arities) yield Arity(a, b, c) | |
| 467 | } | |
| 68295 | 468 | |
| 469 | ||
| 68264 | 470 | /* HOL typedefs */ | 
| 471 | ||
| 472 | sealed case class Typedef(name: String, | |
| 473 | rep_type: Term.Typ, abs_type: Term.Typ, rep_name: String, abs_name: String, axiom_name: String) | |
| 68267 | 474 |   {
 | 
| 475 | def cache(cache: Term.Cache): Typedef = | |
| 476 | Typedef(cache.string(name), | |
| 477 | cache.typ(rep_type), | |
| 478 | cache.typ(abs_type), | |
| 479 | cache.string(rep_name), | |
| 480 | cache.string(abs_name), | |
| 481 | cache.string(axiom_name)) | |
| 482 | } | |
| 68264 | 483 | |
| 68418 | 484 | def read_typedefs(provider: Export.Provider): List[Typedef] = | 
| 485 |   {
 | |
| 486 | val body = provider.uncompressed_yxml(export_prefix + "typedefs") | |
| 487 | val typedefs = | |
| 488 |     {
 | |
| 489 | import XML.Decode._ | |
| 490 | import Term_XML.Decode._ | |
| 491 | list(pair(string, pair(typ, pair(typ, pair(string, pair(string, string))))))(body) | |
| 492 | } | |
| 493 |     for { (name, (rep_type, (abs_type, (rep_name, (abs_name, axiom_name))))) <- typedefs }
 | |
| 494 | yield Typedef(name, rep_type, abs_type, rep_name, abs_name, axiom_name) | |
| 495 | } | |
| 68171 | 496 | } |