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 |
|
|
26 |
def parse(s: String): Thm_Name =
|
|
27 |
s match {
|
|
28 |
case Thm_Name_Regex(name, Value.Nat(index)) => Thm_Name(name, index)
|
|
29 |
case _ => Thm_Name(s, 0)
|
|
30 |
}
|
70576
|
31 |
}
|
|
32 |
|
75393
|
33 |
sealed case class Thm_Name(name: String, index: Int) {
|
70580
|
34 |
def print: String =
|
70576
|
35 |
if (name == "" || index == 0) name
|
|
36 |
else name + "(" + index + ")"
|
|
37 |
|
|
38 |
def flatten: String =
|
|
39 |
if (name == "" || index == 0) name
|
|
40 |
else name + "_" + index
|
|
41 |
}
|