author | wenzelm |
Fri, 27 Nov 2020 21:59:23 +0100 | |
changeset 72747 | 5f9d66155081 |
parent 72745 | 5a6f7212fc4d |
child 72748 | 04d5f6d769a7 |
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:
34865
diff
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:
59699
diff
changeset
|
18 |
|
72745 | 19 |
sealed case class Blob( |
20 |
name: Document.Node.Name, |
|
72747
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
21 |
src_path: Path, |
72745 | 22 |
content: Option[(SHA1.Digest, Symbol.Text_Chunk)]) |
23 |
||
24 |
type Blobs_Info = (List[Exn.Result[Blob]], Int) |
|
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
25 |
val no_blobs: Blobs_Info = (Nil, -1) |
52849 | 26 |
|
27 |
||
38361 | 28 |
/** accumulated results from prover **/ |
29 |
||
50507 | 30 |
/* results */ |
31 |
||
32 |
object Results |
|
33 |
{ |
|
51496
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents:
51494
diff
changeset
|
34 |
type Entry = (Long, XML.Tree) |
68101 | 35 |
val empty: Results = new Results(SortedMap.empty) |
59072 | 36 |
def make(args: TraversableOnce[Results.Entry]): Results = (empty /: args)(_ + _) |
37 |
def merge(args: TraversableOnce[Results]): Results = (empty /: args)(_ ++ _) |
|
50507 | 38 |
} |
39 |
||
51494 | 40 |
final class Results private(private val rep: SortedMap[Long, XML.Tree]) |
50507 | 41 |
{ |
64802 | 42 |
def is_empty: Boolean = rep.isEmpty |
50507 | 43 |
def defined(serial: Long): Boolean = rep.isDefinedAt(serial) |
44 |
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:
56359
diff
changeset
|
45 |
def iterator: Iterator[Results.Entry] = rep.iterator |
50508
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
46 |
|
51496
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents:
51494
diff
changeset
|
47 |
def + (entry: Results.Entry): Results = |
50508
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
48 |
if (defined(entry._1)) this |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
49 |
else new Results(rep + entry) |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
50 |
|
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
51 |
def ++ (other: Results): Results = |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
52 |
if (this eq other) this |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
53 |
else if (rep.isEmpty) other |
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56359
diff
changeset
|
54 |
else (this /: other.iterator)(_ + _) |
50540 | 55 |
|
51494 | 56 |
override def hashCode: Int = rep.hashCode |
57 |
override def equals(that: Any): Boolean = |
|
58 |
that match { |
|
59 |
case other: Results => rep == other.rep |
|
60 |
case _ => false |
|
61 |
} |
|
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56359
diff
changeset
|
62 |
override def toString: String = iterator.mkString("Results(", ", ", ")") |
50507 | 63 |
} |
64 |
||
65 |
||
68101 | 66 |
/* exports */ |
67 |
||
68 |
object Exports |
|
69 |
{ |
|
70 |
type Entry = (Long, Export.Entry) |
|
71 |
val empty: Exports = new Exports(SortedMap.empty) |
|
72 |
def merge(args: TraversableOnce[Exports]): Exports = (empty /: args)(_ ++ _) |
|
73 |
} |
|
74 |
||
75 |
final class Exports private(private val rep: SortedMap[Long, Export.Entry]) |
|
76 |
{ |
|
69634 | 77 |
def is_empty: Boolean = rep.isEmpty |
68101 | 78 |
def iterator: Iterator[Exports.Entry] = rep.iterator |
79 |
||
80 |
def + (entry: Exports.Entry): Exports = |
|
81 |
if (rep.isDefinedAt(entry._1)) this |
|
82 |
else new Exports(rep + entry) |
|
83 |
||
84 |
def ++ (other: Exports): Exports = |
|
85 |
if (this eq other) this |
|
86 |
else if (rep.isEmpty) other |
|
87 |
else (this /: other.iterator)(_ + _) |
|
88 |
||
89 |
override def hashCode: Int = rep.hashCode |
|
90 |
override def equals(that: Any): Boolean = |
|
91 |
that match { |
|
92 |
case other: Exports => rep == other.rep |
|
93 |
case _ => false |
|
94 |
} |
|
95 |
override def toString: String = iterator.mkString("Exports(", ", ", ")") |
|
96 |
} |
|
97 |
||
98 |
||
99 |
/* markups */ |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
100 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
101 |
object Markup_Index |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
102 |
{ |
56746 | 103 |
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:
55648
diff
changeset
|
104 |
} |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
105 |
|
56746 | 106 |
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:
55648
diff
changeset
|
107 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
108 |
object Markups |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
109 |
{ |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
110 |
val empty: Markups = new Markups(Map.empty) |
65335 | 111 |
def init(markup: Markup_Tree): Markups = new Markups(Map(Markup_Index.markup -> markup)) |
112 |
def merge(args: TraversableOnce[Markups]): Markups = (empty /: args)(_ ++ _) |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
113 |
} |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
114 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
115 |
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:
55648
diff
changeset
|
116 |
{ |
56489 | 117 |
def is_empty: Boolean = rep.isEmpty |
118 |
||
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
119 |
def apply(index: Markup_Index): Markup_Tree = |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
120 |
rep.getOrElse(index, Markup_Tree.empty) |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
121 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
122 |
def add(index: Markup_Index, markup: Text.Markup): Markups = |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
123 |
new Markups(rep + (index -> (this(index) + markup))) |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
124 |
|
65335 | 125 |
def + (entry: (Markup_Index, Markup_Tree)): Markups = |
126 |
{ |
|
127 |
val (index, tree) = entry |
|
128 |
new Markups(rep + (index -> (this(index).merge(tree, Text.Range.full, Markup.Elements.full)))) |
|
129 |
} |
|
130 |
||
131 |
def ++ (other: Markups): Markups = |
|
132 |
if (this eq other) this |
|
133 |
else if (rep.isEmpty) other |
|
134 |
else (this /: other.rep.iterator)(_ + _) |
|
135 |
||
56475 | 136 |
def redirection_iterator: Iterator[Document_ID.Generic] = |
56746 | 137 |
for (Markup_Index(_, Symbol.Text_Chunk.Id(id)) <- rep.keysIterator) |
56475 | 138 |
yield id |
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56469
diff
changeset
|
139 |
|
56475 | 140 |
def redirect(other_id: Document_ID.Generic): Markups = |
56489 | 141 |
{ |
142 |
val rep1 = |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56469
diff
changeset
|
143 |
(for { |
56746 | 144 |
(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:
56469
diff
changeset
|
145 |
if other_id == id |
56746 | 146 |
} yield (Markup_Index(status, Symbol.Text_Chunk.Default), markup)).toMap |
56489 | 147 |
if (rep1.isEmpty) Markups.empty else new Markups(rep1) |
148 |
} |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56469
diff
changeset
|
149 |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
150 |
override def hashCode: Int = rep.hashCode |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
151 |
override def equals(that: Any): Boolean = |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
152 |
that match { |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
153 |
case other: Markups => rep == other.rep |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
154 |
case _ => false |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
155 |
} |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
156 |
override def toString: String = rep.iterator.mkString("Markups(", ", ", ")") |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
157 |
} |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
158 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
159 |
|
50507 | 160 |
/* state */ |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
161 |
|
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56295
diff
changeset
|
162 |
object State |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56295
diff
changeset
|
163 |
{ |
67824
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67446
diff
changeset
|
164 |
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:
67446
diff
changeset
|
165 |
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:
67446
diff
changeset
|
166 |
|
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67446
diff
changeset
|
167 |
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:
67446
diff
changeset
|
168 |
for { |
661cd25304ae
more compact markup tree: output messages are already stored in command results (e.g. relevant for XML data representation);
wenzelm
parents:
67446
diff
changeset
|
169 |
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:
67446
diff
changeset
|
170 |
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:
67446
diff
changeset
|
171 |
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:
67446
diff
changeset
|
172 |
} 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:
67446
diff
changeset
|
173 |
|
65335 | 174 |
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:
56295
diff
changeset
|
175 |
Results.merge(states.map(_.results)) |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56295
diff
changeset
|
176 |
|
68101 | 177 |
def merge_exports(states: List[State]): Exports = |
178 |
Exports.merge(states.map(_.exports)) |
|
179 |
||
65335 | 180 |
def merge_markups(states: List[State]): Markups = |
181 |
Markups.merge(states.map(_.markups)) |
|
182 |
||
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56299
diff
changeset
|
183 |
def merge_markup(states: List[State], index: Markup_Index, |
56743 | 184 |
range: Text.Range, elements: Markup.Elements): Markup_Tree = |
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56299
diff
changeset
|
185 |
Markup_Tree.merge(states.map(_.markup(index)), range, elements) |
65335 | 186 |
|
187 |
def merge(command: Command, states: List[State]): State = |
|
68101 | 188 |
State(command, states.flatMap(_.status), merge_results(states), |
189 |
merge_exports(states), merge_markups(states)) |
|
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56295
diff
changeset
|
190 |
} |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56295
diff
changeset
|
191 |
|
43714 | 192 |
sealed case class State( |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
193 |
command: Command, |
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
194 |
status: List[Markup] = Nil, |
50507 | 195 |
results: Results = Results.empty, |
68101 | 196 |
exports: Exports = Exports.empty, |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
197 |
markups: Markups = Markups.empty) |
38361 | 198 |
{ |
68323 | 199 |
def initialized: Boolean = status.exists(markup => markup.name == Markup.INITIALIZED) |
70780
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
wenzelm
parents:
70713
diff
changeset
|
200 |
def consolidating: Boolean = status.exists(markup => markup.name == Markup.CONSOLIDATING) |
68335 | 201 |
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:
65522
diff
changeset
|
202 |
|
68758 | 203 |
lazy val maybe_consolidated: Boolean = |
204 |
{ |
|
205 |
var touched = false |
|
206 |
var forks = 0 |
|
207 |
var runs = 0 |
|
208 |
for (markup <- status) { |
|
209 |
markup.name match { |
|
210 |
case Markup.FORKED => touched = true; forks += 1 |
|
211 |
case Markup.JOINED => forks -= 1 |
|
212 |
case Markup.RUNNING => touched = true; runs += 1 |
|
213 |
case Markup.FINISHED => runs -= 1 |
|
214 |
case _ => |
|
215 |
} |
|
216 |
} |
|
217 |
touched && forks == 0 && runs == 0 |
|
218 |
} |
|
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68335
diff
changeset
|
219 |
|
68758 | 220 |
lazy val document_status: Document_Status.Command_Status = |
56395
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
221 |
{ |
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
222 |
val warnings = |
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59072
diff
changeset
|
223 |
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:
56372
diff
changeset
|
224 |
List(Markup(Markup.WARNING, Nil)) |
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
225 |
else Nil |
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
226 |
val errors = |
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
227 |
if (results.iterator.exists(p => Protocol.is_error(p._2))) |
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
228 |
List(Markup(Markup.ERROR, Nil)) |
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
229 |
else Nil |
68758 | 230 |
Document_Status.Command_Status.make((warnings ::: errors ::: status).iterator) |
56395
0546e036d1c0
more direct warning within persistent Protocol.Status;
wenzelm
parents:
56372
diff
changeset
|
231 |
} |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
232 |
|
55650 | 233 |
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:
55431
diff
changeset
|
234 |
|
56489 | 235 |
def redirect(other_command: Command): Option[State] = |
236 |
{ |
|
237 |
val markups1 = markups.redirect(other_command.id) |
|
238 |
if (markups1.is_empty) None |
|
68101 | 239 |
else Some(new State(other_command, markups = markups1)) |
56489 | 240 |
} |
49614 | 241 |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
242 |
private def add_status(st: Markup): State = |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
243 |
copy(status = st :: status) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
244 |
|
67826 | 245 |
private def add_result(entry: Results.Entry): State = |
246 |
copy(results = results + entry) |
|
247 |
||
68114 | 248 |
def add_export(entry: Exports.Entry): Option[State] = |
249 |
if (command.node_name.theory == entry._2.theory_name) Some(copy(exports = exports + entry)) |
|
250 |
else None |
|
68101 | 251 |
|
56746 | 252 |
private def add_markup( |
253 |
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:
55648
diff
changeset
|
254 |
{ |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
255 |
val markups1 = |
68758 | 256 |
if (status || Document_Status.Command_Status.liberal_elements(m.info.name)) |
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
56395
diff
changeset
|
257 |
markups.add(Markup_Index(true, chunk_name), m) |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55648
diff
changeset
|
258 |
else markups |
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
56395
diff
changeset
|
259 |
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:
55648
diff
changeset
|
260 |
} |
38361 | 261 |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56469
diff
changeset
|
262 |
def accumulate( |
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56469
diff
changeset
|
263 |
self_id: Document_ID.Generic => Boolean, |
56746 | 264 |
other_id: Document_ID.Generic => Option[(Symbol.Text_Chunk.Id, Symbol.Text_Chunk)], |
67825 | 265 |
message: XML.Elem, |
266 |
xml_cache: XML.Cache): State = |
|
38361 | 267 |
message match { |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50163
diff
changeset
|
268 |
case XML.Elem(Markup(Markup.STATUS, _), msgs) => |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
269 |
if (command.span.is_theory) this |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
270 |
else { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
271 |
(this /: msgs)((state, msg) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
272 |
msg match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
273 |
case elem @ XML.Elem(markup, Nil) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
274 |
state. |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
275 |
add_status(markup). |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
276 |
add_markup(true, Symbol.Text_Chunk.Default, Text.Info(command.core_range, elem)) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
277 |
case _ => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
278 |
Output.warning("Ignored status message: " + msg) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
279 |
state |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
280 |
}) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
281 |
} |
38581
d503a0912e14
simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents:
38579
diff
changeset
|
282 |
|
72709
cb9d5af781b4
more complete report positions, notably for command 'back' (amending eca176f773e0);
wenzelm
parents:
72708
diff
changeset
|
283 |
case XML.Elem(Markup(Markup.REPORT, atts0), msgs) => |
38572
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
wenzelm
parents:
38564
diff
changeset
|
284 |
(this /: msgs)((state, msg) => |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
285 |
{ |
56782
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
56746
diff
changeset
|
286 |
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:
55431
diff
changeset
|
287 |
|
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
288 |
msg match { |
72709
cb9d5af781b4
more complete report positions, notably for command 'back' (amending eca176f773e0);
wenzelm
parents:
72708
diff
changeset
|
289 |
case XML.Elem(Markup(name, atts1), args) => |
cb9d5af781b4
more complete report positions, notably for command 'back' (amending eca176f773e0);
wenzelm
parents:
72708
diff
changeset
|
290 |
val atts = atts1 ::: atts0 |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
291 |
command.reported_position(atts) match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
292 |
case Some((id, chunk_name)) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
293 |
val target = |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
294 |
if (self_id(id) && command.chunks.isDefinedAt(chunk_name)) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
295 |
Some((chunk_name, command.chunks(chunk_name))) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
296 |
else if (chunk_name == Symbol.Text_Chunk.Default) other_id(id) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
297 |
else None |
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56469
diff
changeset
|
298 |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
299 |
(target, atts) match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
300 |
case (Some((target_name, target_chunk)), Position.Range(symbol_range)) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
301 |
target_chunk.incorporate(symbol_range) match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
302 |
case Some(range) => |
72708 | 303 |
val props = atts.filterNot(Markup.position_property) |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
304 |
val elem = xml_cache.elem(XML.Elem(Markup(name, props), args)) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
305 |
state.add_markup(false, target_name, Text.Info(range, elem)) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
306 |
case None => bad(); state |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
307 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
308 |
case _ => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
309 |
// silently ignore excessive reports |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
310 |
state |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
311 |
} |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
312 |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
313 |
case _ => bad(); state |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
314 |
} |
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56469
diff
changeset
|
315 |
case _ => bad(); state |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
316 |
} |
38361 | 317 |
}) |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
318 |
|
52930
5fab62ae3532
retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents:
52849
diff
changeset
|
319 |
case XML.Elem(Markup(name, props), body) => |
5fab62ae3532
retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents:
52849
diff
changeset
|
320 |
props match { |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50163
diff
changeset
|
321 |
case Markup.Serial(i) => |
67825 | 322 |
val markup_message = |
323 |
xml_cache.elem(XML.Elem(Markup(Markup.message(name), props), body)) |
|
324 |
val message_markup = |
|
325 |
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:
50158
diff
changeset
|
326 |
|
67826 | 327 |
var st = add_result(i -> markup_message) |
55433
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
328 |
if (Protocol.is_inlined(message)) { |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
329 |
for { |
56469 | 330 |
(chunk_name, chunk) <- command.chunks.iterator |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
331 |
range <- command.message_positions(self_id, 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:
67446
diff
changeset
|
332 |
} st = st.add_markup(false, chunk_name, Text.Info(range, message_markup)) |
55433
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
333 |
} |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
334 |
st |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
335 |
|
52536 | 336 |
case _ => |
56782
433cf57550fa
more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
56746
diff
changeset
|
337 |
Output.warning("Ignored message without serial number: " + message) |
52536 | 338 |
this |
38872 | 339 |
} |
68101 | 340 |
} |
38361 | 341 |
} |
38367 | 342 |
|
343 |
||
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
344 |
|
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
345 |
/** static content **/ |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
346 |
|
45644 | 347 |
/* make commands */ |
348 |
||
55648
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
349 |
def apply( |
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
350 |
id: Document_ID.Command, |
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
351 |
node_name: Document.Node.Name, |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
352 |
blobs_info: Blobs_Info, |
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
57904
diff
changeset
|
353 |
span: Command_Span.Span): Command = |
55648
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
354 |
{ |
57901
e1abca2527da
more explicit type Span in Scala, according to ML version;
wenzelm
parents:
57842
diff
changeset
|
355 |
val (source, span1) = span.compact_source |
72722
ade53fbc6f03
clarified signature: initial markup is_empty, not init_markup;
wenzelm
parents:
72709
diff
changeset
|
356 |
new Command(id, node_name, blobs_info, span1, source, Results.empty, Markups.empty) |
55648
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
357 |
} |
49414 | 358 |
|
57901
e1abca2527da
more explicit type Span in Scala, according to ML version;
wenzelm
parents:
57842
diff
changeset
|
359 |
val empty: Command = |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
360 |
Command(Document_ID.none, Document.Node.Name.empty, no_blobs, Command_Span.empty) |
55648
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
361 |
|
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
362 |
def unparsed( |
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
363 |
source: String, |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
364 |
theory: Boolean = false, |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
365 |
id: Document_ID.Command = Document_ID.none, |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
366 |
node_name: Document.Node.Name = Document.Node.Name.empty, |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
367 |
results: Results = Results.empty, |
72722
ade53fbc6f03
clarified signature: initial markup is_empty, not init_markup;
wenzelm
parents:
72709
diff
changeset
|
368 |
markups: Markups = Markups.empty): Command = |
55648
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
369 |
{ |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
370 |
val (source1, span1) = Command_Span.unparsed(source, theory).compact_source |
72722
ade53fbc6f03
clarified signature: initial markup is_empty, not init_markup;
wenzelm
parents:
72709
diff
changeset
|
371 |
new Command(id, node_name, no_blobs, span1, source1, results, markups) |
55648
38f264741609
tuned signature -- avoid obscure default arguments;
wenzelm
parents:
55622
diff
changeset
|
372 |
} |
49414 | 373 |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
374 |
def text(source: String): Command = unparsed(source) |
44384 | 375 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
376 |
def rich_text(id: Document_ID.Command, results: Results, body: XML.Body): Command = |
72722
ade53fbc6f03
clarified signature: initial markup is_empty, not init_markup;
wenzelm
parents:
72709
diff
changeset
|
377 |
unparsed(XML.content(body), id = id, results = results, |
ade53fbc6f03
clarified signature: initial markup is_empty, not init_markup;
wenzelm
parents:
72709
diff
changeset
|
378 |
markups = Markups.init(Markup_Tree.from_XML(body))) |
49359
c1262d7389fb
refined output panel: more value-oriented approach to update and caret focus;
wenzelm
parents:
49037
diff
changeset
|
379 |
|
44384 | 380 |
|
381 |
/* perspective */ |
|
382 |
||
44474 | 383 |
object Perspective |
384 |
{ |
|
385 |
val empty: Perspective = Perspective(Nil) |
|
386 |
} |
|
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
387 |
|
44474 | 388 |
sealed case class Perspective(commands: List[Command]) // visible commands in canonical order |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
389 |
{ |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
56782
diff
changeset
|
390 |
def is_empty: Boolean = commands.isEmpty |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
56782
diff
changeset
|
391 |
|
44474 | 392 |
def same(that: Perspective): Boolean = |
393 |
{ |
|
394 |
val cmds1 = this.commands |
|
395 |
val cmds2 = that.commands |
|
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48745
diff
changeset
|
396 |
require(!cmds1.exists(_.is_undefined)) |
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48745
diff
changeset
|
397 |
require(!cmds2.exists(_.is_undefined)) |
44474 | 398 |
cmds1.length == cmds2.length && |
399 |
(cmds1.iterator zip cmds2.iterator).forall({ case (c1, c2) => c1.id == c2.id }) |
|
400 |
} |
|
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
401 |
} |
59689
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
wenzelm
parents:
59684
diff
changeset
|
402 |
|
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
wenzelm
parents:
59684
diff
changeset
|
403 |
|
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
404 |
/* blobs: inlined errors and auxiliary files */ |
59689
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
wenzelm
parents:
59684
diff
changeset
|
405 |
|
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
406 |
def blobs_info( |
59699 | 407 |
resources: Resources, |
63584
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
wenzelm
parents:
62969
diff
changeset
|
408 |
syntax: Outer_Syntax, |
59699 | 409 |
get_blob: Document.Node.Name => Option[Document.Blob], |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
410 |
can_import: Document.Node.Name => Boolean, |
59699 | 411 |
node_name: Document.Node.Name, |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
412 |
span: Command_Span.Span): Blobs_Info = |
59689
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
wenzelm
parents:
59684
diff
changeset
|
413 |
{ |
59735 | 414 |
span.name match { |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
415 |
// inlined errors |
59735 | 416 |
case Thy_Header.THEORY => |
64825 | 417 |
val reader = Scan.char_reader(Token.implode(span.content)) |
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
69891
diff
changeset
|
418 |
val imports_pos = resources.check_thy_reader(node_name, reader).imports_pos |
66768 | 419 |
val raw_imports = |
420 |
try { |
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
69891
diff
changeset
|
421 |
val read_imports = Thy_Header.read(reader, Token.Pos.none).imports |
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
69891
diff
changeset
|
422 |
if (imports_pos.length == read_imports.length) read_imports else error("") |
66768 | 423 |
} |
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
69891
diff
changeset
|
424 |
catch { case exn: Throwable => List.fill(imports_pos.length)("") } |
66768 | 425 |
|
59715
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
wenzelm
parents:
59713
diff
changeset
|
426 |
val errors = |
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
69891
diff
changeset
|
427 |
for { ((import_name, pos), s) <- imports_pos zip raw_imports if !can_import(import_name) } |
66768 | 428 |
yield { |
429 |
val completion = |
|
70713
fd188463066e
clarified theory imports completion, based on session directories and current master directory (no support for local session-subdirectories);
wenzelm
parents:
70638
diff
changeset
|
430 |
if (Thy_Header.is_base_name(s)) resources.complete_import_name(node_name, s) else Nil |
59715
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
wenzelm
parents:
59713
diff
changeset
|
431 |
val msg = |
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
wenzelm
parents:
59713
diff
changeset
|
432 |
"Bad theory import " + |
66768 | 433 |
Markup.Path(import_name.node).markup(quote(import_name.toString)) + |
434 |
Position.here(pos) + Completion.report_theories(pos, completion) |
|
72745 | 435 |
Exn.Exn[Command.Blob](ERROR(msg)) |
59708
aed304412e43
more markup, which helps to create missing imports;
wenzelm
parents:
59706
diff
changeset
|
436 |
} |
59715
4f0d0e4ad68d
avoid duplicate header errors, more precise positions;
wenzelm
parents:
59713
diff
changeset
|
437 |
(errors, -1) |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
438 |
|
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
439 |
// auxiliary files |
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
440 |
case _ => |
72742 | 441 |
val (files, index) = span.loaded_files(syntax) |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
442 |
val blobs = |
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
443 |
files.map(file => |
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
444 |
(Exn.capture { |
72747
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
445 |
val src_path = Path.explode(file) |
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
446 |
val name = Document.Node.Name(resources.append(node_name, src_path)) |
72745 | 447 |
val content = get_blob(name).map(blob => (blob.bytes.sha1_digest, blob.chunk)) |
72747
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
448 |
Blob(name, src_path, content) |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
449 |
}).user_error) |
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
450 |
(blobs, index) |
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
451 |
} |
59689
7968c57ea240
simplified Command.resolve_files in ML, using blobs_index from Scala;
wenzelm
parents:
59684
diff
changeset
|
452 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
453 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
454 |
|
38361 | 455 |
|
46712 | 456 |
final class Command private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
457 |
val id: Document_ID.Command, |
44615 | 458 |
val node_name: Document.Node.Name, |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
459 |
val blobs_info: Command.Blobs_Info, |
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
57904
diff
changeset
|
460 |
val span: Command_Span.Span, |
49414 | 461 |
val source: String, |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
462 |
val init_results: Command.Results, |
72722
ade53fbc6f03
clarified signature: initial markup is_empty, not init_markup;
wenzelm
parents:
72709
diff
changeset
|
463 |
val init_markups: Command.Markups) |
34451 | 464 |
{ |
57912 | 465 |
override def toString: String = id + "/" + span.kind.toString |
34495 | 466 |
|
57910 | 467 |
|
468 |
/* classification */ |
|
469 |
||
57905
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
57904
diff
changeset
|
470 |
def is_proper: Boolean = span.kind.isInstanceOf[Command_Span.Command_Span] |
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
wenzelm
parents:
57904
diff
changeset
|
471 |
def is_ignored: Boolean = span.kind == Command_Span.Ignored_Span |
57904 | 472 |
|
473 |
def is_undefined: Boolean = id == Document_ID.none |
|
474 |
val is_unparsed: Boolean = span.content.exists(_.is_unparsed) |
|
475 |
val is_unfinished: Boolean = span.content.exists(_.is_unfinished) |
|
476 |
||
68323 | 477 |
def potentially_initialized: Boolean = span.name == Thy_Header.THEORY |
478 |
||
34859 | 479 |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
480 |
/* blobs */ |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
481 |
|
72745 | 482 |
def blobs: List[Exn.Result[Command.Blob]] = blobs_info._1 |
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
483 |
def blobs_index: Int = blobs_info._2 |
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59699
diff
changeset
|
484 |
|
65335 | 485 |
def blobs_ok: Boolean = |
486 |
blobs.forall({ case Exn.Res(_) => true case _ => false }) |
|
487 |
||
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54524
diff
changeset
|
488 |
def blobs_names: List[Document.Node.Name] = |
72745 | 489 |
for (Exn.Res(blob) <- blobs) yield blob.name |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54524
diff
changeset
|
490 |
|
60916
a6e2a667b0a8
resolve undefined blobs by default, e.g. relevant for ML debugger to avoid reset of breakpoints after reload;
wenzelm
parents:
60215
diff
changeset
|
491 |
def blobs_undefined: List[Document.Node.Name] = |
72745 | 492 |
for (Exn.Res(blob) <- blobs if blob.content.isEmpty) yield blob.name |
60916
a6e2a667b0a8
resolve undefined blobs by default, e.g. relevant for ML debugger to avoid reset of breakpoints after reload;
wenzelm
parents:
60215
diff
changeset
|
493 |
|
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:
57615
diff
changeset
|
494 |
def blobs_defined: List[(Document.Node.Name, SHA1.Digest)] = |
72745 | 495 |
for (Exn.Res(blob) <- blobs; (digest, _) <- blob.content) yield (blob.name, digest) |
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:
57615
diff
changeset
|
496 |
|
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:
57615
diff
changeset
|
497 |
def blobs_changed(doc_blobs: Document.Blobs): Boolean = |
72745 | 498 |
blobs.exists({ case Exn.Res(blob) => doc_blobs.changed(blob.name) case _ => false }) |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
499 |
|
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
500 |
|
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
56395
diff
changeset
|
501 |
/* source chunks */ |
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
502 |
|
56746 | 503 |
val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(source) |
56473 | 504 |
|
56746 | 505 |
val chunks: Map[Symbol.Text_Chunk.Name, Symbol.Text_Chunk] = |
506 |
((Symbol.Text_Chunk.Default -> chunk) :: |
|
72745 | 507 |
(for (Exn.Res(blob) <- blobs; (_, file) <- blob.content) |
508 |
yield Symbol.Text_Chunk.File(blob.name.node) -> file)).toMap |
|
56473 | 509 |
|
46813 | 510 |
def length: Int = source.length |
56473 | 511 |
def range: Text.Range = chunk.range |
46813 | 512 |
|
68728 | 513 |
val core_range: Text.Range = |
57901
e1abca2527da
more explicit type Span in Scala, according to ML version;
wenzelm
parents:
57842
diff
changeset
|
514 |
Text.Range(0, |
68729
3a02b424d5fb
clarified ignored span / core range: include formal comments, e.g. relevant for error messages from antiquotations;
wenzelm
parents:
68728
diff
changeset
|
515 |
(length /: span.content.reverse.iterator.takeWhile(_.is_ignored))(_ - _.source.length)) |
46813 | 516 |
|
65522 | 517 |
def source(range: Text.Range): String = range.substring(source) |
38572
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
wenzelm
parents:
38564
diff
changeset
|
518 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
519 |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
520 |
/* reported positions */ |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
521 |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
522 |
def reported_position(pos: Position.T): Option[(Document_ID.Generic, Symbol.Text_Chunk.Name)] = |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
523 |
pos match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
524 |
case Position.Id(id) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
525 |
val chunk_name = |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
526 |
pos match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
527 |
case Position.File(name) if name != node_name.node => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
528 |
Symbol.Text_Chunk.File(name) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
529 |
case _ => Symbol.Text_Chunk.Default |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
530 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
531 |
Some((id, chunk_name)) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
532 |
case _ => None |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
533 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
534 |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
535 |
def message_positions( |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
536 |
self_id: Document_ID.Generic => Boolean, |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
537 |
chunk_name: Symbol.Text_Chunk.Name, |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
538 |
chunk: Symbol.Text_Chunk, |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
539 |
message: XML.Elem): Set[Text.Range] = |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
540 |
{ |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
541 |
def elem(props: Properties.T, set: Set[Text.Range]): Set[Text.Range] = |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
542 |
reported_position(props) match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
543 |
case Some((id, name)) if self_id(id) && name == chunk_name => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
544 |
val opt_range = |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
545 |
Position.Range.unapply(props) orElse { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
546 |
if (name == Symbol.Text_Chunk.Default) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
547 |
Position.Range.unapply(span.position) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
548 |
else None |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
549 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
550 |
opt_range match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
551 |
case Some(symbol_range) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
552 |
chunk.incorporate(symbol_range) match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
553 |
case Some(range) => set + range |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
554 |
case _ => set |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
555 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
556 |
case None => set |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
557 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
558 |
case _ => set |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
559 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
560 |
def tree(set: Set[Text.Range], t: XML.Tree): Set[Text.Range] = |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
561 |
t match { |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
562 |
case XML.Wrapped_Elem(Markup(name, props), _, body) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
563 |
body.foldLeft(if (Rendering.position_elements(name)) elem(props, set) else set)(tree) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
564 |
case XML.Elem(Markup(name, props), body) => |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
565 |
body.foldLeft(if (Rendering.position_elements(name)) elem(props, set) else set)(tree) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
566 |
case XML.Text(_) => set |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
567 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
568 |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
569 |
val set = tree(Set.empty, message) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
570 |
if (set.isEmpty) elem(message.markup.properties, set) |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
571 |
else set |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
572 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
573 |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
70780
diff
changeset
|
574 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
575 |
/* accumulated results */ |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
576 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
577 |
val init_state: Command.State = |
72722
ade53fbc6f03
clarified signature: initial markup is_empty, not init_markup;
wenzelm
parents:
72709
diff
changeset
|
578 |
Command.State(this, results = init_results, markups = init_markups) |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52524
diff
changeset
|
579 |
|
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52524
diff
changeset
|
580 |
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:
34675
diff
changeset
|
581 |
} |