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