author | wenzelm |
Sat, 31 Dec 2016 21:00:43 +0100 | |
changeset 64728 | 601866c61ded |
parent 64667 | cdb0d559a24b |
child 65402 | 37d3657e8513 |
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 |
|
55490 | 17 |
val none: T = Nil |
18 |
||
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
19 |
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
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
val Id = new Properties.Long(Markup.ID) |
59706
bf6ca55aae13
proper command id for inlined errors, which is important for Command.State.accumulate;
wenzelm
parents:
59671
diff
changeset
|
24 |
val Id_String = new Properties.String(Markup.ID) |
31705 | 25 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
26 |
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
|
27 |
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
|
28 |
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
|
29 |
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
|
30 |
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
|
31 |
|
48920 | 32 |
object Line_File |
33 |
{ |
|
56464 | 34 |
def apply(line: Int, file: String): T = |
35 |
(if (line > 0) Line(line) else Nil) ::: |
|
36 |
(if (file != "") File(file) else Nil) |
|
37 |
||
48920 | 38 |
def unapply(pos: T): Option[(Int, String)] = |
39 |
(pos, pos) match { |
|
40 |
case (Line(i), File(name)) => Some((i, name)) |
|
41 |
case (_, File(name)) => Some((1, name)) |
|
42 |
case _ => None |
|
43 |
} |
|
44 |
} |
|
45 |
||
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
46 |
object Def_Line_File |
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 |
def unapply(pos: T): Option[(Int, String)] = |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
49 |
(pos, pos) match { |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
50 |
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
|
51 |
case (_, Def_File(name)) => Some((1, name)) |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
52 |
case _ => None |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
53 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
54 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
55 |
|
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
56 |
object Range |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
57 |
{ |
57910 | 58 |
def apply(range: Symbol.Range): T = Offset(range.start) ::: End_Offset(range.stop) |
55884
f2c0eaedd579
tuned signature -- emphasize symbol positions (prover) vs. decoded text offsets (editor);
wenzelm
parents:
55555
diff
changeset
|
59 |
def unapply(pos: T): Option[Symbol.Range] = |
48920 | 60 |
(pos, pos) match { |
61 |
case (Offset(start), End_Offset(stop)) if start <= stop => Some(Text.Range(start, stop)) |
|
62 |
case (Offset(start), _) => Some(Text.Range(start, start + 1)) |
|
63 |
case _ => None |
|
64 |
} |
|
65 |
} |
|
66 |
||
64662 | 67 |
object Item_Id |
48920 | 68 |
{ |
64667 | 69 |
def unapply(pos: T): Option[(Long, Symbol.Range)] = |
57931 | 70 |
pos match { |
64667 | 71 |
case Id(id) => |
72 |
val offset = Offset.unapply(pos) getOrElse 0 |
|
73 |
val end_offset = End_Offset.unapply(pos) getOrElse (offset + 1) |
|
74 |
Some((id, Text.Range(offset, end_offset))) |
|
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
75 |
case _ => None |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
76 |
} |
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38568
diff
changeset
|
77 |
} |
38872 | 78 |
|
64662 | 79 |
object Item_Def_Id |
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
80 |
{ |
64667 | 81 |
def unapply(pos: T): Option[(Long, Symbol.Range)] = |
57931 | 82 |
pos match { |
64667 | 83 |
case Def_Id(id) => |
84 |
val offset = Def_Offset.unapply(pos) getOrElse 0 |
|
85 |
val end_offset = Def_End_Offset.unapply(pos) getOrElse (offset + 1) |
|
86 |
Some((id, Text.Range(offset, end_offset))) |
|
49419
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
87 |
case _ => None |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
88 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
89 |
} |
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
wenzelm
parents:
48992
diff
changeset
|
90 |
|
64662 | 91 |
object Item_File |
92 |
{ |
|
64667 | 93 |
def unapply(pos: T): Option[(String, Int, Symbol.Range)] = |
64662 | 94 |
pos match { |
95 |
case Line_File(line, name) => |
|
64667 | 96 |
val offset = Offset.unapply(pos) getOrElse 0 |
97 |
val end_offset = End_Offset.unapply(pos) getOrElse (offset + 1) |
|
98 |
Some((name, line, Text.Range(offset, end_offset))) |
|
64662 | 99 |
case _ => None |
100 |
} |
|
101 |
} |
|
102 |
||
103 |
object Item_Def_File |
|
104 |
{ |
|
64667 | 105 |
def unapply(pos: T): Option[(String, Int, Symbol.Range)] = |
64662 | 106 |
pos match { |
107 |
case Def_Line_File(line, name) => |
|
64667 | 108 |
val offset = Def_Offset.unapply(pos) getOrElse 0 |
109 |
val end_offset = Def_End_Offset.unapply(pos) getOrElse (offset + 1) |
|
110 |
Some((name, line, Text.Range(offset, end_offset))) |
|
64662 | 111 |
case _ => None |
112 |
} |
|
113 |
} |
|
114 |
||
57911
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
wenzelm
parents:
57910
diff
changeset
|
115 |
object Identified |
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
|
116 |
{ |
57911
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
wenzelm
parents:
57910
diff
changeset
|
117 |
def unapply(pos: T): Option[(Long, Symbol.Text_Chunk.Name)] = |
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
wenzelm
parents:
57910
diff
changeset
|
118 |
pos match { |
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
wenzelm
parents:
57910
diff
changeset
|
119 |
case Id(id) => |
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
55884
diff
changeset
|
120 |
val chunk_name = |
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
55884
diff
changeset
|
121 |
pos match { |
56746 | 122 |
case File(name) => Symbol.Text_Chunk.File(name) |
123 |
case _ => Symbol.Text_Chunk.Default |
|
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
55884
diff
changeset
|
124 |
} |
57911
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
wenzelm
parents:
57910
diff
changeset
|
125 |
Some((id, chunk_name)) |
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
|
126 |
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
|
127 |
} |
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
|
128 |
} |
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
|
129 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49419
diff
changeset
|
130 |
def purge(props: T): T = props.filterNot(p => Markup.POSITION_PROPERTIES(p._1)) |
48370 | 131 |
|
132 |
||
56532
3da244bc02bd
tuned message, to accommodate extra brackets produced by Scala parsers;
wenzelm
parents:
56473
diff
changeset
|
133 |
/* here: user output */ |
48992 | 134 |
|
64728 | 135 |
def here(props: T, delimited: Boolean = false): String = |
136 |
{ |
|
137 |
val pos = props.filter(p => Markup.POSITION_PROPERTIES(p._1)) |
|
138 |
if (pos.isEmpty) "" |
|
139 |
else { |
|
140 |
val s0 = |
|
141 |
(Line.unapply(pos), File.unapply(pos)) match { |
|
142 |
case (Some(i), None) => "line " + i.toString |
|
143 |
case (Some(i), Some(name)) => "line " + i.toString + " of " + quote(name) |
|
144 |
case (None, Some(name)) => "file " + quote(name) |
|
145 |
case _ => "" |
|
146 |
} |
|
147 |
val s = if (s0 == "") s0 else if (delimited) " (" + s0 + ")" else " " + s0 |
|
148 |
Markup(Markup.POSITION, pos).markup(s) |
|
149 |
} |
|
150 |
} |
|
27968 | 151 |
} |