author | wenzelm |
Fri, 04 Apr 2014 10:41:53 +0200 | |
changeset 56398 | 15d0821c8667 |
parent 56394 | bbf4d512f395 |
child 56462 | b64b0cb845fe |
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 |
||
34823 | 14 |
object Document |
34483 | 15 |
{ |
38424 | 16 |
/** document structure **/ |
17 |
||
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
18 |
/* overlays -- print functions with arguments */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
19 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
20 |
object Overlays |
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 |
val empty = new Overlays(Map.empty) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
23 |
} |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
24 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
25 |
final class Overlays private(rep: Map[Node.Name, Node.Overlays]) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
26 |
{ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
27 |
def apply(name: Document.Node.Name): Node.Overlays = |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
28 |
rep.getOrElse(name, Node.Overlays.empty) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
29 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
30 |
private def update(name: Node.Name, f: Node.Overlays => Node.Overlays): Overlays = |
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 |
val node_overlays = f(apply(name)) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
33 |
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
|
34 |
} |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
35 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
36 |
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
|
37 |
update(command.node_name, _.insert(command, fn, args)) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
38 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
39 |
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
|
40 |
update(command.node_name, _.remove(command, fn, args)) |
55800 | 41 |
|
42 |
override def toString: String = rep.mkString("Overlays(", ",", ")") |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
43 |
} |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
44 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
45 |
|
55783 | 46 |
/* document blobs: auxiliary files */ |
47 |
||
48 |
sealed case class Blob(bytes: Bytes, file: Command.File, changed: Boolean) |
|
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
49 |
{ |
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
50 |
def unchanged: Blob = copy(changed = false) |
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
51 |
} |
55783 | 52 |
|
53 |
object Blobs |
|
54 |
{ |
|
56336 | 55 |
def apply(blobs: Map[Node.Name, Blob]): Blobs = new Blobs(blobs) |
55783 | 56 |
val empty: Blobs = apply(Map.empty) |
57 |
} |
|
58 |
||
56336 | 59 |
final class Blobs private(blobs: Map[Node.Name, Blob]) |
55783 | 60 |
{ |
55801 | 61 |
private lazy val digests: Map[SHA1.Digest, Blob] = |
62 |
for ((_, blob) <- blobs) yield (blob.bytes.sha1_digest, blob) |
|
63 |
||
64 |
def get(digest: SHA1.Digest): Option[Blob] = digests.get(digest) |
|
56336 | 65 |
def get(name: Node.Name): Option[Blob] = blobs.get(name) |
55783 | 66 |
|
67 |
def changed(name: Node.Name): Boolean = |
|
68 |
get(name) match { |
|
69 |
case Some(blob) => blob.changed |
|
70 |
case None => false |
|
71 |
} |
|
72 |
||
55800 | 73 |
override def toString: String = blobs.mkString("Blobs(", ",", ")") |
55783 | 74 |
} |
75 |
||
76 |
||
77 |
/* document nodes: theories and auxiliary files */ |
|
38424 | 78 |
|
44615 | 79 |
type Edit[A, B] = (Node.Name, Node.Edit[A, B]) |
44384 | 80 |
type Edit_Text = Edit[Text.Edit, Text.Perspective] |
52849 | 81 |
type Edit_Command = Edit[Command.Edit, Command.Perspective] |
38151 | 82 |
|
83 |
object Node |
|
84 |
{ |
|
52887 | 85 |
val empty: Node = new Node() |
86 |
||
87 |
||
88 |
/* header and name */ |
|
89 |
||
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
90 |
sealed case class Header( |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46814
diff
changeset
|
91 |
imports: List[Name], |
48706 | 92 |
keywords: Thy_Header.Keywords, |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
93 |
errors: List[String] = Nil) |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
94 |
{ |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
95 |
def error(msg: String): Header = copy(errors = errors ::: List(msg)) |
54549
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
96 |
|
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
97 |
def cat_errors(msg2: String): Header = |
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
98 |
copy(errors = errors.map(msg1 => Library.cat_message(msg1, msg2))) |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
99 |
} |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
100 |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
101 |
def bad_header(msg: String): Header = Header(Nil, Nil, List(msg)) |
46737 | 102 |
|
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
|
103 |
val no_header = bad_header("No theory header") |
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
|
104 |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
105 |
object Name |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
106 |
{ |
54515 | 107 |
val empty = Name("") |
46723 | 108 |
|
109 |
object Ordering extends scala.math.Ordering[Name] |
|
110 |
{ |
|
111 |
def compare(name1: Name, name2: Name): Int = name1.node compare name2.node |
|
112 |
} |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
113 |
} |
52887 | 114 |
|
54515 | 115 |
sealed case class Name(node: String, master_dir: String = "", theory: String = "") |
44615 | 116 |
{ |
117 |
override def hashCode: Int = node.hashCode |
|
118 |
override def equals(that: Any): Boolean = |
|
119 |
that match { |
|
120 |
case other: Name => node == other.node |
|
121 |
case _ => false |
|
122 |
} |
|
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
|
123 |
|
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
|
124 |
def is_theory: Boolean = !theory.isEmpty |
54510 | 125 |
override def toString: String = if (is_theory) theory else node |
44615 | 126 |
} |
127 |
||
52887 | 128 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
129 |
/* node overlays */ |
52887 | 130 |
|
131 |
object Overlays |
|
132 |
{ |
|
52976 | 133 |
val empty = new Overlays(Multi_Map.empty) |
52887 | 134 |
} |
135 |
||
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
136 |
final class Overlays private(rep: Multi_Map[Command, (String, List[String])]) |
52887 | 137 |
{ |
138 |
def commands: Set[Command] = rep.keySet |
|
139 |
def is_empty: Boolean = rep.isEmpty |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
new Overlays(rep.insert(cmd, (fn, args))) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
143 |
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
|
144 |
new Overlays(rep.remove(cmd, (fn, args))) |
55800 | 145 |
|
146 |
override def toString: String = rep.mkString("Node.Overlays(", ",", ")") |
|
52887 | 147 |
} |
148 |
||
149 |
||
150 |
/* edits */ |
|
151 |
||
44384 | 152 |
sealed abstract class Edit[A, B] |
44156 | 153 |
{ |
44383 | 154 |
def foreach(f: A => Unit) |
155 |
{ |
|
44156 | 156 |
this match { |
44383 | 157 |
case Edits(es) => es.foreach(f) |
158 |
case _ => |
|
44156 | 159 |
} |
44383 | 160 |
} |
44156 | 161 |
} |
44384 | 162 |
case class Clear[A, B]() extends Edit[A, B] |
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
163 |
case class Blob[A, B](blob: Document.Blob) 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
|
164 |
|
44384 | 165 |
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
|
166 |
case class Deps[A, B](header: Header) extends Edit[A, B] |
52849 | 167 |
case class Perspective[A, B](required: Boolean, visible: B, overlays: Overlays) extends Edit[A, B] |
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52568
diff
changeset
|
168 |
type Perspective_Text = Perspective[Text.Edit, Text.Perspective] |
52849 | 169 |
type Perspective_Command = Perspective[Command.Edit, Command.Perspective] |
44156 | 170 |
|
52887 | 171 |
|
172 |
/* commands */ |
|
173 |
||
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
174 |
object Commands |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
175 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
176 |
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
|
177 |
val empty: Commands = apply(Linear_Set.empty) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
178 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
179 |
def starts(commands: Iterator[Command], offset: Text.Offset = 0) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
180 |
: Iterator[(Command, Text.Offset)] = |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
181 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
182 |
var i = offset |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
183 |
for (command <- commands) yield { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
184 |
val start = i |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
185 |
i += command.length |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
186 |
(command, start) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
187 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
188 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
189 |
|
56398
15d0821c8667
afford larger full_index, to save a few milliseconds during rendering (notably text_overview);
wenzelm
parents:
56394
diff
changeset
|
190 |
private val block_size = 256 |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
191 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
192 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
193 |
final class Commands private(val commands: Linear_Set[Command]) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
194 |
{ |
56314 | 195 |
lazy val load_commands: List[Command] = |
54513 | 196 |
commands.iterator.filter(cmd => !cmd.blobs.isEmpty).toList |
54462 | 197 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
198 |
private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) = |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
199 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
200 |
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
|
201 |
var next_block = 0 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
202 |
var last_stop = 0 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
203 |
for ((command, start) <- Commands.starts(commands.iterator)) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
204 |
last_stop = start + command.length |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
205 |
while (last_stop + 1 > next_block) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
206 |
blocks += (command -> start) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
207 |
next_block += Commands.block_size |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
208 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
209 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
210 |
(blocks.toArray, Text.Range(0, last_stop)) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
211 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
212 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
213 |
private def full_range: Text.Range = full_index._2 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
214 |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
215 |
def iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
216 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
217 |
if (!commands.isEmpty && full_range.contains(i)) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
case (cmd, start) => start + cmd.length <= i } |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
221 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
222 |
else Iterator.empty |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
223 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
224 |
} |
38151 | 225 |
} |
226 |
||
46712 | 227 |
final class Node private( |
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
228 |
val get_blob: Option[Document.Blob] = None, |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
229 |
val header: Node.Header = Node.bad_header("Bad theory header"), |
52849 | 230 |
val perspective: Node.Perspective_Command = |
52887 | 231 |
Node.Perspective(false, Command.Perspective.empty, Node.Overlays.empty), |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
232 |
_commands: Node.Commands = Node.Commands.empty) |
38151 | 233 |
{ |
46680 | 234 |
def clear: Node = new Node(header = header) |
235 |
||
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
236 |
def init_blob(blob: Document.Blob): Node = new Node(Some(blob.unchanged)) |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
237 |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
238 |
def update_header(new_header: Node.Header): Node = |
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
239 |
new Node(get_blob, new_header, perspective, _commands) |
46680 | 240 |
|
52849 | 241 |
def update_perspective(new_perspective: Node.Perspective_Command): Node = |
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
242 |
new Node(get_blob, header, new_perspective, _commands) |
46680 | 243 |
|
52849 | 244 |
def same_perspective(other_perspective: Node.Perspective_Command): Boolean = |
245 |
perspective.required == other_perspective.required && |
|
246 |
perspective.visible.same(other_perspective.visible) && |
|
247 |
perspective.overlays == other_perspective.overlays |
|
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52568
diff
changeset
|
248 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
249 |
def commands: Linear_Set[Command] = _commands.commands |
56314 | 250 |
def load_commands: List[Command] = _commands.load_commands |
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
251 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
252 |
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
|
253 |
if (new_commands eq _commands.commands) this |
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
254 |
else new Node(get_blob, header, perspective, Node.Commands(new_commands)) |
38151 | 255 |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
256 |
def command_iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
257 |
_commands.iterator(i) |
38151 | 258 |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
259 |
def command_iterator(range: Text.Range): Iterator[(Command, Text.Offset)] = |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
260 |
command_iterator(range.start) takeWhile { case (_, start) => start < range.stop } |
38151 | 261 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
262 |
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
|
263 |
Node.Commands.starts(commands.iterator).find(_._1 == cmd).map(_._2) |
38151 | 264 |
} |
265 |
||
266 |
||
46723 | 267 |
/* development graph */ |
268 |
||
269 |
object Nodes |
|
270 |
{ |
|
271 |
val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering)) |
|
272 |
} |
|
273 |
||
274 |
final class Nodes private(graph: Graph[Node.Name, Node]) |
|
275 |
{ |
|
276 |
def get_name(s: String): Option[Node.Name] = |
|
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
277 |
graph.keys_iterator.find(name => name.node == s) |
46723 | 278 |
|
279 |
def apply(name: Node.Name): Node = |
|
280 |
graph.default_node(name, Node.empty).get_node(name) |
|
281 |
||
282 |
def + (entry: (Node.Name, Node)): Nodes = |
|
283 |
{ |
|
284 |
val (name, node) = entry |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
285 |
val imports = node.header.imports |
46723 | 286 |
val graph1 = |
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
287 |
(graph.default_node(name, Node.empty) /: imports)((g, p) => g.default_node(p, Node.empty)) |
46723 | 288 |
val graph2 = (graph1 /: graph1.imm_preds(name))((g, dep) => g.del_edge(dep, name)) |
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
289 |
val graph3 = (graph2 /: imports)((g, dep) => g.add_edge(dep, name)) |
46723 | 290 |
new Nodes(graph3.map_node(name, _ => node)) |
291 |
} |
|
292 |
||
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
293 |
def iterator: Iterator[(Node.Name, Node)] = |
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
294 |
graph.iterator.map({ case (name, (node, _)) => (name, node) }) |
46723 | 295 |
|
56314 | 296 |
def load_commands(file_name: Node.Name): List[Command] = |
54528 | 297 |
(for { |
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
298 |
(_, node) <- iterator |
56314 | 299 |
cmd <- node.load_commands.iterator |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54528
diff
changeset
|
300 |
name <- cmd.blobs_names.iterator |
54528 | 301 |
if name == file_name |
302 |
} yield cmd).toList |
|
303 |
||
46942
f5c2d66faa04
basic support for outer syntax keywords in theory header;
wenzelm
parents:
46941
diff
changeset
|
304 |
def descendants(names: List[Node.Name]): List[Node.Name] = graph.all_succs(names) |
46723 | 305 |
def topological_order: List[Node.Name] = graph.topological_order |
56337 | 306 |
|
307 |
override def toString: String = topological_order.mkString("Nodes(", ",", ")") |
|
46723 | 308 |
} |
309 |
||
310 |
||
38424 | 311 |
|
312 |
/** versioning **/ |
|
313 |
||
314 |
/* particular document versions */ |
|
34485 | 315 |
|
38417 | 316 |
object Version |
317 |
{ |
|
46681 | 318 |
val init: Version = new Version() |
319 |
||
56394
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
wenzelm
parents:
56393
diff
changeset
|
320 |
def make(syntax: Option[Prover.Syntax], nodes: Nodes): Version = |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
321 |
new Version(Document_ID.make(), syntax, nodes) |
38417 | 322 |
} |
323 |
||
46712 | 324 |
final class Version private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
325 |
val id: Document_ID.Version = Document_ID.none, |
56394
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
wenzelm
parents:
56393
diff
changeset
|
326 |
val syntax: Option[Prover.Syntax] = None, |
46723 | 327 |
val nodes: Nodes = Nodes.empty) |
46941 | 328 |
{ |
55777 | 329 |
override def toString: String = "Version(" + id + ")" |
46941 | 330 |
} |
34660 | 331 |
|
34859 | 332 |
|
38424 | 333 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
334 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
335 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
336 |
{ |
46678 | 337 |
val init: Change = new Change() |
338 |
||
339 |
def make(previous: Future[Version], edits: List[Edit_Text], version: Future[Version]): Change = |
|
340 |
new Change(Some(previous), edits, version) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
341 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
342 |
|
46712 | 343 |
final class Change private( |
46677 | 344 |
val previous: Option[Future[Version]] = Some(Future.value(Version.init)), |
345 |
val edits: List[Edit_Text] = Nil, |
|
346 |
val version: Future[Version] = Future.value(Version.init)) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
347 |
{ |
44672 | 348 |
def is_finished: Boolean = |
349 |
(previous match { case None => true case Some(future) => future.is_finished }) && |
|
350 |
version.is_finished |
|
351 |
||
46678 | 352 |
def truncate: Change = new Change(None, Nil, version) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
353 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
354 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
355 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
356 |
/* history navigation */ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
357 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
358 |
object History |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
359 |
{ |
46679 | 360 |
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
|
361 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
362 |
|
46712 | 363 |
final class History private( |
46679 | 364 |
val undo_list: List[Change] = List(Change.init)) // non-empty list |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
365 |
{ |
46679 | 366 |
def tip: Change = undo_list.head |
367 |
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
|
368 |
|
46679 | 369 |
def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] = |
370 |
{ |
|
371 |
val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1 |
|
372 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
373 |
||
374 |
retained.splitAt(retained.length - 1) match { |
|
375 |
case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate))) |
|
376 |
case _ => None |
|
377 |
} |
|
378 |
} |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
379 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
380 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
381 |
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
382 |
/* markup elements */ |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
383 |
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
384 |
object Elements |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
385 |
{ |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
386 |
def apply(elems: Set[String]): Elements = new Elements(elems) |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
387 |
def apply(elems: String*): Elements = apply(Set(elems: _*)) |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
388 |
val empty: Elements = apply() |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
389 |
val full: Elements = new Full_Elements |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
390 |
} |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
391 |
|
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
392 |
sealed class Elements private[Document](private val rep: Set[String]) |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
393 |
{ |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
394 |
def apply(elem: String): Boolean = rep.contains(elem) |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
395 |
def + (elem: String): Elements = new Elements(rep + elem) |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
396 |
def ++ (elems: Elements): Elements = new Elements(rep ++ elems.rep) |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
397 |
override def toString: String = rep.mkString("Elements(", ",", ")") |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
398 |
} |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
399 |
|
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
400 |
private class Full_Elements extends Elements(Set.empty) |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
401 |
{ |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
402 |
override def apply(elem: String): Boolean = true |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
403 |
override def toString: String = "Full_Elements()" |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
404 |
} |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
405 |
|
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
406 |
|
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
407 |
/* snapshot */ |
38424 | 408 |
|
52972 | 409 |
object Snapshot |
410 |
{ |
|
411 |
val init = State.init.snapshot() |
|
412 |
} |
|
413 |
||
38424 | 414 |
abstract class Snapshot |
415 |
{ |
|
44582 | 416 |
val state: State |
38424 | 417 |
val version: Version |
418 |
val is_outdated: Boolean |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
419 |
|
38427 | 420 |
def convert(i: Text.Offset): Text.Offset |
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
421 |
def revert(i: Text.Offset): Text.Offset |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
422 |
def convert(range: Text.Range): Text.Range |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
423 |
def revert(range: Text.Range): Text.Range |
52972 | 424 |
|
425 |
val node_name: Node.Name |
|
426 |
val node: Node |
|
56314 | 427 |
val load_commands: List[Command] |
56176
0bc9b0ad6287
tuned rendering -- avoid flashing background of aux. files that are disconnected from the document model;
wenzelm
parents:
55820
diff
changeset
|
428 |
def is_loaded: Boolean |
51494 | 429 |
def eq_content(other: Snapshot): Boolean |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
430 |
|
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
431 |
def cumulate[A]( |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
432 |
range: Text.Range, |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
433 |
info: A, |
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
434 |
elements: Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
435 |
result: List[Command.State] => (A, Text.Markup) => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
436 |
status: Boolean = false): List[Text.Info[A]] |
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
437 |
|
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
438 |
def select[A]( |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
439 |
range: Text.Range, |
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
440 |
elements: Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
441 |
result: List[Command.State] => Text.Markup => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
442 |
status: Boolean = false): List[Text.Info[A]] |
38424 | 443 |
} |
444 |
||
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
445 |
|
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
446 |
|
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
447 |
/** global state -- document structure, execution process, editing history **/ |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
448 |
|
52563 | 449 |
type Assign_Update = |
450 |
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
|
451 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
452 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
453 |
{ |
38373 | 454 |
class Fail(state: State) extends Exception |
455 |
||
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
456 |
object Assignment |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
457 |
{ |
46683 | 458 |
val init: Assignment = new Assignment() |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
459 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
460 |
|
46712 | 461 |
final class Assignment private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
462 |
val command_execs: Map[Document_ID.Command, List[Document_ID.Exec]] = Map.empty, |
46677 | 463 |
val is_finished: Boolean = false) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
464 |
{ |
44477 | 465 |
def check_finished: Assignment = { require(is_finished); this } |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
466 |
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
|
467 |
|
52563 | 468 |
def assign(update: Assign_Update): Assignment = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
469 |
{ |
38976
a4a465dc89d9
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
wenzelm
parents:
38885
diff
changeset
|
470 |
require(!is_finished) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
471 |
val command_execs1 = |
52563 | 472 |
(command_execs /: update) { |
473 |
case (res, (command_id, exec_ids)) => |
|
474 |
if (exec_ids.isEmpty) res - command_id |
|
475 |
else res + (command_id -> exec_ids) |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
476 |
} |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
477 |
new Assignment(command_execs1, true) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
478 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
479 |
} |
46682 | 480 |
|
481 |
val init: State = |
|
52563 | 482 |
State().define_version(Version.init, Assignment.init).assign(Version.init.id, Nil)._2 |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
483 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
484 |
|
46712 | 485 |
final case class State private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
486 |
val versions: Map[Document_ID.Version, Version] = Map.empty, |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
487 |
val blobs: Set[SHA1.Digest] = Set.empty, // inlined files |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
488 |
val commands: Map[Document_ID.Command, Command.State] = Map.empty, // static markup from define_command |
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
489 |
val execs: Map[Document_ID.Exec, Command.State] = Map.empty, // dynamic markup from execution |
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
490 |
val assignments: Map[Document_ID.Version, State.Assignment] = Map.empty, |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
491 |
val history: History = History.init) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
492 |
{ |
38373 | 493 |
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
|
494 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
495 |
def define_version(version: Version, assignment: State.Assignment): State = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
496 |
{ |
38417 | 497 |
val id = version.id |
498 |
copy(versions = versions + (id -> version), |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
499 |
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
|
500 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
501 |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
502 |
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
|
503 |
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
|
504 |
|
38373 | 505 |
def define_command(command: Command): State = |
506 |
{ |
|
507 |
val id = command.id |
|
49414 | 508 |
copy(commands = commands + (id -> command.init_state)) |
38373 | 509 |
} |
510 |
||
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
511 |
def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id) |
44582 | 512 |
|
52531 | 513 |
def find_command(version: Version, id: Document_ID.Generic): Option[(Node, Command)] = |
44582 | 514 |
commands.get(id) orElse execs.get(id) match { |
515 |
case None => None |
|
516 |
case Some(st) => |
|
517 |
val command = st.command |
|
46681 | 518 |
val node = version.nodes(command.node_name) |
54328
ffa4e0b1701e
more strict find_command -- avoid invalid hyperlink_command;
wenzelm
parents:
52978
diff
changeset
|
519 |
if (node.commands.contains(command)) Some((node, command)) else None |
44582 | 520 |
} |
38373 | 521 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
522 |
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
|
523 |
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
|
524 |
def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail) |
52563 | 525 |
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
|
526 |
|
56295
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
527 |
def valid_id(st: Command.State)(id: Document_ID.Generic): Boolean = |
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
528 |
id == st.command.id || |
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
529 |
(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
|
530 |
|
52531 | 531 |
def accumulate(id: Document_ID.Generic, message: XML.Elem): (Command.State, State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
532 |
execs.get(id) match { |
44446 | 533 |
case Some(st) => |
56295
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
534 |
val new_st = st + (valid_id(st), message) |
44446 | 535 |
(new_st, copy(execs = execs + (id -> new_st))) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
536 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
537 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
538 |
case Some(st) => |
56295
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
539 |
val new_st = st + (valid_id(st), message) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
540 |
(new_st, copy(commands = commands + (id -> new_st))) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
541 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
542 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
543 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
544 |
|
52563 | 545 |
def assign(id: Document_ID.Version, update: Assign_Update): (List[Command], State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
546 |
{ |
38417 | 547 |
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
|
548 |
|
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
549 |
def upd(exec_id: Document_ID.Exec, st: Command.State) |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
550 |
: Option[(Document_ID.Exec, Command.State)] = |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
551 |
if (execs.isDefinedAt(exec_id)) None else Some(exec_id -> st) |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
552 |
|
44543 | 553 |
val (changed_commands, new_execs) = |
52563 | 554 |
((Nil: List[Command], execs) /: update) { |
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
555 |
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
|
556 |
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
|
557 |
val command = st.command |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
558 |
val commands2 = command :: commands1 |
44543 | 559 |
val execs2 = |
560 |
exec match { |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
561 |
case Nil => execs1 |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
562 |
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
|
563 |
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
|
564 |
(for (id <- print_ids; up <- upd(id, command.empty_state)) yield up) |
44543 | 565 |
} |
566 |
(commands2, execs2) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
567 |
} |
52563 | 568 |
val new_assignment = the_assignment(version).assign(update) |
43722 | 569 |
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
|
570 |
|
44543 | 571 |
(changed_commands, new_state) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
572 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
573 |
|
38417 | 574 |
def is_assigned(version: Version): Boolean = |
43722 | 575 |
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
|
576 |
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
|
577 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
578 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
579 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
580 |
def is_stable(change: Change): Boolean = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
581 |
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
|
582 |
|
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
583 |
def recent_finished: Change = history.undo_list.find(_.is_finished) getOrElse fail |
44672 | 584 |
def recent_stable: Change = history.undo_list.find(is_stable) getOrElse fail |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
585 |
def tip_stable: Boolean = is_stable(history.tip) |
44475 | 586 |
def tip_version: Version = history.tip.version.get_finished |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
587 |
|
44446 | 588 |
def continue_history( |
589 |
previous: Future[Version], |
|
40479 | 590 |
edits: List[Edit_Text], |
43722 | 591 |
version: Future[Version]): (Change, State) = |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
592 |
{ |
46678 | 593 |
val change = Change.make(previous, edits, version) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
594 |
(change, copy(history = history + change)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
595 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
596 |
|
44672 | 597 |
def prune_history(retain: Int = 0): (List[Version], State) = |
598 |
{ |
|
46679 | 599 |
history.prune(is_stable, retain) match { |
600 |
case Some((dropped, history1)) => |
|
44672 | 601 |
val dropped_versions = dropped.map(change => change.version.get_finished) |
46679 | 602 |
val state1 = copy(history = history1) |
44672 | 603 |
(dropped_versions, state1) |
46679 | 604 |
case None => fail |
44672 | 605 |
} |
606 |
} |
|
607 |
||
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
608 |
def removed_versions(removed: List[Document_ID.Version]): State = |
44676 | 609 |
{ |
610 |
val versions1 = versions -- removed |
|
611 |
val assignments1 = assignments -- removed |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
612 |
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
|
613 |
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
|
614 |
var execs1 = Map.empty[Document_ID.Exec, Command.State] |
44676 | 615 |
for { |
616 |
(version_id, version) <- versions1.iterator |
|
46997 | 617 |
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
|
618 |
(_, node) <- version.nodes.iterator |
44676 | 619 |
command <- node.commands.iterator |
620 |
} { |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
621 |
for (digest <- command.blobs_digests; if !blobs1.contains(digest)) |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
622 |
blobs1 += digest |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
623 |
|
52568 | 624 |
if (!commands1.isDefinedAt(command.id)) |
625 |
commands.get(command.id).foreach(st => commands1 += (command.id -> st)) |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
626 |
|
52568 | 627 |
for (exec_id <- command_execs.getOrElse(command.id, Nil)) { |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
628 |
if (!execs1.isDefinedAt(exec_id)) |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
629 |
execs.get(exec_id).foreach(st => execs1 += (exec_id -> st)) |
44676 | 630 |
} |
631 |
} |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
632 |
copy(versions = versions1, blobs = blobs1, commands = commands1, execs = execs1, |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
633 |
assignments = assignments1) |
44676 | 634 |
} |
635 |
||
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
636 |
def command_states(version: Version, command: Command): List[Command.State] = |
44613 | 637 |
{ |
638 |
require(is_assigned(version)) |
|
639 |
try { |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
640 |
the_assignment(version).check_finished.command_execs.getOrElse(command.id, Nil) |
52564
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
wenzelm
parents:
52563
diff
changeset
|
641 |
.map(the_dynamic_state(_)) match { |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
642 |
case Nil => fail |
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
643 |
case states => states |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
644 |
} |
44613 | 645 |
} |
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
646 |
catch { |
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
647 |
case _: State.Fail => |
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
648 |
try { List(the_static_state(command.id)) } |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
649 |
catch { case _: State.Fail => List(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
|
650 |
} |
44613 | 651 |
} |
652 |
||
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
653 |
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
|
654 |
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
|
655 |
|
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
656 |
def command_markup(version: Version, command: Command, index: Command.Markup_Index, |
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
657 |
range: Text.Range, elements: Elements): Markup_Tree = |
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
658 |
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
|
659 |
|
56300 | 660 |
def markup_to_XML(version: Version, node: Node, elements: Elements): XML.Body = |
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
661 |
(for { |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
662 |
command <- node.commands.iterator |
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
663 |
markup = |
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
664 |
command_markup(version, command, Command.Markup_Index.markup, command.range, elements) |
56300 | 665 |
tree <- markup.to_XML(command.range, command.source, elements) |
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
666 |
} yield tree).toList |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
667 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
668 |
// persistent user-view |
49346 | 669 |
def snapshot(name: Node.Name = Node.Name.empty, pending_edits: List[Text.Edit] = Nil) |
670 |
: Snapshot = |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
671 |
{ |
44672 | 672 |
val stable = recent_stable |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
673 |
val latest = history.tip |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
674 |
|
44156 | 675 |
// FIXME proper treatment of removed nodes |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
676 |
val edits = |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
677 |
(pending_edits /: history.undo_list.takeWhile(_ != stable))((edits, change) => |
44156 | 678 |
(for ((a, Node.Edits(es)) <- change.edits if a == name) yield es).flatten ::: edits) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
679 |
lazy val reverse_edits = edits.reverse |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
680 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
681 |
new Snapshot |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
682 |
{ |
52972 | 683 |
/* global information */ |
684 |
||
44582 | 685 |
val state = State.this |
39698 | 686 |
val version = stable.version.get_finished |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
687 |
val is_outdated = !(pending_edits.isEmpty && latest == stable) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
688 |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
689 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
690 |
/* local node content */ |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
691 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
692 |
def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
693 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
43425 | 694 |
def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r)) |
695 |
def revert(range: Text.Range) = (range /: reverse_edits)((r, edit) => edit.revert(r)) |
|
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
696 |
|
52972 | 697 |
val node_name = name |
698 |
val node = version.nodes(name) |
|
699 |
||
56314 | 700 |
val load_commands: List[Command] = |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
701 |
if (node_name.is_theory) Nil |
56314 | 702 |
else version.nodes.load_commands(node_name) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
703 |
|
56314 | 704 |
val is_loaded: Boolean = node_name.is_theory || !load_commands.isEmpty |
56176
0bc9b0ad6287
tuned rendering -- avoid flashing background of aux. files that are disconnected from the document model;
wenzelm
parents:
55820
diff
changeset
|
705 |
|
51494 | 706 |
def eq_content(other: Snapshot): Boolean = |
55434 | 707 |
{ |
708 |
def eq_commands(commands: (Command, Command)): Boolean = |
|
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
709 |
{ |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
710 |
val states1 = state.command_states(version, commands._1) |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
711 |
val states2 = other.state.command_states(other.version, commands._2) |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
712 |
states1.length == states2.length && |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
713 |
(states1 zip states2).forall({ case (st1, st2) => st1 eq_content st2 }) |
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
714 |
} |
55434 | 715 |
|
49346 | 716 |
!is_outdated && !other.is_outdated && |
55434 | 717 |
node.commands.size == other.node.commands.size && |
718 |
(node.commands.iterator zip other.node.commands.iterator).forall(eq_commands) && |
|
56314 | 719 |
load_commands.length == other.load_commands.length && |
720 |
(load_commands zip other.load_commands).forall(eq_commands) |
|
55434 | 721 |
} |
49346 | 722 |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
723 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
724 |
/* cumulate markup */ |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
725 |
|
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
726 |
def cumulate[A]( |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
727 |
range: Text.Range, |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
728 |
info: A, |
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
729 |
elements: Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
730 |
result: List[Command.State] => (A, Text.Markup) => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
731 |
status: Boolean = false): List[Text.Info[A]] = |
45459 | 732 |
{ |
45467 | 733 |
val former_range = revert(range) |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
734 |
val (file_name, command_iterator) = |
56314 | 735 |
load_commands match { |
56309 | 736 |
case command :: _ => (node_name.node, Iterator((command, 0))) |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
737 |
case _ => ("", node.command_iterator(former_range)) |
56309 | 738 |
} |
739 |
val markup_index = Command.Markup_Index(status, file_name) |
|
740 |
(for { |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
741 |
(command, command_start) <- command_iterator |
56309 | 742 |
chunk <- command.chunks.get(file_name).iterator |
743 |
states = state.command_states(version, command) |
|
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
744 |
res = result(states) |
56309 | 745 |
range = (former_range - command_start).restrict(chunk.range) |
746 |
markup = Command.State.merge_markup(states, markup_index, range, elements) |
|
747 |
Text.Info(r0, a) <- markup.cumulate[A](range, info, elements, |
|
748 |
{ |
|
749 |
case (a, Text.Info(r0, b)) => res(a, Text.Info(convert(r0 + command_start), b)) |
|
750 |
}).iterator |
|
751 |
} yield Text.Info(convert(r0 + command_start), a)).toList |
|
45459 | 752 |
} |
753 |
||
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
754 |
def select[A]( |
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
755 |
range: Text.Range, |
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
756 |
elements: Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
757 |
result: List[Command.State] => Text.Markup => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
758 |
status: Boolean = false): List[Text.Info[A]] = |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
759 |
{ |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
760 |
def result1(states: List[Command.State]): (Option[A], Text.Markup) => Option[Option[A]] = |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
761 |
{ |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
762 |
val res = result(states) |
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
763 |
(_: Option[A], x: Text.Markup) => |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
764 |
res(x) match { |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
765 |
case None => None |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
766 |
case some => Some(some) |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
767 |
} |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
768 |
} |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
769 |
for (Text.Info(r, Some(x)) <- cumulate(range, None, elements, result1 _, status)) |
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
770 |
yield Text.Info(r, x) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
771 |
} |
55800 | 772 |
|
773 |
||
774 |
/* output */ |
|
775 |
||
776 |
override def toString: String = |
|
777 |
"Snapshot(node = " + node_name.node + ", version = " + version.id + |
|
778 |
(if (is_outdated) ", outdated" else "") + ")" |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
779 |
} |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
780 |
} |
34485 | 781 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
782 |
} |
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
783 |