author | wenzelm |
Fri, 24 Aug 2012 16:43:37 +0200 | |
changeset 48920 | 9f84d872feba |
parent 48548 | 49afe0e92163 |
child 48992 | 0518bf89c777 |
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 |
||
48409 | 10 |
import java.io.{File => JFile} |
11 |
||
12 |
||
32450 | 13 |
object Position |
14 |
{ |
|
43780 | 15 |
type T = Properties.T |
27968 | 16 |
|
45666 | 17 |
val Line = new Properties.Int(Isabelle_Markup.LINE) |
18 |
val Offset = new Properties.Int(Isabelle_Markup.OFFSET) |
|
19 |
val End_Offset = new Properties.Int(Isabelle_Markup.END_OFFSET) |
|
20 |
val File = new Properties.String(Isabelle_Markup.FILE) |
|
21 |
val Id = new Properties.Long(Isabelle_Markup.ID) |
|
31705 | 22 |
|
48920 | 23 |
object Line_File |
24 |
{ |
|
25 |
def unapply(pos: T): Option[(Int, String)] = |
|
26 |
(pos, pos) match { |
|
27 |
case (Line(i), File(name)) => Some((i, name)) |
|
28 |
case (_, File(name)) => Some((1, name)) |
|
29 |
case _ => None |
|
30 |
} |
|
31 |
} |
|
32 |
||
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
33 |
object Range |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
34 |
{ |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
35 |
def apply(range: Text.Range): T = Offset(range.start) ++ Offset(range.stop) |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
36 |
def unapply(pos: T): Option[Text.Range] = |
48920 | 37 |
(pos, pos) match { |
38 |
case (Offset(start), End_Offset(stop)) if start <= stop => Some(Text.Range(start, stop)) |
|
39 |
case (Offset(start), _) => Some(Text.Range(start, start + 1)) |
|
40 |
case _ => None |
|
41 |
} |
|
42 |
} |
|
43 |
||
44 |
object Id_Offset |
|
45 |
{ |
|
46 |
def unapply(pos: T): Option[(Long, Text.Offset)] = |
|
47 |
(pos, pos) match { |
|
48 |
case (Id(id), Offset(offset)) => Some((id, offset)) |
|
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
49 |
case _ => None |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
50 |
} |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
51 |
} |
38872 | 52 |
|
38887
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
53 |
object Id_Range |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
54 |
{ |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
55 |
def unapply(pos: T): Option[(Long, Text.Range)] = |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
56 |
(pos, pos) match { |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
57 |
case (Id(id), Range(range)) => Some((id, range)) |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
58 |
case _ => None |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
59 |
} |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
60 |
} |
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38872
diff
changeset
|
61 |
|
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
41483
diff
changeset
|
62 |
private val purge_pos = Map( |
45666 | 63 |
Isabelle_Markup.DEF_LINE -> Isabelle_Markup.LINE, |
64 |
Isabelle_Markup.DEF_OFFSET -> Isabelle_Markup.OFFSET, |
|
65 |
Isabelle_Markup.DEF_END_OFFSET -> Isabelle_Markup.END_OFFSET, |
|
66 |
Isabelle_Markup.DEF_FILE -> Isabelle_Markup.FILE, |
|
67 |
Isabelle_Markup.DEF_ID -> Isabelle_Markup.ID) |
|
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
41483
diff
changeset
|
68 |
|
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
41483
diff
changeset
|
69 |
def purge(props: T): T = |
45666 | 70 |
for ((x, y) <- props if !Isabelle_Markup.POSITION_PROPERTIES(x)) |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
41483
diff
changeset
|
71 |
yield (if (purge_pos.isDefinedAt(x)) (purge_pos(x), y) else (x, y)) |
48370 | 72 |
|
73 |
||
48920 | 74 |
def str_of(pos: T): String = |
75 |
(Line.unapply(pos), File.unapply(pos)) match { |
|
48370 | 76 |
case (Some(i), None) => " (line " + i.toString + ")" |
77 |
case (Some(i), Some(name)) => " (line " + i.toString + " of " + quote(name) + ")" |
|
78 |
case (None, Some(name)) => " (file " + quote(name) + ")" |
|
79 |
case _ => "" |
|
80 |
} |
|
27968 | 81 |
} |