author | wenzelm |
Fri, 20 Aug 2010 20:11:25 +0200 | |
changeset 38569 | 9d480f6a2589 |
parent 38427 | 7066fbd315ae |
child 38841 | 4df7b76249a0 |
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 |
38414
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
19 |
|
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
20 |
object ID { |
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
21 |
def apply(id: ID): String = Markup.Long.apply(id) |
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
22 |
def unapply(s: String): Option[ID] = Markup.Long.unapply(s) |
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
23 |
} |
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
24 |
|
38373 | 25 |
type Version_ID = ID |
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
26 |
type Command_ID = ID |
38373 | 27 |
type Exec_ID = ID |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
28 |
|
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
29 |
val NO_ID: ID = 0 |
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
|
30 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
31 |
|
34818
7df68a8f0e3e
register Proof_Document instances as session entities -- handle Markup.EDIT messages locally;
wenzelm
parents:
34815
diff
changeset
|
32 |
|
38424 | 33 |
/** document structure **/ |
34 |
||
35 |
/* named nodes -- development graph */ |
|
36 |
||
38425 | 37 |
type Node_Text_Edit = (String, List[Text.Edit]) // FIXME None: remove |
38424 | 38 |
|
39 |
type Edit[C] = |
|
40 |
(String, // node name |
|
41 |
Option[List[(Option[C], Option[C])]]) // None: remove, Some: insert/remove commands |
|
38151 | 42 |
|
43 |
object Node |
|
44 |
{ |
|
45 |
val empty: Node = new Node(Linear_Set()) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
46 |
|
38424 | 47 |
// FIXME not scalable |
38426 | 48 |
def command_starts(commands: Iterator[Command], offset: Text.Offset = 0) |
49 |
: Iterator[(Command, Text.Offset)] = |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
50 |
{ |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
51 |
var i = offset |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
52 |
for (command <- commands) yield { |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
53 |
val start = i |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
54 |
i += command.length |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
55 |
(command, start) |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
56 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
57 |
} |
38151 | 58 |
} |
59 |
||
60 |
class Node(val commands: Linear_Set[Command]) |
|
61 |
{ |
|
38426 | 62 |
def command_starts: Iterator[(Command, Text.Offset)] = |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
63 |
Node.command_starts(commands.iterator) |
38151 | 64 |
|
38426 | 65 |
def command_start(cmd: Command): Option[Text.Offset] = |
38151 | 66 |
command_starts.find(_._1 == cmd).map(_._2) |
67 |
||
38569 | 68 |
def command_range(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
38151 | 69 |
command_starts dropWhile { case (cmd, start) => start + cmd.length <= i } |
70 |
||
38569 | 71 |
def command_range(range: Text.Range): Iterator[(Command, Text.Offset)] = |
72 |
command_range(range.start) takeWhile { case (_, start) => start < range.stop } |
|
38151 | 73 |
|
38426 | 74 |
def command_at(i: Text.Offset): Option[(Command, Text.Offset)] = |
38151 | 75 |
{ |
76 |
val range = command_range(i) |
|
77 |
if (range.hasNext) Some(range.next) else None |
|
78 |
} |
|
79 |
||
38426 | 80 |
def proper_command_at(i: Text.Offset): Option[Command] = |
38151 | 81 |
command_at(i) match { |
82 |
case Some((command, _)) => |
|
83 |
commands.reverse_iterator(command).find(cmd => !cmd.is_ignored) |
|
84 |
case None => None |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
||
38424 | 89 |
|
90 |
/** versioning **/ |
|
91 |
||
92 |
/* particular document versions */ |
|
34485 | 93 |
|
38417 | 94 |
object Version |
95 |
{ |
|
96 |
val init: Version = new Version(NO_ID, Map().withDefaultValue(Node.empty)) |
|
97 |
} |
|
98 |
||
99 |
class Version(val id: Version_ID, val nodes: Map[String, Node]) |
|
34660 | 100 |
|
34859 | 101 |
|
38424 | 102 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
103 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
104 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
105 |
{ |
38417 | 106 |
val init = new Change(Future.value(Version.init), Nil, Future.value(Nil, Version.init)) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
107 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
108 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
109 |
class Change( |
38417 | 110 |
val previous: Future[Version], |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
111 |
val edits: List[Node_Text_Edit], |
38417 | 112 |
val result: Future[(List[Edit[Command]], Version)]) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
113 |
{ |
38417 | 114 |
val current: Future[Version] = result.map(_._2) |
115 |
def is_finished: Boolean = previous.is_finished && current.is_finished |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
116 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
117 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
118 |
|
38424 | 119 |
/* history navigation and persistent snapshots */ |
120 |
||
121 |
abstract class Snapshot |
|
122 |
{ |
|
123 |
val version: Version |
|
124 |
val node: Node |
|
125 |
val is_outdated: Boolean |
|
126 |
def lookup_command(id: Command_ID): Option[Command] |
|
127 |
def state(command: Command): Command.State |
|
38427 | 128 |
def convert(i: Text.Offset): Text.Offset |
129 |
def convert(range: Text.Range): Text.Range = range.map(convert(_)) |
|
130 |
def revert(i: Text.Offset): Text.Offset |
|
131 |
def revert(range: Text.Range): Text.Range = range.map(revert(_)) |
|
38424 | 132 |
} |
133 |
||
134 |
object History |
|
135 |
{ |
|
136 |
val init = new History(List(Change.init)) |
|
137 |
} |
|
138 |
||
139 |
// FIXME pruning, purging of state |
|
140 |
class History(undo_list: List[Change]) |
|
141 |
{ |
|
142 |
require(!undo_list.isEmpty) |
|
143 |
||
144 |
def tip: Change = undo_list.head |
|
145 |
def +(ch: Change): History = new History(ch :: undo_list) |
|
146 |
||
38425 | 147 |
def snapshot(name: String, pending_edits: List[Text.Edit], state_snapshot: State): Snapshot = |
38424 | 148 |
{ |
149 |
val found_stable = undo_list.find(change => |
|
150 |
change.is_finished && state_snapshot.is_assigned(change.current.join)) |
|
151 |
require(found_stable.isDefined) |
|
152 |
val stable = found_stable.get |
|
153 |
val latest = undo_list.head |
|
154 |
||
155 |
val edits = |
|
156 |
(pending_edits /: undo_list.takeWhile(_ != stable))((edits, change) => |
|
157 |
(for ((a, eds) <- change.edits if a == name) yield eds).flatten ::: edits) |
|
158 |
lazy val reverse_edits = edits.reverse |
|
159 |
||
160 |
new Snapshot |
|
161 |
{ |
|
162 |
val version = stable.current.join |
|
163 |
val node = version.nodes(name) |
|
164 |
val is_outdated = !(pending_edits.isEmpty && latest == stable) |
|
165 |
def lookup_command(id: Command_ID): Option[Command] = state_snapshot.lookup_command(id) |
|
166 |
def state(command: Command): Command.State = |
|
167 |
try { state_snapshot.command_state(version, command) } |
|
168 |
catch { case _: State.Fail => command.empty_state } |
|
38427 | 169 |
|
170 |
def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i)) |
|
171 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
|
38424 | 172 |
} |
173 |
} |
|
174 |
} |
|
175 |
||
176 |
||
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
177 |
|
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
178 |
/** global state -- document structure and execution process **/ |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
179 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
180 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
181 |
{ |
38373 | 182 |
class Fail(state: State) extends Exception |
183 |
||
38417 | 184 |
val init = State().define_version(Version.init, Map()).assign(Version.init.id, Nil) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
185 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
186 |
class Assignment(former_assignment: Map[Command, Exec_ID]) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
187 |
{ |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
188 |
@volatile private var tmp_assignment = former_assignment |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
189 |
private val promise = Future.promise[Map[Command, Exec_ID]] |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
190 |
def is_finished: Boolean = promise.is_finished |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
191 |
def join: Map[Command, Exec_ID] = promise.join |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
192 |
def assign(command_execs: List[(Command, Exec_ID)]) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
193 |
{ |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
194 |
promise.fulfill(tmp_assignment ++ command_execs) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
195 |
tmp_assignment = Map() |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
196 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
197 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
198 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
199 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
200 |
case class State( |
38417 | 201 |
val versions: Map[Version_ID, Version] = Map(), |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
202 |
val commands: Map[Command_ID, Command.State] = Map(), |
38417 | 203 |
val execs: Map[Exec_ID, (Command.State, Set[Version])] = Map(), |
204 |
val assignments: Map[Version, State.Assignment] = Map(), |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
205 |
val disposed: Set[ID] = Set()) // FIXME unused!? |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
206 |
{ |
38373 | 207 |
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
|
208 |
|
38417 | 209 |
def define_version(version: Version, former_assignment: Map[Command, Exec_ID]): State = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
210 |
{ |
38417 | 211 |
val id = version.id |
212 |
if (versions.isDefinedAt(id) || disposed(id)) fail |
|
213 |
copy(versions = versions + (id -> version), |
|
214 |
assignments = assignments + (version -> new State.Assignment(former_assignment))) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
215 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
216 |
|
38373 | 217 |
def define_command(command: Command): State = |
218 |
{ |
|
219 |
val id = command.id |
|
220 |
if (commands.isDefinedAt(id) || disposed(id)) fail |
|
221 |
copy(commands = commands + (id -> command.empty_state)) |
|
222 |
} |
|
223 |
||
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
224 |
def lookup_command(id: Command_ID): Option[Command] = commands.get(id).map(_.command) |
38373 | 225 |
|
38417 | 226 |
def the_version(id: Version_ID): Version = versions.getOrElse(id, fail) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
227 |
def the_command(id: Command_ID): Command.State = commands.getOrElse(id, fail) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
228 |
def the_exec_state(id: Exec_ID): Command.State = execs.getOrElse(id, fail)._1 |
38417 | 229 |
def the_assignment(version: Version): State.Assignment = assignments.getOrElse(version, fail) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
230 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
231 |
def accumulate(id: ID, message: XML.Tree): (Command.State, State) = |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
232 |
execs.get(id) match { |
38417 | 233 |
case Some((st, occs)) => |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
234 |
val new_st = st.accumulate(message) |
38417 | 235 |
(new_st, copy(execs = execs + (id -> (new_st, occs)))) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
236 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
237 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
238 |
case Some(st) => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
239 |
val new_st = st.accumulate(message) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
240 |
(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
|
241 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
242 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
243 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
244 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
245 |
def assign(id: Version_ID, edits: List[(Command_ID, Exec_ID)]): State = |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
246 |
{ |
38417 | 247 |
val version = the_version(id) |
248 |
val occs = Set(version) // FIXME unused (!?) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
249 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
250 |
var new_execs = execs |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
251 |
val assigned_execs = |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
252 |
for ((cmd_id, exec_id) <- edits) yield { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
253 |
val st = the_command(cmd_id) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
254 |
if (new_execs.isDefinedAt(exec_id) || disposed(exec_id)) fail |
38417 | 255 |
new_execs += (exec_id -> (st, occs)) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
256 |
(st.command, exec_id) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
257 |
} |
38417 | 258 |
the_assignment(version).assign(assigned_execs) // FIXME explicit value instead of promise (!?) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
259 |
copy(execs = new_execs) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
260 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
261 |
|
38417 | 262 |
def is_assigned(version: Version): Boolean = |
263 |
assignments.get(version) match { |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
264 |
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
|
265 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
266 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
267 |
|
38417 | 268 |
def command_state(version: Version, command: Command): Command.State = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
269 |
{ |
38417 | 270 |
val assgn = the_assignment(version) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
271 |
require(assgn.is_finished) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
272 |
the_exec_state(assgn.join.getOrElse(command, fail)) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
273 |
} |
34485 | 274 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
275 |
} |
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
276 |