author | wenzelm |
Sun, 04 Mar 2012 19:16:09 +0100 | |
changeset 46814 | d68ea01d5084 |
parent 46739 | 6024353549ca |
child 46938 | cda018294515 |
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 |
|
46737 | 38 |
type Node_Header = Exn.Result[Node.Deps] |
44182 | 39 |
|
38151 | 40 |
object Node |
41 |
{ |
|
46737 | 42 |
sealed case class Deps(imports: List[Name], uses: List[(String, Boolean)]) |
43 |
||
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
44 |
object Name |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
45 |
{ |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
46 |
val empty = Name("", "", "") |
44959 | 47 |
def apply(path: Path): Name = |
48 |
{ |
|
49 |
val node = path.implode |
|
50 |
val dir = path.dir.implode |
|
51 |
val theory = Thy_Header.thy_name(node) getOrElse error("Bad theory file name: " + path) |
|
52 |
Name(node, dir, theory) |
|
53 |
} |
|
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] |
|
83 |
case class Header[A, B](header: Node_Header) extends Edit[A, B] |
|
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( |
46677 | 103 |
val header: Node_Header = Exn.Exn(ERROR("Bad theory header")), |
104 |
val perspective: Command.Perspective = Command.Perspective.empty, |
|
105 |
val blobs: Map[String, Blob] = Map.empty, |
|
106 |
val commands: Linear_Set[Command] = Linear_Set.empty) |
|
38151 | 107 |
{ |
46680 | 108 |
def clear: Node = new Node(header = header) |
109 |
||
110 |
def update_header(new_header: Node_Header): Node = |
|
111 |
new Node(new_header, perspective, blobs, commands) |
|
112 |
||
113 |
def update_perspective(new_perspective: Command.Perspective): Node = |
|
114 |
new Node(header, new_perspective, blobs, commands) |
|
115 |
||
116 |
def update_blobs(new_blobs: Map[String, Blob]): Node = |
|
117 |
new Node(header, perspective, new_blobs, commands) |
|
118 |
||
119 |
def update_commands(new_commands: Linear_Set[Command]): Node = |
|
120 |
new Node(header, perspective, blobs, new_commands) |
|
44443
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
121 |
|
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
122 |
|
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
123 |
/* commands */ |
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
124 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
125 |
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
|
126 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
127 |
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
|
128 |
var next_block = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
129 |
var last_stop = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
130 |
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
|
131 |
last_stop = start + command.length |
38885
06582837872b
Node.full_index: allow command spans larger than block_size;
wenzelm
parents:
38882
diff
changeset
|
132 |
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
|
133 |
blocks += (command -> start) |
46680 | 134 |
next_block += Node.block_size |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
135 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
136 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
137 |
(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
|
138 |
} |
38151 | 139 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
140 |
def full_range: Text.Range = full_index._2 |
38151 | 141 |
|
38569 | 142 |
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
|
143 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
144 |
if (!commands.isEmpty && full_range.contains(i)) { |
46680 | 145 |
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
|
146 |
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
|
147 |
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
|
148 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
149 |
else Iterator.empty |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
150 |
} |
38151 | 151 |
|
38569 | 152 |
def command_range(range: Text.Range): Iterator[(Command, Text.Offset)] = |
153 |
command_range(range.start) takeWhile { case (_, start) => start < range.stop } |
|
38151 | 154 |
|
38426 | 155 |
def command_at(i: Text.Offset): Option[(Command, Text.Offset)] = |
38151 | 156 |
{ |
157 |
val range = command_range(i) |
|
158 |
if (range.hasNext) Some(range.next) else None |
|
159 |
} |
|
160 |
||
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
161 |
def command_start(cmd: Command): Option[Text.Offset] = |
46677 | 162 |
Node.command_starts(commands.iterator).find(_._1 == cmd).map(_._2) |
38151 | 163 |
} |
164 |
||
165 |
||
46723 | 166 |
/* development graph */ |
167 |
||
168 |
object Nodes |
|
169 |
{ |
|
170 |
val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering)) |
|
171 |
} |
|
172 |
||
173 |
final class Nodes private(graph: Graph[Node.Name, Node]) |
|
174 |
{ |
|
175 |
def get_name(s: String): Option[Node.Name] = |
|
176 |
graph.keys.find(name => name.node == s) |
|
177 |
||
178 |
def apply(name: Node.Name): Node = |
|
179 |
graph.default_node(name, Node.empty).get_node(name) |
|
180 |
||
181 |
def + (entry: (Node.Name, Node)): Nodes = |
|
182 |
{ |
|
183 |
val (name, node) = entry |
|
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
184 |
val imports = |
46723 | 185 |
node.header match { |
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
186 |
case Exn.Res(deps) => deps.imports |
46723 | 187 |
case _ => Nil |
188 |
} |
|
189 |
val graph1 = |
|
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
190 |
(graph.default_node(name, Node.empty) /: imports)((g, p) => g.default_node(p, Node.empty)) |
46723 | 191 |
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
|
192 |
val graph3 = (graph2 /: imports)((g, dep) => g.add_edge(dep, name)) |
46723 | 193 |
new Nodes(graph3.map_node(name, _ => node)) |
194 |
} |
|
195 |
||
196 |
def entries: Iterator[(Node.Name, Node)] = |
|
197 |
graph.entries.map({ case (name, (node, _)) => (name, node) }) |
|
198 |
||
199 |
def topological_order: List[Node.Name] = graph.topological_order |
|
200 |
} |
|
201 |
||
202 |
||
38424 | 203 |
|
204 |
/** versioning **/ |
|
205 |
||
206 |
/* particular document versions */ |
|
34485 | 207 |
|
38417 | 208 |
object Version |
209 |
{ |
|
46681 | 210 |
val init: Version = new Version() |
211 |
||
212 |
def make(nodes: Nodes): Version = new Version(new_id(), nodes) |
|
38417 | 213 |
} |
214 |
||
46712 | 215 |
final class Version private( |
46677 | 216 |
val id: Version_ID = no_id, |
46723 | 217 |
val nodes: Nodes = Nodes.empty) |
34660 | 218 |
|
34859 | 219 |
|
38424 | 220 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
221 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
222 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
223 |
{ |
46678 | 224 |
val init: Change = new Change() |
225 |
||
226 |
def make(previous: Future[Version], edits: List[Edit_Text], version: Future[Version]): Change = |
|
227 |
new Change(Some(previous), edits, version) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
228 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
229 |
|
46712 | 230 |
final class Change private( |
46677 | 231 |
val previous: Option[Future[Version]] = Some(Future.value(Version.init)), |
232 |
val edits: List[Edit_Text] = Nil, |
|
233 |
val version: Future[Version] = Future.value(Version.init)) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
234 |
{ |
44672 | 235 |
def is_finished: Boolean = |
236 |
(previous match { case None => true case Some(future) => future.is_finished }) && |
|
237 |
version.is_finished |
|
238 |
||
46678 | 239 |
def truncate: Change = new Change(None, Nil, version) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
240 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
241 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
242 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
243 |
/* history navigation */ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
244 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
245 |
object History |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
246 |
{ |
46679 | 247 |
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
|
248 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
249 |
|
46712 | 250 |
final class History private( |
46679 | 251 |
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
|
252 |
{ |
46679 | 253 |
def tip: Change = undo_list.head |
254 |
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
|
255 |
|
46679 | 256 |
def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] = |
257 |
{ |
|
258 |
val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1 |
|
259 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
260 |
||
261 |
retained.splitAt(retained.length - 1) match { |
|
262 |
case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate))) |
|
263 |
case _ => None |
|
264 |
} |
|
265 |
} |
|
38841
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 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
269 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
270 |
/** global state -- document structure, execution process, editing history **/ |
38424 | 271 |
|
272 |
abstract class Snapshot |
|
273 |
{ |
|
44582 | 274 |
val state: State |
38424 | 275 |
val version: Version |
276 |
val node: Node |
|
277 |
val is_outdated: Boolean |
|
38427 | 278 |
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
|
279 |
def convert(range: Text.Range): Text.Range |
38427 | 280 |
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
|
281 |
def revert(range: Text.Range): Text.Range |
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]], |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
283 |
result: PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]] |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
284 |
def select_markup[A](range: Text.Range, elements: Option[Set[String]], |
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
285 |
result: PartialFunction[Text.Markup, A]): Stream[Text.Info[A]] |
38424 | 286 |
} |
287 |
||
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
288 |
type Assign = |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
289 |
(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
|
290 |
List[(String, Option[Document.Command_ID])]) // last exec |
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
291 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
292 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
293 |
{ |
38373 | 294 |
class Fail(state: State) extends Exception |
295 |
||
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
296 |
object Assignment |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
297 |
{ |
46683 | 298 |
val init: Assignment = new Assignment() |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
299 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
300 |
|
46712 | 301 |
final class Assignment private( |
46677 | 302 |
val command_execs: Map[Command_ID, Exec_ID] = Map.empty, |
303 |
val last_execs: Map[String, Option[Command_ID]] = Map.empty, |
|
304 |
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
|
305 |
{ |
44477 | 306 |
def check_finished: Assignment = { require(is_finished); this } |
46683 | 307 |
def unfinished: Assignment = new Assignment(command_execs, last_execs, false) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
308 |
|
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
309 |
def assign(add_command_execs: List[(Command_ID, Option[Exec_ID])], |
44477 | 310 |
add_last_execs: List[(String, Option[Command_ID])]): Assignment = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
311 |
{ |
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
|
312 |
require(!is_finished) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
313 |
val command_execs1 = |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
314 |
(command_execs /: add_command_execs) { |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
315 |
case (res, (command_id, None)) => res - command_id |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
316 |
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
|
317 |
} |
46683 | 318 |
new Assignment(command_execs1, last_execs ++ add_last_execs, true) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
319 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
320 |
} |
46682 | 321 |
|
322 |
val init: State = |
|
323 |
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
|
324 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
325 |
|
46712 | 326 |
final case class State private( |
46677 | 327 |
val versions: Map[Version_ID, Version] = Map.empty, |
328 |
val commands: Map[Command_ID, Command.State] = Map.empty, // static markup from define_command |
|
329 |
val execs: Map[Exec_ID, Command.State] = Map.empty, // dynamic markup from execution |
|
330 |
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
|
331 |
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
|
332 |
{ |
38373 | 333 |
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
|
334 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
335 |
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
|
336 |
{ |
38417 | 337 |
val id = version.id |
338 |
copy(versions = versions + (id -> version), |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
339 |
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
|
340 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
341 |
|
38373 | 342 |
def define_command(command: Command): State = |
343 |
{ |
|
344 |
val id = command.id |
|
345 |
copy(commands = commands + (id -> command.empty_state)) |
|
346 |
} |
|
347 |
||
44582 | 348 |
def defined_command(id: Command_ID): Boolean = commands.isDefinedAt(id) |
349 |
||
44607
274eff0ea12e
maintain name of *the* enclosing node as part of command -- avoid full document traversal;
wenzelm
parents:
44582
diff
changeset
|
350 |
def find_command(version: Version, id: ID): Option[(Node, Command)] = |
44582 | 351 |
commands.get(id) orElse execs.get(id) match { |
352 |
case None => None |
|
353 |
case Some(st) => |
|
354 |
val command = st.command |
|
46681 | 355 |
val node = version.nodes(command.node_name) |
356 |
Some((node, command)) |
|
44582 | 357 |
} |
38373 | 358 |
|
38417 | 359 |
def the_version(id: Version_ID): Version = versions.getOrElse(id, fail) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
360 |
def the_command(id: Command_ID): Command.State = commands.getOrElse(id, fail) // FIXME rename |
44446 | 361 |
def the_exec(id: Exec_ID): Command.State = execs.getOrElse(id, fail) |
43722 | 362 |
def the_assignment(version: Version): State.Assignment = |
363 |
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
|
364 |
|
38872 | 365 |
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
|
366 |
execs.get(id) match { |
44446 | 367 |
case Some(st) => |
46152
793cecd4ffc0
accumulate status as regular markup for command range;
wenzelm
parents:
45900
diff
changeset
|
368 |
val new_st = st + message |
44446 | 369 |
(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
|
370 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
371 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
372 |
case Some(st) => |
46152
793cecd4ffc0
accumulate status as regular markup for command range;
wenzelm
parents:
45900
diff
changeset
|
373 |
val new_st = st + message |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
374 |
(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
|
375 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
376 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
377 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
378 |
|
46682 | 379 |
def assign(id: Version_ID, arg: Assign = (Nil, Nil)): (List[Command], State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
380 |
{ |
38417 | 381 |
val version = the_version(id) |
44477 | 382 |
val (command_execs, last_execs) = arg |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
383 |
|
44543 | 384 |
val (changed_commands, new_execs) = |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
385 |
((Nil: List[Command], execs) /: command_execs) { |
44543 | 386 |
case ((commands1, execs1), (cmd_id, exec)) => |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
387 |
val st = the_command(cmd_id) |
44543 | 388 |
val commands2 = st.command :: commands1 |
389 |
val execs2 = |
|
390 |
exec match { |
|
391 |
case None => execs1 |
|
392 |
case Some(exec_id) => execs1 + (exec_id -> st) |
|
393 |
} |
|
394 |
(commands2, execs2) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
395 |
} |
44477 | 396 |
val new_assignment = the_assignment(version).assign(command_execs, last_execs) |
43722 | 397 |
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
|
398 |
|
44543 | 399 |
(changed_commands, new_state) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
400 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
401 |
|
38417 | 402 |
def is_assigned(version: Version): Boolean = |
43722 | 403 |
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
|
404 |
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
|
405 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
406 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
407 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
408 |
def is_stable(change: Change): Boolean = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
409 |
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
|
410 |
|
44672 | 411 |
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
|
412 |
def tip_stable: Boolean = is_stable(history.tip) |
44475 | 413 |
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
|
414 |
|
44615 | 415 |
def last_exec_offset(name: Node.Name): Text.Offset = |
44484
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
416 |
{ |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
417 |
val version = tip_version |
44615 | 418 |
the_assignment(version).last_execs.get(name.node) match { |
44484
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
419 |
case Some(Some(id)) => |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
420 |
val node = version.nodes(name) |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
421 |
val cmd = the_command(id).command |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
422 |
node.command_start(cmd) match { |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
423 |
case None => 0 |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
424 |
case Some(start) => start + cmd.length |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
425 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
426 |
case _ => 0 |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
427 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
428 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
429 |
|
44446 | 430 |
def continue_history( |
431 |
previous: Future[Version], |
|
40479 | 432 |
edits: List[Edit_Text], |
43722 | 433 |
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
|
434 |
{ |
46678 | 435 |
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
|
436 |
(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
|
437 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
438 |
|
44672 | 439 |
def prune_history(retain: Int = 0): (List[Version], State) = |
440 |
{ |
|
46679 | 441 |
history.prune(is_stable, retain) match { |
442 |
case Some((dropped, history1)) => |
|
44672 | 443 |
val dropped_versions = dropped.map(change => change.version.get_finished) |
46679 | 444 |
val state1 = copy(history = history1) |
44672 | 445 |
(dropped_versions, state1) |
46679 | 446 |
case None => fail |
44672 | 447 |
} |
448 |
} |
|
449 |
||
44676 | 450 |
def removed_versions(removed: List[Version_ID]): State = |
451 |
{ |
|
452 |
val versions1 = versions -- removed |
|
453 |
val assignments1 = assignments -- removed |
|
454 |
var commands1 = Map.empty[Command_ID, Command.State] |
|
455 |
var execs1 = Map.empty[Exec_ID, Command.State] |
|
456 |
for { |
|
457 |
(version_id, version) <- versions1.iterator |
|
458 |
val command_execs = assignments1(version_id).command_execs |
|
46723 | 459 |
(_, node) <- version.nodes.entries |
44676 | 460 |
command <- node.commands.iterator |
461 |
} { |
|
462 |
val id = command.id |
|
463 |
if (!commands1.isDefinedAt(id) && commands.isDefinedAt(id)) |
|
464 |
commands1 += (id -> commands(id)) |
|
465 |
if (command_execs.isDefinedAt(id)) { |
|
466 |
val exec_id = command_execs(id) |
|
467 |
if (!execs1.isDefinedAt(exec_id) && execs.isDefinedAt(exec_id)) |
|
468 |
execs1 += (exec_id -> execs(exec_id)) |
|
469 |
} |
|
470 |
} |
|
471 |
copy(versions = versions1, commands = commands1, execs = execs1, assignments = assignments1) |
|
472 |
} |
|
473 |
||
44613 | 474 |
def command_state(version: Version, command: Command): Command.State = |
475 |
{ |
|
476 |
require(is_assigned(version)) |
|
477 |
try { |
|
478 |
the_exec(the_assignment(version).check_finished.command_execs |
|
479 |
.getOrElse(command.id, fail)) |
|
480 |
} |
|
481 |
catch { case _: State.Fail => command.empty_state } |
|
482 |
} |
|
483 |
||
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
484 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
485 |
// persistent user-view |
44615 | 486 |
def snapshot(name: Node.Name, pending_edits: List[Text.Edit]): Snapshot = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
487 |
{ |
44672 | 488 |
val stable = recent_stable |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
489 |
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
|
490 |
|
44156 | 491 |
// 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
|
492 |
val edits = |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
493 |
(pending_edits /: history.undo_list.takeWhile(_ != stable))((edits, change) => |
44156 | 494 |
(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
|
495 |
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
|
496 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
497 |
new Snapshot |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
498 |
{ |
44582 | 499 |
val state = State.this |
39698 | 500 |
val version = stable.version.get_finished |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
501 |
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
|
502 |
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
|
503 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
504 |
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
|
505 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
43425 | 506 |
def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r)) |
507 |
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
|
508 |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
509 |
def cumulate_markup[A](range: Text.Range, info: A, elements: Option[Set[String]], |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
510 |
result: PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]] = |
45459 | 511 |
{ |
45467 | 512 |
val former_range = revert(range) |
45459 | 513 |
for { |
514 |
(command, command_start) <- node.command_range(former_range).toStream |
|
46208 | 515 |
Text.Info(r0, a) <- state.command_state(version, command).markup. |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
516 |
cumulate[A]((former_range - command_start).restrict(command.range), info, elements, |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
517 |
{ |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
518 |
case (a, Text.Info(r0, b)) |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
519 |
if result.isDefinedAt((a, Text.Info(convert(r0 + command_start), b))) => |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
520 |
result((a, Text.Info(convert(r0 + command_start), b))) |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
521 |
}) |
45459 | 522 |
} yield Text.Info(convert(r0 + command_start), a) |
523 |
} |
|
524 |
||
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
525 |
def select_markup[A](range: Text.Range, elements: Option[Set[String]], |
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
526 |
result: 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
|
527 |
{ |
45468 | 528 |
val result1 = |
529 |
new PartialFunction[(Option[A], Text.Markup), Option[A]] { |
|
530 |
def isDefinedAt(arg: (Option[A], Text.Markup)): Boolean = result.isDefinedAt(arg._2) |
|
531 |
def apply(arg: (Option[A], Text.Markup)): Option[A] = Some(result(arg._2)) |
|
532 |
} |
|
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
533 |
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
|
534 |
yield Text.Info(r, x) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
535 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
536 |
} |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
537 |
} |
34485 | 538 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
539 |
} |
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
540 |