author | blanchet |
Fri, 20 Dec 2013 20:36:38 +0100 | |
changeset 54838 | 16511f84913c |
parent 50201 | c26369c9eda6 |
child 55429 | 4a50f9e70dc1 |
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 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
17 |
val Line = new Properties.Int(Markup.LINE) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
18 |
val Offset = new Properties.Int(Markup.OFFSET) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
19 |
val End_Offset = new Properties.Int(Markup.END_OFFSET) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
20 |
val File = new Properties.String(Markup.FILE) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
21 |
val Id = new Properties.Long(Markup.ID) |
31705 | 22 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
23 |
val Def_Line = new Properties.Int(Markup.DEF_LINE) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
24 |
val Def_Offset = new Properties.Int(Markup.DEF_OFFSET) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
25 |
val Def_End_Offset = new Properties.Int(Markup.DEF_END_OFFSET) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
26 |
val Def_File = new Properties.String(Markup.DEF_FILE) |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
27 |
val Def_Id = new Properties.Long(Markup.DEF_ID) |
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
28 |
|
48920 | 29 |
object Line_File |
30 |
{ |
|
31 |
def unapply(pos: T): Option[(Int, String)] = |
|
32 |
(pos, pos) match { |
|
33 |
case (Line(i), File(name)) => Some((i, name)) |
|
34 |
case (_, File(name)) => Some((1, name)) |
|
35 |
case _ => None |
|
36 |
} |
|
37 |
} |
|
38 |
||
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
39 |
object Def_Line_File |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
40 |
{ |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
41 |
def unapply(pos: T): Option[(Int, String)] = |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
42 |
(pos, pos) match { |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
43 |
case (Def_Line(i), Def_File(name)) => Some((i, name)) |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
44 |
case (_, Def_File(name)) => Some((1, name)) |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
45 |
case _ => None |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
46 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
47 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
48 |
|
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
49 |
object Range |
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 |
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
|
52 |
def unapply(pos: T): Option[Text.Range] = |
48920 | 53 |
(pos, pos) match { |
54 |
case (Offset(start), End_Offset(stop)) if start <= stop => Some(Text.Range(start, stop)) |
|
55 |
case (Offset(start), _) => Some(Text.Range(start, start + 1)) |
|
56 |
case _ => None |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
object Id_Offset |
|
61 |
{ |
|
62 |
def unapply(pos: T): Option[(Long, Text.Offset)] = |
|
63 |
(pos, pos) match { |
|
64 |
case (Id(id), Offset(offset)) => Some((id, offset)) |
|
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
65 |
case _ => None |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
66 |
} |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
67 |
} |
38872 | 68 |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
69 |
object Def_Id_Offset |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
70 |
{ |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
71 |
def unapply(pos: T): Option[(Long, Text.Offset)] = |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
72 |
(pos, pos) match { |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
73 |
case (Def_Id(id), Def_Offset(offset)) => Some((id, offset)) |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
74 |
case _ => None |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
75 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
76 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
77 |
|
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
|
78 |
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
|
79 |
{ |
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
|
80 |
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
|
81 |
(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
|
82 |
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
|
83 |
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
|
84 |
} |
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
|
85 |
} |
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
|
86 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
87 |
def purge(props: T): T = props.filterNot(p => Markup.POSITION_PROPERTIES(p._1)) |
48370 | 88 |
|
89 |
||
48992 | 90 |
/* here: inlined formal markup */ |
91 |
||
92 |
def here(pos: T): String = |
|
48920 | 93 |
(Line.unapply(pos), File.unapply(pos)) match { |
48370 | 94 |
case (Some(i), None) => " (line " + i.toString + ")" |
95 |
case (Some(i), Some(name)) => " (line " + i.toString + " of " + quote(name) + ")" |
|
96 |
case (None, Some(name)) => " (file " + quote(name) + ")" |
|
97 |
case _ => "" |
|
98 |
} |
|
27968 | 99 |
} |