src/Pure/thm_name.scala
author Fabian Huch <huch@in.tum.de>
Thu, 06 Jun 2024 08:58:58 +0200
changeset 80258 60013c49cedc
parent 79376 b275e3379024
child 80295 8a9588ffc133
permissions -rw-r--r--
more build manager page;

/*  Title:      Pure/thm_name.scala
    Author:     Makarius

Systematic naming of individual theorems, as selections from multi-facts.
*/

package isabelle


import scala.math.Ordering


object Thm_Name {
  object Ordering extends scala.math.Ordering[Thm_Name] {
    def compare(thm_name1: Thm_Name, thm_name2: Thm_Name): Int =
      thm_name1.name compare thm_name2.name match {
        case 0 => thm_name1.index compare thm_name2.index
        case ord => ord
      }
  }

  def graph[A]: Graph[Thm_Name, A] = Graph.empty(Ordering)

  private val Thm_Name_Regex = """^(.)+\((\d+)\)$""".r

  def parse(s: String): Thm_Name =
    s match {
      case Thm_Name_Regex(name, Value.Nat(index)) => Thm_Name(name, index)
      case _ => Thm_Name(s, 0)
    }
}

sealed case class Thm_Name(name: String, index: Int) {
  def print: String =
    if (name == "" || index == 0) name
    else name + "(" + index + ")"

  def short: String =
    if (name == "" || index == 0) name
    else name + "_" + index
}