| author | Fabian Huch <huch@in.tum.de> | 
| Wed, 05 Feb 2025 15:28:17 +0100 | |
| changeset 82107 | 6c3b7d1f2115 | 
| parent 80312 | b48768f9567f | 
| child 82142 | 508a673c87ac | 
| permissions | -rw-r--r-- | 
| 70576 | 1 | /* Title: Pure/thm_name.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 4 | Systematic naming of individual theorems, as selections from multi-facts. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 9 | ||
| 10 | import scala.math.Ordering | |
| 11 | ||
| 12 | ||
| 75393 | 13 | object Thm_Name {
 | 
| 14 |   object Ordering extends scala.math.Ordering[Thm_Name] {
 | |
| 70576 | 15 | def compare(thm_name1: Thm_Name, thm_name2: Thm_Name): Int = | 
| 16 |       thm_name1.name compare thm_name2.name match {
 | |
| 17 | case 0 => thm_name1.index compare thm_name2.index | |
| 18 | case ord => ord | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | def graph[A]: Graph[Thm_Name, A] = Graph.empty(Ordering) | |
| 70580 | 23 | |
| 24 | private val Thm_Name_Regex = """^(.)+\((\d+)\)$""".r | |
| 25 | ||
| 80295 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 26 |   val empty: Thm_Name = Thm_Name("", 0)
 | 
| 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 27 | |
| 70580 | 28 | def parse(s: String): Thm_Name = | 
| 29 |     s match {
 | |
| 30 | case Thm_Name_Regex(name, Value.Nat(index)) => Thm_Name(name, index) | |
| 31 | case _ => Thm_Name(s, 0) | |
| 32 | } | |
| 80312 | 33 | |
| 34 | ||
| 35 | /* XML data representation */ | |
| 36 | ||
| 37 |   def encode: XML.Encode.T[Thm_Name] = { (thm_name: Thm_Name) =>
 | |
| 38 | import XML.Encode._ | |
| 39 | pair(string, int)((thm_name.name, thm_name.index)) | |
| 40 | } | |
| 41 | ||
| 42 |   def decode: XML.Decode.T[Thm_Name] = { (body: XML.Body) =>
 | |
| 43 | import XML.Decode._ | |
| 44 | val (name, index) = pair(string, int)(body) | |
| 45 | Thm_Name(name, index) | |
| 46 | } | |
| 70576 | 47 | } | 
| 48 | ||
| 75393 | 49 | sealed case class Thm_Name(name: String, index: Int) {
 | 
| 80295 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 50 | def is_empty: Boolean = name.isEmpty | 
| 
8a9588ffc133
more accurate Thm_Name.T for PThm / Thm.name_derivation / Thm.derivation_name;
 wenzelm parents: 
79376diff
changeset | 51 | |
| 70580 | 52 | def print: String = | 
| 70576 | 53 | if (name == "" || index == 0) name | 
| 54 |     else name + "(" + index + ")"
 | |
| 55 | ||
| 79376 | 56 | def short: String = | 
| 70576 | 57 | if (name == "" || index == 0) name | 
| 58 | else name + "_" + index | |
| 59 | } |