author | ballarin |
Tue, 29 Sep 2009 22:15:54 +0200 | |
changeset 32804 | ca430e6aee1c |
parent 31705 | 0c83e3e75fcf |
child 32450 | 375db037f4d2 |
permissions | -rw-r--r-- |
27968 | 1 |
/* Title: Pure/General/position.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Position properties. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
import java.util.Properties |
|
10 |
||
11 |
||
12 |
object Position { |
|
13 |
||
31705 | 14 |
type T = List[(String, String)] |
27968 | 15 |
|
31705 | 16 |
private def get_string(name: String, pos: T): Option[String] = |
17 |
pos.find(p => p._1 == name).map(_._2) |
|
18 |
||
19 |
private def get_int(name: String, pos: T): Option[Int] = |
|
20 |
{ |
|
21 |
get_string(name, pos) match { |
|
27968 | 22 |
case None => None |
23 |
case Some(value) => |
|
24 |
try { Some(Integer.parseInt(value)) } |
|
27993
6dd90ef9f927
simplified exceptions: use plain error function / RuntimeException;
wenzelm
parents:
27989
diff
changeset
|
25 |
catch { case _: NumberFormatException => None } |
27968 | 26 |
} |
27 |
} |
|
28 |
||
31705 | 29 |
def line_of(pos: T) = get_int(Markup.LINE, pos) |
30 |
def column_of(pos: T) = get_int(Markup.COLUMN, pos) |
|
31 |
def offset_of(pos: T) = get_int(Markup.OFFSET, pos) |
|
32 |
def end_line_of(pos: T) = get_int(Markup.END_LINE, pos) |
|
33 |
def end_column_of(pos: T) = get_int(Markup.END_COLUMN, pos) |
|
34 |
def end_offset_of(pos: T) = get_int(Markup.END_OFFSET, pos) |
|
35 |
def file_of(pos: T) = get_string(Markup.FILE, pos) |
|
36 |
def id_of(pos: T) = get_string(Markup.ID, pos) |
|
37 |
||
38 |
def offsets_of(pos: T): (Option[Int], Option[Int]) = |
|
39 |
{ |
|
40 |
val begin = offset_of(pos) |
|
41 |
val end = end_offset_of(pos) |
|
42 |
(begin, if (end.isDefined) end else begin.map(_ + 1)) |
|
43 |
} |
|
44 |
||
27968 | 45 |
} |