author | wenzelm |
Thu, 30 Aug 2018 17:24:43 +0200 | |
changeset 68857 | b888de4fe58c |
parent 68836 | cf52379c0776 |
child 69255 | 800b1ce96fce |
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 |
{ |
64799 | 27 |
def apply(name: Node.Name): Node.Overlays = |
52977
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 |
||
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67264
diff
changeset
|
48 |
sealed case class Blob(bytes: Bytes, source: String, chunk: Symbol.Text_Chunk, 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 |
{ |
56336 | 61 |
def get(name: Node.Name): Option[Blob] = blobs.get(name) |
55783 | 62 |
|
63 |
def changed(name: Node.Name): Boolean = |
|
64 |
get(name) match { |
|
65 |
case Some(blob) => blob.changed |
|
66 |
case None => false |
|
67 |
} |
|
68 |
||
55800 | 69 |
override def toString: String = blobs.mkString("Blobs(", ",", ")") |
55783 | 70 |
} |
71 |
||
72 |
||
73 |
/* document nodes: theories and auxiliary files */ |
|
38424 | 74 |
|
44615 | 75 |
type Edit[A, B] = (Node.Name, Node.Edit[A, B]) |
44384 | 76 |
type Edit_Text = Edit[Text.Edit, Text.Perspective] |
52849 | 77 |
type Edit_Command = Edit[Command.Edit, Command.Perspective] |
38151 | 78 |
|
79 |
object Node |
|
80 |
{ |
|
52887 | 81 |
/* header and name */ |
82 |
||
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
83 |
sealed case class Header( |
63020 | 84 |
imports: List[(Name, Position.T)] = Nil, |
85 |
keywords: Thy_Header.Keywords = Nil, |
|
63579 | 86 |
abbrevs: Thy_Header.Abbrevs = Nil, |
63020 | 87 |
errors: List[String] = Nil) |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
88 |
{ |
66773 | 89 |
def append_errors(msgs: List[String]): Header = |
90 |
copy(errors = errors ::: msgs) |
|
54549
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
91 |
|
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
92 |
def cat_errors(msg2: String): Header = |
62492 | 93 |
copy(errors = errors.map(msg1 => Exn.cat_message(msg1, msg2))) |
48707
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 |
|
63020 | 96 |
val no_header = Header() |
97 |
def bad_header(msg: String): Header = Header(errors = List(msg)) |
|
46737 | 98 |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
99 |
object Name |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
100 |
{ |
54515 | 101 |
val empty = Name("") |
46723 | 102 |
|
65471
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65445
diff
changeset
|
103 |
def loaded_theory(theory: String): Name = Name(theory, "", theory) |
05e5bffcf1d8
clarified loaded_theories: map to qualified theory name;
wenzelm
parents:
65445
diff
changeset
|
104 |
|
46723 | 105 |
object Ordering extends scala.math.Ordering[Name] |
106 |
{ |
|
107 |
def compare(name1: Name, name2: Name): Int = name1.node compare name2.node |
|
108 |
} |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
109 |
} |
52887 | 110 |
|
54515 | 111 |
sealed case class Name(node: String, master_dir: String = "", theory: String = "") |
44615 | 112 |
{ |
113 |
override def hashCode: Int = node.hashCode |
|
114 |
override def equals(that: Any): Boolean = |
|
115 |
that match { |
|
116 |
case other: Name => node == other.node |
|
117 |
case _ => false |
|
118 |
} |
|
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
|
119 |
|
66849 | 120 |
def path: Path = Path.explode(File.standard_path(node)) |
66716 | 121 |
|
67290 | 122 |
def is_bibtex: Boolean = Bibtex.is_bibtex(node) |
67293 | 123 |
def is_bibtex_theory: Boolean = Bibtex.is_bibtex(theory) |
67247 | 124 |
|
59319 | 125 |
def is_theory: Boolean = theory.nonEmpty |
65409 | 126 |
|
65439 | 127 |
def theory_base_name: String = Long_Name.base_name(theory) |
128 |
||
54510 | 129 |
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
|
130 |
|
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
|
131 |
def map(f: String => String): Name = copy(f(node), f(master_dir), theory) |
66195 | 132 |
def map_theory(f: String => String): Name = copy(node, master_dir, f(theory)) |
67943 | 133 |
|
134 |
def json: JSON.Object.T = |
|
135 |
JSON.Object("node_name" -> node, "theory_name" -> theory) |
|
44615 | 136 |
} |
137 |
||
66714 | 138 |
sealed case class Entry(name: Node.Name, header: Node.Header) |
139 |
{ |
|
68306
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68300
diff
changeset
|
140 |
def map(f: String => String): Entry = copy(name = name.map(f)) |
d575281e18d0
clarified signature: Known.theories retains Document.Node.Entry (with header);
wenzelm
parents:
68300
diff
changeset
|
141 |
|
66714 | 142 |
override def toString: String = name.toString |
143 |
} |
|
144 |
||
52887 | 145 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
146 |
/* node overlays */ |
52887 | 147 |
|
148 |
object Overlays |
|
149 |
{ |
|
52976 | 150 |
val empty = new Overlays(Multi_Map.empty) |
52887 | 151 |
} |
152 |
||
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
153 |
final class Overlays private(rep: Multi_Map[Command, (String, List[String])]) |
52887 | 154 |
{ |
155 |
def commands: Set[Command] = rep.keySet |
|
156 |
def is_empty: Boolean = rep.isEmpty |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
157 |
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
|
158 |
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
|
159 |
new Overlays(rep.insert(cmd, (fn, args))) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
160 |
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
|
161 |
new Overlays(rep.remove(cmd, (fn, args))) |
55800 | 162 |
|
163 |
override def toString: String = rep.mkString("Node.Overlays(", ",", ")") |
|
52887 | 164 |
} |
165 |
||
166 |
||
167 |
/* edits */ |
|
168 |
||
44384 | 169 |
sealed abstract class Edit[A, B] |
44156 | 170 |
{ |
44383 | 171 |
def foreach(f: A => Unit) |
172 |
{ |
|
44156 | 173 |
this match { |
44383 | 174 |
case Edits(es) => es.foreach(f) |
175 |
case _ => |
|
44156 | 176 |
} |
44383 | 177 |
} |
57621 | 178 |
|
179 |
def is_void: Boolean = |
|
180 |
this match { |
|
181 |
case Edits(Nil) => true |
|
182 |
case _ => false |
|
183 |
} |
|
44156 | 184 |
} |
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56314
diff
changeset
|
185 |
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
|
186 |
|
44384 | 187 |
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
|
188 |
case class Deps[A, B](header: Header) extends Edit[A, B] |
52849 | 189 |
case class Perspective[A, B](required: Boolean, visible: B, overlays: Overlays) extends Edit[A, B] |
57610 | 190 |
|
191 |
||
192 |
/* perspective */ |
|
193 |
||
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52568
diff
changeset
|
194 |
type Perspective_Text = Perspective[Text.Edit, Text.Perspective] |
52849 | 195 |
type Perspective_Command = Perspective[Command.Edit, Command.Perspective] |
44156 | 196 |
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
197 |
val no_perspective_text: Perspective_Text = |
57610 | 198 |
Perspective(false, Text.Perspective.empty, Overlays.empty) |
199 |
||
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
200 |
val no_perspective_command: Perspective_Command = |
57614 | 201 |
Perspective(false, Command.Perspective.empty, Overlays.empty) |
202 |
||
64867 | 203 |
def is_no_perspective_text(perspective: Perspective_Text): Boolean = |
204 |
!perspective.required && |
|
205 |
perspective.visible.is_empty && |
|
206 |
perspective.overlays.is_empty |
|
207 |
||
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
208 |
def is_no_perspective_command(perspective: Perspective_Command): Boolean = |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
209 |
!perspective.required && |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
210 |
perspective.visible.is_empty && |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
211 |
perspective.overlays.is_empty |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
212 |
|
52887 | 213 |
|
214 |
/* commands */ |
|
215 |
||
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
216 |
object Commands |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
217 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
218 |
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
|
219 |
val empty: Commands = apply(Linear_Set.empty) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
220 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
221 |
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
|
222 |
: Iterator[(Command, Text.Offset)] = |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
223 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
224 |
var i = offset |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
225 |
for (command <- commands) yield { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
226 |
val start = i |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
227 |
i += command.length |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
228 |
(command, start) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
229 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
230 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
231 |
|
67895 | 232 |
def starts_pos(commands: Iterator[Command], pos: Token.Pos = Token.Pos.start) |
233 |
: Iterator[(Command, Token.Pos)] = |
|
234 |
{ |
|
235 |
var p = pos |
|
236 |
for (command <- commands) yield { |
|
237 |
val start = p |
|
238 |
p = (p /: command.span.content)(_.advance(_)) |
|
239 |
(command, start) |
|
240 |
} |
|
241 |
} |
|
242 |
||
56398
15d0821c8667
afford larger full_index, to save a few milliseconds during rendering (notably text_overview);
wenzelm
parents:
56394
diff
changeset
|
243 |
private val block_size = 256 |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
244 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
245 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
246 |
final class Commands private(val commands: Linear_Set[Command]) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
247 |
{ |
56314 | 248 |
lazy val load_commands: List[Command] = |
59319 | 249 |
commands.iterator.filter(cmd => cmd.blobs.nonEmpty).toList |
54462 | 250 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
251 |
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
|
252 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
253 |
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
|
254 |
var next_block = 0 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
255 |
var last_stop = 0 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
256 |
for ((command, start) <- Commands.starts(commands.iterator)) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
257 |
last_stop = start + command.length |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
258 |
while (last_stop + 1 > next_block) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
259 |
blocks += (command -> start) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
260 |
next_block += Commands.block_size |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
261 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
262 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
263 |
(blocks.toArray, Text.Range(0, last_stop)) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
264 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
265 |
|
66043 | 266 |
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
|
267 |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
268 |
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
|
269 |
{ |
59319 | 270 |
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
|
271 |
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
|
272 |
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
|
273 |
case (cmd, start) => start + cmd.length <= i } |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
274 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
275 |
else Iterator.empty |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
276 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
277 |
} |
57614 | 278 |
|
279 |
val empty: Node = new Node() |
|
38151 | 280 |
} |
281 |
||
46712 | 282 |
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
|
283 |
val get_blob: Option[Document.Blob] = None, |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
284 |
val header: Node.Header = Node.no_header, |
63584
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
wenzelm
parents:
63579
diff
changeset
|
285 |
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
|
286 |
val text_perspective: Text.Perspective = Text.Perspective.empty, |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
287 |
val perspective: Node.Perspective_Command = Node.no_perspective_command, |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
288 |
_commands: Node.Commands = Node.Commands.empty) |
38151 | 289 |
{ |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
290 |
def is_empty: Boolean = |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
291 |
get_blob.isEmpty && |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
292 |
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
|
293 |
text_perspective.is_empty && |
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
294 |
Node.is_no_perspective_command(perspective) && |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
295 |
commands.isEmpty |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
296 |
|
59702
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59695
diff
changeset
|
297 |
def has_header: Boolean = header != Node.no_header |
58dfaa369c11
hybrid use of command blobs: inlined errors and auxiliary files;
wenzelm
parents:
59695
diff
changeset
|
298 |
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
299 |
def commands: Linear_Set[Command] = _commands.commands |
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
300 |
def load_commands: List[Command] = _commands.load_commands |
64799 | 301 |
def load_commands_changed(doc_blobs: Blobs): Boolean = |
302 |
load_commands.exists(_.blobs_changed(doc_blobs)) |
|
57615
df1b3452d71c
more explicit discrimination of empty nodes -- suppress from Theories panel;
wenzelm
parents:
57614
diff
changeset
|
303 |
|
64799 | 304 |
def init_blob(blob: Blob): Node = new Node(get_blob = Some(blob.unchanged)) |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
305 |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
306 |
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
|
307 |
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
|
308 |
|
63584
68751fe1c036
tuned signature -- prover-independence is presently theoretical;
wenzelm
parents:
63579
diff
changeset
|
309 |
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
|
310 |
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
|
311 |
|
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
312 |
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
|
313 |
new_text_perspective: Text.Perspective, |
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
314 |
new_perspective: Node.Perspective_Command): Node = |
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
315 |
new Node(get_blob, header, syntax, new_text_perspective, new_perspective, _commands) |
46680 | 316 |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
317 |
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
|
318 |
Node.Perspective(perspective.required, text_perspective, perspective.overlays) |
46680 | 319 |
|
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
320 |
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
|
321 |
other_text_perspective: Text.Perspective, |
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
322 |
other_perspective: Node.Perspective_Command): Boolean = |
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
323 |
text_perspective == other_text_perspective && |
52849 | 324 |
perspective.required == other_perspective.required && |
325 |
perspective.visible.same(other_perspective.visible) && |
|
326 |
perspective.overlays == other_perspective.overlays |
|
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52568
diff
changeset
|
327 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
328 |
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
|
329 |
if (new_commands eq _commands.commands) this |
59372
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
330 |
else |
503739360344
proper update of perspective after implicit edit due to reparse (e.g. ~~/src/HOL/Nat.thy);
wenzelm
parents:
59319
diff
changeset
|
331 |
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
|
332 |
Node.Commands(new_commands)) |
38151 | 333 |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
334 |
def command_iterator(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
335 |
_commands.iterator(i) |
38151 | 336 |
|
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
337 |
def command_iterator(range: Text.Range): Iterator[(Command, Text.Offset)] = |
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
338 |
command_iterator(range.start) takeWhile { case (_, start) => start < range.stop } |
38151 | 339 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
340 |
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
|
341 |
Node.Commands.starts(commands.iterator).find(_._1 == cmd).map(_._2) |
67247 | 342 |
|
67251 | 343 |
def source: String = |
67247 | 344 |
get_blob match { |
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67264
diff
changeset
|
345 |
case Some(blob) => blob.source |
67247 | 346 |
case None => command_iterator(0).map({ case (cmd, _) => cmd.source }).mkString |
347 |
} |
|
38151 | 348 |
} |
349 |
||
350 |
||
46723 | 351 |
/* development graph */ |
352 |
||
353 |
object Nodes |
|
354 |
{ |
|
355 |
val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering)) |
|
356 |
} |
|
357 |
||
358 |
final class Nodes private(graph: Graph[Node.Name, Node]) |
|
359 |
{ |
|
360 |
def apply(name: Node.Name): Node = |
|
361 |
graph.default_node(name, Node.empty).get_node(name) |
|
362 |
||
68299
0b5a23477911
clarified signature -- avoid confusion with Resources.is_hidden;
wenzelm
parents:
68114
diff
changeset
|
363 |
def is_suppressed(name: Node.Name): Boolean = |
57619 | 364 |
{ |
365 |
val graph1 = graph.default_node(name, Node.empty) |
|
366 |
graph1.is_maximal(name) && graph1.get_node(name).is_empty |
|
367 |
} |
|
57617 | 368 |
|
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
|
369 |
def purge_suppressed: Option[Nodes] = |
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
|
370 |
graph.keys_iterator.filter(is_suppressed(_)).toList match { |
67112 | 371 |
case Nil => None |
372 |
case del => Some(new Nodes((graph /: del)(_.del_node(_)))) |
|
373 |
} |
|
67110
3156faac30a7
purge hidden nodes more thoroughly: is_hidden may become true only later;
wenzelm
parents:
67014
diff
changeset
|
374 |
|
46723 | 375 |
def + (entry: (Node.Name, Node)): Nodes = |
376 |
{ |
|
377 |
val (name, node) = entry |
|
59695 | 378 |
val imports = node.header.imports.map(_._1) |
46723 | 379 |
val graph1 = |
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
380 |
(graph.default_node(name, Node.empty) /: imports)((g, p) => g.default_node(p, Node.empty)) |
46723 | 381 |
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
|
382 |
val graph3 = (graph2 /: imports)((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
|
383 |
new Nodes(graph3.map_node(name, _ => node)) |
46723 | 384 |
} |
385 |
||
68321 | 386 |
def domain: Set[Node.Name] = graph.domain |
387 |
||
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
388 |
def iterator: Iterator[(Node.Name, Node)] = |
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
389 |
graph.iterator.map({ case (name, (node, _)) => (name, node) }) |
46723 | 390 |
|
64799 | 391 |
def commands_loading(file_name: Node.Name): List[Command] = |
54528 | 392 |
(for { |
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
56354
diff
changeset
|
393 |
(_, node) <- iterator |
56314 | 394 |
cmd <- node.load_commands.iterator |
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54528
diff
changeset
|
395 |
name <- cmd.blobs_names.iterator |
54528 | 396 |
if name == file_name |
397 |
} yield cmd).toList |
|
398 |
||
46942
f5c2d66faa04
basic support for outer syntax keywords in theory header;
wenzelm
parents:
46941
diff
changeset
|
399 |
def descendants(names: List[Node.Name]): List[Node.Name] = graph.all_succs(names) |
46723 | 400 |
def topological_order: List[Node.Name] = graph.topological_order |
56337 | 401 |
|
402 |
override def toString: String = topological_order.mkString("Nodes(", ",", ")") |
|
46723 | 403 |
} |
404 |
||
405 |
||
38424 | 406 |
|
407 |
/** versioning **/ |
|
408 |
||
409 |
/* particular document versions */ |
|
34485 | 410 |
|
38417 | 411 |
object Version |
412 |
{ |
|
46681 | 413 |
val init: Version = new Version() |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
57976
diff
changeset
|
414 |
def make(nodes: Nodes): Version = new Version(Document_ID.make(), nodes) |
67112 | 415 |
|
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
416 |
def purge_future(versions: Map[Document_ID.Version, Version], future: Future[Version]) |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
417 |
: Future[Version] = |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
418 |
{ |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
419 |
if (future.is_finished) { |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
420 |
val version = future.join |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
421 |
versions.get(version.id) match { |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
422 |
case Some(version1) if !(version eq version1) => Future.value(version1) |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
423 |
case _ => future |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
424 |
} |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
425 |
} |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
426 |
else future |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
427 |
} |
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
|
428 |
|
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
|
429 |
def purge_suppressed( |
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
|
430 |
versions: Map[Document_ID.Version, Version]): Map[Document_ID.Version, Version] = |
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
|
431 |
{ |
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
|
432 |
(versions /: |
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
|
433 |
(for ((id, v) <- versions.iterator; v1 <- v.purge_suppressed) yield (id, v1)))(_ + _) |
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
|
434 |
} |
38417 | 435 |
} |
436 |
||
46712 | 437 |
final class Version private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
438 |
val id: Document_ID.Version = Document_ID.none, |
46723 | 439 |
val nodes: Nodes = Nodes.empty) |
46941 | 440 |
{ |
55777 | 441 |
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
|
442 |
|
68299
0b5a23477911
clarified signature -- avoid confusion with Resources.is_hidden;
wenzelm
parents:
68114
diff
changeset
|
443 |
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
|
444 |
nodes.purge_suppressed.map(new Version(id, _)) |
46941 | 445 |
} |
34660 | 446 |
|
34859 | 447 |
|
38424 | 448 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
449 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
450 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
451 |
{ |
46678 | 452 |
val init: Change = new Change() |
453 |
||
454 |
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
|
455 |
new Change(Some(previous), edits.reverse, version) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
456 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
457 |
|
46712 | 458 |
final class Change private( |
46677 | 459 |
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
|
460 |
val rev_edits: List[Edit_Text] = Nil, |
46677 | 461 |
val version: Future[Version] = Future.value(Version.init)) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
462 |
{ |
44672 | 463 |
def is_finished: Boolean = |
464 |
(previous match { case None => true case Some(future) => future.is_finished }) && |
|
465 |
version.is_finished |
|
466 |
||
46678 | 467 |
def truncate: Change = new Change(None, Nil, version) |
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
468 |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
469 |
def purge(versions: Map[Document_ID.Version, Version]): Option[Change] = |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
470 |
{ |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
471 |
val previous1 = previous.map(Version.purge_future(versions, _)) |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
472 |
val version1 = Version.purge_future(versions, version) |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
473 |
if ((previous eq previous1) && (version eq version1)) None |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
474 |
else Some(new Change(previous1, rev_edits, version1)) |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
475 |
} |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
476 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
477 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
478 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
479 |
/* history navigation */ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
480 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
481 |
object History |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
482 |
{ |
46679 | 483 |
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
|
484 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
485 |
|
46712 | 486 |
final class History private( |
46679 | 487 |
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
|
488 |
{ |
67114 | 489 |
override def toString: String = "History(" + undo_list.length + ")" |
490 |
||
46679 | 491 |
def tip: Change = undo_list.head |
492 |
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
|
493 |
|
46679 | 494 |
def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] = |
495 |
{ |
|
496 |
val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1 |
|
497 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
498 |
||
499 |
retained.splitAt(retained.length - 1) match { |
|
500 |
case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate))) |
|
501 |
case _ => None |
|
502 |
} |
|
503 |
} |
|
68066
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
504 |
|
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
505 |
def purge(versions: Map[Document_ID.Version, Version]): History = |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
506 |
{ |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
507 |
val undo_list1 = undo_list.map(_.purge(versions)) |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
508 |
if (undo_list1.forall(_.isEmpty)) this |
63f03ee4057e
purge history more thoroughly (see also 3156faac30a7);
wenzelm
parents:
67943
diff
changeset
|
509 |
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
|
510 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
511 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
512 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
513 |
|
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
514 |
/* snapshot */ |
38424 | 515 |
|
52972 | 516 |
object Snapshot |
517 |
{ |
|
518 |
val init = State.init.snapshot() |
|
519 |
} |
|
520 |
||
38424 | 521 |
abstract class Snapshot |
522 |
{ |
|
64798 | 523 |
def state: State |
524 |
def version: Version |
|
525 |
def is_outdated: Boolean |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
526 |
|
38427 | 527 |
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
|
528 |
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
|
529 |
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
|
530 |
def revert(range: Text.Range): Text.Range |
52972 | 531 |
|
64798 | 532 |
def node_name: Node.Name |
533 |
def node: Node |
|
66040 | 534 |
|
64799 | 535 |
def commands_loading: List[Command] |
536 |
def commands_loading_ranges(pred: Node.Name => Boolean): List[Text.Range] |
|
65199
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
537 |
def current_command(other_node_name: Node.Name, offset: Text.Offset): Option[Command] |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
538 |
|
66043 | 539 |
def markup_to_XML(range: Text.Range, elements: Markup.Elements): XML.Body |
68365 | 540 |
def messages: List[(XML.Tree, Position.T)] |
541 |
def exports: List[Export.Entry] |
|
68417 | 542 |
def exports_map: Map[String, Export.Entry] |
66040 | 543 |
|
64665 | 544 |
def find_command(id: Document_ID.Generic): Option[(Node, Command)] |
545 |
def find_command_position(id: Document_ID.Generic, offset: Symbol.Offset) |
|
546 |
: Option[Line.Node_Position] |
|
547 |
||
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
548 |
def cumulate[A]( |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
549 |
range: Text.Range, |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
550 |
info: A, |
56743 | 551 |
elements: Markup.Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
552 |
result: List[Command.State] => (A, Text.Markup) => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
553 |
status: Boolean = false): List[Text.Info[A]] |
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
554 |
|
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
555 |
def select[A]( |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
556 |
range: Text.Range, |
56743 | 557 |
elements: Markup.Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
558 |
result: List[Command.State] => Text.Markup => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
559 |
status: Boolean = false): List[Text.Info[A]] |
65332 | 560 |
|
561 |
def command_results(range: Text.Range): Command.Results |
|
562 |
def command_results(command: Command): Command.Results |
|
68836 | 563 |
|
564 |
def command_id_map: Map[Document_ID.Generic, Command] |
|
38424 | 565 |
} |
566 |
||
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
567 |
|
64814 | 568 |
/* model */ |
569 |
||
65221 | 570 |
trait Session |
571 |
{ |
|
572 |
def resources: Resources |
|
573 |
} |
|
574 |
||
64814 | 575 |
trait Model |
576 |
{ |
|
577 |
def session: Session |
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
578 |
def is_stable: Boolean |
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
579 |
def snapshot(): Snapshot |
64814 | 580 |
|
65356 | 581 |
def node_name: Node.Name |
64814 | 582 |
def is_theory: Boolean = node_name.is_theory |
583 |
override def toString: String = node_name.toString |
|
584 |
||
67014 | 585 |
def get_text(range: Text.Range): Option[String] |
66114 | 586 |
|
64815 | 587 |
def node_required: Boolean |
65356 | 588 |
def get_blob: Option[Blob] |
67247 | 589 |
def is_bibtex: Boolean = node_name.is_bibtex |
67309 | 590 |
def is_bibtex_theory: Boolean = node_name.is_bibtex_theory |
66150 | 591 |
def bibtex_entries: List[Text.Info[String]] |
64815 | 592 |
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
593 |
def node_edits( |
64867 | 594 |
node_header: Node.Header, |
595 |
text_edits: List[Text.Edit], |
|
596 |
perspective: Node.Perspective_Text): List[Edit_Text] = |
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
597 |
{ |
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
598 |
val edits: List[Node.Edit[Text.Edit, Text.Perspective]] = |
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
599 |
get_blob match { |
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
600 |
case None => |
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
601 |
List( |
65356 | 602 |
Node.Deps( |
66773 | 603 |
if (session.resources.session_base.loaded_theory(node_name)) { |
604 |
node_header.append_errors( |
|
605 |
List("Cannot update finished theory " + quote(node_name.theory))) |
|
606 |
} |
|
64827
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
607 |
else node_header), |
65356 | 608 |
Node.Edits(text_edits), perspective) |
609 |
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
|
610 |
} |
4ef1eb75f1cd
uniform Document.Model.node_edits (without void edits);
wenzelm
parents:
64819
diff
changeset
|
611 |
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
|
612 |
} |
64814 | 613 |
} |
614 |
||
615 |
||
55820
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
616 |
/** global state -- document structure, execution process, editing history **/ |
61869776ce1f
tuned signature -- more explicit Document.Elements;
wenzelm
parents:
55801
diff
changeset
|
617 |
|
52563 | 618 |
type Assign_Update = |
619 |
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
|
620 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
621 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
622 |
{ |
38373 | 623 |
class Fail(state: State) extends Exception |
624 |
||
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
625 |
object Assignment |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
626 |
{ |
46683 | 627 |
val init: Assignment = new Assignment() |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
628 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
629 |
|
46712 | 630 |
final class Assignment private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
631 |
val command_execs: Map[Document_ID.Command, List[Document_ID.Exec]] = Map.empty, |
46677 | 632 |
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
|
633 |
{ |
67114 | 634 |
override def toString: String = "Assignment(" + command_execs.size + "," + is_finished + ")" |
635 |
||
44477 | 636 |
def check_finished: Assignment = { require(is_finished); this } |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
637 |
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
|
638 |
|
52563 | 639 |
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
|
640 |
{ |
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
|
641 |
require(!is_finished) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
642 |
val command_execs1 = |
52563 | 643 |
(command_execs /: update) { |
644 |
case (res, (command_id, exec_ids)) => |
|
645 |
if (exec_ids.isEmpty) res - command_id |
|
646 |
else res + (command_id -> exec_ids) |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
647 |
} |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
648 |
new Assignment(command_execs1, true) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
649 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
650 |
} |
46682 | 651 |
|
652 |
val init: State = |
|
52563 | 653 |
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
|
654 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
655 |
|
46712 | 656 |
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
|
657 |
/*reachable versions*/ |
60215 | 658 |
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
|
659 |
/*inlined auxiliary files*/ |
60215 | 660 |
blobs: Set[SHA1.Digest] = Set.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
|
661 |
/*static markup from define_command*/ |
60215 | 662 |
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
|
663 |
/*dynamic markup from execution*/ |
60215 | 664 |
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
|
665 |
/*command-exec assignment for each version*/ |
60215 | 666 |
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
|
667 |
/*commands with markup produced by other commands (imm_succs)*/ |
60215 | 668 |
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
|
669 |
/*explicit (linear) history*/ |
60215 | 670 |
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
|
671 |
/*intermediate state between remove_versions/removed_versions*/ |
60215 | 672 |
removing_versions: Boolean = false) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
673 |
{ |
68496 | 674 |
override def toString: String = |
675 |
"State(versions = " + versions.size + |
|
676 |
", blobs = " + blobs.size + |
|
677 |
", commands = " + commands.size + |
|
678 |
", execs = " + execs.size + |
|
679 |
", assignments = " + assignments.size + |
|
680 |
", commands_redirection = " + commands_redirection.size + |
|
681 |
", history = " + history.undo_list.size + |
|
682 |
", removing_versions = " + removing_versions + ")" |
|
683 |
||
38373 | 684 |
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
|
685 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
686 |
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
|
687 |
{ |
38417 | 688 |
val id = version.id |
689 |
copy(versions = versions + (id -> version), |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
690 |
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
|
691 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
692 |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
693 |
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
|
694 |
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
|
695 |
|
38373 | 696 |
def define_command(command: Command): State = |
697 |
{ |
|
698 |
val id = command.id |
|
49414 | 699 |
copy(commands = commands + (id -> command.init_state)) |
38373 | 700 |
} |
701 |
||
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
702 |
def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id) |
44582 | 703 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
704 |
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
|
705 |
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
|
706 |
def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail) |
52563 | 707 |
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
|
708 |
|
68857 | 709 |
def lookup_id(id: Document_ID.Generic): Option[Command.State] = |
710 |
commands.get(id) orElse execs.get(id) |
|
711 |
||
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
|
712 |
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
|
713 |
id == st.command.id || |
a40e67ce4f84
clarified valid_id: always standardize towards static command.id;
wenzelm
parents:
56176
diff
changeset
|
714 |
(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
|
715 |
|
56746 | 716 |
private def other_id(id: Document_ID.Generic) |
63032
e0fa59bbc956
reactivated other_id reports (see also db929027e701, 8eda56033203);
wenzelm
parents:
63020
diff
changeset
|
717 |
: Option[(Symbol.Text_Chunk.Id, Symbol.Text_Chunk)] = |
68857 | 718 |
lookup_id(id).map(st => ((Symbol.Text_Chunk.Id(st.command.id), st.command.chunk))) |
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
|
719 |
|
56475 | 720 |
private def redirection(st: Command.State): Graph[Document_ID.Command, Unit] = |
721 |
(commands_redirection /: st.markups.redirection_iterator)({ case (graph, 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
|
722 |
graph.default_node(id, ()).default_node(st.command.id, ()).add_edge(id, st.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
|
723 |
|
67825 | 724 |
def accumulate(id: Document_ID.Generic, message: XML.Elem, xml_cache: XML.Cache) |
725 |
: (Command.State, 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
|
726 |
{ |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
727 |
execs.get(id) match { |
44446 | 728 |
case Some(st) => |
67825 | 729 |
val new_st = st.accumulate(self_id(st), other_id _, message, xml_cache) |
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
|
730 |
val execs1 = execs + (id -> new_st) |
56475 | 731 |
(new_st, copy(execs = execs1, commands_redirection = redirection(new_st))) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
732 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
733 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
734 |
case Some(st) => |
67825 | 735 |
val new_st = st.accumulate(self_id(st), other_id _, message, xml_cache) |
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
|
736 |
val commands1 = commands + (id -> new_st) |
56475 | 737 |
(new_st, copy(commands = commands1, commands_redirection = redirection(new_st))) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
738 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
739 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
740 |
} |
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
|
741 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
742 |
|
68101 | 743 |
def add_export(id: Document_ID.Generic, entry: Command.Exports.Entry): (Command.State, State) = |
744 |
{ |
|
745 |
execs.get(id) match { |
|
746 |
case Some(st) => |
|
68114 | 747 |
st.add_export(entry) match { |
748 |
case Some(new_st) => (new_st, copy(execs = execs + (id -> new_st))) |
|
749 |
case None => fail |
|
750 |
} |
|
68101 | 751 |
case None => |
752 |
commands.get(id) match { |
|
753 |
case Some(st) => |
|
68114 | 754 |
st.add_export(entry) match { |
755 |
case Some(new_st) => (new_st, copy(commands = commands + (id -> new_st))) |
|
756 |
case None => fail |
|
757 |
} |
|
68101 | 758 |
case None => fail |
759 |
} |
|
760 |
} |
|
761 |
} |
|
762 |
||
52563 | 763 |
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
|
764 |
{ |
38417 | 765 |
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
|
766 |
|
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
767 |
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
|
768 |
: 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
|
769 |
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
|
770 |
|
44543 | 771 |
val (changed_commands, new_execs) = |
52563 | 772 |
((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
|
773 |
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
|
774 |
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
|
775 |
val command = st.command |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
776 |
val commands2 = command :: commands1 |
44543 | 777 |
val execs2 = |
778 |
exec match { |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
779 |
case Nil => execs1 |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
780 |
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
|
781 |
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
|
782 |
(for (id <- print_ids; up <- upd(id, command.empty_state)) yield up) |
44543 | 783 |
} |
784 |
(commands2, execs2) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
785 |
} |
52563 | 786 |
val new_assignment = the_assignment(version).assign(update) |
43722 | 787 |
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
|
788 |
|
44543 | 789 |
(changed_commands, new_state) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
790 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
791 |
|
38417 | 792 |
def is_assigned(version: Version): Boolean = |
43722 | 793 |
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
|
794 |
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
|
795 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
796 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
797 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
798 |
def is_stable(change: Change): Boolean = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
799 |
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
|
800 |
|
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
801 |
def recent_finished: Change = history.undo_list.find(_.is_finished) getOrElse fail |
44672 | 802 |
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
|
803 |
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
|
804 |
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
|
805 |
|
44446 | 806 |
def continue_history( |
56711 | 807 |
previous: Future[Version], |
808 |
edits: List[Edit_Text], |
|
809 |
version: Future[Version]): State = |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
810 |
{ |
46678 | 811 |
val change = Change.make(previous, edits, version) |
56711 | 812 |
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
|
813 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
814 |
|
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
|
815 |
def remove_versions(retain: Int = 0): (List[Version], State) = |
44672 | 816 |
{ |
46679 | 817 |
history.prune(is_stable, retain) match { |
818 |
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
|
819 |
val old_versions = dropped.map(change => change.version.get_finished) |
59319 | 820 |
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
|
821 |
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
|
822 |
(old_versions, state1) |
46679 | 823 |
case None => fail |
44672 | 824 |
} |
825 |
} |
|
826 |
||
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
827 |
def removed_versions(removed: List[Document_ID.Version]): State = |
44676 | 828 |
{ |
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
|
829 |
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
|
830 |
|
44676 | 831 |
val assignments1 = assignments -- removed |
67112 | 832 |
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
|
833 |
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
|
834 |
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
|
835 |
var execs1 = Map.empty[Document_ID.Exec, Command.State] |
44676 | 836 |
for { |
67112 | 837 |
(version_id, version) <- versions1.iterator |
46997 | 838 |
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
|
839 |
(_, node) <- version.nodes.iterator |
44676 | 840 |
command <- node.commands.iterator |
841 |
} { |
|
67112 | 842 |
for ((name, digest) <- command.blobs_defined) { |
843 |
blobs1_names += name |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
844 |
blobs1 += digest |
67112 | 845 |
} |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
846 |
|
52568 | 847 |
if (!commands1.isDefinedAt(command.id)) |
848 |
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
|
849 |
|
52568 | 850 |
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
|
851 |
if (!execs1.isDefinedAt(exec_id)) |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
852 |
execs.get(exec_id).foreach(st => execs1 += (exec_id -> st)) |
44676 | 853 |
} |
854 |
} |
|
67112 | 855 |
|
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
|
856 |
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
|
857 |
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
|
858 |
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
|
859 |
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
|
860 |
execs = execs1, |
56475 | 861 |
commands_redirection = commands_redirection.restrict(commands1.isDefinedAt(_)), |
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
|
862 |
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
|
863 |
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
|
864 |
removing_versions = false) |
44676 | 865 |
} |
866 |
||
68836 | 867 |
def command_id_map(version: Version, commands: Iterable[Command]) |
868 |
: Map[Document_ID.Generic, Command] = |
|
869 |
{ |
|
870 |
require(is_assigned(version)) |
|
871 |
val assignment = the_assignment(version).check_finished |
|
872 |
(for { |
|
873 |
command <- commands.iterator |
|
874 |
id <- (command.id :: assignment.command_execs.getOrElse(command.id, Nil)).iterator |
|
875 |
} yield (id -> command)).toMap |
|
876 |
} |
|
877 |
||
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
878 |
def command_state_eval(version: Version, command: Command): Option[Command.State] = |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
879 |
{ |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
880 |
require(is_assigned(version)) |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
881 |
try { |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
882 |
the_assignment(version).check_finished.command_execs.getOrElse(command.id, Nil) match { |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
883 |
case eval_id :: _ => Some(the_dynamic_state(eval_id)) |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
884 |
case Nil => None |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
885 |
} |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
886 |
} |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
887 |
catch { case _: State.Fail => None } |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
888 |
} |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
889 |
|
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
|
890 |
private def command_states_self(version: Version, command: 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
|
891 |
: List[(Document_ID.Generic, Command.State)] = |
44613 | 892 |
{ |
893 |
require(is_assigned(version)) |
|
894 |
try { |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
895 |
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
|
896 |
.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
|
897 |
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
|
898 |
case res => res |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
899 |
} |
44613 | 900 |
} |
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
901 |
catch { |
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
902 |
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
|
903 |
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
|
904 |
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
|
905 |
} |
44613 | 906 |
} |
907 |
||
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
|
908 |
def command_states(version: Version, command: Command): List[Command.State] = |
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
909 |
{ |
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
910 |
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
|
911 |
val others = |
56475 | 912 |
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
|
913 |
(for { |
56475 | 914 |
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
|
915 |
(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
|
916 |
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
|
917 |
} 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
|
918 |
} |
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
919 |
else Nil |
56489 | 920 |
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
|
921 |
} |
8eda56033203
accumulate markup reports for "other" command ids, which are later retargeted and merged for rendering (in erratic order);
wenzelm
parents:
56468
diff
changeset
|
922 |
|
56299
8201790fdeb9
more careful treatment of multiple command states (eval + prints): merge content that is actually required;
wenzelm
parents:
56298
diff
changeset
|
923 |
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
|
924 |
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
|
925 |
|
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56300
diff
changeset
|
926 |
def command_markup(version: Version, command: Command, index: Command.Markup_Index, |
56743 | 927 |
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
|
928 |
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
|
929 |
|
66041 | 930 |
def markup_to_XML( |
931 |
version: Version, |
|
67264 | 932 |
node_name: Node.Name, |
66043 | 933 |
range: Text.Range, |
66041 | 934 |
elements: Markup.Elements): XML.Body = |
935 |
{ |
|
67264 | 936 |
val node = version.nodes(node_name) |
937 |
if (node_name.is_theory) { |
|
938 |
val markup_index = Command.Markup_Index.markup |
|
939 |
(for { |
|
940 |
command <- node.commands.iterator |
|
941 |
command_range <- command.range.try_restrict(range).iterator |
|
942 |
markup = command_markup(version, command, markup_index, command_range, elements) |
|
943 |
tree <- markup.to_XML(command_range, command.source, elements).iterator |
|
944 |
} yield tree).toList |
|
945 |
} |
|
946 |
else { |
|
67265
f32287c95432
store full blob source for the sake of markup_to_XML;
wenzelm
parents:
67264
diff
changeset
|
947 |
val node_source = node.source |
67264 | 948 |
Text.Range(0, node_source.length).try_restrict(range) match { |
949 |
case None => Nil |
|
950 |
case Some(node_range) => |
|
951 |
val markup = |
|
952 |
version.nodes.commands_loading(node_name).headOption match { |
|
953 |
case None => Markup_Tree.empty |
|
954 |
case Some(command) => |
|
955 |
val chunk_name = Symbol.Text_Chunk.File(node_name.node) |
|
956 |
val markup_index = Command.Markup_Index(false, chunk_name) |
|
957 |
command_markup(version, command, markup_index, node_range, elements) |
|
958 |
} |
|
959 |
markup.to_XML(node_range, node_source, elements) |
|
960 |
} |
|
961 |
} |
|
66041 | 962 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
963 |
|
68323 | 964 |
def node_initialized(version: Version, name: Node.Name): Boolean = |
965 |
name.is_theory && |
|
966 |
(version.nodes(name).commands.iterator.find(_.potentially_initialized) match { |
|
967 |
case None => false |
|
968 |
case Some(command) => command_states(version, command).headOption.exists(_.initialized) |
|
969 |
}) |
|
970 |
||
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
971 |
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
|
972 |
name.is_theory && |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
973 |
{ |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
974 |
version.nodes(name).commands.reverse.iterator.forall(command => |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
975 |
command_state_eval(version, command) match { |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
976 |
case None => false |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
977 |
case Some(st) => st.maybe_consolidated |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
978 |
}) |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
979 |
} |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68365
diff
changeset
|
980 |
|
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
|
981 |
def node_consolidated(version: Version, name: Node.Name): Boolean = |
6392766f3c25
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm
parents:
66195
diff
changeset
|
982 |
!name.is_theory || |
68335 | 983 |
{ |
984 |
val it = version.nodes(name).commands.reverse.iterator |
|
985 |
it.hasNext && command_states(version, it.next).exists(_.consolidated) |
|
986 |
} |
|
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
|
987 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
988 |
// persistent user-view |
49346 | 989 |
def snapshot(name: Node.Name = Node.Name.empty, pending_edits: List[Text.Edit] = Nil) |
990 |
: Snapshot = |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
991 |
{ |
44672 | 992 |
val stable = recent_stable |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
993 |
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
|
994 |
|
57620
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
995 |
|
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
996 |
/* pending edits and unstable changes */ |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
997 |
|
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
998 |
val rev_pending_changes = |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
999 |
for { |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1000 |
change <- history.undo_list.takeWhile(_ != stable) |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1001 |
(a, edits) <- change.rev_edits |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1002 |
if a == name |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1003 |
} yield edits |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1004 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1005 |
val edits = |
64819 | 1006 |
(pending_edits /: rev_pending_changes)({ |
1007 |
case (edits, Node.Edits(es)) => es ::: edits |
|
1008 |
case (edits, _) => edits |
|
1009 |
}) |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1010 |
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
|
1011 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1012 |
new Snapshot |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1013 |
{ |
52972 | 1014 |
/* global information */ |
1015 |
||
64798 | 1016 |
val state: State = State.this |
1017 |
val version: Version = stable.version.get_finished |
|
1018 |
val is_outdated: Boolean = pending_edits.nonEmpty || latest != stable |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
1019 |
|
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1020 |
|
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1021 |
/* local node content */ |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1022 |
|
64819 | 1023 |
def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i)) |
1024 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
|
57620
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1025 |
|
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1026 |
def convert(range: Text.Range) = range.map(convert(_)) |
c30ab960875e
more explicit treatment of cleared nodes (removal is implicit);
wenzelm
parents:
57619
diff
changeset
|
1027 |
def revert(range: Text.Range) = range.map(revert(_)) |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
1028 |
|
64798 | 1029 |
val node_name: Node.Name = name |
64799 | 1030 |
val node: Node = version.nodes(name) |
52972 | 1031 |
|
64799 | 1032 |
val commands_loading: List[Command] = |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
1033 |
if (node_name.is_theory) Nil |
64799 | 1034 |
else version.nodes.commands_loading(node_name) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
1035 |
|
64799 | 1036 |
def commands_loading_ranges(pred: Node.Name => Boolean): List[Text.Range] = |
1037 |
(for { |
|
1038 |
cmd <- node.load_commands.iterator |
|
1039 |
blob_name <- cmd.blobs_names.iterator |
|
1040 |
if pred(blob_name) |
|
1041 |
start <- node.command_start(cmd) |
|
68728 | 1042 |
} yield convert(cmd.core_range + start)).toList |
56176
0bc9b0ad6287
tuned rendering -- avoid flashing background of aux. files that are disconnected from the document model;
wenzelm
parents:
55820
diff
changeset
|
1043 |
|
65199
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1044 |
def current_command(other_node_name: Node.Name, offset: Text.Offset): Option[Command] = |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1045 |
if (other_node_name.is_theory) { |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1046 |
val other_node = version.nodes(other_node_name) |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1047 |
val iterator = other_node.command_iterator(revert(offset) max 0) |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1048 |
if (iterator.hasNext) { |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1049 |
val (command0, _) = iterator.next |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1050 |
other_node.commands.reverse.iterator(command0).find(command => !command.is_ignored) |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1051 |
} |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1052 |
else other_node.commands.reverse.iterator.find(command => !command.is_ignored) |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1053 |
} |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1054 |
else version.nodes.commands_loading(other_node_name).headOption |
6bd7081f8319
clarified current_command: index refers to node content, negative index means first command;
wenzelm
parents:
65196
diff
changeset
|
1055 |
|
66043 | 1056 |
def markup_to_XML(range: Text.Range, elements: Markup.Elements): XML.Body = |
67264 | 1057 |
state.markup_to_XML(version, node_name, range, elements) |
66040 | 1058 |
|
68417 | 1059 |
lazy val messages: List[(XML.Tree, Position.T)] = |
68365 | 1060 |
(for { |
1061 |
(command, start) <- |
|
1062 |
Document.Node.Commands.starts_pos( |
|
1063 |
node.commands.iterator, Token.Pos.file(node_name.node)) |
|
1064 |
pos = command.span.keyword_pos(start).position(command.span.name) |
|
1065 |
(_, tree) <- state.command_results(version, command).iterator |
|
1066 |
} yield (tree, pos)).toList |
|
1067 |
||
68417 | 1068 |
lazy val exports: List[Export.Entry] = |
68365 | 1069 |
Command.Exports.merge( |
1070 |
for { |
|
1071 |
command <- node.commands.iterator |
|
1072 |
st <- state.command_states(version, command).iterator |
|
1073 |
} yield st.exports).iterator.map(_._2).toList |
|
1074 |
||
68417 | 1075 |
lazy val exports_map: Map[String, Export.Entry] = |
1076 |
(for (entry <- exports.iterator) yield (entry.name, entry)).toMap |
|
1077 |
||
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1078 |
|
64665 | 1079 |
/* find command */ |
1080 |
||
1081 |
def find_command(id: Document_ID.Generic): Option[(Node, Command)] = |
|
68857 | 1082 |
state.lookup_id(id) match { |
64665 | 1083 |
case None => None |
1084 |
case Some(st) => |
|
1085 |
val command = st.command |
|
1086 |
val node = version.nodes(command.node_name) |
|
1087 |
if (node.commands.contains(command)) Some((node, command)) else None |
|
1088 |
} |
|
1089 |
||
1090 |
def find_command_position(id: Document_ID.Generic, offset: Symbol.Offset) |
|
1091 |
: Option[Line.Node_Position] = |
|
1092 |
for ((node, command) <- find_command(id)) |
|
1093 |
yield { |
|
1094 |
val name = command.node_name.node |
|
1095 |
val sources_iterator = |
|
1096 |
node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
|
1097 |
(if (offset == 0) Iterator.empty |
|
1098 |
else Iterator.single(command.source(Text.Range(0, command.chunk.decode(offset))))) |
|
65196
e8760a98db78
discontinued pointless Text.Length: Javascript and Java agree in old-fashioned UTF-16;
wenzelm
parents:
65195
diff
changeset
|
1099 |
val pos = (Line.Position.zero /: sources_iterator)(_.advance(_)) |
64665 | 1100 |
Line.Node_Position(name, pos) |
1101 |
} |
|
1102 |
||
1103 |
||
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1104 |
/* cumulate markup */ |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1105 |
|
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
1106 |
def cumulate[A]( |
55649
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1107 |
range: Text.Range, |
1532ab0dc67b
more general / abstract Command.Markups, with separate index for status elements;
wenzelm
parents:
55620
diff
changeset
|
1108 |
info: A, |
56743 | 1109 |
elements: Markup.Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
1110 |
result: List[Command.State] => (A, Text.Markup) => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
1111 |
status: Boolean = false): List[Text.Info[A]] = |
45459 | 1112 |
{ |
56590
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
wenzelm
parents:
56514
diff
changeset
|
1113 |
val former_range = revert(range).inflate_singularity |
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
56398
diff
changeset
|
1114 |
val (chunk_name, command_iterator) = |
65187 | 1115 |
commands_loading.headOption match { |
1116 |
case None => (Symbol.Text_Chunk.Default, node.command_iterator(former_range)) |
|
1117 |
case Some(command) => (Symbol.Text_Chunk.File(node_name.node), Iterator((command, 0))) |
|
56309 | 1118 |
} |
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
56398
diff
changeset
|
1119 |
val markup_index = Command.Markup_Index(status, chunk_name) |
56309 | 1120 |
(for { |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56372
diff
changeset
|
1121 |
(command, command_start) <- command_iterator |
56462
b64b0cb845fe
more explicit Command.Chunk types, less ooddities;
wenzelm
parents:
56398
diff
changeset
|
1122 |
chunk <- command.chunks.get(chunk_name).iterator |
56309 | 1123 |
states = state.command_states(version, command) |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
1124 |
res = result(states) |
56590
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
wenzelm
parents:
56514
diff
changeset
|
1125 |
markup_range <- (former_range - command_start).try_restrict(chunk.range).iterator |
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
wenzelm
parents:
56514
diff
changeset
|
1126 |
markup = Command.State.merge_markup(states, markup_index, markup_range, elements) |
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
wenzelm
parents:
56514
diff
changeset
|
1127 |
Text.Info(r0, a) <- markup.cumulate[A](markup_range, info, elements, |
56309 | 1128 |
{ |
1129 |
case (a, Text.Info(r0, b)) => res(a, Text.Info(convert(r0 + command_start), b)) |
|
1130 |
}).iterator |
|
56590
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
wenzelm
parents:
56514
diff
changeset
|
1131 |
r1 <- convert(r0 + command_start).try_restrict(range).iterator |
d01d183e84ea
clarified treatment of markup ranges wrt. revert/convert: inflate_singularity allows to retrieve information like language_context more reliably during editing;
wenzelm
parents:
56514
diff
changeset
|
1132 |
} yield Text.Info(r1, a)).toList |
45459 | 1133 |
} |
1134 |
||
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
1135 |
def select[A]( |
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
1136 |
range: Text.Range, |
56743 | 1137 |
elements: Markup.Elements, |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
1138 |
result: List[Command.State] => Text.Markup => Option[A], |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
1139 |
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
|
1140 |
{ |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
1141 |
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
|
1142 |
{ |
56354
a6f8c3566560
more direct command states -- merge_results is hardly ever needed;
wenzelm
parents:
56337
diff
changeset
|
1143 |
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
|
1144 |
(_: 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
|
1145 |
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
|
1146 |
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
|
1147 |
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
|
1148 |
} |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
1149 |
} |
55651
fa42cf3fe79b
tuned signature -- avoid redundancy and confusion of flags;
wenzelm
parents:
55650
diff
changeset
|
1150 |
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
|
1151 |
yield Text.Info(r, x) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
1152 |
} |
55800 | 1153 |
|
1154 |
||
65332 | 1155 |
/* command results */ |
1156 |
||
1157 |
def command_results(range: Text.Range): Command.Results = |
|
1158 |
Command.State.merge_results( |
|
1159 |
select[List[Command.State]](range, Markup.Elements.full, command_states => |
|
1160 |
{ case _ => Some(command_states) }).flatMap(_.info)) |
|
1161 |
||
1162 |
def command_results(command: Command): Command.Results = |
|
1163 |
state.command_results(version, command) |
|
1164 |
||
1165 |
||
68836 | 1166 |
/* command ids: static and dynamic */ |
1167 |
||
1168 |
def command_id_map: Map[Document_ID.Generic, Command] = |
|
1169 |
state.command_id_map(version, version.nodes(node_name).commands) |
|
1170 |
||
1171 |
||
55800 | 1172 |
/* output */ |
1173 |
||
1174 |
override def toString: String = |
|
1175 |
"Snapshot(node = " + node_name.node + ", version = " + version.id + |
|
1176 |
(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
|
1177 |
} |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
1178 |
} |
34485 | 1179 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
1180 |
} |