| author | wenzelm |
| Tue, 16 Sep 2025 10:39:53 +0200 | |
| changeset 83163 | 64c9d94478b8 |
| parent 82954 | 1d6dc0eef4cf |
| child 83164 | 851f3f9440ef |
| permissions | -rw-r--r-- |
| 36676 | 1 |
/* Title: Pure/PIDE/document.scala |
2 |
Author: Makarius |
|
3 |
||
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
4 |
Document as collection of named nodes, each consisting of an editable |
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
5 |
list of commands, associated with asynchronous execution process. |
| 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:
34868
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 |
|
| 34760 | 10 |
|
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
11 |
import scala.collection.mutable |
| 37073 | 12 |
|
13 |
||
| 75393 | 14 |
object Document {
|
| 38424 | 15 |
/** document structure **/ |
16 |
||
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
17 |
/* overlays -- print functions with arguments */ |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
18 |
|
| 75393 | 19 |
object Overlays {
|
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
20 |
val empty = new Overlays(Map.empty) |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
21 |
} |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
22 |
|
| 75393 | 23 |
final class Overlays private(rep: Map[Node.Name, Node.Overlays]) {
|
| 64799 | 24 |
def apply(name: Node.Name): Node.Overlays = |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
25 |
rep.getOrElse(name, Node.Overlays.empty) |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
26 |
|
| 75393 | 27 |
private def update(name: Node.Name, f: Node.Overlays => Node.Overlays): Overlays = {
|
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
28 |
val node_overlays = f(apply(name)) |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
29 |
new Overlays(if (node_overlays.is_empty) rep - name else rep + (name -> node_overlays)) |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
30 |
} |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
31 |
|
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
32 |
def insert(command: Command, fn: String, args: List[String]): Overlays = |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
33 |
update(command.node_name, _.insert(command, fn, args)) |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
34 |
|
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
35 |
def remove(command: Command, fn: String, args: List[String]): Overlays = |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
36 |
update(command.node_name, _.remove(command, fn, args)) |
| 55800 | 37 |
|
38 |
override def toString: String = rep.mkString("Overlays(", ",", ")")
|
|
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
39 |
} |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
40 |
|
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
41 |
|
| 55783 | 42 |
/* document blobs: auxiliary files */ |
43 |
||
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
44 |
object Blobs {
|
| 76916 | 45 |
sealed case class Item( |
46 |
bytes: Bytes, |
|
47 |
source: String, |
|
48 |
chunk: Symbol.Text_Chunk, |
|
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
49 |
command_offset: Symbol.Offset = 0, |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
50 |
changed: Boolean = false |
| 76916 | 51 |
) {
|
| 82954 | 52 |
override def toString: String = |
53 |
"Blobs.Item(bytes = " + bytes.size + ", source = " + source.length + |
|
54 |
if_proper(command_offset > 0, ", command_offset = " + command_offset) + |
|
55 |
if_proper(changed, ", changed = true") + ")" |
|
| 82953 | 56 |
|
| 76924 | 57 |
def source_wellformed: Boolean = bytes.wellformed_text.nonEmpty |
| 82790 | 58 |
def unchanged: Item = if (changed) copy(changed = false) else this |
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
59 |
} |
| 55783 | 60 |
|
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
61 |
def apply(blobs: Map[Node.Name, Item]): Blobs = new Blobs(blobs) |
| 55783 | 62 |
val empty: Blobs = apply(Map.empty) |
| 76913 | 63 |
|
64 |
def make(blobs: List[(Command.Blob, Item)]): Blobs = |
|
65 |
if (blobs.isEmpty) empty |
|
66 |
else apply((for ((a, b) <- blobs.iterator) yield a.name -> b).toMap) |
|
| 55783 | 67 |
} |
68 |
||
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
69 |
final class Blobs private(blobs: Map[Node.Name, Blobs.Item]) {
|
|
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
70 |
def get(name: Node.Name): Option[Blobs.Item] = blobs.get(name) |
| 55783 | 71 |
|
72 |
def changed(name: Node.Name): Boolean = |
|
73 |
get(name) match {
|
|
74 |
case Some(blob) => blob.changed |
|
75 |
case None => false |
|
76 |
} |
|
77 |
||
| 55800 | 78 |
override def toString: String = blobs.mkString("Blobs(", ",", ")")
|
| 55783 | 79 |
} |
80 |
||
81 |
||
82 |
/* document nodes: theories and auxiliary files */ |
|
| 38424 | 83 |
|
| 44615 | 84 |
type Edit[A, B] = (Node.Name, Node.Edit[A, B]) |
| 44384 | 85 |
type Edit_Text = Edit[Text.Edit, Text.Perspective] |
| 52849 | 86 |
type Edit_Command = Edit[Command.Edit, Command.Perspective] |
| 38151 | 87 |
|
| 75393 | 88 |
object Node {
|
| 52887 | 89 |
/* header and name */ |
90 |
||
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
91 |
sealed case class Header( |
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70636
diff
changeset
|
92 |
imports_pos: List[(Name, Position.T)] = Nil, |
| 63020 | 93 |
keywords: Thy_Header.Keywords = Nil, |
| 63579 | 94 |
abbrevs: Thy_Header.Abbrevs = Nil, |
| 75393 | 95 |
errors: List[String] = Nil |
96 |
) {
|
|
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70636
diff
changeset
|
97 |
def imports: List[Name] = imports_pos.map(_._1) |
|
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70636
diff
changeset
|
98 |
|
| 66773 | 99 |
def append_errors(msgs: List[String]): Header = |
100 |
copy(errors = errors ::: msgs) |
|
|
54549
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
101 |
|
|
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
102 |
def cat_errors(msg2: String): Header = |
| 62492 | 103 |
copy(errors = errors.map(msg1 => Exn.cat_message(msg1, msg2))) |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
104 |
} |
|
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
105 |
|
| 71601 | 106 |
val no_header: Header = Header() |
| 63020 | 107 |
def bad_header(msg: String): Header = Header(errors = List(msg)) |
| 46737 | 108 |
|
| 75393 | 109 |
object Name {
|
|
76860
f95ed5a0600c
clarified signature: uniform master_dir instead of separate field;
wenzelm
parents:
76848
diff
changeset
|
110 |
def apply(node: String, theory: String = ""): Name = new Name(node, theory) |
|
76671
254964ca1b98
clarified signature: avoid case class with redefined equality;
wenzelm
parents:
76481
diff
changeset
|
111 |
|
| 76905 | 112 |
def loaded_theory(theory: String): Name = Name(theory, theory = theory) |
| 46723 | 113 |
|
| 76848 | 114 |
val empty: Name = Name("")
|
| 76845 | 115 |
|
| 75393 | 116 |
object Ordering extends scala.math.Ordering[Name] {
|
| 46723 | 117 |
def compare(name1: Name, name2: Name): Int = name1.node compare name2.node |
118 |
} |
|
| 70636 | 119 |
|
|
70674
29bb1ebb188f
clarified signature: proper Document.Node.Ordering conforming to equality (e.g. required in situations where theory names are ambiguous due to overlapping session directories);
wenzelm
parents:
70650
diff
changeset
|
120 |
type Graph[A] = isabelle.Graph[Node.Name, A] |
|
29bb1ebb188f
clarified signature: proper Document.Node.Ordering conforming to equality (e.g. required in situations where theory names are ambiguous due to overlapping session directories);
wenzelm
parents:
70650
diff
changeset
|
121 |
|
| 70692 | 122 |
def make_graph[A](entries: List[((Name, A), List[Name])]): Graph[A] = |
| 76840 | 123 |
Graph.make(entries, converse = true)(Ordering) |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
124 |
} |
| 52887 | 125 |
|
|
76860
f95ed5a0600c
clarified signature: uniform master_dir instead of separate field;
wenzelm
parents:
76848
diff
changeset
|
126 |
final class Name private(val node: String, val theory: String) {
|
| 44615 | 127 |
override def hashCode: Int = node.hashCode |
128 |
override def equals(that: Any): Boolean = |
|
129 |
that match {
|
|
130 |
case other: Name => node == other.node |
|
131 |
case _ => false |
|
132 |
} |
|
|
54509
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54462
diff
changeset
|
133 |
|
|
76829
f2a8ba0b8c96
more robust: avoid detour via somewhat fragile Node.Name.path;
wenzelm
parents:
76792
diff
changeset
|
134 |
def file_name: String = Url.get_base_name(node).getOrElse("")
|
|
f2a8ba0b8c96
more robust: avoid detour via somewhat fragile Node.Name.path;
wenzelm
parents:
76792
diff
changeset
|
135 |
|
| 66849 | 136 |
def path: Path = Path.explode(File.standard_path(node)) |
|
76860
f95ed5a0600c
clarified signature: uniform master_dir instead of separate field;
wenzelm
parents:
76848
diff
changeset
|
137 |
|
|
f95ed5a0600c
clarified signature: uniform master_dir instead of separate field;
wenzelm
parents:
76848
diff
changeset
|
138 |
def master_dir: String = Url.strip_base_name(node).getOrElse("")
|
| 66716 | 139 |
|
| 59319 | 140 |
def is_theory: Boolean = theory.nonEmpty |
| 65409 | 141 |
|
| 65439 | 142 |
def theory_base_name: String = Long_Name.base_name(theory) |
143 |
||
| 54510 | 144 |
override def toString: String = if (is_theory) theory else node |
|
56801
8dd9df88f647
some support for session-qualified theories: allow to refer to resources via qualified name instead of odd file-system path;
wenzelm
parents:
56746
diff
changeset
|
145 |
|
| 67943 | 146 |
def json: JSON.Object.T = |
147 |
JSON.Object("node_name" -> node, "theory_name" -> theory)
|
|
| 44615 | 148 |
} |
149 |
||
| 75393 | 150 |
sealed case class Entry(name: Node.Name, header: Node.Header) {
|
| 66714 | 151 |
override def toString: String = name.toString |
152 |
} |
|
153 |
||
| 52887 | 154 |
|
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
155 |
/* node overlays */ |
| 52887 | 156 |
|
| 75393 | 157 |
object Overlays {
|
| 52976 | 158 |
val empty = new Overlays(Multi_Map.empty) |
| 52887 | 159 |
} |
160 |
||
| 75393 | 161 |
final class Overlays private(rep: Multi_Map[Command, (String, List[String])]) {
|
| 52887 | 162 |
def commands: Set[Command] = rep.keySet |
163 |
def is_empty: Boolean = rep.isEmpty |
|
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
164 |
def dest: List[(Command, (String, List[String]))] = rep.iterator.toList |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
165 |
def insert(cmd: Command, fn: String, args: List[String]): Overlays = |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
166 |
new Overlays(rep.insert(cmd, (fn, args))) |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
167 |
def remove(cmd: Command, fn: String, args: List[String]): Overlays = |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
168 |
new Overlays(rep.remove(cmd, (fn, args))) |
| 55800 | 169 |
|
170 |
override def toString: String = rep.mkString("Node.Overlays(", ",", ")")
|
|
| 52887 | 171 |
} |
172 |
||
173 |
||
174 |
/* edits */ |
|
175 |
||
| 75393 | 176 |
sealed abstract class Edit[A, B] {
|
177 |
def foreach(f: A => Unit): Unit = {
|
|
| 44156 | 178 |
this match {
|
| 44383 | 179 |
case Edits(es) => es.foreach(f) |
180 |
case _ => |
|
| 44156 | 181 |
} |
| 44383 | 182 |
} |
| 57621 | 183 |
|
184 |
def is_void: Boolean = |
|
185 |
this match {
|
|
186 |
case Edits(Nil) => true |
|
187 |
case _ => false |
|
188 |
} |
|
| 44156 | 189 |
} |
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
190 |
case class Blob[A, B](blob: Blobs.Item) extends Edit[A, B] |
|
54562
301a721af68b
clarified node edits sent to prover -- Clear/Blob only required for text edits within editor;
wenzelm
parents:
54549
diff
changeset
|
191 |
|
| 44384 | 192 |
case class Edits[A, B](edits: List[A]) extends Edit[A, B] |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
193 |
case class Deps[A, B](header: Header) extends Edit[A, B] |
| 52849 | 194 |
case class Perspective[A, B](required: Boolean, visible: B, overlays: Overlays) extends Edit[A, B] |
| 57610 | 195 |
|
196 |
||
197 |
/* perspective */ |
|
198 |
||
| 76702 | 199 |
object Perspective_Text {
|
200 |
type T = Perspective[Text.Edit, Text.Perspective] |
|
201 |
val empty: T = Perspective(false, Text.Perspective.empty, Overlays.empty) |
|
202 |
def is_empty(perspective: T): Boolean = |
|
203 |
!perspective.required && |
|
204 |
perspective.visible.is_empty && |
|
205 |
perspective.overlays.is_empty |
|
206 |
} |
|
| 57614 | 207 |
|
| 76702 | 208 |
object Perspective_Command {
|
209 |
type T = Perspective[Command.Edit, Command.Perspective] |
|
210 |
val empty: T = Perspective(false, Command.Perspective.empty, Overlays.empty) |
|
211 |
def is_empty(perspective: T): Boolean = |
|
212 |
!perspective.required && |
|
213 |
perspective.visible.is_empty && |
|
214 |
perspective.overlays.is_empty |
|
215 |
} |
|
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
216 |
|
| 52887 | 217 |
|
218 |
/* commands */ |
|
219 |
||
| 75393 | 220 |
object Commands {
|
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
221 |
def apply(commands: Linear_Set[Command]): Commands = new Commands(commands) |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
222 |
val empty: Commands = apply(Linear_Set.empty) |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
223 |
|
| 75393 | 224 |
def starts( |
225 |
commands: Iterator[Command], |
|
|
77006
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
226 |
init: Int = 0, |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
227 |
count: Command => Int = _.length |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
228 |
) : Iterator[(Command, Int)] = {
|
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
229 |
var i = init |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
230 |
for (command <- commands) yield {
|
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
231 |
val start = i |
|
77006
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
232 |
i += count(command) |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
233 |
(command, start) |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
234 |
} |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
235 |
} |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
236 |
|
| 75393 | 237 |
def starts_pos( |
238 |
commands: Iterator[Command], |
|
239 |
pos: Token.Pos = Token.Pos.start |
|
240 |
) : Iterator[(Command, Token.Pos)] = {
|
|
| 67895 | 241 |
var p = pos |
242 |
for (command <- commands) yield {
|
|
243 |
val start = p |
|
| 73359 | 244 |
p = command.span.content.foldLeft(p)(_.advance(_)) |
| 67895 | 245 |
(command, start) |
246 |
} |
|
247 |
} |
|
248 |
||
|
56398
15d0821c8667
afford larger full_index, to save a few milliseconds during rendering (notably text_overview);
wenzelm
parents:
56394
diff
changeset
|
249 |
private val block_size = 256 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
250 |
} |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
251 |
|
| 75393 | 252 |
final class Commands private(val commands: Linear_Set[Command]) {
|
|
77006
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
253 |
lazy val start_lines: Map[Document_ID.Command, Int] = |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
254 |
(for {
|
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
255 |
(command, line) <- |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
256 |
Node.Commands.starts(commands.iterator, init = 1, |
| 77007 | 257 |
count = cmd => Library.count_newlines(cmd.source)) |
|
77006
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
258 |
} yield command.id -> line).toMap |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
259 |
|
| 56314 | 260 |
lazy val load_commands: List[Command] = |
| 59319 | 261 |
commands.iterator.filter(cmd => cmd.blobs.nonEmpty).toList |
| 54462 | 262 |
|
| 75393 | 263 |
private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) = {
|
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
264 |
val blocks = new mutable.ListBuffer[(Command, Text.Offset)] |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
265 |
var next_block = 0 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
266 |
var last_stop = 0 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
267 |
for ((command, start) <- Commands.starts(commands.iterator)) {
|
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
268 |
last_stop = start + command.length |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
269 |
while (last_stop + 1 > next_block) {
|
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
270 |
blocks += (command -> start) |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
271 |
next_block += Commands.block_size |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
272 |
} |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
273 |
} |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
274 |
(blocks.toArray, Text.Range(0, last_stop)) |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
275 |
} |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
276 |
|
| 66043 | 277 |
private def full_range: Text.Range = full_index._2 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
278 |
|
| 75393 | 279 |
def iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = {
|
| 59319 | 280 |
if (commands.nonEmpty && full_range.contains(i)) {
|
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
281 |
val (cmd0, start0) = full_index._1(i / Commands.block_size) |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
282 |
Node.Commands.starts(commands.iterator(cmd0), start0) dropWhile {
|
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
283 |
case (cmd, start) => start + cmd.length <= i } |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
284 |
} |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
285 |
else Iterator.empty |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
286 |
} |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
287 |
} |
| 57614 | 288 |
|
289 |
val empty: Node = new Node() |
|
| 76903 | 290 |
|
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
291 |
def init_blob(blob: Blobs.Item): Node = |
|
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
292 |
new Node(get_blob = Some(blob.unchanged)) |
| 38151 | 293 |
} |
294 |
||
| 46712 | 295 |
final class Node private( |
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
296 |
val get_blob: Option[Blobs.Item] = None, |
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
297 |
val header: Node.Header = Node.no_header, |
|
63584
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
wenzelm
parents:
63579
diff
changeset
|
298 |
val syntax: Option[Outer_Syntax] = None, |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
299 |
val text_perspective: Text.Perspective = Text.Perspective.empty, |
| 76702 | 300 |
val perspective: Node.Perspective_Command.T = Node.Perspective_Command.empty, |
| 75393 | 301 |
_commands: Node.Commands = Node.Commands.empty |
302 |
) {
|
|
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
303 |
def is_empty: Boolean = |
|
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
304 |
get_blob.isEmpty && |
|
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
305 |
header == Node.no_header && |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
306 |
text_perspective.is_empty && |
| 76702 | 307 |
Node.Perspective_Command.is_empty(perspective) && |
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
308 |
commands.isEmpty |
|
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
309 |
|
|
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59695
diff
changeset
|
310 |
def has_header: Boolean = header != Node.no_header |
|
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59695
diff
changeset
|
311 |
|
| 69556 | 312 |
override def toString: String = |
313 |
if (is_empty) "empty" |
|
314 |
else if (get_blob.isDefined) "blob" |
|
315 |
else "node" |
|
316 |
||
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
317 |
def commands: Linear_Set[Command] = _commands.commands |
|
77006
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
318 |
def command_start_line(command: Command): Option[Int] = |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
319 |
_commands.start_lines.get(command.id) |
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
320 |
def load_commands: List[Command] = _commands.load_commands |
| 64799 | 321 |
def load_commands_changed(doc_blobs: Blobs): Boolean = |
322 |
load_commands.exists(_.blobs_changed(doc_blobs)) |
|
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
323 |
|
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
324 |
def update_header(new_header: Node.Header): Node = |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
325 |
new Node(get_blob, new_header, syntax, text_perspective, perspective, _commands) |
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
57976
diff
changeset
|
326 |
|
|
63584
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
wenzelm
parents:
63579
diff
changeset
|
327 |
def update_syntax(new_syntax: Option[Outer_Syntax]): Node = |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
328 |
new Node(get_blob, header, new_syntax, text_perspective, perspective, _commands) |
|
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
329 |
|
|
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
330 |
def update_perspective( |
|
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
331 |
new_text_perspective: Text.Perspective, |
| 76702 | 332 |
new_perspective: Node.Perspective_Command.T): Node = |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
333 |
new Node(get_blob, header, syntax, new_text_perspective, new_perspective, _commands) |
| 46680 | 334 |
|
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
335 |
def edit_perspective: Node.Edit[Text.Edit, Text.Perspective] = |
|
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
336 |
Node.Perspective(perspective.required, text_perspective, perspective.overlays) |
| 46680 | 337 |
|
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
338 |
def same_perspective( |
|
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
339 |
other_text_perspective: Text.Perspective, |
| 76702 | 340 |
other_perspective: Node.Perspective_Command.T): Boolean = |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
341 |
text_perspective == other_text_perspective && |
| 52849 | 342 |
perspective.required == other_perspective.required && |
343 |
perspective.visible.same(other_perspective.visible) && |
|
344 |
perspective.overlays == other_perspective.overlays |
|
|
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52568
diff
changeset
|
345 |
|
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
346 |
def update_commands(new_commands: Linear_Set[Command]): Node = |
|
52918
038458a4d11b
proper low-level comparison -- heed warning by Scala compiler;
wenzelm
parents:
52901
diff
changeset
|
347 |
if (new_commands eq _commands.commands) this |
| 76759 | 348 |
else {
|
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
349 |
new Node(get_blob, header, syntax, text_perspective, perspective, |
|
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
350 |
Node.Commands(new_commands)) |
| 76759 | 351 |
} |
| 38151 | 352 |
|
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
353 |
def command_iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
|
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
354 |
_commands.iterator(i) |
| 38151 | 355 |
|
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
356 |
def command_iterator(range: Text.Range): Iterator[(Command, Text.Offset)] = |
|
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
357 |
command_iterator(range.start) takeWhile { case (_, start) => start < range.stop }
|
| 38151 | 358 |
|
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
359 |
def command_start(cmd: Command): Option[Text.Offset] = |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
360 |
Node.Commands.starts(commands.iterator).find(_._1 == cmd).map(_._2) |
| 67247 | 361 |
|
| 76924 | 362 |
lazy val source_wellformed: Boolean = |
| 76916 | 363 |
get_blob match {
|
| 76924 | 364 |
case Some(blob) => blob.source_wellformed |
| 76916 | 365 |
case None => true |
366 |
} |
|
367 |
||
|
76204
b80b2fbc46c3
clarified signature: persistent Node.source / Snapshot.source;
wenzelm
parents:
75914
diff
changeset
|
368 |
lazy val source: String = |
| 67247 | 369 |
get_blob match {
|
|
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67264
diff
changeset
|
370 |
case Some(blob) => blob.source |
| 75819 | 371 |
case None => command_iterator().map({ case (cmd, _) => cmd.source }).mkString
|
| 67247 | 372 |
} |
| 38151 | 373 |
} |
374 |
||
375 |
||
| 46723 | 376 |
/* development graph */ |
377 |
||
| 75393 | 378 |
object Nodes {
|
| 46723 | 379 |
val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering)) |
| 77299 | 380 |
|
381 |
private def init(graph: Graph[Node.Name, Node], name: Node.Name): Graph[Node.Name, Node] = |
|
382 |
graph.default_node(name, Node.empty) |
|
| 46723 | 383 |
} |
384 |
||
| 75393 | 385 |
final class Nodes private(graph: Graph[Node.Name, Node]) {
|
| 77299 | 386 |
def apply(name: Node.Name): Node = Nodes.init(graph, name).get_node(name) |
| 46723 | 387 |
|
| 83163 | 388 |
def suppressed(name: Node.Name): Boolean = {
|
| 77299 | 389 |
val graph1 = Nodes.init(graph, name) |
| 57619 | 390 |
graph1.is_maximal(name) && graph1.get_node(name).is_empty |
391 |
} |
|
| 57617 | 392 |
|
|
68300
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
393 |
def purge_suppressed: Option[Nodes] = |
| 83163 | 394 |
graph.keys_iterator.filter(suppressed).toList match {
|
| 67112 | 395 |
case Nil => None |
| 73359 | 396 |
case del => Some(new Nodes(del.foldLeft(graph)(_.del_node(_)))) |
| 67112 | 397 |
} |
|
67110
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
wenzelm
parents:
67014
diff
changeset
|
398 |
|
| 75393 | 399 |
def + (entry: (Node.Name, Node)): Nodes = {
|
| 46723 | 400 |
val (name, node) = entry |
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70636
diff
changeset
|
401 |
val imports = node.header.imports |
| 77299 | 402 |
val graph1 = (name :: imports).foldLeft(graph)(Nodes.init) |
| 73359 | 403 |
val graph2 = |
404 |
graph1.imm_preds(name).foldLeft(graph1) { case (g, dep) => g.del_edge(dep, name) }
|
|
405 |
val graph3 = imports.foldLeft(graph2) { case (g, dep) => g.add_edge(dep, name) }
|
|
|
67110
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
wenzelm
parents:
67014
diff
changeset
|
406 |
new Nodes(graph3.map_node(name, _ => node)) |
| 46723 | 407 |
} |
408 |
||
| 68321 | 409 |
def domain: Set[Node.Name] = graph.domain |
410 |
||
|
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
411 |
def iterator: Iterator[(Node.Name, Node)] = |
|
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
412 |
graph.iterator.map({ case (name, (node, _)) => (name, node) })
|
| 46723 | 413 |
|
|
70539
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70284
diff
changeset
|
414 |
def theory_name(theory: String): Option[Node.Name] = |
|
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70284
diff
changeset
|
415 |
graph.keys_iterator.find(name => name.theory == theory) |
|
30b3c58a1933
support Export_Theory.read_proof, based on theory_name and serial;
wenzelm
parents:
70284
diff
changeset
|
416 |
|
| 64799 | 417 |
def commands_loading(file_name: Node.Name): List[Command] = |
| 54528 | 418 |
(for {
|
|
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
419 |
(_, node) <- iterator |
| 56314 | 420 |
cmd <- node.load_commands.iterator |
|
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54528
diff
changeset
|
421 |
name <- cmd.blobs_names.iterator |
| 54528 | 422 |
if name == file_name |
423 |
} yield cmd).toList |
|
424 |
||
| 77301 | 425 |
def descendants(names: List[Node.Name]): List[Node.Name] = |
426 |
names.foldLeft(graph)(Nodes.init).all_succs(names) |
|
| 46723 | 427 |
def topological_order: List[Node.Name] = graph.topological_order |
| 56337 | 428 |
|
429 |
override def toString: String = topological_order.mkString("Nodes(", ",", ")")
|
|
| 46723 | 430 |
} |
431 |
||
432 |
||
| 38424 | 433 |
|
434 |
/** versioning **/ |
|
435 |
||
436 |
/* particular document versions */ |
|
| 34485 | 437 |
|
| 75393 | 438 |
object Version {
|
| 46681 | 439 |
val init: Version = new Version() |
|
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
57976
diff
changeset
|
440 |
def make(nodes: Nodes): Version = new Version(Document_ID.make(), nodes) |
| 67112 | 441 |
|
| 75393 | 442 |
def purge_future( |
443 |
versions: Map[Document_ID.Version, Version], |
|
444 |
future: Future[Version] |
|
445 |
) : Future[Version] = {
|
|
|
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
446 |
if (future.is_finished) {
|
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
447 |
val version = future.join |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
448 |
versions.get(version.id) match {
|
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
449 |
case Some(version1) if !(version eq version1) => Future.value(version1) |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
450 |
case _ => future |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
451 |
} |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
452 |
} |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
453 |
else future |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
454 |
} |
|
68300
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
455 |
|
|
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
456 |
def purge_suppressed( |
| 75393 | 457 |
versions: Map[Document_ID.Version, Version] |
458 |
): Map[Document_ID.Version, Version] = {
|
|
| 73359 | 459 |
(for ((id, v) <- versions.iterator; v1 <- v.purge_suppressed) yield (id, v1)). |
460 |
foldLeft(versions)(_ + _) |
|
|
68300
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
461 |
} |
| 38417 | 462 |
} |
463 |
||
| 46712 | 464 |
final class Version private( |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
465 |
val id: Document_ID.Version = Document_ID.none, |
| 75393 | 466 |
val nodes: Nodes = Nodes.empty |
467 |
) {
|
|
| 55777 | 468 |
override def toString: String = "Version(" + id + ")"
|
|
67110
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
wenzelm
parents:
67014
diff
changeset
|
469 |
|
|
68299
0b5a23477911
clarified signature -- avoid confusion with Resources.is_hidden;
wenzelm
parents:
68114
diff
changeset
|
470 |
def purge_suppressed: Option[Version] = |
|
68300
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
471 |
nodes.purge_suppressed.map(new Version(id, _)) |
| 46941 | 472 |
} |
| 34660 | 473 |
|
| 34859 | 474 |
|
| 38424 | 475 |
/* changes of plain text, eventually resulting in document edits */ |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
476 |
|
| 75393 | 477 |
object Change {
|
| 46678 | 478 |
val init: Change = new Change() |
479 |
||
480 |
def make(previous: Future[Version], edits: List[Edit_Text], version: Future[Version]): Change = |
|
|
57620
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
481 |
new Change(Some(previous), edits.reverse, version) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
482 |
} |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
483 |
|
| 46712 | 484 |
final class Change private( |
| 46677 | 485 |
val previous: Option[Future[Version]] = Some(Future.value(Version.init)), |
|
57620
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
486 |
val rev_edits: List[Edit_Text] = Nil, |
| 75393 | 487 |
val version: Future[Version] = Future.value(Version.init) |
488 |
) {
|
|
| 44672 | 489 |
def is_finished: Boolean = |
490 |
(previous match { case None => true case Some(future) => future.is_finished }) &&
|
|
491 |
version.is_finished |
|
492 |
||
| 46678 | 493 |
def truncate: Change = new Change(None, Nil, version) |
|
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
494 |
|
| 75393 | 495 |
def purge(versions: Map[Document_ID.Version, Version]): Option[Change] = {
|
|
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
496 |
val previous1 = previous.map(Version.purge_future(versions, _)) |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
497 |
val version1 = Version.purge_future(versions, version) |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
498 |
if ((previous eq previous1) && (version eq version1)) None |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
499 |
else Some(new Change(previous1, rev_edits, version1)) |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
500 |
} |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
501 |
} |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
502 |
|
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
503 |
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
504 |
/* history navigation */ |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
505 |
|
| 75393 | 506 |
object History {
|
| 46679 | 507 |
val init: History = new History() |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
508 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
509 |
|
| 46712 | 510 |
final class History private( |
| 75393 | 511 |
val undo_list: List[Change] = List(Change.init) // non-empty list |
512 |
) {
|
|
| 67114 | 513 |
override def toString: String = "History(" + undo_list.length + ")"
|
514 |
||
| 46679 | 515 |
def tip: Change = undo_list.head |
516 |
def + (change: Change): History = new History(change :: undo_list) |
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
517 |
|
| 75393 | 518 |
def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] = {
|
| 46679 | 519 |
val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1 |
520 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
521 |
||
522 |
retained.splitAt(retained.length - 1) match {
|
|
523 |
case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate))) |
|
524 |
case _ => None |
|
525 |
} |
|
526 |
} |
|
|
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
527 |
|
| 75393 | 528 |
def purge(versions: Map[Document_ID.Version, Version]): History = {
|
|
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
529 |
val undo_list1 = undo_list.map(_.purge(versions)) |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
530 |
if (undo_list1.forall(_.isEmpty)) this |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
531 |
else new History(for ((a, b) <- undo_list1 zip undo_list) yield a.getOrElse(b)) |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
532 |
} |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
533 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
534 |
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
535 |
|
| 72818 | 536 |
/* snapshot: persistent user-view of document state */ |
| 38424 | 537 |
|
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
538 |
object Pending_Edits {
|
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
539 |
val empty: Pending_Edits = make(Nil) |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
540 |
|
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
541 |
def make(models: Iterable[Model]): Pending_Edits = |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
542 |
new Pending_Edits( |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
543 |
(for {
|
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
544 |
model <- models.iterator |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
545 |
edits = model.pending_edits if edits.nonEmpty |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
546 |
} yield model.node_name -> edits).toMap) |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
547 |
} |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
548 |
|
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
549 |
final class Pending_Edits(pending_edits: Map[Node.Name, List[Text.Edit]]) {
|
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
550 |
def is_stable: Boolean = pending_edits.isEmpty |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
551 |
|
| 76905 | 552 |
def + (entry: (Node.Name, List[Text.Edit])): Pending_Edits = {
|
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
553 |
val (name, es) = entry |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
554 |
if (es.isEmpty) this |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
555 |
else new Pending_Edits(pending_edits + (name -> (es ::: edits(name)))) |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
556 |
} |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
557 |
|
| 76905 | 558 |
def edits(name: Node.Name): List[Text.Edit] = |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
559 |
pending_edits.getOrElse(name, Nil) |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
560 |
|
| 76905 | 561 |
def reverse_edits(name: Node.Name): List[Text.Edit] = |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
562 |
reverse_pending_edits.getOrElse(name, Nil) |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
563 |
|
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
564 |
private lazy val reverse_pending_edits = |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
565 |
(for ((name, es) <- pending_edits.iterator) yield (name, es.reverse)).toMap |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
566 |
} |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
567 |
|
| 75393 | 568 |
object Snapshot {
|
| 71601 | 569 |
val init: Snapshot = State.init.snapshot() |
| 52972 | 570 |
} |
571 |
||
| 72821 | 572 |
class Snapshot private[Document]( |
| 72818 | 573 |
val state: State, |
574 |
val version: Version, |
|
575 |
val node_name: Node.Name, |
|
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
576 |
pending_edits: Pending_Edits, |
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
577 |
val snippet_commands: List[Command] |
| 75393 | 578 |
) {
|
| 72821 | 579 |
override def toString: String = |
580 |
"Snapshot(node = " + node_name.node + ", version = " + version.id + |
|
581 |
(if (is_outdated) ", outdated" else "") + ")" |
|
582 |
||
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
583 |
def switch(name: Node.Name): Snapshot = |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
584 |
if (name == node_name) this |
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
585 |
else new Snapshot(state, version, name, pending_edits, Nil) |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
586 |
|
| 72821 | 587 |
|
| 72822 | 588 |
/* nodes */ |
589 |
||
| 72823 | 590 |
def get_node(name: Node.Name): Node = version.nodes(name) |
591 |
||
592 |
val node: Node = get_node(node_name) |
|
| 72822 | 593 |
|
594 |
def node_files: List[Node.Name] = |
|
|
72829
a28a4105883f
avoid duplicate entries: snippet_command is defined within node;
wenzelm
parents:
72823
diff
changeset
|
595 |
node_name :: node.load_commands.flatMap(_.blobs_names) |
| 72822 | 596 |
|
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
597 |
def node_export_files: List[(Symbol.Offset, String)] = |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
598 |
for ((i, name) <- (0, node_name) :: node.load_commands.flatMap(_.blobs_files)) |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
599 |
yield (i, File.symbolic_path(name.path)) |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
600 |
|
|
77161
913c781ff6ba
support document preparation from already loaded theories;
wenzelm
parents:
77147
diff
changeset
|
601 |
def node_consolidated(name: Node.Name): Boolean = |
| 77147 | 602 |
state.node_consolidated(version, name) |
603 |
||
|
77197
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77161
diff
changeset
|
604 |
def theory_consolidated(theory: String): Boolean = |
|
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77161
diff
changeset
|
605 |
version.nodes.theory_name(theory) match {
|
|
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77161
diff
changeset
|
606 |
case Some(name) => node_consolidated(name) |
|
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77161
diff
changeset
|
607 |
case None => false |
|
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77161
diff
changeset
|
608 |
} |
|
a541da01ba67
clarified signature selection: SortedSet[String], which fits better to stored json and works properly on Windows (NB: document theories have an authentic session-theory name);
wenzelm
parents:
77161
diff
changeset
|
609 |
|
|
82946
962b73cc57dc
clarified signature: more self-contained operation;
wenzelm
parents:
82935
diff
changeset
|
610 |
def loaded_theory_command(caret_offset: Text.Offset): Option[(Command, Text.Range)] = |
|
962b73cc57dc
clarified signature: more self-contained operation;
wenzelm
parents:
82935
diff
changeset
|
611 |
if (node_name.is_theory) {
|
|
82935
2b7080493211
more accurate output, based on persistent "command_range" markup;
wenzelm
parents:
82931
diff
changeset
|
612 |
node.commands.get_after(None) match {
|
|
82946
962b73cc57dc
clarified signature: more self-contained operation;
wenzelm
parents:
82935
diff
changeset
|
613 |
case Some(command) if command.span.is_theory => |
|
962b73cc57dc
clarified signature: more self-contained operation;
wenzelm
parents:
82935
diff
changeset
|
614 |
Some(command -> command_range(Text.Range(caret_offset)).getOrElse(Text.Range.offside)) |
|
82935
2b7080493211
more accurate output, based on persistent "command_range" markup;
wenzelm
parents:
82931
diff
changeset
|
615 |
case _ => None |
|
2b7080493211
more accurate output, based on persistent "command_range" markup;
wenzelm
parents:
82931
diff
changeset
|
616 |
} |
|
2b7080493211
more accurate output, based on persistent "command_range" markup;
wenzelm
parents:
82931
diff
changeset
|
617 |
} |
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
618 |
else {
|
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
619 |
for {
|
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
620 |
command <- version.nodes.commands_loading(node_name).find(_.span.is_theory) |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
621 |
(symbol_offset, _) <- command.blobs_files.find({ case (_, name) => node_name == name })
|
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
622 |
} yield {
|
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
623 |
val chunk_offset = command.chunk.decode(symbol_offset) |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
624 |
val command_range = switch(command.node_name).command_range(Text.Range(chunk_offset)) |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
625 |
command -> command_range.getOrElse(Text.Range.offside) |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
626 |
} |
|
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82946
diff
changeset
|
627 |
} |
|
82935
2b7080493211
more accurate output, based on persistent "command_range" markup;
wenzelm
parents:
82931
diff
changeset
|
628 |
|
| 72822 | 629 |
|
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
630 |
/* pending edits */ |
| 72820 | 631 |
|
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
632 |
def is_outdated: Boolean = !pending_edits.is_stable |
| 72820 | 633 |
|
634 |
def convert(offset: Text.Offset): Text.Offset = |
|
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
635 |
pending_edits.edits(node_name).foldLeft(offset) { case (i, edit) => edit.convert(i) }
|
| 72820 | 636 |
def revert(offset: Text.Offset): Text.Offset = |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
637 |
pending_edits.reverse_edits(node_name).foldLeft(offset) { case (i, edit) => edit.revert(i) }
|
| 72820 | 638 |
|
639 |
def convert(range: Text.Range): Text.Range = range.map(convert) |
|
640 |
def revert(range: Text.Range): Text.Range = range.map(revert) |
|
641 |
||
| 52972 | 642 |
|
| 72821 | 643 |
/* theory load commands */ |
644 |
||
645 |
val commands_loading: List[Command] = |
|
646 |
if (node_name.is_theory) Nil |
|
647 |
else version.nodes.commands_loading(node_name) |
|
648 |
||
649 |
def commands_loading_ranges(pred: Node.Name => Boolean): List[Text.Range] = |
|
650 |
(for {
|
|
651 |
cmd <- node.load_commands.iterator |
|
652 |
blob_name <- cmd.blobs_names.iterator |
|
653 |
if pred(blob_name) |
|
654 |
start <- node.command_start(cmd) |
|
655 |
} yield convert(cmd.core_range + start)).toList |
|
656 |
||
657 |
||
| 82738 | 658 |
/* add-on snippet via pro-forma commands */ |
| 72821 | 659 |
|
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
660 |
def snippet(commands: List[Command], doc_blobs: Blobs): Snapshot = {
|
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
661 |
require(commands.nonEmpty, "no snippet commands") |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
662 |
|
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
663 |
val node_name = commands.head.node_name |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
664 |
val node_commands = Linear_Set.from(commands) |
| 72718 | 665 |
|
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
666 |
require(commands.forall(command => command.node_name == node_name), |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
667 |
"incoherent snippet node names") |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
668 |
|
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
669 |
val blobs = |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
670 |
for {
|
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
671 |
command <- commands |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
672 |
a <- command.blobs_names |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
673 |
b <- doc_blobs.get(a) |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
674 |
} yield a -> b |
|
76915
e5f67cfedecd
proper Node.init_blobs, not just edits (amending ca872f20cf5b);
wenzelm
parents:
76913
diff
changeset
|
675 |
|
| 72718 | 676 |
val nodes0 = version.nodes |
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
677 |
val nodes1 = nodes0 + (node_name -> nodes0(node_name).update_commands(node_commands)) |
|
76915
e5f67cfedecd
proper Node.init_blobs, not just edits (amending ca872f20cf5b);
wenzelm
parents:
76913
diff
changeset
|
678 |
val nodes2 = blobs.foldLeft(nodes1) { case (ns, (a, b)) => ns + (a -> Node.init_blob(b)) }
|
|
e5f67cfedecd
proper Node.init_blobs, not just edits (amending ca872f20cf5b);
wenzelm
parents:
76913
diff
changeset
|
679 |
val version1 = Version.make(nodes2) |
| 72718 | 680 |
|
|
81422
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
681 |
val text_edits: List[Text.Edit] = {
|
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
682 |
var offset = 0 |
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
683 |
val result = new mutable.ListBuffer[Text.Edit] |
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
684 |
for (command <- commands) {
|
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
685 |
result += Text.Edit.insert(offset, command.source) |
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
686 |
offset += command.source.length |
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
687 |
} |
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
688 |
result.toList |
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
689 |
} |
|
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
690 |
|
| 72718 | 691 |
val edits: List[Edit_Text] = |
|
81422
b6928aa389f7
minor performance tuning: avoid concatenation of existing string material;
wenzelm
parents:
81414
diff
changeset
|
692 |
List(node_name -> Node.Edits(text_edits)) ::: |
|
76915
e5f67cfedecd
proper Node.init_blobs, not just edits (amending ca872f20cf5b);
wenzelm
parents:
76913
diff
changeset
|
693 |
blobs.map({ case (a, b) => a -> Node.Blob(b) })
|
| 72718 | 694 |
|
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
695 |
val assign_update: Assign_Update = |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
696 |
commands.map(command => command.id -> List(Document_ID.make())) |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
697 |
|
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
698 |
val state0 = commands.foldLeft(state)(_.define_command(_)) |
| 72718 | 699 |
val state1 = |
700 |
state0.continue_history(Future.value(version), edits, Future.value(version1)) |
|
701 |
.define_version(version1, state0.the_assignment(version)) |
|
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
702 |
.assign(version1.id, Nil, assign_update)._2 |
| 72718 | 703 |
|
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
704 |
state1.snapshot(node_name = node_name, snippet_commands = commands) |
| 72718 | 705 |
} |
706 |
||
| 72821 | 707 |
|
| 76932 | 708 |
/* markup and messages */ |
| 72821 | 709 |
|
| 72723 | 710 |
def xml_markup( |
| 72821 | 711 |
range: Text.Range = Text.Range.full, |
712 |
elements: Markup.Elements = Markup.Elements.full): XML.Body = |
|
713 |
state.xml_markup(version, node_name, range = range, elements = elements) |
|
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
714 |
|
| 72869 | 715 |
lazy val messages: List[(XML.Elem, Position.T)] = |
| 72821 | 716 |
(for {
|
717 |
(command, start) <- |
|
| 76905 | 718 |
Node.Commands.starts_pos(node.commands.iterator, Token.Pos.file(node_name.node)) |
| 72821 | 719 |
pos = command.span.keyword_pos(start).position(command.span.name) |
| 72869 | 720 |
(_, elem) <- state.command_results(version, command).iterator |
721 |
} yield (elem, pos)).toList |
|
| 72821 | 722 |
|
723 |
||
724 |
/* exports */ |
|
725 |
||
726 |
lazy val exports: List[Export.Entry] = |
|
727 |
state.node_exports(version, node_name).iterator.map(_._2).toList |
|
728 |
||
|
75770
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
wenzelm
parents:
75394
diff
changeset
|
729 |
lazy val all_exports: Map[Export.Entry_Name, Export.Entry] = |
|
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
wenzelm
parents:
75394
diff
changeset
|
730 |
(for {
|
|
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
wenzelm
parents:
75394
diff
changeset
|
731 |
(name, _) <- version.nodes.iterator |
|
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
wenzelm
parents:
75394
diff
changeset
|
732 |
(_, entry) <- state.node_exports(version, name).iterator |
|
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
wenzelm
parents:
75394
diff
changeset
|
733 |
if entry.entry_name.session == Sessions.DRAFT |
|
62e2c6f65f9a
clarified Document.Snapshot.all_exports: refer to material from this (virtual) session;
wenzelm
parents:
75394
diff
changeset
|
734 |
} yield entry.entry_name -> entry).toMap |
| 72821 | 735 |
|
736 |
||
737 |
/* find command */ |
|
738 |
||
739 |
def find_command(id: Document_ID.Generic): Option[(Node, Command)] = |
|
740 |
state.lookup_id(id) match {
|
|
741 |
case None => None |
|
742 |
case Some(st) => |
|
743 |
val command = st.command |
|
| 72823 | 744 |
val command_node = get_node(command.node_name) |
745 |
if (command_node.commands.contains(command)) Some((command_node, command)) else None |
|
| 72821 | 746 |
} |
| 66040 | 747 |
|
| 77004 | 748 |
def find_command_position( |
749 |
id: Document_ID.Generic, |
|
750 |
offset: Symbol.Offset |
|
751 |
): Option[Line.Node_Position] = {
|
|
| 72821 | 752 |
for ((node, command) <- find_command(id)) |
753 |
yield {
|
|
754 |
val name = command.node_name.node |
|
755 |
val sources_iterator = |
|
756 |
node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
|
757 |
(if (offset == 0) Iterator.empty |
|
758 |
else Iterator.single(command.source(Text.Range(0, command.chunk.decode(offset))))) |
|
| 73359 | 759 |
val pos = sources_iterator.foldLeft(Line.Position.zero)(_.advance(_)) |
| 72821 | 760 |
Line.Node_Position(name, pos) |
761 |
} |
|
| 77004 | 762 |
} |
| 72821 | 763 |
|
|
77006
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
764 |
def find_command_line(id: Document_ID.Generic, offset: Symbol.Offset): Option[Int] = |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
765 |
for {
|
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
766 |
(node, command) <- find_command(id) |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
767 |
range = Text.Range(0, command.chunk.decode(offset)) |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
768 |
text <- range.try_substring(command.source) |
|
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
769 |
line <- node.command_start_line(command) |
| 77007 | 770 |
} yield line + Library.count_newlines(text) |
|
77006
d9a4b3a73d8c
more efficient, thanks to persistent lazy data in Document.Node;
wenzelm
parents:
77004
diff
changeset
|
771 |
|
| 72821 | 772 |
def current_command(other_node_name: Node.Name, offset: Text.Offset): Option[Command] = |
773 |
if (other_node_name.is_theory) {
|
|
| 72823 | 774 |
val other_node = get_node(other_node_name) |
| 72821 | 775 |
val iterator = other_node.command_iterator(revert(offset) max 0) |
776 |
if (iterator.hasNext) {
|
|
| 73344 | 777 |
val (command0, _) = iterator.next() |
| 72821 | 778 |
other_node.commands.reverse.iterator(command0).find(command => !command.is_ignored) |
779 |
} |
|
780 |
else other_node.commands.reverse.iterator.find(command => !command.is_ignored) |
|
781 |
} |
|
782 |
else version.nodes.commands_loading(other_node_name).headOption |
|
783 |
||
784 |
||
785 |
/* command results */ |
|
786 |
||
787 |
def command_results(range: Text.Range): Command.Results = |
|
788 |
Command.State.merge_results( |
|
| 75393 | 789 |
select[List[Command.State]](range, Markup.Elements.full, |
| 75394 | 790 |
command_states => _ => Some(command_states)).flatMap(_.info)) |
| 72821 | 791 |
|
792 |
def command_results(command: Command): Command.Results = |
|
793 |
state.command_results(version, command) |
|
794 |
||
795 |
||
796 |
/* cumulate markup */ |
|
| 64665 | 797 |
|
|
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
798 |
def cumulate[A]( |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
799 |
range: Text.Range, |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
800 |
info: A, |
| 56743 | 801 |
elements: Markup.Elements, |
|
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
802 |
result: List[Command.State] => (A, Text.Markup) => Option[A], |
| 75393 | 803 |
status: Boolean = false |
804 |
): List[Text.Info[A]] = {
|
|
| 72821 | 805 |
val former_range = revert(range).inflate_singularity |
806 |
val (chunk_name, command_iterator) = |
|
807 |
commands_loading.headOption match {
|
|
808 |
case None => (Symbol.Text_Chunk.Default, node.command_iterator(former_range)) |
|
809 |
case Some(command) => (Symbol.Text_Chunk.File(node_name.node), Iterator((command, 0))) |
|
810 |
} |
|
811 |
val markup_index = Command.Markup_Index(status, chunk_name) |
|
812 |
(for {
|
|
813 |
(command, command_start) <- command_iterator |
|
814 |
chunk <- command.chunks.get(chunk_name).iterator |
|
815 |
states = state.command_states(version, command) |
|
816 |
res = result(states) |
|
817 |
markup_range <- (former_range - command_start).try_restrict(chunk.range).iterator |
|
818 |
markup = Command.State.merge_markup(states, markup_index, markup_range, elements) |
|
819 |
Text.Info(r0, a) <- markup.cumulate[A](markup_range, info, elements, |
|
820 |
{
|
|
821 |
case (a, Text.Info(r0, b)) => res(a, Text.Info(convert(r0 + command_start), b)) |
|
822 |
}).iterator |
|
823 |
r1 <- convert(r0 + command_start).try_restrict(range).iterator |
|
824 |
} yield Text.Info(r1, a)).toList |
|
825 |
} |
|
|
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
826 |
|
|
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
827 |
def select[A]( |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
828 |
range: Text.Range, |
| 56743 | 829 |
elements: Markup.Elements, |
|
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
830 |
result: List[Command.State] => Text.Markup => Option[A], |
| 75393 | 831 |
status: Boolean = false |
832 |
): List[Text.Info[A]] = {
|
|
833 |
def result1(states: List[Command.State]): (Option[A], Text.Markup) => Option[Option[A]] = {
|
|
| 72821 | 834 |
val res = result(states) |
835 |
(_: Option[A], x: Text.Markup) => |
|
836 |
res(x) match {
|
|
837 |
case None => None |
|
838 |
case some => Some(some) |
|
839 |
} |
|
840 |
} |
|
| 78592 | 841 |
for (case Text.Info(r, Some(x)) <- cumulate(range, None, elements, result1, status)) |
| 72821 | 842 |
yield Text.Info(r, x) |
843 |
} |
|
|
82906
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
844 |
|
|
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
845 |
|
|
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
846 |
/* command spans --- according to PIDE markup */ |
|
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
847 |
|
|
82931
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
848 |
// Text.Info: core range |
| 82908 | 849 |
def command_spans(range: Text.Range = Text.Range.full): List[Text.Info[Markup.Command_Span.Args]] = |
|
82906
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
850 |
select(range, Markup.Elements(Markup.COMMAND_SPAN), _ => |
|
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
851 |
{
|
| 82907 | 852 |
case Text.Info(range, XML.Elem(Markup.Command_Span(args), _)) => |
853 |
Some(Text.Info(range, args)) |
|
|
82906
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
854 |
case _ => None |
|
a27841dcd7df
more direct support for "command_span" markup property "is_begin";
wenzelm
parents:
82790
diff
changeset
|
855 |
}).map(_.info) |
|
82931
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
856 |
|
|
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
857 |
// Text.Range: full source with trailing whitespace etc. |
|
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
858 |
def command_range(caret_range: Text.Range): Option[Text.Range] = |
|
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
859 |
select(caret_range, Markup.Elements(Markup.COMMAND_RANGE), _ => |
|
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
860 |
{
|
|
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
861 |
case Text.Info(range, _) => Some(range) |
|
fa8067dc6787
more markup for batch build: command ranges with trailing whitespace;
wenzelm
parents:
82918
diff
changeset
|
862 |
}).headOption.map(_.info) |
| 38424 | 863 |
} |
864 |
||
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
865 |
|
| 64814 | 866 |
/* model */ |
867 |
||
| 75393 | 868 |
trait Session {
|
| 82781 | 869 |
def session_options: Options |
| 65221 | 870 |
def resources: Resources |
| 82781 | 871 |
def store: Store |
| 65221 | 872 |
} |
873 |
||
| 75393 | 874 |
trait Model {
|
| 64814 | 875 |
def session: Session |
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
876 |
def is_stable: Boolean |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
877 |
def pending_edits: List[Text.Edit] |
| 64814 | 878 |
|
| 65356 | 879 |
def node_name: Node.Name |
| 64814 | 880 |
def is_theory: Boolean = node_name.is_theory |
881 |
override def toString: String = node_name.toString |
|
882 |
||
| 67014 | 883 |
def get_text(range: Text.Range): Option[String] |
| 66114 | 884 |
|
|
76703
8fac11f7f0f4
clarified state: node_required is guarded by PIDE.editor.document_active (e.g. open panel);
wenzelm
parents:
76702
diff
changeset
|
885 |
def node_required: Boolean |
|
76481
a9d52d02bd83
clarified node_required status: distinguish theory_required vs. document_required;
wenzelm
parents:
76235
diff
changeset
|
886 |
|
|
76904
e27d097d7d15
tuned signature: avoid confusion with Document.Node.Blob and Command.Blob;
wenzelm
parents:
76903
diff
changeset
|
887 |
def get_blob: Option[Blobs.Item] |
|
76792
23f433294173
support for generic File_Format.parse_data, with persistent result in document model;
wenzelm
parents:
76776
diff
changeset
|
888 |
|
|
23f433294173
support for generic File_Format.parse_data, with persistent result in document model;
wenzelm
parents:
76776
diff
changeset
|
889 |
def untyped_data: AnyRef |
|
23f433294173
support for generic File_Format.parse_data, with persistent result in document model;
wenzelm
parents:
76776
diff
changeset
|
890 |
def get_data[C](c: Class[C]): Option[C] = Library.as_subclass(c)(untyped_data) |
| 64815 | 891 |
|
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
892 |
def node_edits( |
| 64867 | 893 |
node_header: Node.Header, |
894 |
text_edits: List[Text.Edit], |
|
| 76702 | 895 |
perspective: Node.Perspective_Text.T |
| 75393 | 896 |
): List[Edit_Text] = {
|
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
897 |
val edits: List[Node.Edit[Text.Edit, Text.Perspective]] = |
|
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
898 |
get_blob match {
|
|
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
899 |
case None => |
|
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
900 |
List( |
| 65356 | 901 |
Node.Deps( |
| 82918 | 902 |
if (session.resources.loaded_theory(node_name)) {
|
| 66773 | 903 |
node_header.append_errors( |
904 |
List("Cannot update finished theory " + quote(node_name.theory)))
|
|
905 |
} |
|
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
906 |
else node_header), |
| 65356 | 907 |
Node.Edits(text_edits), perspective) |
908 |
case Some(blob) => List(Node.Blob(blob), Node.Edits(text_edits)) |
|
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
909 |
} |
|
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
910 |
edits.flatMap(edit => if (edit.is_void) None else Some(node_name -> edit)) |
|
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
911 |
} |
| 64814 | 912 |
} |
913 |
||
914 |
||
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
915 |
/** global state -- document structure, execution process, editing history **/ |
|
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
916 |
|
| 52563 | 917 |
type Assign_Update = |
918 |
List[(Document_ID.Command, List[Document_ID.Exec])] // update of exec state assignment |
|
|
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
919 |
|
| 75393 | 920 |
object State {
|
| 38373 | 921 |
class Fail(state: State) extends Exception |
922 |
||
| 75393 | 923 |
object Assignment {
|
| 46683 | 924 |
val init: Assignment = new Assignment() |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
925 |
} |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
926 |
|
| 46712 | 927 |
final class Assignment private( |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
928 |
val command_execs: Map[Document_ID.Command, List[Document_ID.Exec]] = Map.empty, |
| 75393 | 929 |
val is_finished: Boolean = false |
930 |
) {
|
|
| 67114 | 931 |
override def toString: String = "Assignment(" + command_execs.size + "," + is_finished + ")"
|
932 |
||
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73031
diff
changeset
|
933 |
def check_finished: Assignment = { require(is_finished, "assignment not finished"); this }
|
|
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
934 |
def unfinished: Assignment = new Assignment(command_execs, false) |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
935 |
|
| 75393 | 936 |
def assign(update: Assign_Update): Assignment = {
|
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73031
diff
changeset
|
937 |
require(!is_finished, "assignment already finished") |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
938 |
val command_execs1 = |
| 73359 | 939 |
update.foldLeft(command_execs) {
|
| 52563 | 940 |
case (res, (command_id, exec_ids)) => |
941 |
if (exec_ids.isEmpty) res - command_id |
|
942 |
else res + (command_id -> exec_ids) |
|
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
943 |
} |
|
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
944 |
new Assignment(command_execs1, true) |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
945 |
} |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
946 |
} |
| 46682 | 947 |
|
948 |
val init: State = |
|
|
70284
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69633
diff
changeset
|
949 |
State().define_version(Version.init, Assignment.init).assign(Version.init.id, Nil, Nil)._2 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
950 |
} |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
951 |
|
| 46712 | 952 |
final case class State private( |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
953 |
/*reachable versions*/ |
| 60215 | 954 |
versions: Map[Document_ID.Version, Version] = Map.empty, |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
955 |
/*inlined auxiliary files*/ |
| 60215 | 956 |
blobs: Set[SHA1.Digest] = Set.empty, |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
957 |
/*loaded theories in batch builds*/ |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
958 |
theories: Map[Document_ID.Exec, Command.State] = Map.empty, |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
959 |
/*static markup from define_command*/ |
| 60215 | 960 |
commands: Map[Document_ID.Command, Command.State] = Map.empty, |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
961 |
/*dynamic markup from execution*/ |
| 60215 | 962 |
execs: Map[Document_ID.Exec, Command.State] = Map.empty, |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
963 |
/*command-exec assignment for each version*/ |
| 60215 | 964 |
assignments: Map[Document_ID.Version, State.Assignment] = Map.empty, |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
965 |
/*commands with markup produced by other commands (imm_succs)*/ |
| 60215 | 966 |
commands_redirection: Graph[Document_ID.Command, Unit] = Graph.long, |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
967 |
/*explicit (linear) history*/ |
| 60215 | 968 |
history: History = History.init, |
|
57976
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
wenzelm
parents:
57842
diff
changeset
|
969 |
/*intermediate state between remove_versions/removed_versions*/ |
| 75393 | 970 |
removing_versions: Boolean = false |
971 |
) {
|
|
| 68496 | 972 |
override def toString: String = |
973 |
"State(versions = " + versions.size + |
|
974 |
", blobs = " + blobs.size + |
|
975 |
", commands = " + commands.size + |
|
976 |
", execs = " + execs.size + |
|
977 |
", assignments = " + assignments.size + |
|
978 |
", commands_redirection = " + commands_redirection.size + |
|
979 |
", history = " + history.undo_list.size + |
|
980 |
", removing_versions = " + removing_versions + ")" |
|
981 |
||
| 38373 | 982 |
private def fail[A]: A = throw new State.Fail(this) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
983 |
|
| 75393 | 984 |
def define_version(version: Version, assignment: State.Assignment): State = {
|
| 38417 | 985 |
val id = version.id |
986 |
copy(versions = versions + (id -> version), |
|
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
987 |
assignments = assignments + (id -> assignment.unfinished)) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
988 |
} |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
989 |
|
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
990 |
def define_blob(digest: SHA1.Digest): State = copy(blobs = blobs + digest) |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
991 |
def defined_blob(digest: SHA1.Digest): Boolean = blobs.contains(digest) |
|
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
992 |
|
| 75393 | 993 |
def define_command(command: Command): State = {
|
| 38373 | 994 |
val id = command.id |
| 72719 | 995 |
if (commands.isDefinedAt(id)) fail |
996 |
else copy(commands = commands + (id -> command.init_state)) |
|
| 38373 | 997 |
} |
998 |
||
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
999 |
def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id) |
| 44582 | 1000 |
|
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
1001 |
def the_version(id: Document_ID.Version): Version = versions.getOrElse(id, fail) |
|
52564
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
wenzelm
parents:
52563
diff
changeset
|
1002 |
def the_static_state(id: Document_ID.Command): Command.State = commands.getOrElse(id, fail) |
|
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
wenzelm
parents:
52563
diff
changeset
|
1003 |
def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail) |
| 52563 | 1004 |
def the_assignment(version: Version): State.Assignment = assignments.getOrElse(version.id, fail) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1005 |
|
| 68857 | 1006 |
def lookup_id(id: Document_ID.Generic): Option[Command.State] = |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1007 |
theories.get(id) orElse commands.get(id) orElse execs.get(id) |
| 68857 | 1008 |
|
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1009 |
private def self_id(st: Command.State)(id: Document_ID.Generic): Boolean = |
|
56295
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
1010 |
id == st.command.id || |
|
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
1011 |
(execs.get(id) match { case Some(st1) => st1.command.id == st.command.id case None => false })
|
|
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
1012 |
|
| 75393 | 1013 |
private def other_id( |
1014 |
node_name: Node.Name, |
|
1015 |
id: Document_ID.Generic |
|
1016 |
) : Option[(Symbol.Text_Chunk.Id, Symbol.Text_Chunk)] = {
|
|
| 72780 | 1017 |
for {
|
1018 |
st <- lookup_id(id) |
|
1019 |
if st.command.node_name == node_name |
|
1020 |
} yield (Symbol.Text_Chunk.Id(st.command.id), st.command.chunk) |
|
1021 |
} |
|
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1022 |
|
| 56475 | 1023 |
private def redirection(st: Command.State): Graph[Document_ID.Command, Unit] = |
| 73359 | 1024 |
st.markups.redirection_iterator.foldLeft(commands_redirection) {
|
1025 |
case (graph, id) => |
|
1026 |
graph.default_node(id, ()).default_node(st.command.id, ()).add_edge(id, st.command.id) |
|
1027 |
} |
|
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1028 |
|
| 75393 | 1029 |
def accumulate( |
1030 |
id: Document_ID.Generic, |
|
1031 |
message: XML.Elem, |
|
1032 |
cache: XML.Cache |
|
1033 |
) : (Command.State, State) = {
|
|
1034 |
def update(st: Command.State): (Command.State, State) = {
|
|
|
73031
f93f0597f4fb
clarified signature: absorb XZ.Cache into XML.Cache;
wenzelm
parents:
72962
diff
changeset
|
1035 |
val st1 = st.accumulate(self_id(st), other_id, message, cache) |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1036 |
(st1, copy(commands_redirection = redirection(st1))) |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1037 |
} |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1038 |
execs.get(id).map(update) match {
|
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1039 |
case Some((st1, state1)) => (st1, state1.copy(execs = execs + (id -> st1))) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1040 |
case None => |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1041 |
commands.get(id).map(update) match {
|
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1042 |
case Some((st1, state1)) => (st1, state1.copy(commands = commands + (id -> st1))) |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1043 |
case None => |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1044 |
theories.get(id).map(update) match {
|
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1045 |
case Some((st1, state1)) => (st1, state1.copy(theories = theories + (id -> st1))) |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1046 |
case None => fail |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1047 |
} |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1048 |
} |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1049 |
} |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1050 |
} |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1051 |
|
| 75393 | 1052 |
def add_export( |
1053 |
id: Document_ID.Generic, |
|
1054 |
entry: Command.Exports.Entry |
|
1055 |
): (Command.State, State) = {
|
|
| 68101 | 1056 |
execs.get(id) match {
|
1057 |
case Some(st) => |
|
| 68114 | 1058 |
st.add_export(entry) match {
|
1059 |
case Some(new_st) => (new_st, copy(execs = execs + (id -> new_st))) |
|
1060 |
case None => fail |
|
1061 |
} |
|
| 68101 | 1062 |
case None => |
1063 |
commands.get(id) match {
|
|
1064 |
case Some(st) => |
|
| 68114 | 1065 |
st.add_export(entry) match {
|
1066 |
case Some(new_st) => (new_st, copy(commands = commands + (id -> new_st))) |
|
1067 |
case None => fail |
|
1068 |
} |
|
| 68101 | 1069 |
case None => fail |
1070 |
} |
|
1071 |
} |
|
1072 |
} |
|
1073 |
||
| 69633 | 1074 |
def node_exports(version: Version, node_name: Node.Name): Command.Exports = |
1075 |
Command.Exports.merge( |
|
1076 |
for {
|
|
1077 |
command <- version.nodes(node_name).commands.iterator |
|
1078 |
st <- command_states(version, command).iterator |
|
1079 |
} yield st.exports) |
|
1080 |
||
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1081 |
def begin_theory( |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1082 |
node_name: Node.Name, |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1083 |
id: Document_ID.Exec, |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1084 |
source: String, |
| 75393 | 1085 |
blobs_info: Command.Blobs_Info |
1086 |
): State = {
|
|
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1087 |
if (theories.isDefinedAt(id)) fail |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1088 |
else {
|
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1089 |
val command = |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1090 |
Command.unparsed(source, theory = true, id = id, node_name = node_name, |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1091 |
blobs_info = blobs_info) |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1092 |
copy(theories = theories + (id -> command.empty_state)) |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1093 |
} |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1094 |
} |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1095 |
|
|
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76905
diff
changeset
|
1096 |
def end_theory(id: Document_ID.Exec, document_blobs: Node.Name => Blobs): (Snapshot, State) = |
|
72861
3f5e6da08687
clarified protocol: support "isabelle log" on failed theories as well;
wenzelm
parents:
72860
diff
changeset
|
1097 |
theories.get(id) match {
|
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1098 |
case None => fail |
|
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72719
diff
changeset
|
1099 |
case Some(st) => |
|
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72719
diff
changeset
|
1100 |
val command = st.command |
|
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72719
diff
changeset
|
1101 |
val node_name = command.node_name |
|
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76905
diff
changeset
|
1102 |
val doc_blobs = document_blobs(node_name) |
|
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72719
diff
changeset
|
1103 |
val command1 = |
|
72861
3f5e6da08687
clarified protocol: support "isabelle log" on failed theories as well;
wenzelm
parents:
72860
diff
changeset
|
1104 |
Command.unparsed(command.source, theory = true, id = id, node_name = node_name, |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1105 |
blobs_info = command.blobs_info, results = st.results, markups = st.markups) |
|
72861
3f5e6da08687
clarified protocol: support "isabelle log" on failed theories as well;
wenzelm
parents:
72860
diff
changeset
|
1106 |
val state1 = copy(theories = theories - id) |
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
1107 |
(state1.snippet(List(command1), doc_blobs), state1) |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1108 |
} |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72669
diff
changeset
|
1109 |
|
| 75393 | 1110 |
def assign( |
1111 |
id: Document_ID.Version, |
|
1112 |
edited: List[String], |
|
1113 |
update: Assign_Update |
|
1114 |
) : ((List[Node.Name], List[Command]), State) = {
|
|
| 38417 | 1115 |
val version = the_version(id) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1116 |
|
|
70284
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69633
diff
changeset
|
1117 |
val edited_set = edited.toSet |
|
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69633
diff
changeset
|
1118 |
val edited_nodes = |
|
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69633
diff
changeset
|
1119 |
(for { (name, _) <- version.nodes.iterator if edited_set(name.node) } yield name).toList
|
|
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69633
diff
changeset
|
1120 |
|
| 76759 | 1121 |
def upd( |
1122 |
exec_id: Document_ID.Exec, |
|
1123 |
st: Command.State |
|
1124 |
): Option[(Document_ID.Exec, Command.State)] = {
|
|
|
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
1125 |
if (execs.isDefinedAt(exec_id)) None else Some(exec_id -> st) |
| 76759 | 1126 |
} |
|
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
1127 |
|
| 44543 | 1128 |
val (changed_commands, new_execs) = |
| 73361 | 1129 |
update.foldLeft((List.empty[Command], execs)) {
|
|
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
1130 |
case ((commands1, execs1), (command_id, exec)) => |
|
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
1131 |
val st = the_static_state(command_id) |
|
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
1132 |
val command = st.command |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
1133 |
val commands2 = command :: commands1 |
| 44543 | 1134 |
val execs2 = |
1135 |
exec match {
|
|
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
1136 |
case Nil => execs1 |
|
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
1137 |
case eval_id :: print_ids => |
|
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
1138 |
execs1 ++ upd(eval_id, st) ++ |
|
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
1139 |
(for (id <- print_ids; up <- upd(id, command.empty_state)) yield up) |
| 44543 | 1140 |
} |
1141 |
(commands2, execs2) |
|
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1142 |
} |
| 52563 | 1143 |
val new_assignment = the_assignment(version).assign(update) |
| 43722 | 1144 |
val new_state = copy(assignments = assignments + (id -> new_assignment), execs = new_execs) |
|
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
1145 |
|
|
70284
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69633
diff
changeset
|
1146 |
((edited_nodes, changed_commands), new_state) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1147 |
} |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1148 |
|
| 38417 | 1149 |
def is_assigned(version: Version): Boolean = |
| 43722 | 1150 |
assignments.get(version.id) match {
|
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1151 |
case Some(assgn) => assgn.is_finished |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1152 |
case None => false |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1153 |
} |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
1154 |
|
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
1155 |
def is_stable(change: Change): Boolean = |
|
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
1156 |
change.is_finished && is_assigned(change.version.get_finished) |
|
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
1157 |
|
|
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
1158 |
def recent_finished: Change = history.undo_list.find(_.is_finished) getOrElse fail |
| 44672 | 1159 |
def recent_stable: Change = history.undo_list.find(is_stable) getOrElse fail |
|
60933
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60916
diff
changeset
|
1160 |
def stable_tip_version: Option[Version] = |
|
6d03e05ef041
more robust access to stable tip version: take all pending edits into account, don't assume model for current buffer;
wenzelm
parents:
60916
diff
changeset
|
1161 |
if (is_stable(history.tip)) Some(history.tip.version.get_finished) else None |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
1162 |
|
| 44446 | 1163 |
def continue_history( |
| 56711 | 1164 |
previous: Future[Version], |
1165 |
edits: List[Edit_Text], |
|
| 75393 | 1166 |
version: Future[Version] |
1167 |
): State = {
|
|
| 46678 | 1168 |
val change = Change.make(previous, edits, version) |
| 56711 | 1169 |
copy(history = history + change) |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1170 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1171 |
|
| 75393 | 1172 |
def remove_versions(retain: Int = 0): (List[Version], State) = {
|
| 46679 | 1173 |
history.prune(is_stable, retain) match {
|
1174 |
case Some((dropped, history1)) => |
|
|
57976
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
wenzelm
parents:
57842
diff
changeset
|
1175 |
val old_versions = dropped.map(change => change.version.get_finished) |
| 59319 | 1176 |
val removing = old_versions.nonEmpty |
|
57976
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
wenzelm
parents:
57842
diff
changeset
|
1177 |
val state1 = copy(history = history1, removing_versions = removing) |
|
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
wenzelm
parents:
57842
diff
changeset
|
1178 |
(old_versions, state1) |
| 46679 | 1179 |
case None => fail |
| 44672 | 1180 |
} |
1181 |
} |
|
1182 |
||
| 75393 | 1183 |
def removed_versions(removed: List[Document_ID.Version]): State = {
|
|
68300
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
1184 |
val versions1 = Version.purge_suppressed(versions -- removed) |
|
67110
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
wenzelm
parents:
67014
diff
changeset
|
1185 |
|
| 44676 | 1186 |
val assignments1 = assignments -- removed |
| 67112 | 1187 |
var blobs1_names = Set.empty[Node.Name] |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
1188 |
var blobs1 = Set.empty[SHA1.Digest] |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
1189 |
var commands1 = Map.empty[Document_ID.Command, Command.State] |
|
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
1190 |
var execs1 = Map.empty[Document_ID.Exec, Command.State] |
| 44676 | 1191 |
for {
|
| 67112 | 1192 |
(version_id, version) <- versions1.iterator |
| 46997 | 1193 |
command_execs = assignments1(version_id).command_execs |
|
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
1194 |
(_, node) <- version.nodes.iterator |
| 44676 | 1195 |
command <- node.commands.iterator |
1196 |
} {
|
|
| 67112 | 1197 |
for ((name, digest) <- command.blobs_defined) {
|
1198 |
blobs1_names += name |
|
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
1199 |
blobs1 += digest |
| 67112 | 1200 |
} |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
1201 |
|
| 76759 | 1202 |
if (!commands1.isDefinedAt(command.id)) {
|
| 52568 | 1203 |
commands.get(command.id).foreach(st => commands1 += (command.id -> st)) |
| 76759 | 1204 |
} |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
1205 |
|
| 76760 | 1206 |
for {
|
1207 |
exec_id <- command_execs.getOrElse(command.id, Nil) |
|
1208 |
if !execs1.isDefinedAt(exec_id) |
|
1209 |
st <- execs.get(exec_id) |
|
1210 |
} execs1 += (exec_id -> st) |
|
| 44676 | 1211 |
} |
| 67112 | 1212 |
|
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1213 |
copy( |
|
68300
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
1214 |
versions = versions1, |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1215 |
blobs = blobs1, |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1216 |
commands = commands1, |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1217 |
execs = execs1, |
| 70699 | 1218 |
commands_redirection = commands_redirection.restrict(commands1.keySet), |
|
57976
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
wenzelm
parents:
57842
diff
changeset
|
1219 |
assignments = assignments1, |
|
68300
cd8ab1a7a286
retain isolated blob nodes (amending deb2fcbda16e): avoid failure of Session.handle_change with "Missing blob", when opening theory with load command later;
wenzelm
parents:
68299
diff
changeset
|
1220 |
history = history.purge(versions1), |
|
57976
bf99106b6672
postpone changes in intermediate state between remove_versions/removed_versions, which is important for handle_change to refer to defined items on prover side;
wenzelm
parents:
57842
diff
changeset
|
1221 |
removing_versions = false) |
| 44676 | 1222 |
} |
1223 |
||
| 75393 | 1224 |
def command_maybe_consolidated(version: Version, command: Command): Boolean = {
|
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73031
diff
changeset
|
1225 |
require(is_assigned(version), "version not assigned (command_maybe_consolidated)") |
|
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1226 |
try {
|
|
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1227 |
the_assignment(version).check_finished.command_execs.getOrElse(command.id, Nil) match {
|
|
70780
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
wenzelm
parents:
70716
diff
changeset
|
1228 |
case eval_id :: print_ids => |
|
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
wenzelm
parents:
70716
diff
changeset
|
1229 |
the_dynamic_state(eval_id).maybe_consolidated && |
|
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
wenzelm
parents:
70716
diff
changeset
|
1230 |
!print_ids.exists(print_id => the_dynamic_state(print_id).consolidating) |
|
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
wenzelm
parents:
70716
diff
changeset
|
1231 |
case Nil => false |
|
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1232 |
} |
|
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1233 |
} |
|
70780
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
wenzelm
parents:
70716
diff
changeset
|
1234 |
catch { case _: State.Fail => false }
|
|
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1235 |
} |
|
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1236 |
|
| 75393 | 1237 |
private def command_states_self( |
1238 |
version: Version, |
|
1239 |
command: Command |
|
1240 |
) : List[(Document_ID.Generic, Command.State)] = {
|
|
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
73031
diff
changeset
|
1241 |
require(is_assigned(version), "version not assigned (command_states_self)") |
| 44613 | 1242 |
try {
|
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
1243 |
the_assignment(version).check_finished.command_execs.getOrElse(command.id, Nil) |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1244 |
.map(id => id -> the_dynamic_state(id)) match {
|
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
1245 |
case Nil => fail |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1246 |
case res => res |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
1247 |
} |
| 44613 | 1248 |
} |
|
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
1249 |
catch {
|
|
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
1250 |
case _: State.Fail => |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1251 |
try { List(command.id -> the_static_state(command.id)) }
|
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1252 |
catch { case _: State.Fail => List(command.id -> command.init_state) }
|
|
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
1253 |
} |
| 44613 | 1254 |
} |
1255 |
||
| 75393 | 1256 |
def command_states(version: Version, command: Command): List[Command.State] = {
|
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1257 |
val self = command_states_self(version, command) |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1258 |
val others = |
| 56475 | 1259 |
if (commands_redirection.defined(command.id)) {
|
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1260 |
(for {
|
| 56475 | 1261 |
command_id <- commands_redirection.imm_succs(command.id).iterator |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1262 |
(id, st) <- command_states_self(version, the_static_state(command_id).command) |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1263 |
if !self.exists(_._1 == id) |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1264 |
} yield (id, st)).toMap.valuesIterator.toList |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1265 |
} |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1266 |
else Nil |
| 56489 | 1267 |
self.map(_._2) ::: others.flatMap(_.redirect(command)) |
|
56470
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1268 |
} |
|
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
1269 |
|
|
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
1270 |
def command_results(version: Version, command: Command): Command.Results = |
|
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
1271 |
Command.State.merge_results(command_states(version, command)) |
|
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
1272 |
|
|
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
1273 |
def command_markup(version: Version, command: Command, index: Command.Markup_Index, |
| 56743 | 1274 |
range: Text.Range, elements: Markup.Elements): Markup_Tree = |
|
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
1275 |
Command.State.merge_markup(command_states(version, command), index, range, elements) |
|
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
1276 |
|
| 72723 | 1277 |
def xml_markup( |
| 66041 | 1278 |
version: Version, |
| 67264 | 1279 |
node_name: Node.Name, |
| 72723 | 1280 |
range: Text.Range = Text.Range.full, |
| 75393 | 1281 |
elements: Markup.Elements = Markup.Elements.full |
1282 |
): XML.Body = {
|
|
| 67264 | 1283 |
val node = version.nodes(node_name) |
1284 |
if (node_name.is_theory) {
|
|
1285 |
val markup_index = Command.Markup_Index.markup |
|
1286 |
(for {
|
|
1287 |
command <- node.commands.iterator |
|
1288 |
command_range <- command.range.try_restrict(range).iterator |
|
1289 |
markup = command_markup(version, command, markup_index, command_range, elements) |
|
1290 |
tree <- markup.to_XML(command_range, command.source, elements).iterator |
|
1291 |
} yield tree).toList |
|
1292 |
} |
|
| 76924 | 1293 |
else if (node.source_wellformed) {
|
| 76235 | 1294 |
Text.Range.length(node.source).try_restrict(range) match {
|
| 67264 | 1295 |
case Some(node_range) => |
1296 |
val markup = |
|
1297 |
version.nodes.commands_loading(node_name).headOption match {
|
|
1298 |
case None => Markup_Tree.empty |
|
1299 |
case Some(command) => |
|
1300 |
val chunk_name = Symbol.Text_Chunk.File(node_name.node) |
|
1301 |
val markup_index = Command.Markup_Index(false, chunk_name) |
|
1302 |
command_markup(version, command, markup_index, node_range, elements) |
|
1303 |
} |
|
|
76204
b80b2fbc46c3
clarified signature: persistent Node.source / Snapshot.source;
wenzelm
parents:
75914
diff
changeset
|
1304 |
markup.to_XML(node_range, node.source, elements) |
| 76917 | 1305 |
case None => Nil |
| 67264 | 1306 |
} |
1307 |
} |
|
| 76917 | 1308 |
else Nil |
| 66041 | 1309 |
} |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1310 |
|
| 68323 | 1311 |
def node_initialized(version: Version, name: Node.Name): Boolean = |
1312 |
name.is_theory && |
|
1313 |
(version.nodes(name).commands.iterator.find(_.potentially_initialized) match {
|
|
1314 |
case None => false |
|
1315 |
case Some(command) => command_states(version, command).headOption.exists(_.initialized) |
|
1316 |
}) |
|
1317 |
||
|
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1318 |
def node_maybe_consolidated(version: Version, name: Node.Name): Boolean = |
|
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1319 |
name.is_theory && |
|
70780
034742453594
more robust: avoid update/interrupt of long-running print_consolidation;
wenzelm
parents:
70716
diff
changeset
|
1320 |
version.nodes(name).commands.reverse.iterator.forall(command_maybe_consolidated(version, _)) |
|
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
1321 |
|
|
66379
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm
parents:
66195
diff
changeset
|
1322 |
def node_consolidated(version: Version, name: Node.Name): Boolean = |
| 75393 | 1323 |
!name.is_theory || {
|
| 68335 | 1324 |
val it = version.nodes(name).commands.reverse.iterator |
| 73344 | 1325 |
it.hasNext && command_states(version, it.next()).exists(_.consolidated) |
| 68335 | 1326 |
} |
|
66379
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm
parents:
66195
diff
changeset
|
1327 |
|
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72780
diff
changeset
|
1328 |
def snapshot( |
| 72818 | 1329 |
node_name: Node.Name = Node.Name.empty, |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
1330 |
pending_edits: Pending_Edits = Pending_Edits.empty, |
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
1331 |
snippet_commands: List[Command] = Nil |
| 75393 | 1332 |
): Snapshot = {
|
| 72819 | 1333 |
val stable = recent_stable |
| 72820 | 1334 |
val version = stable.version.get_finished |
|
57620
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1335 |
|
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
1336 |
val pending_edits1 = |
|
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
1337 |
(for {
|
|
57620
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1338 |
change <- history.undo_list.takeWhile(_ != stable) |
| 78592 | 1339 |
case (name, Node.Edits(es)) <- change.rev_edits |
|
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
76760
diff
changeset
|
1340 |
} yield (name -> es)).foldLeft(pending_edits)(_ + _) |
|
57620
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1341 |
|
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
1342 |
new Snapshot(this, version, node_name, pending_edits1, snippet_commands) |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
1343 |
} |
| 72859 | 1344 |
|
|
81414
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
1345 |
def snippet(commands: List[Command], doc_blobs: Blobs): Snapshot = |
|
ed4ff84e9b21
Document.Snapshot: support for multiple snippet_commands;
wenzelm
parents:
78592
diff
changeset
|
1346 |
snapshot().snippet(commands, doc_blobs) |
| 34485 | 1347 |
} |
|
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
1348 |
} |