src/Pure/General/long_name.scala
author wenzelm
Tue, 21 Jun 2022 14:51:17 +0200
changeset 75571 ac5e633ad9b3
parent 75393 87ebf5a50283
child 78961 11045cf2b5c2
permissions -rw-r--r--
tuned signature: more operations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56800
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/General/long_name.scala
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     3
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     4
Long names.
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     5
*/
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     6
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     7
package isabelle
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     8
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
     9
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 66923
diff changeset
    10
object Long_Name {
56800
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    11
  val separator = "."
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    12
  val separator_char = '.'
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    13
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    14
  def is_qualified(name: String): Boolean = name.contains(separator_char)
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    15
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    16
  def implode(names: List[String]): String = names.mkString(separator)
66923
wenzelm
parents: 65440
diff changeset
    17
  def explode(name: String): List[String] = space_explode(separator_char, name)
56800
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    18
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    19
  def qualify(qual: String, name: String): String =
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    20
    if (qual == "" || name == "") name
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    21
    else qual + separator + name
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    22
65440
fd147f56d9be more operations;
wenzelm
parents: 65358
diff changeset
    23
  def qualifier(name: String): String =
fd147f56d9be more operations;
wenzelm
parents: 65358
diff changeset
    24
    if (name == "") ""
fd147f56d9be more operations;
wenzelm
parents: 65358
diff changeset
    25
    else implode(explode(name).dropRight(1))
fd147f56d9be more operations;
wenzelm
parents: 65358
diff changeset
    26
56800
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    27
  def base_name(name: String): String =
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    28
    if (name == "") ""
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    29
    else explode(name).last
b904ea8edd73 support for long names in Scala;
wenzelm
parents:
diff changeset
    30
}