src/Pure/General/position.scala
author wenzelm
Sun, 24 Aug 2008 21:15:44 +0200
changeset 27989 a4fdc97cd2ff
parent 27968 85b5f024d94b
child 27993 6dd90ef9f927
permissions -rw-r--r--
get: allow null;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27968
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/General/position.scala
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     4
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     5
Position properties.
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     6
*/
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     7
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     8
package isabelle
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     9
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    10
import java.util.Properties
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    11
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    12
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    13
object Position {
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    14
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    15
  private def get_string(name: String, props: Properties) = {
27989
a4fdc97cd2ff get: allow null;
wenzelm
parents: 27968
diff changeset
    16
    val value = if (props != null) props.getProperty(name) else null
27968
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    17
    if (value != null) Some(value) else None
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    18
  }
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    19
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    20
  private def get_int(name: String, props: Properties) = {
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    21
    get_string(name, props) match {
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    22
      case None => None
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    23
      case Some(value) =>
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    24
        try { Some(Integer.parseInt(value)) }
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    25
        catch { case e: NumberFormatException => None }
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    26
    }
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    27
  }
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    28
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    29
  def line_of(props: Properties) = get_int(Markup.LINE, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    30
  def column_of(props: Properties) = get_int(Markup.COLUMN, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    31
  def offset_of(props: Properties) = get_int(Markup.OFFSET, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    32
  def end_line_of(props: Properties) = get_int(Markup.END_LINE, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    33
  def end_column_of(props: Properties) = get_int(Markup.END_COLUMN, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    34
  def end_offset_of(props: Properties) = get_int(Markup.END_OFFSET, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    35
  def file_of(props: Properties) = get_string(Markup.FILE, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    36
  def id_of(props: Properties) = get_string(Markup.ID, props)
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    37
}