src/Pure/thm_name.scala
author nipkow
Fri, 11 Dec 2020 17:58:01 +0100
changeset 72884 50f18a822ee9
parent 70580 e6101f131d0d
child 75393 87ebf5a50283
permissions -rw-r--r--
merged

/*  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 flatten: String =
    if (name == "" || index == 0) name
    else name + "_" + index
}