src/Pure/General/value.scala
author wenzelm
Sat, 15 Oct 2016 20:47:31 +0200
changeset 64229 12aa3980f65c
parent 63805 c272680df665
child 68944 ce68b1488612
permissions -rw-r--r--
more operations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63805
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/General/value.scala
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     3
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     4
Plain values, represented as string.
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     5
*/
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     6
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     8
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
     9
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    10
object Value
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    11
{
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    12
  object Boolean
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    13
  {
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    14
    def apply(x: scala.Boolean): java.lang.String = x.toString
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    15
    def unapply(s: java.lang.String): Option[scala.Boolean] =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    16
      s match {
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    17
        case "true" => Some(true)
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    18
        case "false" => Some(false)
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    19
        case _ => None
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    20
      }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    21
    def parse(s: java.lang.String): scala.Boolean =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    22
      unapply(s) getOrElse error("Bad boolean: " + quote(s))
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    23
  }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    24
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    25
  object Int
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    26
  {
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    27
    def apply(x: scala.Int): java.lang.String = Library.signed_string_of_int(x)
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    28
    def unapply(s: java.lang.String): Option[scala.Int] =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    29
      try { Some(Integer.parseInt(s)) }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    30
      catch { case _: NumberFormatException => None }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    31
    def parse(s: java.lang.String): scala.Int =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    32
      unapply(s) getOrElse error("Bad integer: " + quote(s))
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    33
  }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    34
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    35
  object Long
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    36
  {
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    37
    def apply(x: scala.Long): java.lang.String = Library.signed_string_of_long(x)
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    38
    def unapply(s: java.lang.String): Option[scala.Long] =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    39
      try { Some(java.lang.Long.parseLong(s)) }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    40
      catch { case _: NumberFormatException => None }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    41
    def parse(s: java.lang.String): scala.Long =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    42
      unapply(s) getOrElse error("Bad integer: " + quote(s))
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    43
  }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    44
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    45
  object Double
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    46
  {
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    47
    def apply(x: scala.Double): java.lang.String = x.toString
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    48
    def unapply(s: java.lang.String): Option[scala.Double] =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    49
      try { Some(java.lang.Double.parseDouble(s)) }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    50
      catch { case _: NumberFormatException => None }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    51
    def parse(s: java.lang.String): scala.Double =
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    52
      unapply(s) getOrElse error("Bad real: " + quote(s))
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    53
  }
c272680df665 clarified modules;
wenzelm
parents:
diff changeset
    54
}