| author | wenzelm | 
| Sun, 02 Sep 2018 23:55:25 +0200 | |
| changeset 68889 | d9c051e9da2b | 
| parent 68758 | a110e7e24e55 | 
| child 69634 | 70f1994988d4 | 
| permissions | -rw-r--r-- | 
| 36676 | 1 | /* Title: Pure/PIDE/command.scala | 
| 2 | Author: Fabian Immler, TU Munich | |
| 3 | Author: Makarius | |
| 4 | ||
| 52536 | 5 | Prover commands with accumulated results from execution. | 
| 36676 | 6 | */ | 
| 34407 | 7 | |
| 34871 
e596a0b71f3c
incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
 wenzelm parents: 
34865diff
changeset | 8 | package isabelle | 
| 34318 
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
 wenzelm parents: diff
changeset | 9 | |
| 34451 | 10 | |
| 45644 | 11 | import scala.collection.mutable | 
| 38872 | 12 | import scala.collection.immutable.SortedMap | 
| 13 | ||
| 14 | ||
| 34637 | 15 | object Command | 
| 16 | {
 | |
| 52849 | 17 | type Edit = (Option[Command], Option[Command]) | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 18 | |
| 56746 | 19 | type Blob = Exn.Result[(Document.Node.Name, Option[(SHA1.Digest, Symbol.Text_Chunk)])] | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 20 | type Blobs_Info = (List[Blob], Int) | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 21 | val no_blobs: Blobs_Info = (Nil, -1) | 
| 52849 | 22 | |
| 23 | ||
| 38361 | 24 | /** accumulated results from prover **/ | 
| 25 | ||
| 50507 | 26 | /* results */ | 
| 27 | ||
| 28 | object Results | |
| 29 |   {
 | |
| 51496 
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
 wenzelm parents: 
51494diff
changeset | 30 | type Entry = (Long, XML.Tree) | 
| 68101 | 31 | val empty: Results = new Results(SortedMap.empty) | 
| 59072 | 32 | def make(args: TraversableOnce[Results.Entry]): Results = (empty /: args)(_ + _) | 
| 33 | def merge(args: TraversableOnce[Results]): Results = (empty /: args)(_ ++ _) | |
| 65335 | 34 | |
| 35 | ||
| 36 | /* XML data representation */ | |
| 37 | ||
| 38 | val encode: XML.Encode.T[Results] = (results: Results) => | |
| 39 |     { import XML.Encode._; list(pair(long, tree))(results.rep.toList) }
 | |
| 40 | ||
| 41 | val decode: XML.Decode.T[Results] = (body: XML.Body) => | |
| 42 |     { import XML.Decode._; make(list(pair(long, tree))(body)) }
 | |
| 50507 | 43 | } | 
| 44 | ||
| 51494 | 45 | final class Results private(private val rep: SortedMap[Long, XML.Tree]) | 
| 50507 | 46 |   {
 | 
| 64802 | 47 | def is_empty: Boolean = rep.isEmpty | 
| 50507 | 48 | def defined(serial: Long): Boolean = rep.isDefinedAt(serial) | 
| 49 | def get(serial: Long): Option[XML.Tree] = rep.get(serial) | |
| 56372 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56359diff
changeset | 50 | def iterator: Iterator[Results.Entry] = rep.iterator | 
| 50508 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 wenzelm parents: 
50507diff
changeset | 51 | |
| 51496 
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
 wenzelm parents: 
51494diff
changeset | 52 | def + (entry: Results.Entry): Results = | 
| 50508 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 wenzelm parents: 
50507diff
changeset | 53 | if (defined(entry._1)) this | 
| 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 wenzelm parents: 
50507diff
changeset | 54 | else new Results(rep + entry) | 
| 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 wenzelm parents: 
50507diff
changeset | 55 | |
| 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 wenzelm parents: 
50507diff
changeset | 56 | def ++ (other: Results): Results = | 
| 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 wenzelm parents: 
50507diff
changeset | 57 | if (this eq other) this | 
| 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 wenzelm parents: 
50507diff
changeset | 58 | else if (rep.isEmpty) other | 
| 56372 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56359diff
changeset | 59 | else (this /: other.iterator)(_ + _) | 
| 50540 | 60 | |
| 51494 | 61 | override def hashCode: Int = rep.hashCode | 
| 62 | override def equals(that: Any): Boolean = | |
| 63 |       that match {
 | |
| 64 | case other: Results => rep == other.rep | |
| 65 | case _ => false | |
| 66 | } | |
| 56372 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 wenzelm parents: 
56359diff
changeset | 67 |     override def toString: String = iterator.mkString("Results(", ", ", ")")
 | 
| 50507 | 68 | } | 
| 69 | ||
| 70 | ||
| 68101 | 71 | /* exports */ | 
| 72 | ||
| 73 | object Exports | |
| 74 |   {
 | |
| 75 | type Entry = (Long, Export.Entry) | |
| 76 | val empty: Exports = new Exports(SortedMap.empty) | |
| 77 | def merge(args: TraversableOnce[Exports]): Exports = (empty /: args)(_ ++ _) | |
| 78 | } | |
| 79 | ||
| 80 | final class Exports private(private val rep: SortedMap[Long, Export.Entry]) | |
| 81 |   {
 | |
| 82 | def iterator: Iterator[Exports.Entry] = rep.iterator | |
| 83 | ||
| 84 | def + (entry: Exports.Entry): Exports = | |
| 85 | if (rep.isDefinedAt(entry._1)) this | |
| 86 | else new Exports(rep + entry) | |
| 87 | ||
| 88 | def ++ (other: Exports): Exports = | |
| 89 | if (this eq other) this | |
| 90 | else if (rep.isEmpty) other | |
| 91 | else (this /: other.iterator)(_ + _) | |
| 92 | ||
| 93 | override def hashCode: Int = rep.hashCode | |
| 94 | override def equals(that: Any): Boolean = | |
| 95 |       that match {
 | |
| 96 | case other: Exports => rep == other.rep | |
| 97 | case _ => false | |
| 98 | } | |
| 99 |     override def toString: String = iterator.mkString("Exports(", ", ", ")")
 | |
| 100 | } | |
| 101 | ||
| 102 | ||
| 103 | /* markups */ | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 104 | |
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 105 | object Markup_Index | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 106 |   {
 | 
| 56746 | 107 | val markup: Markup_Index = Markup_Index(false, Symbol.Text_Chunk.Default) | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 108 | } | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 109 | |
| 56746 | 110 | sealed case class Markup_Index(status: Boolean, chunk_name: Symbol.Text_Chunk.Name) | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 111 | |
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 112 | object Markups | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 113 |   {
 | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 114 | val empty: Markups = new Markups(Map.empty) | 
| 65335 | 115 | def init(markup: Markup_Tree): Markups = new Markups(Map(Markup_Index.markup -> markup)) | 
| 116 | def merge(args: TraversableOnce[Markups]): Markups = (empty /: args)(_ ++ _) | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 117 | |
| 65335 | 118 | |
| 119 | /* XML data representation */ | |
| 120 | ||
| 121 | def encode(source_length: Int): XML.Encode.T[Markups] = (markups: Markups) => | |
| 122 |     {
 | |
| 123 | import XML.Encode._ | |
| 124 | ||
| 125 | val markup_index: T[Markup_Index] = (index: Markup_Index) => | |
| 126 | pair(bool, Symbol.Text_Chunk.encode_name)(index.status, index.chunk_name) | |
| 127 | ||
| 128 | val markup_tree: T[Markup_Tree] = | |
| 129 | _.to_XML(Text.Range(0, source_length), Symbol.spaces(source_length), Markup.Elements.full) | |
| 130 | ||
| 131 | list(pair(markup_index, markup_tree))(markups.rep.toList) | |
| 132 | } | |
| 133 | ||
| 134 | val decode: XML.Decode.T[Markups] = (body: XML.Body) => | |
| 135 |     {
 | |
| 136 | import XML.Decode._ | |
| 137 | ||
| 138 | val markup_index: T[Markup_Index] = (body: XML.Body) => | |
| 139 |       {
 | |
| 140 | val (status, chunk_name) = pair(bool, Symbol.Text_Chunk.decode_name)(body) | |
| 141 | Markup_Index(status, chunk_name) | |
| 142 | } | |
| 143 | ||
| 144 | (Markups.empty /: list(pair(markup_index, Markup_Tree.from_XML(_)))(body))(_ + _) | |
| 145 | } | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 146 | } | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 147 | |
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 148 | final class Markups private(private val rep: Map[Markup_Index, Markup_Tree]) | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 149 |   {
 | 
| 56489 | 150 | def is_empty: Boolean = rep.isEmpty | 
| 151 | ||
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 152 | def apply(index: Markup_Index): Markup_Tree = | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 153 | rep.getOrElse(index, Markup_Tree.empty) | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 154 | |
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 155 | def add(index: Markup_Index, markup: Text.Markup): Markups = | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 156 | new Markups(rep + (index -> (this(index) + markup))) | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 157 | |
| 65335 | 158 | def + (entry: (Markup_Index, Markup_Tree)): Markups = | 
| 159 |     {
 | |
| 160 | val (index, tree) = entry | |
| 161 | new Markups(rep + (index -> (this(index).merge(tree, Text.Range.full, Markup.Elements.full)))) | |
| 162 | } | |
| 163 | ||
| 164 | def ++ (other: Markups): Markups = | |
| 165 | if (this eq other) this | |
| 166 | else if (rep.isEmpty) other | |
| 167 | else (this /: other.rep.iterator)(_ + _) | |
| 168 | ||
| 56475 | 169 | def redirection_iterator: Iterator[Document_ID.Generic] = | 
| 56746 | 170 | for (Markup_Index(_, Symbol.Text_Chunk.Id(id)) <- rep.keysIterator) | 
| 56475 | 171 | yield id | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 172 | |
| 56475 | 173 | def redirect(other_id: Document_ID.Generic): Markups = | 
| 56489 | 174 |     {
 | 
| 175 | val rep1 = | |
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 176 |         (for {
 | 
| 56746 | 177 | (Markup_Index(status, Symbol.Text_Chunk.Id(id)), markup) <- rep.iterator | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 178 | if other_id == id | 
| 56746 | 179 | } yield (Markup_Index(status, Symbol.Text_Chunk.Default), markup)).toMap | 
| 56489 | 180 | if (rep1.isEmpty) Markups.empty else new Markups(rep1) | 
| 181 | } | |
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 182 | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 183 | override def hashCode: Int = rep.hashCode | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 184 | override def equals(that: Any): Boolean = | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 185 |       that match {
 | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 186 | case other: Markups => rep == other.rep | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 187 | case _ => false | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 188 | } | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 189 |     override def toString: String = rep.iterator.mkString("Markups(", ", ", ")")
 | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 190 | } | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 191 | |
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 192 | |
| 50507 | 193 | /* state */ | 
| 50501 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 wenzelm parents: 
50500diff
changeset | 194 | |
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56295diff
changeset | 195 | object State | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56295diff
changeset | 196 |   {
 | 
| 67824 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 197 | def get_result(states: List[State], serial: Long): Option[XML.Tree] = | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 198 | states.find(st => st.results.defined(serial)).map(st => st.results.get(serial).get) | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 199 | |
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 200 | def get_result_proper(states: List[State], props: Properties.T): Option[Results.Entry] = | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 201 |       for {
 | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 202 | serial <- Markup.Serial.unapply(props) | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 203 | tree @ XML.Elem(_, body) <- get_result(states, serial) | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 204 | if body.nonEmpty | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 205 | } yield (serial -> tree) | 
| 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 206 | |
| 65335 | 207 | def merge_results(states: List[State]): Results = | 
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56295diff
changeset | 208 | Results.merge(states.map(_.results)) | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56295diff
changeset | 209 | |
| 68101 | 210 | def merge_exports(states: List[State]): Exports = | 
| 211 | Exports.merge(states.map(_.exports)) | |
| 212 | ||
| 65335 | 213 | def merge_markups(states: List[State]): Markups = | 
| 214 | Markups.merge(states.map(_.markups)) | |
| 215 | ||
| 56301 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 wenzelm parents: 
56299diff
changeset | 216 | def merge_markup(states: List[State], index: Markup_Index, | 
| 56743 | 217 | range: Text.Range, elements: Markup.Elements): Markup_Tree = | 
| 56301 
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
 wenzelm parents: 
56299diff
changeset | 218 | Markup_Tree.merge(states.map(_.markup(index)), range, elements) | 
| 65335 | 219 | |
| 220 | def merge(command: Command, states: List[State]): State = | |
| 68101 | 221 | State(command, states.flatMap(_.status), merge_results(states), | 
| 222 | merge_exports(states), merge_markups(states)) | |
| 65335 | 223 | |
| 224 | ||
| 225 | /* XML data representation */ | |
| 226 | ||
| 227 | val encode: XML.Encode.T[State] = (st: State) => | |
| 228 |     {
 | |
| 229 | import XML.Encode._ | |
| 230 | ||
| 231 | val command = st.command | |
| 232 | val blobs_names = command.blobs_names.map(_.node) | |
| 233 | val blobs_index = command.blobs_index | |
| 234 | require(command.blobs_ok) | |
| 235 | ||
| 236 | pair(long, pair(string, pair(pair(list(string), int), pair(Command_Span.encode, | |
| 237 | pair(list(Markup.encode), pair(Results.encode, Markups.encode(command.source.length)))))))( | |
| 238 | (command.id, (command.node_name.node, ((blobs_names, blobs_index), (command.span, | |
| 239 | (st.status, (st.results, st.markups))))))) | |
| 240 | } | |
| 241 | ||
| 242 | def decode(node_name: String => Document.Node.Name): XML.Decode.T[State] = (body: XML.Body) => | |
| 243 |     {
 | |
| 244 | import XML.Decode._ | |
| 245 | val (id, (node, ((blobs_names, blobs_index), (span, (status, (results, markups)))))) = | |
| 246 | pair(long, pair(string, pair(pair(list(string), int), pair(Command_Span.decode, | |
| 247 | pair(list(Markup.decode), pair(Results.decode, Markups.decode))))))(body) | |
| 248 | ||
| 249 | val blobs_info: Blobs_Info = | |
| 250 | (blobs_names.map(name => Exn.Res((node_name(name), None)): Blob), blobs_index) | |
| 251 | val command = Command(id, node_name(node), blobs_info, span) | |
| 68101 | 252 | State(command, status, results, Exports.empty, markups) | 
| 65335 | 253 | } | 
| 56299 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56295diff
changeset | 254 | } | 
| 
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
 wenzelm parents: 
56295diff
changeset | 255 | |
| 43714 | 256 | sealed case class State( | 
| 50501 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 wenzelm parents: 
50500diff
changeset | 257 | command: Command, | 
| 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 wenzelm parents: 
50500diff
changeset | 258 | status: List[Markup] = Nil, | 
| 50507 | 259 | results: Results = Results.empty, | 
| 68101 | 260 | exports: Exports = Exports.empty, | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 261 | markups: Markups = Markups.empty) | 
| 38361 | 262 |   {
 | 
| 68323 | 263 | def initialized: Boolean = status.exists(markup => markup.name == Markup.INITIALIZED) | 
| 68335 | 264 | def consolidated: Boolean = status.exists(markup => markup.name == Markup.CONSOLIDATED) | 
| 66379 
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
 wenzelm parents: 
65522diff
changeset | 265 | |
| 68758 | 266 | lazy val maybe_consolidated: Boolean = | 
| 267 |     {
 | |
| 268 | var touched = false | |
| 269 | var forks = 0 | |
| 270 | var runs = 0 | |
| 271 |       for (markup <- status) {
 | |
| 272 |         markup.name match {
 | |
| 273 | case Markup.FORKED => touched = true; forks += 1 | |
| 274 | case Markup.JOINED => forks -= 1 | |
| 275 | case Markup.RUNNING => touched = true; runs += 1 | |
| 276 | case Markup.FINISHED => runs -= 1 | |
| 277 | case _ => | |
| 278 | } | |
| 279 | } | |
| 280 | touched && forks == 0 && runs == 0 | |
| 281 | } | |
| 68381 
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
 wenzelm parents: 
68335diff
changeset | 282 | |
| 68758 | 283 | lazy val document_status: Document_Status.Command_Status = | 
| 56395 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 284 |     {
 | 
| 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 285 | val warnings = | 
| 59203 
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
 wenzelm parents: 
59072diff
changeset | 286 | if (results.iterator.exists(p => Protocol.is_warning(p._2) || Protocol.is_legacy(p._2))) | 
| 56395 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 287 | List(Markup(Markup.WARNING, Nil)) | 
| 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 288 | else Nil | 
| 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 289 | val errors = | 
| 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 290 | if (results.iterator.exists(p => Protocol.is_error(p._2))) | 
| 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 291 | List(Markup(Markup.ERROR, Nil)) | 
| 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 292 | else Nil | 
| 68758 | 293 | Document_Status.Command_Status.make((warnings ::: errors ::: status).iterator) | 
| 56395 
0546e036d1c0
more direct warning within persistent Protocol.Status;
 wenzelm parents: 
56372diff
changeset | 294 | } | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 295 | |
| 55650 | 296 | def markup(index: Markup_Index): Markup_Tree = markups(index) | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 297 | |
| 56489 | 298 | def redirect(other_command: Command): Option[State] = | 
| 299 |     {
 | |
| 300 | val markups1 = markups.redirect(other_command.id) | |
| 301 | if (markups1.is_empty) None | |
| 68101 | 302 | else Some(new State(other_command, markups = markups1)) | 
| 56489 | 303 | } | 
| 49614 | 304 | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 305 | private def add_status(st: Markup): State = | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 306 | copy(status = st :: status) | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 307 | |
| 67826 | 308 | private def add_result(entry: Results.Entry): State = | 
| 309 | copy(results = results + entry) | |
| 310 | ||
| 68114 | 311 | def add_export(entry: Exports.Entry): Option[State] = | 
| 312 | if (command.node_name.theory == entry._2.theory_name) Some(copy(exports = exports + entry)) | |
| 313 | else None | |
| 68101 | 314 | |
| 56746 | 315 | private def add_markup( | 
| 316 | status: Boolean, chunk_name: Symbol.Text_Chunk.Name, m: Text.Markup): State = | |
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 317 |     {
 | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 318 | val markups1 = | 
| 68758 | 319 | if (status || Document_Status.Command_Status.liberal_elements(m.info.name)) | 
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
56395diff
changeset | 320 | markups.add(Markup_Index(true, chunk_name), m) | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 321 | else markups | 
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
56395diff
changeset | 322 | copy(markups = markups1.add(Markup_Index(false, chunk_name), m)) | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 323 | } | 
| 38361 | 324 | |
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 325 | def accumulate( | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 326 | self_id: Document_ID.Generic => Boolean, | 
| 56746 | 327 | other_id: Document_ID.Generic => Option[(Symbol.Text_Chunk.Id, Symbol.Text_Chunk)], | 
| 67825 | 328 | message: XML.Elem, | 
| 329 | xml_cache: XML.Cache): State = | |
| 38361 | 330 |       message match {
 | 
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
50163diff
changeset | 331 | case XML.Elem(Markup(Markup.STATUS, _), msgs) => | 
| 38714 | 332 | (this /: msgs)((state, msg) => | 
| 333 |             msg match {
 | |
| 46152 
793cecd4ffc0
accumulate status as regular markup for command range;
 wenzelm parents: 
45709diff
changeset | 334 | case elem @ XML.Elem(markup, Nil) => | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 335 | state. | 
| 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 336 | add_status(markup). | 
| 68728 | 337 | add_markup(true, Symbol.Text_Chunk.Default, Text.Info(command.core_range, elem)) | 
| 52536 | 338 | case _ => | 
| 56782 
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
 wenzelm parents: 
56746diff
changeset | 339 |                 Output.warning("Ignored status message: " + msg)
 | 
| 52536 | 340 | state | 
| 38714 | 341 | }) | 
| 38581 
d503a0912e14
simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
 wenzelm parents: 
38579diff
changeset | 342 | |
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
50163diff
changeset | 343 | case XML.Elem(Markup(Markup.REPORT, _), msgs) => | 
| 38572 
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
 wenzelm parents: 
38564diff
changeset | 344 | (this /: msgs)((state, msg) => | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 345 |             {
 | 
| 56782 
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
 wenzelm parents: 
56746diff
changeset | 346 |               def bad(): Unit = Output.warning("Ignored report message: " + msg)
 | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 347 | |
| 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 348 |               msg match {
 | 
| 57911 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 349 | case XML.Elem(Markup(name, atts @ Position.Identified(id, chunk_name)), args) => | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 350 | |
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 351 | val target = | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 352 | if (self_id(id) && command.chunks.isDefinedAt(chunk_name)) | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 353 | Some((chunk_name, command.chunks(chunk_name))) | 
| 56746 | 354 | else if (chunk_name == Symbol.Text_Chunk.Default) other_id(id) | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 355 | else None | 
| 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 356 | |
| 57911 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 357 |                   (target, atts) match {
 | 
| 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 358 | case (Some((target_name, target_chunk)), Position.Range(symbol_range)) => | 
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 359 |                       target_chunk.incorporate(symbol_range) match {
 | 
| 55548 
a645277885cf
more uniform/robust restriction of reported positions, e.g. relevant for "bad" markup due to unclosed comment in ML file;
 wenzelm parents: 
55434diff
changeset | 360 | case Some(range) => | 
| 55822 
ccf2d784be97
incorporate chunk range that is 1 off end-of-input, for improved error positions (NB: command spans are tight, without trailing whitespace);
 wenzelm parents: 
55785diff
changeset | 361 | val props = Position.purge(atts) | 
| 67825 | 362 | val elem = xml_cache.elem(XML.Elem(Markup(name, props), args)) | 
| 363 | state.add_markup(false, target_name, Text.Info(range, elem)) | |
| 55548 
a645277885cf
more uniform/robust restriction of reported positions, e.g. relevant for "bad" markup due to unclosed comment in ML file;
 wenzelm parents: 
55434diff
changeset | 364 | case None => bad(); state | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 365 | } | 
| 57911 
dcb758188aa6
clarified Position.Identified: do not require range from prover, default to command position;
 wenzelm parents: 
57910diff
changeset | 366 | case _ => | 
| 56514 
db929027e701
ignore other_id reports for now (see 8eda56033203): massive amounts of redirections to 'class' etc. makes it difficult to edit main HOL;
 wenzelm parents: 
56489diff
changeset | 367 | // silently ignore excessive reports | 
| 56476 | 368 | state | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 369 | } | 
| 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 370 | |
| 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 371 | case XML.Elem(Markup(name, atts), args) | 
| 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 372 |                 if !atts.exists({ case (a, _) => Markup.POSITION_PROPERTIES(a) }) =>
 | 
| 68728 | 373 | val range = command.core_range | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 374 | val props = Position.purge(atts) | 
| 67825 | 375 | val elem = xml_cache.elem(XML.Elem(Markup(name, props), args)) | 
| 376 | state.add_markup(false, Symbol.Text_Chunk.Default, Text.Info(range, elem)) | |
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 377 | |
| 56470 
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
 wenzelm parents: 
56469diff
changeset | 378 | case _ => bad(); state | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 379 | } | 
| 38361 | 380 | }) | 
| 52930 
5fab62ae3532
retain original messages properties, e.g. for retrieval via Command.Results;
 wenzelm parents: 
52849diff
changeset | 381 | case XML.Elem(Markup(name, props), body) => | 
| 
5fab62ae3532
retain original messages properties, e.g. for retrieval via Command.Results;
 wenzelm parents: 
52849diff
changeset | 382 |           props match {
 | 
| 50201 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 wenzelm parents: 
50163diff
changeset | 383 | case Markup.Serial(i) => | 
| 67825 | 384 | val markup_message = | 
| 385 | xml_cache.elem(XML.Elem(Markup(Markup.message(name), props), body)) | |
| 386 | val message_markup = | |
| 387 | xml_cache.elem(XML.elem(Markup(name, props.filter(p => p._1 == Markup.SERIAL)))) | |
| 50163 
c62ce309dc26
more abstract Sendback operations, with explicit id/exec_id properties;
 wenzelm parents: 
50158diff
changeset | 388 | |
| 67826 | 389 | var st = add_result(i -> markup_message) | 
| 55433 
d2960d67f163
clarified message_positions: cover alt_id as well;
 wenzelm parents: 
55432diff
changeset | 390 |               if (Protocol.is_inlined(message)) {
 | 
| 
d2960d67f163
clarified message_positions: cover alt_id as well;
 wenzelm parents: 
55432diff
changeset | 391 |                 for {
 | 
| 56469 | 392 | (chunk_name, chunk) <- command.chunks.iterator | 
| 59713 | 393 | range <- Protocol_Message.positions( | 
| 59735 | 394 | self_id, command.span.position, chunk_name, chunk, message) | 
| 67824 
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for  XML data representation);
 wenzelm parents: 
67446diff
changeset | 395 | } st = st.add_markup(false, chunk_name, Text.Info(range, message_markup)) | 
| 55433 
d2960d67f163
clarified message_positions: cover alt_id as well;
 wenzelm parents: 
55432diff
changeset | 396 | } | 
| 
d2960d67f163
clarified message_positions: cover alt_id as well;
 wenzelm parents: 
55432diff
changeset | 397 | st | 
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 398 | |
| 52536 | 399 | case _ => | 
| 56782 
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
 wenzelm parents: 
56746diff
changeset | 400 |               Output.warning("Ignored message without serial number: " + message)
 | 
| 52536 | 401 | this | 
| 38872 | 402 | } | 
| 68101 | 403 | } | 
| 38361 | 404 | } | 
| 38367 | 405 | |
| 406 | ||
| 55431 
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
 wenzelm parents: 
55430diff
changeset | 407 | |
| 
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
 wenzelm parents: 
55430diff
changeset | 408 | /** static content **/ | 
| 
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
 wenzelm parents: 
55430diff
changeset | 409 | |
| 45644 | 410 | /* make commands */ | 
| 411 | ||
| 55648 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 412 | def apply( | 
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 413 | id: Document_ID.Command, | 
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 414 | node_name: Document.Node.Name, | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 415 | blobs_info: Blobs_Info, | 
| 57905 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 wenzelm parents: 
57904diff
changeset | 416 | span: Command_Span.Span): Command = | 
| 55648 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 417 |   {
 | 
| 57901 
e1abca2527da
more explicit type Span in Scala, according to ML version;
 wenzelm parents: 
57842diff
changeset | 418 | val (source, span1) = span.compact_source | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 419 | new Command(id, node_name, blobs_info, span1, source, Results.empty, Markup_Tree.empty) | 
| 55648 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 420 | } | 
| 49414 | 421 | |
| 57901 
e1abca2527da
more explicit type Span in Scala, according to ML version;
 wenzelm parents: 
57842diff
changeset | 422 | val empty: Command = | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 423 | Command(Document_ID.none, Document.Node.Name.empty, no_blobs, Command_Span.empty) | 
| 55648 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 424 | |
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 425 | def unparsed( | 
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 426 | id: Document_ID.Command, | 
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 427 | source: String, | 
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 428 | results: Results, | 
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 429 | markup: Markup_Tree): Command = | 
| 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 430 |   {
 | 
| 57905 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 wenzelm parents: 
57904diff
changeset | 431 | val (source1, span1) = Command_Span.unparsed(source).compact_source | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 432 | new Command(id, Document.Node.Name.empty, no_blobs, span1, source1, results, markup) | 
| 55648 
38f264741609
tuned signature -- avoid obscure default arguments;
 wenzelm parents: 
55622diff
changeset | 433 | } | 
| 49414 | 434 | |
| 65341 | 435 | def text(source: String): Command = | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 436 | unparsed(Document_ID.none, source, Results.empty, Markup_Tree.empty) | 
| 44384 | 437 | |
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 438 | def rich_text(id: Document_ID.Command, results: Results, body: XML.Body): Command = | 
| 49414 | 439 |   {
 | 
| 49466 | 440 | val text = XML.content(body) | 
| 441 | val markup = Markup_Tree.from_XML(body) | |
| 50501 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 wenzelm parents: 
50500diff
changeset | 442 | unparsed(id, text, results, markup) | 
| 49414 | 443 | } | 
| 49359 
c1262d7389fb
refined output panel: more value-oriented approach to update and caret focus;
 wenzelm parents: 
49037diff
changeset | 444 | |
| 44384 | 445 | |
| 446 | /* perspective */ | |
| 447 | ||
| 44474 | 448 | object Perspective | 
| 449 |   {
 | |
| 450 | val empty: Perspective = Perspective(Nil) | |
| 451 | } | |
| 44385 
e7fdb008aa7d
propagate editor perspective through document model;
 wenzelm parents: 
44384diff
changeset | 452 | |
| 44474 | 453 | sealed case class Perspective(commands: List[Command]) // visible commands in canonical order | 
| 44385 
e7fdb008aa7d
propagate editor perspective through document model;
 wenzelm parents: 
44384diff
changeset | 454 |   {
 | 
| 57615 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 wenzelm parents: 
56782diff
changeset | 455 | def is_empty: Boolean = commands.isEmpty | 
| 
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
 wenzelm parents: 
56782diff
changeset | 456 | |
| 44474 | 457 | def same(that: Perspective): Boolean = | 
| 458 |     {
 | |
| 459 | val cmds1 = this.commands | |
| 460 | val cmds2 = that.commands | |
| 48754 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 wenzelm parents: 
48745diff
changeset | 461 | require(!cmds1.exists(_.is_undefined)) | 
| 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 wenzelm parents: 
48745diff
changeset | 462 | require(!cmds2.exists(_.is_undefined)) | 
| 44474 | 463 | cmds1.length == cmds2.length && | 
| 464 |         (cmds1.iterator zip cmds2.iterator).forall({ case (c1, c2) => c1.id == c2.id })
 | |
| 465 | } | |
| 44385 
e7fdb008aa7d
propagate editor perspective through document model;
 wenzelm parents: 
44384diff
changeset | 466 | } | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 467 | |
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 468 | |
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 469 | /* blobs: inlined errors and auxiliary files */ | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 470 | |
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 471 | private def clean_tokens(tokens: List[Token]): List[(Token, Int)] = | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 472 |   {
 | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 473 | def clean(toks: List[(Token, Int)]): List[(Token, Int)] = | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 474 |       toks match {
 | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 475 | case (t1, i1) :: (t2, i2) :: rest => | 
| 67446 | 476 | if (t1.is_keyword && t1.source == "%" && t2.is_name) clean(rest) | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 477 | else (t1, i1) :: clean((t2, i2) :: rest) | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 478 | case _ => toks | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 479 | } | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 480 |     clean(tokens.zipWithIndex.filter({ case (t, _) => t.is_proper }))
 | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 481 | } | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 482 | |
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 483 | private def find_file(tokens: List[(Token, Int)]): Option[(String, Int)] = | 
| 59924 
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
 wenzelm parents: 
59735diff
changeset | 484 |     if (tokens.exists({ case (t, _) => t.is_command })) {
 | 
| 
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
 wenzelm parents: 
59735diff
changeset | 485 |       tokens.dropWhile({ case (t, _) => !t.is_command }).
 | 
| 64471 
c40c2975fb02
more uniform path syntax, as in ML (see 5a7c919a4ada);
 wenzelm parents: 
63584diff
changeset | 486 |         collectFirst({ case (t, i) if t.is_embedded => (t.content, i) })
 | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 487 | } | 
| 59924 
801b979ec0c2
more general notion of command span: command keyword not necessarily at start;
 wenzelm parents: 
59735diff
changeset | 488 | else None | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 489 | |
| 63584 
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
 wenzelm parents: 
62969diff
changeset | 490 | def span_files(syntax: Outer_Syntax, span: Command_Span.Span): (List[String], Int) = | 
| 59735 | 491 |     syntax.load_command(span.name) match {
 | 
| 492 | case Some(exts) => | |
| 493 |         find_file(clean_tokens(span.content)) match {
 | |
| 494 | case Some((file, i)) => | |
| 495 | if (exts.isEmpty) (List(file), i) | |
| 496 | else (exts.map(ext => file + "." + ext), i) | |
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 497 | case None => (Nil, -1) | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 498 | } | 
| 59735 | 499 | case None => (Nil, -1) | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 500 | } | 
| 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 501 | |
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 502 | def blobs_info( | 
| 59699 | 503 | resources: Resources, | 
| 63584 
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
 wenzelm parents: 
62969diff
changeset | 504 | syntax: Outer_Syntax, | 
| 59699 | 505 | get_blob: Document.Node.Name => Option[Document.Blob], | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 506 | can_import: Document.Node.Name => Boolean, | 
| 59699 | 507 | node_name: Document.Node.Name, | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 508 | span: Command_Span.Span): Blobs_Info = | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 509 |   {
 | 
| 59735 | 510 |     span.name match {
 | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 511 | // inlined errors | 
| 59735 | 512 | case Thy_Header.THEORY => | 
| 64825 | 513 | val reader = Scan.char_reader(Token.implode(span.content)) | 
| 66768 | 514 | val imports = resources.check_thy_reader(node_name, reader).imports | 
| 515 | val raw_imports = | |
| 516 |           try {
 | |
| 517 | val imports1 = Thy_Header.read(reader, Token.Pos.none).imports | |
| 518 |             if (imports.length == imports1.length) imports1.map(_._1) else error("")
 | |
| 519 | } | |
| 520 |           catch { case exn: Throwable => List.fill(imports.length)("") }
 | |
| 521 | ||
| 59715 
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
 wenzelm parents: 
59713diff
changeset | 522 | val errors = | 
| 66768 | 523 |           for { ((import_name, pos), s) <- imports zip raw_imports if !can_import(import_name) }
 | 
| 524 |           yield {
 | |
| 525 | val completion = | |
| 526 |               if (Thy_Header.is_base_name(s)) {
 | |
| 527 | val completed = Completion.completed(import_name.theory_base_name) | |
| 66966 | 528 | val qualifier = resources.session_base.theory_qualifier(node_name) | 
| 66768 | 529 | val dir = node_name.master_dir | 
| 530 |                 for {
 | |
| 68306 
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
 wenzelm parents: 
68114diff
changeset | 531 | known_name <- resources.session_base.known.theory_names | 
| 66768 | 532 | if completed(known_name.theory_base_name) | 
| 66966 | 533 | } | 
| 534 |                 yield {
 | |
| 535 | resources.standard_import( | |
| 536 | resources.session_base, qualifier, dir, known_name.theory) | |
| 537 | } | |
| 66768 | 538 | }.sorted | 
| 539 | else Nil | |
| 59715 
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
 wenzelm parents: 
59713diff
changeset | 540 | val msg = | 
| 
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
 wenzelm parents: 
59713diff
changeset | 541 | "Bad theory import " + | 
| 66768 | 542 | Markup.Path(import_name.node).markup(quote(import_name.toString)) + | 
| 543 | Position.here(pos) + Completion.report_theories(pos, completion) | |
| 59715 
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
 wenzelm parents: 
59713diff
changeset | 544 | Exn.Exn(ERROR(msg)): Command.Blob | 
| 59708 
aed304412e43
more markup, which helps to create missing imports;
 wenzelm parents: 
59706diff
changeset | 545 | } | 
| 59715 
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
 wenzelm parents: 
59713diff
changeset | 546 | (errors, -1) | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 547 | |
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 548 | // auxiliary files | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 549 | case _ => | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 550 | val (files, index) = span_files(syntax, span) | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 551 | val blobs = | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 552 | files.map(file => | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 553 |             (Exn.capture {
 | 
| 65488 | 554 | val name = Document.Node.Name(resources.append(node_name, Path.explode(file))) | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 555 | val blob = get_blob(name).map(blob => ((blob.bytes.sha1_digest, blob.chunk))) | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 556 | (name, blob) | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 557 | }).user_error) | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 558 | (blobs, index) | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 559 | } | 
| 59689 
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
 wenzelm parents: 
59684diff
changeset | 560 | } | 
| 34318 
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
 wenzelm parents: diff
changeset | 561 | } | 
| 
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
 wenzelm parents: diff
changeset | 562 | |
| 38361 | 563 | |
| 46712 | 564 | final class Command private( | 
| 52530 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 wenzelm parents: 
52527diff
changeset | 565 | val id: Document_ID.Command, | 
| 44615 | 566 | val node_name: Document.Node.Name, | 
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 567 | val blobs_info: Command.Blobs_Info, | 
| 57905 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 wenzelm parents: 
57904diff
changeset | 568 | val span: Command_Span.Span, | 
| 49414 | 569 | val source: String, | 
| 50501 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 wenzelm parents: 
50500diff
changeset | 570 | val init_results: Command.Results, | 
| 49414 | 571 | val init_markup: Markup_Tree) | 
| 34451 | 572 | {
 | 
| 57912 | 573 | override def toString: String = id + "/" + span.kind.toString | 
| 34495 | 574 | |
| 57910 | 575 | |
| 576 | /* classification */ | |
| 577 | ||
| 57905 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 wenzelm parents: 
57904diff
changeset | 578 | def is_proper: Boolean = span.kind.isInstanceOf[Command_Span.Command_Span] | 
| 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 wenzelm parents: 
57904diff
changeset | 579 | def is_ignored: Boolean = span.kind == Command_Span.Ignored_Span | 
| 57904 | 580 | |
| 581 | def is_undefined: Boolean = id == Document_ID.none | |
| 582 | val is_unparsed: Boolean = span.content.exists(_.is_unparsed) | |
| 583 | val is_unfinished: Boolean = span.content.exists(_.is_unfinished) | |
| 584 | ||
| 68323 | 585 | def potentially_initialized: Boolean = span.name == Thy_Header.THEORY | 
| 586 | ||
| 34859 | 587 | |
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54517diff
changeset | 588 | /* blobs */ | 
| 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54517diff
changeset | 589 | |
| 59702 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 590 | def blobs: List[Command.Blob] = blobs_info._1 | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 591 | def blobs_index: Int = blobs_info._2 | 
| 
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
 wenzelm parents: 
59699diff
changeset | 592 | |
| 65335 | 593 | def blobs_ok: Boolean = | 
| 594 |     blobs.forall({ case Exn.Res(_) => true case _ => false })
 | |
| 595 | ||
| 54530 
2c1440f70028
ranges of thy_load commands count as visible within perspective;
 wenzelm parents: 
54524diff
changeset | 596 | def blobs_names: List[Document.Node.Name] = | 
| 
2c1440f70028
ranges of thy_load commands count as visible within perspective;
 wenzelm parents: 
54524diff
changeset | 597 | for (Exn.Res((name, _)) <- blobs) yield name | 
| 
2c1440f70028
ranges of thy_load commands count as visible within perspective;
 wenzelm parents: 
54524diff
changeset | 598 | |
| 60916 
a6e2a667b0a8
resolve undefined blobs by default, e.g. relevant for ML debugger to avoid reset of breakpoints after reload;
 wenzelm parents: 
60215diff
changeset | 599 | def blobs_undefined: List[Document.Node.Name] = | 
| 
a6e2a667b0a8
resolve undefined blobs by default, e.g. relevant for ML debugger to avoid reset of breakpoints after reload;
 wenzelm parents: 
60215diff
changeset | 600 | for (Exn.Res((name, None)) <- blobs) yield name | 
| 
a6e2a667b0a8
resolve undefined blobs by default, e.g. relevant for ML debugger to avoid reset of breakpoints after reload;
 wenzelm parents: 
60215diff
changeset | 601 | |
| 57842 
8e4ae2db1849
more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
 wenzelm parents: 
57615diff
changeset | 602 | def blobs_defined: List[(Document.Node.Name, SHA1.Digest)] = | 
| 
8e4ae2db1849
more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
 wenzelm parents: 
57615diff
changeset | 603 | for (Exn.Res((name, Some((digest, _)))) <- blobs) yield (name, digest) | 
| 
8e4ae2db1849
more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
 wenzelm parents: 
57615diff
changeset | 604 | |
| 
8e4ae2db1849
more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
 wenzelm parents: 
57615diff
changeset | 605 | def blobs_changed(doc_blobs: Document.Blobs): Boolean = | 
| 
8e4ae2db1849
more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
 wenzelm parents: 
57615diff
changeset | 606 |     blobs.exists({ case Exn.Res((name, _)) => doc_blobs.changed(name) case _ => false })
 | 
| 54519 
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
 wenzelm parents: 
54517diff
changeset | 607 | |
| 55432 
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
 wenzelm parents: 
55431diff
changeset | 608 | |
| 56462 
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
 wenzelm parents: 
56395diff
changeset | 609 | /* source chunks */ | 
| 55431 
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
 wenzelm parents: 
55430diff
changeset | 610 | |
| 56746 | 611 | val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(source) | 
| 56473 | 612 | |
| 56746 | 613 | val chunks: Map[Symbol.Text_Chunk.Name, Symbol.Text_Chunk] = | 
| 614 | ((Symbol.Text_Chunk.Default -> chunk) :: | |
| 56473 | 615 | (for (Exn.Res((name, Some((_, file)))) <- blobs) | 
| 60215 | 616 | yield Symbol.Text_Chunk.File(name.node) -> file)).toMap | 
| 56473 | 617 | |
| 46813 | 618 | def length: Int = source.length | 
| 56473 | 619 | def range: Text.Range = chunk.range | 
| 46813 | 620 | |
| 68728 | 621 | val core_range: Text.Range = | 
| 57901 
e1abca2527da
more explicit type Span in Scala, according to ML version;
 wenzelm parents: 
57842diff
changeset | 622 | Text.Range(0, | 
| 68729 
3a02b424d5fb
clarified ignored span / core range: include formal comments, e.g. relevant for error messages from antiquotations;
 wenzelm parents: 
68728diff
changeset | 623 | (length /: span.content.reverse.iterator.takeWhile(_.is_ignored))(_ - _.source.length)) | 
| 46813 | 624 | |
| 65522 | 625 | def source(range: Text.Range): String = range.substring(source) | 
| 38572 
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
 wenzelm parents: 
38564diff
changeset | 626 | |
| 38370 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 627 | |
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 628 | /* accumulated results */ | 
| 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 wenzelm parents: 
38367diff
changeset | 629 | |
| 50501 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 wenzelm parents: 
50500diff
changeset | 630 | val init_state: Command.State = | 
| 55649 
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
 wenzelm parents: 
55648diff
changeset | 631 | Command.State(this, results = init_results, markups = Command.Markups.init(init_markup)) | 
| 52527 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52524diff
changeset | 632 | |
| 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 wenzelm parents: 
52524diff
changeset | 633 | val empty_state: Command.State = Command.State(this) | 
| 34676 
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
 immler@in.tum.de parents: 
34675diff
changeset | 634 | } |