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