author | wenzelm |
Fri, 14 Dec 2012 12:09:08 +0100 | |
changeset 50507 | 9605b0d93d1e |
parent 50500 | c94bba7906d2 |
child 51293 | 05b1bbae748d |
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 |
{ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
16 |
/* formal identifiers */ |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
17 |
|
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
18 |
type ID = Long |
43780 | 19 |
val ID = Properties.Value.Long |
38414
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
20 |
|
38373 | 21 |
type Version_ID = ID |
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
22 |
type Command_ID = ID |
38373 | 23 |
type Exec_ID = ID |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
24 |
|
43662
e3175ec00311
Document.no_id/new_id as in ML (new_id *could* be session-specific but it isn't right now);
wenzelm
parents:
43427
diff
changeset
|
25 |
val no_id: ID = 0 |
45243 | 26 |
val new_id = Counter() |
38355
8cb265fb12fe
represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents:
38227
diff
changeset
|
27 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
28 |
|
34818
7df68a8f0e3e
register Proof_Document instances as session entities -- handle Markup.EDIT messages locally;
wenzelm
parents:
34815
diff
changeset
|
29 |
|
38424 | 30 |
/** document structure **/ |
31 |
||
46723 | 32 |
/* individual nodes */ |
38424 | 33 |
|
44615 | 34 |
type Edit[A, B] = (Node.Name, Node.Edit[A, B]) |
44384 | 35 |
type Edit_Text = Edit[Text.Edit, Text.Perspective] |
36 |
type Edit_Command = Edit[(Option[Command], Option[Command]), Command.Perspective] |
|
38151 | 37 |
|
38 |
object Node |
|
39 |
{ |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
40 |
sealed case class Header( |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46814
diff
changeset
|
41 |
imports: List[Name], |
48706 | 42 |
keywords: Thy_Header.Keywords, |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
43 |
uses: List[(String, Boolean)], |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
44 |
errors: List[String] = Nil) |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
45 |
{ |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
46 |
def error(msg: String): Header = copy(errors = errors ::: List(msg)) |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
47 |
} |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
48 |
|
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
49 |
def bad_header(msg: String): Header = Header(Nil, Nil, Nil, List(msg)) |
46737 | 50 |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
51 |
object Name |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
52 |
{ |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
53 |
val empty = Name("", "", "") |
46723 | 54 |
|
55 |
object Ordering extends scala.math.Ordering[Name] |
|
56 |
{ |
|
57 |
def compare(name1: Name, name2: Name): Int = name1.node compare name2.node |
|
58 |
} |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
59 |
} |
44616 | 60 |
sealed case class Name(node: String, dir: String, theory: String) |
44615 | 61 |
{ |
62 |
override def hashCode: Int = node.hashCode |
|
63 |
override def equals(that: Any): Boolean = |
|
64 |
that match { |
|
65 |
case other: Name => node == other.node |
|
66 |
case _ => false |
|
67 |
} |
|
44642 | 68 |
override def toString: String = theory |
44615 | 69 |
} |
70 |
||
44384 | 71 |
sealed abstract class Edit[A, B] |
44156 | 72 |
{ |
44383 | 73 |
def foreach(f: A => Unit) |
74 |
{ |
|
44156 | 75 |
this match { |
44383 | 76 |
case Edits(es) => es.foreach(f) |
77 |
case _ => |
|
44156 | 78 |
} |
44383 | 79 |
} |
44156 | 80 |
} |
44384 | 81 |
case class Clear[A, B]() extends Edit[A, B] |
82 |
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
|
83 |
case class Deps[A, B](header: Header) extends Edit[A, B] |
44384 | 84 |
case class Perspective[A, B](perspective: B) extends Edit[A, B] |
44156 | 85 |
|
38426 | 86 |
def command_starts(commands: Iterator[Command], offset: Text.Offset = 0) |
87 |
: Iterator[(Command, Text.Offset)] = |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
88 |
{ |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
89 |
var i = offset |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
90 |
for (command <- commands) yield { |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
91 |
val start = i |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
92 |
i += command.length |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
93 |
(command, start) |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
94 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
95 |
} |
46680 | 96 |
|
97 |
private val block_size = 1024 |
|
98 |
||
99 |
val empty: Node = new Node() |
|
38151 | 100 |
} |
101 |
||
46712 | 102 |
final class Node private( |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
103 |
val header: Node.Header = Node.bad_header("Bad theory header"), |
46677 | 104 |
val perspective: Command.Perspective = Command.Perspective.empty, |
105 |
val commands: Linear_Set[Command] = Linear_Set.empty) |
|
38151 | 106 |
{ |
46680 | 107 |
def clear: Node = new Node(header = header) |
108 |
||
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
109 |
def update_header(new_header: Node.Header): Node = |
49678 | 110 |
new Node(new_header, perspective, commands) |
46680 | 111 |
|
112 |
def update_perspective(new_perspective: Command.Perspective): Node = |
|
49678 | 113 |
new Node(header, new_perspective, commands) |
46680 | 114 |
|
115 |
def update_commands(new_commands: Linear_Set[Command]): Node = |
|
49678 | 116 |
new Node(header, perspective, new_commands) |
44443
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
117 |
|
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
118 |
|
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
119 |
/* commands */ |
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
120 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
121 |
private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) = |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
122 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
123 |
val blocks = new mutable.ListBuffer[(Command, Text.Offset)] |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
124 |
var next_block = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
125 |
var last_stop = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
126 |
for ((command, start) <- Node.command_starts(commands.iterator)) { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
127 |
last_stop = start + command.length |
38885
06582837872b
Node.full_index: allow command spans larger than block_size;
wenzelm
parents:
38882
diff
changeset
|
128 |
while (last_stop + 1 > next_block) { |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
129 |
blocks += (command -> start) |
46680 | 130 |
next_block += Node.block_size |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
131 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
132 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
133 |
(blocks.toArray, Text.Range(0, last_stop)) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
134 |
} |
38151 | 135 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
136 |
def full_range: Text.Range = full_index._2 |
38151 | 137 |
|
38569 | 138 |
def command_range(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
139 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
140 |
if (!commands.isEmpty && full_range.contains(i)) { |
46680 | 141 |
val (cmd0, start0) = full_index._1(i / Node.block_size) |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
142 |
Node.command_starts(commands.iterator(cmd0), start0) dropWhile { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
143 |
case (cmd, start) => start + cmd.length <= i } |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
144 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
145 |
else Iterator.empty |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
146 |
} |
38151 | 147 |
|
38569 | 148 |
def command_range(range: Text.Range): Iterator[(Command, Text.Offset)] = |
149 |
command_range(range.start) takeWhile { case (_, start) => start < range.stop } |
|
38151 | 150 |
|
38426 | 151 |
def command_at(i: Text.Offset): Option[(Command, Text.Offset)] = |
38151 | 152 |
{ |
153 |
val range = command_range(i) |
|
154 |
if (range.hasNext) Some(range.next) else None |
|
155 |
} |
|
156 |
||
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
157 |
def command_start(cmd: Command): Option[Text.Offset] = |
46677 | 158 |
Node.command_starts(commands.iterator).find(_._1 == cmd).map(_._2) |
38151 | 159 |
} |
160 |
||
161 |
||
46723 | 162 |
/* development graph */ |
163 |
||
164 |
object Nodes |
|
165 |
{ |
|
166 |
val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering)) |
|
167 |
} |
|
168 |
||
169 |
final class Nodes private(graph: Graph[Node.Name, Node]) |
|
170 |
{ |
|
171 |
def get_name(s: String): Option[Node.Name] = |
|
172 |
graph.keys.find(name => name.node == s) |
|
173 |
||
174 |
def apply(name: Node.Name): Node = |
|
175 |
graph.default_node(name, Node.empty).get_node(name) |
|
176 |
||
177 |
def + (entry: (Node.Name, Node)): Nodes = |
|
178 |
{ |
|
179 |
val (name, node) = entry |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
180 |
val imports = node.header.imports |
46723 | 181 |
val graph1 = |
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
182 |
(graph.default_node(name, Node.empty) /: imports)((g, p) => g.default_node(p, Node.empty)) |
46723 | 183 |
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
|
184 |
val graph3 = (graph2 /: imports)((g, dep) => g.add_edge(dep, name)) |
46723 | 185 |
new Nodes(graph3.map_node(name, _ => node)) |
186 |
} |
|
187 |
||
188 |
def entries: Iterator[(Node.Name, Node)] = |
|
189 |
graph.entries.map({ case (name, (node, _)) => (name, node) }) |
|
190 |
||
46942
f5c2d66faa04
basic support for outer syntax keywords in theory header;
wenzelm
parents:
46941
diff
changeset
|
191 |
def descendants(names: List[Node.Name]): List[Node.Name] = graph.all_succs(names) |
46723 | 192 |
def topological_order: List[Node.Name] = graph.topological_order |
193 |
} |
|
194 |
||
195 |
||
38424 | 196 |
|
197 |
/** versioning **/ |
|
198 |
||
199 |
/* particular document versions */ |
|
34485 | 200 |
|
38417 | 201 |
object Version |
202 |
{ |
|
46681 | 203 |
val init: Version = new Version() |
204 |
||
46941 | 205 |
def make(syntax: Outer_Syntax, nodes: Nodes): Version = |
206 |
new Version(new_id(), syntax, nodes) |
|
38417 | 207 |
} |
208 |
||
46712 | 209 |
final class Version private( |
46677 | 210 |
val id: Version_ID = no_id, |
46941 | 211 |
val syntax: Outer_Syntax = Outer_Syntax.empty, |
46723 | 212 |
val nodes: Nodes = Nodes.empty) |
46941 | 213 |
{ |
214 |
def is_init: Boolean = id == no_id |
|
215 |
} |
|
34660 | 216 |
|
34859 | 217 |
|
38424 | 218 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
219 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
220 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
221 |
{ |
46678 | 222 |
val init: Change = new Change() |
223 |
||
224 |
def make(previous: Future[Version], edits: List[Edit_Text], version: Future[Version]): Change = |
|
225 |
new Change(Some(previous), edits, version) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
226 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
227 |
|
46712 | 228 |
final class Change private( |
46677 | 229 |
val previous: Option[Future[Version]] = Some(Future.value(Version.init)), |
230 |
val edits: List[Edit_Text] = Nil, |
|
231 |
val version: Future[Version] = Future.value(Version.init)) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
232 |
{ |
44672 | 233 |
def is_finished: Boolean = |
234 |
(previous match { case None => true case Some(future) => future.is_finished }) && |
|
235 |
version.is_finished |
|
236 |
||
46678 | 237 |
def truncate: Change = new Change(None, Nil, version) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
238 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
239 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
240 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
241 |
/* history navigation */ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
242 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
243 |
object History |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
244 |
{ |
46679 | 245 |
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
|
246 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
247 |
|
46712 | 248 |
final class History private( |
46679 | 249 |
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
|
250 |
{ |
46679 | 251 |
def tip: Change = undo_list.head |
252 |
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
|
253 |
|
46679 | 254 |
def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] = |
255 |
{ |
|
256 |
val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1 |
|
257 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
258 |
||
259 |
retained.splitAt(retained.length - 1) match { |
|
260 |
case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate))) |
|
261 |
case _ => None |
|
262 |
} |
|
263 |
} |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
264 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
265 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
266 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
267 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
268 |
/** global state -- document structure, execution process, editing history **/ |
38424 | 269 |
|
270 |
abstract class Snapshot |
|
271 |
{ |
|
44582 | 272 |
val state: State |
38424 | 273 |
val version: Version |
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48793
diff
changeset
|
274 |
val node_name: Node.Name |
38424 | 275 |
val node: Node |
276 |
val is_outdated: Boolean |
|
38427 | 277 |
def convert(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
|
278 |
def convert(range: Text.Range): Text.Range |
38427 | 279 |
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
|
280 |
def revert(range: Text.Range): Text.Range |
49346 | 281 |
def eq_markup(other: Snapshot): Boolean |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
282 |
def cumulate_markup[A](range: Text.Range, info: A, elements: Option[Set[String]], |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
283 |
result: Command.State => PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]] |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
284 |
def select_markup[A](range: Text.Range, elements: Option[Set[String]], |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
285 |
result: Command.State => PartialFunction[Text.Markup, A]): Stream[Text.Info[A]] |
38424 | 286 |
} |
287 |
||
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
288 |
type Assign = List[(Document.Command_ID, Option[Document.Exec_ID])] // exec state assignment |
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
289 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
290 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
291 |
{ |
38373 | 292 |
class Fail(state: State) extends Exception |
293 |
||
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
294 |
object Assignment |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
295 |
{ |
46683 | 296 |
val init: Assignment = new Assignment() |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
297 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
298 |
|
46712 | 299 |
final class Assignment private( |
46677 | 300 |
val command_execs: Map[Command_ID, Exec_ID] = Map.empty, |
301 |
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
|
302 |
{ |
44477 | 303 |
def check_finished: Assignment = { require(is_finished); this } |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
304 |
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
|
305 |
|
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
306 |
def assign(add_command_execs: List[(Command_ID, Option[Exec_ID])]): Assignment = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
307 |
{ |
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
|
308 |
require(!is_finished) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
309 |
val command_execs1 = |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
310 |
(command_execs /: add_command_execs) { |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
311 |
case (res, (command_id, None)) => res - command_id |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
312 |
case (res, (command_id, Some(exec_id))) => res + (command_id -> exec_id) |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
313 |
} |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
314 |
new Assignment(command_execs1, true) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
315 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
316 |
} |
46682 | 317 |
|
318 |
val init: State = |
|
319 |
State().define_version(Version.init, Assignment.init).assign(Version.init.id)._2 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
320 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
321 |
|
46712 | 322 |
final case class State private( |
46677 | 323 |
val versions: Map[Version_ID, Version] = Map.empty, |
324 |
val commands: Map[Command_ID, Command.State] = Map.empty, // static markup from define_command |
|
325 |
val execs: Map[Exec_ID, Command.State] = Map.empty, // dynamic markup from execution |
|
326 |
val assignments: Map[Version_ID, State.Assignment] = Map.empty, |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
327 |
val history: History = History.init) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
328 |
{ |
38373 | 329 |
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
|
330 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
331 |
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
|
332 |
{ |
38417 | 333 |
val id = version.id |
334 |
copy(versions = versions + (id -> version), |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
335 |
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
|
336 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
337 |
|
38373 | 338 |
def define_command(command: Command): State = |
339 |
{ |
|
340 |
val id = command.id |
|
49414 | 341 |
copy(commands = commands + (id -> command.init_state)) |
38373 | 342 |
} |
343 |
||
44582 | 344 |
def defined_command(id: Command_ID): Boolean = commands.isDefinedAt(id) |
345 |
||
44607
274eff0ea12e
maintain name of *the* enclosing node as part of command -- avoid full document traversal;
wenzelm
parents:
44582
diff
changeset
|
346 |
def find_command(version: Version, id: ID): Option[(Node, Command)] = |
44582 | 347 |
commands.get(id) orElse execs.get(id) match { |
348 |
case None => None |
|
349 |
case Some(st) => |
|
350 |
val command = st.command |
|
46681 | 351 |
val node = version.nodes(command.node_name) |
352 |
Some((node, command)) |
|
44582 | 353 |
} |
38373 | 354 |
|
38417 | 355 |
def the_version(id: Version_ID): Version = versions.getOrElse(id, fail) |
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
356 |
def the_command_state(id: Command_ID): Command.State = commands.getOrElse(id, fail) |
44446 | 357 |
def the_exec(id: Exec_ID): Command.State = execs.getOrElse(id, fail) |
43722 | 358 |
def the_assignment(version: Version): State.Assignment = |
359 |
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
|
360 |
|
38872 | 361 |
def accumulate(id: ID, message: XML.Elem): (Command.State, State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
362 |
execs.get(id) match { |
44446 | 363 |
case Some(st) => |
49527 | 364 |
val new_st = st + (id, message) |
44446 | 365 |
(new_st, copy(execs = execs + (id -> new_st))) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
366 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
367 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
368 |
case Some(st) => |
49527 | 369 |
val new_st = st + (id, message) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
370 |
(new_st, copy(commands = commands + (id -> new_st))) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
371 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
372 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
373 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
374 |
|
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
375 |
def assign(id: Version_ID, command_execs: Assign = Nil): (List[Command], State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
376 |
{ |
38417 | 377 |
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
|
378 |
|
44543 | 379 |
val (changed_commands, new_execs) = |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
380 |
((Nil: List[Command], execs) /: command_execs) { |
44543 | 381 |
case ((commands1, execs1), (cmd_id, exec)) => |
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
382 |
val st = the_command_state(cmd_id) |
44543 | 383 |
val commands2 = st.command :: commands1 |
384 |
val execs2 = |
|
385 |
exec match { |
|
386 |
case None => execs1 |
|
387 |
case Some(exec_id) => execs1 + (exec_id -> st) |
|
388 |
} |
|
389 |
(commands2, execs2) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
390 |
} |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
391 |
val new_assignment = the_assignment(version).assign(command_execs) |
43722 | 392 |
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
|
393 |
|
44543 | 394 |
(changed_commands, new_state) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
395 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
396 |
|
38417 | 397 |
def is_assigned(version: Version): Boolean = |
43722 | 398 |
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
|
399 |
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
|
400 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
401 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
402 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
403 |
def is_stable(change: Change): Boolean = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
404 |
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
|
405 |
|
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
406 |
def recent_finished: Change = history.undo_list.find(_.is_finished) getOrElse fail |
44672 | 407 |
def recent_stable: Change = history.undo_list.find(is_stable) getOrElse fail |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
408 |
def tip_stable: Boolean = is_stable(history.tip) |
44475 | 409 |
def tip_version: Version = history.tip.version.get_finished |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
410 |
|
44446 | 411 |
def continue_history( |
412 |
previous: Future[Version], |
|
40479 | 413 |
edits: List[Edit_Text], |
43722 | 414 |
version: Future[Version]): (Change, State) = |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
415 |
{ |
46678 | 416 |
val change = Change.make(previous, edits, version) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
417 |
(change, copy(history = history + change)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
418 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
419 |
|
44672 | 420 |
def prune_history(retain: Int = 0): (List[Version], State) = |
421 |
{ |
|
46679 | 422 |
history.prune(is_stable, retain) match { |
423 |
case Some((dropped, history1)) => |
|
44672 | 424 |
val dropped_versions = dropped.map(change => change.version.get_finished) |
46679 | 425 |
val state1 = copy(history = history1) |
44672 | 426 |
(dropped_versions, state1) |
46679 | 427 |
case None => fail |
44672 | 428 |
} |
429 |
} |
|
430 |
||
44676 | 431 |
def removed_versions(removed: List[Version_ID]): State = |
432 |
{ |
|
433 |
val versions1 = versions -- removed |
|
434 |
val assignments1 = assignments -- removed |
|
435 |
var commands1 = Map.empty[Command_ID, Command.State] |
|
436 |
var execs1 = Map.empty[Exec_ID, Command.State] |
|
437 |
for { |
|
438 |
(version_id, version) <- versions1.iterator |
|
46997 | 439 |
command_execs = assignments1(version_id).command_execs |
46723 | 440 |
(_, node) <- version.nodes.entries |
44676 | 441 |
command <- node.commands.iterator |
442 |
} { |
|
443 |
val id = command.id |
|
444 |
if (!commands1.isDefinedAt(id) && commands.isDefinedAt(id)) |
|
445 |
commands1 += (id -> commands(id)) |
|
446 |
if (command_execs.isDefinedAt(id)) { |
|
447 |
val exec_id = command_execs(id) |
|
448 |
if (!execs1.isDefinedAt(exec_id) && execs.isDefinedAt(exec_id)) |
|
449 |
execs1 += (exec_id -> execs(exec_id)) |
|
450 |
} |
|
451 |
} |
|
452 |
copy(versions = versions1, commands = commands1, execs = execs1, assignments = assignments1) |
|
453 |
} |
|
454 |
||
44613 | 455 |
def command_state(version: Version, command: Command): Command.State = |
456 |
{ |
|
457 |
require(is_assigned(version)) |
|
458 |
try { |
|
459 |
the_exec(the_assignment(version).check_finished.command_execs |
|
460 |
.getOrElse(command.id, fail)) |
|
461 |
} |
|
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
462 |
catch { |
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
463 |
case _: State.Fail => |
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
464 |
try { the_command_state(command.id) } |
49414 | 465 |
catch { case _: State.Fail => 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
|
466 |
} |
44613 | 467 |
} |
468 |
||
49645 | 469 |
def markup_to_XML(version: Version, node: Node, filter: XML.Elem => Boolean): XML.Body = |
470 |
node.commands.toList.map(cmd => command_state(version, cmd).markup_to_XML(filter)).flatten |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
471 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
472 |
// persistent user-view |
49346 | 473 |
def snapshot(name: Node.Name = Node.Name.empty, pending_edits: List[Text.Edit] = Nil) |
474 |
: Snapshot = |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
475 |
{ |
44672 | 476 |
val stable = recent_stable |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
477 |
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
|
478 |
|
44156 | 479 |
// FIXME proper treatment of removed nodes |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
480 |
val edits = |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
481 |
(pending_edits /: history.undo_list.takeWhile(_ != stable))((edits, change) => |
44156 | 482 |
(for ((a, Node.Edits(es)) <- change.edits if a == name) yield es).flatten ::: edits) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
483 |
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
|
484 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
485 |
new Snapshot |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
486 |
{ |
44582 | 487 |
val state = State.this |
39698 | 488 |
val version = stable.version.get_finished |
48923
a2df77fcf1eb
prefer jEdit file name representation (potentially via VFS);
wenzelm
parents:
48793
diff
changeset
|
489 |
val node_name = name |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
490 |
val node = version.nodes(name) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
491 |
val is_outdated = !(pending_edits.isEmpty && latest == stable) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
492 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
493 |
def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
494 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
43425 | 495 |
def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r)) |
496 |
def revert(range: Text.Range) = (range /: reverse_edits)((r, edit) => edit.revert(r)) |
|
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
497 |
|
49346 | 498 |
def eq_markup(other: Snapshot): Boolean = |
499 |
!is_outdated && !other.is_outdated && |
|
500 |
node.commands.size == other.node.commands.size && |
|
501 |
((node.commands.iterator zip other.node.commands.iterator) forall { |
|
502 |
case (cmd1, cmd2) => |
|
503 |
cmd1.source == cmd2.source && |
|
504 |
(state.command_state(version, cmd1).markup eq |
|
505 |
other.state.command_state(other.version, cmd2).markup) |
|
506 |
}) |
|
507 |
||
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
508 |
def cumulate_markup[A](range: Text.Range, info: A, elements: Option[Set[String]], |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
509 |
result: Command.State => PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]] = |
45459 | 510 |
{ |
45467 | 511 |
val former_range = revert(range) |
45459 | 512 |
for { |
513 |
(command, command_start) <- node.command_range(former_range).toStream |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
514 |
st = state.command_state(version, command) |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
515 |
res = result(st) |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
516 |
Text.Info(r0, a) <- st.markup. |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
517 |
cumulate[A]((former_range - command_start).restrict(command.range), info, elements, |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
518 |
{ |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
519 |
case (a, Text.Info(r0, b)) |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
520 |
if res.isDefinedAt((a, Text.Info(convert(r0 + command_start), b))) => |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
521 |
res((a, Text.Info(convert(r0 + command_start), b))) |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
522 |
}) |
45459 | 523 |
} yield Text.Info(convert(r0 + command_start), a) |
524 |
} |
|
525 |
||
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
526 |
def select_markup[A](range: Text.Range, elements: Option[Set[String]], |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
527 |
result: Command.State => PartialFunction[Text.Markup, A]): Stream[Text.Info[A]] = |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
528 |
{ |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
529 |
def result1(st: Command.State) = |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
530 |
{ |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
531 |
val res = result(st) |
45468 | 532 |
new PartialFunction[(Option[A], Text.Markup), Option[A]] { |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
533 |
def isDefinedAt(arg: (Option[A], Text.Markup)): Boolean = res.isDefinedAt(arg._2) |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
534 |
def apply(arg: (Option[A], Text.Markup)): Option[A] = Some(res(arg._2)) |
45468 | 535 |
} |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
536 |
} |
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
537 |
for (Text.Info(r, Some(x)) <- cumulate_markup(range, None, elements, result1)) |
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
538 |
yield Text.Info(r, x) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
539 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
540 |
} |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
541 |
} |
34485 | 542 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
543 |
} |
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
544 |