src/Pure/General/position.scala
author wenzelm
Mon, 07 Jun 2010 11:42:32 +0200
changeset 37352 c4f393759c59
parent 36683 41a1210519fd
child 38355 8cb265fb12fe
permissions -rw-r--r--
more NEWS;
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
    Author:     Makarius
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     3
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     4
Position properties.
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     5
*/
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     6
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     7
package isabelle
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     8
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
     9
32450
375db037f4d2 misc tuning;
wenzelm
parents: 31705
diff changeset
    10
object Position
375db037f4d2 misc tuning;
wenzelm
parents: 31705
diff changeset
    11
{
31705
0c83e3e75fcf replaced java Properties by pure property lists;
wenzelm
parents: 29140
diff changeset
    12
  type T = List[(String, String)]
27968
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    13
36683
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    14
  def get_line(pos: T): Option[Int] = Markup.get_int(Markup.LINE, pos)
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    15
  def get_column(pos: T): Option[Int] = Markup.get_int(Markup.COLUMN, pos)
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    16
  def get_offset(pos: T): Option[Int] = Markup.get_int(Markup.OFFSET, pos)
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    17
  def get_end_line(pos: T): Option[Int] = Markup.get_int(Markup.END_LINE, pos)
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    18
  def get_end_column(pos: T): Option[Int] = Markup.get_int(Markup.END_COLUMN, pos)
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    19
  def get_end_offset(pos: T): Option[Int] = Markup.get_int(Markup.END_OFFSET, pos)
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    20
  def get_file(pos: T): Option[String] = Markup.get_string(Markup.FILE, pos)
41a1210519fd basic support for symbolic pretty printing;
wenzelm
parents: 36677
diff changeset
    21
  def get_id(pos: T): Option[String] = Markup.get_string(Markup.ID, pos)
31705
0c83e3e75fcf replaced java Properties by pure property lists;
wenzelm
parents: 29140
diff changeset
    22
36677
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    23
  def get_range(pos: T): Option[(Int, Int)] =
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    24
    (get_offset(pos), get_end_offset(pos)) match {
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    25
      case (Some(begin), Some(end)) => Some(begin, end)
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    26
      case (Some(begin), None) => Some(begin, begin + 1)
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    27
      case (None, _) => None
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    28
    }
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    29
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    30
  object Id { def unapply(pos: T): Option[String] = get_id(pos) }
1225dd15827d simplified via Position extractors;
wenzelm
parents: 34211
diff changeset
    31
  object Range { def unapply(pos: T): Option[(Int, Int)] = get_range(pos) }
27968
85b5f024d94b Position properties.
wenzelm
parents:
diff changeset
    32
}