src/Pure/General/position.scala
author haftmann
Tue, 23 Sep 2008 18:11:44 +0200
changeset 28337 93964076e7b8
parent 27993 6dd90ef9f927
child 29140 e7ac5bb20aed
permissions -rw-r--r--
case default fallback for NBE

/*  Title:      Pure/General/position.scala
    ID:         $Id$
    Author:     Makarius

Position properties.
*/

package isabelle

import java.util.Properties


object Position {

  private def get_string(name: String, props: Properties) = {
    val value = if (props != null) props.getProperty(name) else null
    if (value != null) Some(value) else None
  }

  private def get_int(name: String, props: Properties) = {
    get_string(name, props) match {
      case None => None
      case Some(value) =>
        try { Some(Integer.parseInt(value)) }
        catch { case _: NumberFormatException => None }
    }
  }

  def line_of(props: Properties) = get_int(Markup.LINE, props)
  def column_of(props: Properties) = get_int(Markup.COLUMN, props)
  def offset_of(props: Properties) = get_int(Markup.OFFSET, props)
  def end_line_of(props: Properties) = get_int(Markup.END_LINE, props)
  def end_column_of(props: Properties) = get_int(Markup.END_COLUMN, props)
  def end_offset_of(props: Properties) = get_int(Markup.END_OFFSET, props)
  def file_of(props: Properties) = get_string(Markup.FILE, props)
  def id_of(props: Properties) = get_string(Markup.ID, props)
}