| author | wenzelm | 
| Tue, 29 Sep 2015 16:58:33 +0200 | |
| changeset 61280 | 12f9ab87a06d | 
| parent 59707 | 10effab11669 | 
| child 64662 | 5a2c15faf89c | 
| 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: 
49419diff
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: 
49419diff
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: 
49419diff
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: 
49419diff
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: 
49419diff
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: 
59671diff
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: 
49419diff
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: 
49419diff
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: 
49419diff
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: 
49419diff
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: 
49419diff
changeset | 30 | val Def_Id = new Properties.Long(Markup.DEF_ID) | 
| 49419 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
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: 
48992diff
changeset | 46 | object Def_Line_File | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 47 |   {
 | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 48 | def unapply(pos: T): Option[(Int, String)] = | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 49 |       (pos, pos) match {
 | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 50 | case (Def_Line(i), Def_File(name)) => Some((i, name)) | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 51 | case (_, Def_File(name)) => Some((1, name)) | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 52 | case _ => None | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 53 | } | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 54 | } | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 55 | |
| 38722 
ba31936497c2
organized markup properties via apply/unapply patterns;
 wenzelm parents: 
38568diff
changeset | 56 | object Range | 
| 
ba31936497c2
organized markup properties via apply/unapply patterns;
 wenzelm parents: 
38568diff
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: 
55555diff
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 | ||
| 57931 | 67 | object Id_Offset0 | 
| 48920 | 68 |   {
 | 
| 55884 
f2c0eaedd579
tuned signature -- emphasize symbol positions (prover) vs. decoded text offsets (editor);
 wenzelm parents: 
55555diff
changeset | 69 | def unapply(pos: T): Option[(Long, Symbol.Offset)] = | 
| 57931 | 70 |       pos match {
 | 
| 71 | case Id(id) => Some((id, Offset.unapply(pos) getOrElse 0)) | |
| 38722 
ba31936497c2
organized markup properties via apply/unapply patterns;
 wenzelm parents: 
38568diff
changeset | 72 | case _ => None | 
| 
ba31936497c2
organized markup properties via apply/unapply patterns;
 wenzelm parents: 
38568diff
changeset | 73 | } | 
| 
ba31936497c2
organized markup properties via apply/unapply patterns;
 wenzelm parents: 
38568diff
changeset | 74 | } | 
| 38872 | 75 | |
| 57931 | 76 | object Def_Id_Offset0 | 
| 49419 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 77 |   {
 | 
| 55884 
f2c0eaedd579
tuned signature -- emphasize symbol positions (prover) vs. decoded text offsets (editor);
 wenzelm parents: 
55555diff
changeset | 78 | def unapply(pos: T): Option[(Long, Symbol.Offset)] = | 
| 57931 | 79 |       pos match {
 | 
| 80 | case Def_Id(id) => Some((id, Def_Offset.unapply(pos) getOrElse 0)) | |
| 49419 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 81 | case _ => None | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 82 | } | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 83 | } | 
| 
e2726211f834
pass base_snapshot to enable hyperlinks into other nodes;
 wenzelm parents: 
48992diff
changeset | 84 | |
| 57911 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 85 | 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: 
38872diff
changeset | 86 |   {
 | 
| 57911 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 87 | 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: 
57910diff
changeset | 88 |       pos match {
 | 
| 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 89 | case Id(id) => | 
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
55884diff
changeset | 90 | val chunk_name = | 
| 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
55884diff
changeset | 91 |             pos match {
 | 
| 56746 | 92 | case File(name) => Symbol.Text_Chunk.File(name) | 
| 93 | case _ => Symbol.Text_Chunk.Default | |
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
55884diff
changeset | 94 | } | 
| 57911 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 95 | 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: 
38872diff
changeset | 96 | 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: 
38872diff
changeset | 97 | } | 
| 
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
 wenzelm parents: 
38872diff
changeset | 98 | } | 
| 
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
 wenzelm parents: 
38872diff
changeset | 99 | |
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
49419diff
changeset | 100 | def purge(props: T): T = props.filterNot(p => Markup.POSITION_PROPERTIES(p._1)) | 
| 48370 | 101 | |
| 102 | ||
| 56532 
3da244bc02bd
tuned message, to accommodate extra brackets produced by Scala parsers;
 wenzelm parents: 
56473diff
changeset | 103 | /* here: user output */ | 
| 48992 | 104 | |
| 105 | def here(pos: T): String = | |
| 59707 | 106 | Markup(Markup.POSITION, pos).markup( | 
| 59671 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 107 |       (Line.unapply(pos), File.unapply(pos)) match {
 | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 108 | case (Some(i), None) => " (line " + i.toString + ")" | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 109 | case (Some(i), Some(name)) => " (line " + i.toString + " of " + quote(name) + ")" | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 110 | case (None, Some(name)) => " (file " + quote(name) + ")" | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 111 | case _ => "" | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 112 | }) | 
| 56532 
3da244bc02bd
tuned message, to accommodate extra brackets produced by Scala parsers;
 wenzelm parents: 
56473diff
changeset | 113 | |
| 
3da244bc02bd
tuned message, to accommodate extra brackets produced by Scala parsers;
 wenzelm parents: 
56473diff
changeset | 114 | def here_undelimited(pos: T): String = | 
| 59707 | 115 | Markup(Markup.POSITION, pos).markup( | 
| 59671 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 116 |       (Line.unapply(pos), File.unapply(pos)) match {
 | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 117 | case (Some(i), None) => "line " + i.toString | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 118 | case (Some(i), Some(name)) => "line " + i.toString + " of " + quote(name) | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 119 | case (None, Some(name)) => "file " + quote(name) | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 120 | case _ => "" | 
| 
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
 wenzelm parents: 
57931diff
changeset | 121 | }) | 
| 27968 | 122 | } |