src/Pure/General/markup.scala
changeset 38722 ba31936497c2
parent 38721 ca8b14fa0d0d
child 38724 d1feec02cf02
equal deleted inserted replaced
38721:ca8b14fa0d0d 38722:ba31936497c2
     7 package isabelle
     7 package isabelle
     8 
     8 
     9 
     9 
    10 object Markup
    10 object Markup
    11 {
    11 {
    12   /* integers */
    12   /* plain values */
    13 
    13 
    14   object Int {
    14   object Int {
    15     def apply(i: scala.Int): String = i.toString
    15     def apply(i: scala.Int): String = i.toString
    16     def unapply(s: String): Option[scala.Int] =
    16     def unapply(s: String): Option[scala.Int] =
    17       try { Some(Integer.parseInt(s)) }
    17       try { Some(Integer.parseInt(s)) }
    24       try { Some(java.lang.Long.parseLong(s)) }
    24       try { Some(java.lang.Long.parseLong(s)) }
    25       catch { case _: NumberFormatException => None }
    25       catch { case _: NumberFormatException => None }
    26   }
    26   }
    27 
    27 
    28 
    28 
    29   /* property values */
    29   /* named properties */
    30 
    30 
    31   def get_string(name: String, props: List[(String, String)]): Option[String] =
    31   class Property(val name: String)
    32     props.find(p => p._1 == name).map(_._2)
       
    33 
       
    34   def get_long(name: String, props: List[(String, String)]): Option[scala.Long] =
       
    35   {
    32   {
    36     get_string(name, props) match {
    33     def apply(value: String): List[(String, String)] = List((name, value))
    37       case None => None
    34     def unapply(props: List[(String, String)]): Option[String] =
    38       case Some(Long(i)) => Some(i)
    35       props.find(_._1 == name).map(_._2)
    39     }
    36   }
    40   }
    37 
    41 
    38   class Int_Property(name: String)
    42   def get_int(name: String, props: List[(String, String)]): Option[scala.Int] =
       
    43   {
    39   {
    44     get_string(name, props) match {
    40     def apply(value: scala.Int): List[(String, String)] = List((name, Int(value)))
    45       case None => None
    41     def unapply(props: List[(String, String)]): Option[Int] =
    46       case Some(Int(i)) => Some(i)
    42       props.find(_._1 == name) match {
    47     }
    43         case None => None
       
    44         case Some((_, value)) => Int.unapply(value)
       
    45       }
       
    46   }
       
    47 
       
    48   class Long_Property(name: String)
       
    49   {
       
    50     def apply(value: scala.Long): List[(String, String)] = List((name, Long(value)))
       
    51     def unapply(props: List[(String, String)]): Option[Long] =
       
    52       props.find(_._1 == name) match {
       
    53         case None => None
       
    54         case Some((_, value)) => Long.unapply(value)
       
    55       }
    48   }
    56   }
    49 
    57 
    50 
    58 
    51   /* empty */
    59   /* empty */
    52 
    60