author | wenzelm |
Thu, 20 Feb 2014 16:00:37 +0100 | |
changeset 55620 | 19dffae33cde |
parent 55435 | 662e0fd39823 |
child 55649 | 1532ab0dc67b |
permissions | -rw-r--r-- |
36676 | 1 |
/* Title: Pure/PIDE/document.scala |
2 |
Author: Makarius |
|
3 |
||
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
4 |
Document as collection of named nodes, each consisting of an editable |
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
5 |
list of commands, associated with asynchronous execution process. |
36676 | 6 |
*/ |
34407 | 7 |
|
34871
e596a0b71f3c
incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents:
34868
diff
changeset
|
8 |
package isabelle |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
|
34760 | 10 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
11 |
import scala.collection.mutable |
37073 | 12 |
|
13 |
||
34823 | 14 |
object Document |
34483 | 15 |
{ |
38424 | 16 |
/** document structure **/ |
17 |
||
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
18 |
/* overlays -- print functions with arguments */ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
19 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
20 |
object Overlays |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
21 |
{ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
22 |
val empty = new Overlays(Map.empty) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
23 |
} |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
24 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
25 |
final class Overlays private(rep: Map[Node.Name, Node.Overlays]) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
26 |
{ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
27 |
def apply(name: Document.Node.Name): Node.Overlays = |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
28 |
rep.getOrElse(name, Node.Overlays.empty) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
29 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
30 |
private def update(name: Node.Name, f: Node.Overlays => Node.Overlays): Overlays = |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
31 |
{ |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
32 |
val node_overlays = f(apply(name)) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
33 |
new Overlays(if (node_overlays.is_empty) rep - name else rep + (name -> node_overlays)) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
34 |
} |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
35 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
36 |
def insert(command: Command, fn: String, args: List[String]): Overlays = |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
37 |
update(command.node_name, _.insert(command, fn, args)) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
38 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
39 |
def remove(command: Command, fn: String, args: List[String]): Overlays = |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
40 |
update(command.node_name, _.remove(command, fn, args)) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
41 |
} |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
42 |
|
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
43 |
|
46723 | 44 |
/* individual nodes */ |
38424 | 45 |
|
44615 | 46 |
type Edit[A, B] = (Node.Name, Node.Edit[A, B]) |
44384 | 47 |
type Edit_Text = Edit[Text.Edit, Text.Perspective] |
52849 | 48 |
type Edit_Command = Edit[Command.Edit, Command.Perspective] |
38151 | 49 |
|
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
54562
diff
changeset
|
50 |
type Blobs = Map[Node.Name, (Bytes, Command.File)] |
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
51 |
|
38151 | 52 |
object Node |
53 |
{ |
|
52887 | 54 |
val empty: Node = new Node() |
55 |
||
56 |
||
57 |
/* header and name */ |
|
58 |
||
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
59 |
sealed case class Header( |
46938
cda018294515
some support for outer syntax keyword declarations within theory header;
wenzelm
parents:
46814
diff
changeset
|
60 |
imports: List[Name], |
48706 | 61 |
keywords: Thy_Header.Keywords, |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
62 |
errors: List[String] = Nil) |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
63 |
{ |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
64 |
def error(msg: String): Header = copy(errors = errors ::: List(msg)) |
54549
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
65 |
|
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
66 |
def cat_errors(msg2: String): Header = |
2a3053472ec3
actually expose errors of cumulative theory dependencies;
wenzelm
parents:
54530
diff
changeset
|
67 |
copy(errors = errors.map(msg1 => Library.cat_message(msg1, msg2))) |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
68 |
} |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
69 |
|
51294
0850d43cb355
discontinued obsolete header "files" -- these are loaded explicitly after exploring dependencies;
wenzelm
parents:
51293
diff
changeset
|
70 |
def bad_header(msg: String): Header = Header(Nil, Nil, List(msg)) |
46737 | 71 |
|
54509
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54462
diff
changeset
|
72 |
val no_header = bad_header("No theory header") |
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54462
diff
changeset
|
73 |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
74 |
object Name |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
75 |
{ |
54515 | 76 |
val empty = Name("") |
46723 | 77 |
|
78 |
object Ordering extends scala.math.Ordering[Name] |
|
79 |
{ |
|
80 |
def compare(name1: Name, name2: Name): Int = name1.node compare name2.node |
|
81 |
} |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
82 |
} |
52887 | 83 |
|
54515 | 84 |
sealed case class Name(node: String, master_dir: String = "", theory: String = "") |
44615 | 85 |
{ |
86 |
override def hashCode: Int = node.hashCode |
|
87 |
override def equals(that: Any): Boolean = |
|
88 |
that match { |
|
89 |
case other: Name => node == other.node |
|
90 |
case _ => false |
|
91 |
} |
|
54509
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54462
diff
changeset
|
92 |
|
1f77110c94ef
maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents:
54462
diff
changeset
|
93 |
def is_theory: Boolean = !theory.isEmpty |
54510 | 94 |
override def toString: String = if (is_theory) theory else node |
44615 | 95 |
} |
96 |
||
52887 | 97 |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
98 |
/* node overlays */ |
52887 | 99 |
|
100 |
object Overlays |
|
101 |
{ |
|
52976 | 102 |
val empty = new Overlays(Multi_Map.empty) |
52887 | 103 |
} |
104 |
||
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
105 |
final class Overlays private(rep: Multi_Map[Command, (String, List[String])]) |
52887 | 106 |
{ |
107 |
def commands: Set[Command] = rep.keySet |
|
108 |
def is_empty: Boolean = rep.isEmpty |
|
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
109 |
def dest: List[(Command, (String, List[String]))] = rep.iterator.toList |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
110 |
def insert(cmd: Command, fn: String, args: List[String]): Overlays = |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
111 |
new Overlays(rep.insert(cmd, (fn, args))) |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
112 |
def remove(cmd: Command, fn: String, args: List[String]): Overlays = |
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52976
diff
changeset
|
113 |
new Overlays(rep.remove(cmd, (fn, args))) |
52887 | 114 |
} |
115 |
||
116 |
||
117 |
/* edits */ |
|
118 |
||
44384 | 119 |
sealed abstract class Edit[A, B] |
44156 | 120 |
{ |
44383 | 121 |
def foreach(f: A => Unit) |
122 |
{ |
|
44156 | 123 |
this match { |
44383 | 124 |
case Edits(es) => es.foreach(f) |
125 |
case _ => |
|
44156 | 126 |
} |
44383 | 127 |
} |
44156 | 128 |
} |
44384 | 129 |
case class Clear[A, B]() extends Edit[A, B] |
54562
301a721af68b
clarified node edits sent to prover -- Clear/Blob only required for text edits within editor;
wenzelm
parents:
54549
diff
changeset
|
130 |
case class Blob[A, B]() extends Edit[A, B] |
301a721af68b
clarified node edits sent to prover -- Clear/Blob only required for text edits within editor;
wenzelm
parents:
54549
diff
changeset
|
131 |
|
44384 | 132 |
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
|
133 |
case class Deps[A, B](header: Header) extends Edit[A, B] |
52849 | 134 |
case class Perspective[A, B](required: Boolean, visible: B, overlays: Overlays) extends Edit[A, B] |
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52568
diff
changeset
|
135 |
type Perspective_Text = Perspective[Text.Edit, Text.Perspective] |
52849 | 136 |
type Perspective_Command = Perspective[Command.Edit, Command.Perspective] |
44156 | 137 |
|
52887 | 138 |
|
139 |
/* commands */ |
|
140 |
||
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
141 |
object Commands |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
142 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
143 |
def apply(commands: Linear_Set[Command]): Commands = new Commands(commands) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
144 |
val empty: Commands = apply(Linear_Set.empty) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
145 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
146 |
def starts(commands: Iterator[Command], offset: Text.Offset = 0) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
147 |
: Iterator[(Command, Text.Offset)] = |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
148 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
149 |
var i = offset |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
150 |
for (command <- commands) yield { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
151 |
val start = i |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
152 |
i += command.length |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
153 |
(command, start) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
154 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
155 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
156 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
157 |
private val block_size = 1024 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
158 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
159 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
160 |
final class Commands private(val commands: Linear_Set[Command]) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
161 |
{ |
54462 | 162 |
lazy val thy_load_commands: List[Command] = |
54513 | 163 |
commands.iterator.filter(cmd => !cmd.blobs.isEmpty).toList |
54462 | 164 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
165 |
private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) = |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
166 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
167 |
val blocks = new mutable.ListBuffer[(Command, Text.Offset)] |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
168 |
var next_block = 0 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
169 |
var last_stop = 0 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
170 |
for ((command, start) <- Commands.starts(commands.iterator)) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
171 |
last_stop = start + command.length |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
172 |
while (last_stop + 1 > next_block) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
173 |
blocks += (command -> start) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
174 |
next_block += Commands.block_size |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
175 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
176 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
177 |
(blocks.toArray, Text.Range(0, last_stop)) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
178 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
179 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
180 |
private def full_range: Text.Range = full_index._2 |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
181 |
|
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
182 |
def range(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
183 |
{ |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
184 |
if (!commands.isEmpty && full_range.contains(i)) { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
185 |
val (cmd0, start0) = full_index._1(i / Commands.block_size) |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
186 |
Node.Commands.starts(commands.iterator(cmd0), start0) dropWhile { |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
187 |
case (cmd, start) => start + cmd.length <= i } |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
188 |
} |
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
189 |
else Iterator.empty |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
190 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
191 |
} |
38151 | 192 |
} |
193 |
||
46712 | 194 |
final class Node private( |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
195 |
val is_blob: Boolean = false, |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
196 |
val header: Node.Header = Node.bad_header("Bad theory header"), |
52849 | 197 |
val perspective: Node.Perspective_Command = |
52887 | 198 |
Node.Perspective(false, Command.Perspective.empty, Node.Overlays.empty), |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
199 |
_commands: Node.Commands = Node.Commands.empty) |
38151 | 200 |
{ |
46680 | 201 |
def clear: Node = new Node(header = header) |
202 |
||
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
203 |
def init_blob: Node = new Node(is_blob = true) |
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
204 |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
205 |
def update_header(new_header: Node.Header): Node = |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
206 |
new Node(is_blob, new_header, perspective, _commands) |
46680 | 207 |
|
52849 | 208 |
def update_perspective(new_perspective: Node.Perspective_Command): Node = |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
209 |
new Node(is_blob, header, new_perspective, _commands) |
46680 | 210 |
|
52849 | 211 |
def same_perspective(other_perspective: Node.Perspective_Command): Boolean = |
212 |
perspective.required == other_perspective.required && |
|
213 |
perspective.visible.same(other_perspective.visible) && |
|
214 |
perspective.overlays == other_perspective.overlays |
|
52808
143f225e50f5
allow explicit indication of required node: full eval, no prints;
wenzelm
parents:
52568
diff
changeset
|
215 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
216 |
def commands: Linear_Set[Command] = _commands.commands |
54462 | 217 |
def thy_load_commands: List[Command] = _commands.thy_load_commands |
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
218 |
|
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
219 |
def update_commands(new_commands: Linear_Set[Command]): Node = |
52918
038458a4d11b
proper low-level comparison -- heed warning by Scala compiler;
wenzelm
parents:
52901
diff
changeset
|
220 |
if (new_commands eq _commands.commands) this |
55435
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
wenzelm
parents:
55434
diff
changeset
|
221 |
else new Node(is_blob, header, perspective, Node.Commands(new_commands)) |
38151 | 222 |
|
38569 | 223 |
def command_range(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
224 |
_commands.range(i) |
38151 | 225 |
|
38569 | 226 |
def command_range(range: Text.Range): Iterator[(Command, Text.Offset)] = |
227 |
command_range(range.start) takeWhile { case (_, start) => start < range.stop } |
|
38151 | 228 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
229 |
def command_start(cmd: Command): Option[Text.Offset] = |
52901
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents:
52900
diff
changeset
|
230 |
Node.Commands.starts(commands.iterator).find(_._1 == cmd).map(_._2) |
38151 | 231 |
} |
232 |
||
233 |
||
46723 | 234 |
/* development graph */ |
235 |
||
236 |
object Nodes |
|
237 |
{ |
|
238 |
val empty: Nodes = new Nodes(Graph.empty(Node.Name.Ordering)) |
|
239 |
} |
|
240 |
||
241 |
final class Nodes private(graph: Graph[Node.Name, Node]) |
|
242 |
{ |
|
243 |
def get_name(s: String): Option[Node.Name] = |
|
244 |
graph.keys.find(name => name.node == s) |
|
245 |
||
246 |
def apply(name: Node.Name): Node = |
|
247 |
graph.default_node(name, Node.empty).get_node(name) |
|
248 |
||
249 |
def + (entry: (Node.Name, Node)): Nodes = |
|
250 |
{ |
|
251 |
val (name, node) = entry |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48706
diff
changeset
|
252 |
val imports = node.header.imports |
46723 | 253 |
val graph1 = |
46739
6024353549ca
clarified document nodes (full import graph) vs. node_status (non-preloaded theories);
wenzelm
parents:
46737
diff
changeset
|
254 |
(graph.default_node(name, Node.empty) /: imports)((g, p) => g.default_node(p, Node.empty)) |
46723 | 255 |
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
|
256 |
val graph3 = (graph2 /: imports)((g, dep) => g.add_edge(dep, name)) |
46723 | 257 |
new Nodes(graph3.map_node(name, _ => node)) |
258 |
} |
|
259 |
||
260 |
def entries: Iterator[(Node.Name, Node)] = |
|
261 |
graph.entries.map({ case (name, (node, _)) => (name, node) }) |
|
262 |
||
54528 | 263 |
def thy_load_commands(file_name: Node.Name): List[Command] = |
264 |
(for { |
|
265 |
(_, node) <- entries |
|
266 |
cmd <- node.thy_load_commands.iterator |
|
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54528
diff
changeset
|
267 |
name <- cmd.blobs_names.iterator |
54528 | 268 |
if name == file_name |
269 |
} yield cmd).toList |
|
270 |
||
46942
f5c2d66faa04
basic support for outer syntax keywords in theory header;
wenzelm
parents:
46941
diff
changeset
|
271 |
def descendants(names: List[Node.Name]): List[Node.Name] = graph.all_succs(names) |
46723 | 272 |
def topological_order: List[Node.Name] = graph.topological_order |
273 |
} |
|
274 |
||
275 |
||
38424 | 276 |
|
277 |
/** versioning **/ |
|
278 |
||
279 |
/* particular document versions */ |
|
34485 | 280 |
|
38417 | 281 |
object Version |
282 |
{ |
|
46681 | 283 |
val init: Version = new Version() |
284 |
||
46941 | 285 |
def make(syntax: Outer_Syntax, nodes: Nodes): Version = |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
286 |
new Version(Document_ID.make(), syntax, nodes) |
38417 | 287 |
} |
288 |
||
46712 | 289 |
final class Version private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
290 |
val id: Document_ID.Version = Document_ID.none, |
46941 | 291 |
val syntax: Outer_Syntax = Outer_Syntax.empty, |
46723 | 292 |
val nodes: Nodes = Nodes.empty) |
46941 | 293 |
{ |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
294 |
def is_init: Boolean = id == Document_ID.none |
46941 | 295 |
} |
34660 | 296 |
|
34859 | 297 |
|
38424 | 298 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
299 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
300 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
301 |
{ |
46678 | 302 |
val init: Change = new Change() |
303 |
||
304 |
def make(previous: Future[Version], edits: List[Edit_Text], version: Future[Version]): Change = |
|
305 |
new Change(Some(previous), edits, version) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
306 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
307 |
|
46712 | 308 |
final class Change private( |
46677 | 309 |
val previous: Option[Future[Version]] = Some(Future.value(Version.init)), |
310 |
val edits: List[Edit_Text] = Nil, |
|
311 |
val version: Future[Version] = Future.value(Version.init)) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
312 |
{ |
44672 | 313 |
def is_finished: Boolean = |
314 |
(previous match { case None => true case Some(future) => future.is_finished }) && |
|
315 |
version.is_finished |
|
316 |
||
46678 | 317 |
def truncate: Change = new Change(None, Nil, version) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
318 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
319 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
320 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
321 |
/* history navigation */ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
322 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
323 |
object History |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
324 |
{ |
46679 | 325 |
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
|
326 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
327 |
|
46712 | 328 |
final class History private( |
46679 | 329 |
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
|
330 |
{ |
46679 | 331 |
def tip: Change = undo_list.head |
332 |
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
|
333 |
|
46679 | 334 |
def prune(check: Change => Boolean, retain: Int): Option[(List[Change], History)] = |
335 |
{ |
|
336 |
val n = undo_list.iterator.zipWithIndex.find(p => check(p._1)).get._2 + 1 |
|
337 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
338 |
||
339 |
retained.splitAt(retained.length - 1) match { |
|
340 |
case (prefix, List(last)) => Some(dropped, new History(prefix ::: List(last.truncate))) |
|
341 |
case _ => None |
|
342 |
} |
|
343 |
} |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
344 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
345 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
346 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
347 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
348 |
/** global state -- document structure, execution process, editing history **/ |
38424 | 349 |
|
52972 | 350 |
object Snapshot |
351 |
{ |
|
352 |
val init = State.init.snapshot() |
|
353 |
} |
|
354 |
||
38424 | 355 |
abstract class Snapshot |
356 |
{ |
|
44582 | 357 |
val state: State |
38424 | 358 |
val version: Version |
359 |
val is_outdated: Boolean |
|
38427 | 360 |
def convert(i: Text.Offset): Text.Offset |
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
361 |
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
|
362 |
def convert(range: Text.Range): Text.Range |
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
363 |
def revert(range: Text.Range): Text.Range |
52972 | 364 |
|
365 |
val node_name: Node.Name |
|
366 |
val node: Node |
|
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
367 |
val thy_load_commands: List[Command] |
51494 | 368 |
def eq_content(other: Snapshot): Boolean |
52508 | 369 |
def cumulate_markup[A]( |
370 |
range: Text.Range, |
|
371 |
info: A, |
|
55620 | 372 |
elements: String => Boolean, |
52900
d29bf6db8a2d
more elementary list structures for markup tree traversal;
wenzelm
parents:
52889
diff
changeset
|
373 |
result: Command.State => (A, Text.Markup) => Option[A]): List[Text.Info[A]] |
52508 | 374 |
def select_markup[A]( |
375 |
range: Text.Range, |
|
55620 | 376 |
elements: String => Boolean, |
52900
d29bf6db8a2d
more elementary list structures for markup tree traversal;
wenzelm
parents:
52889
diff
changeset
|
377 |
result: Command.State => Text.Markup => Option[A]): List[Text.Info[A]] |
38424 | 378 |
} |
379 |
||
52563 | 380 |
type Assign_Update = |
381 |
List[(Document_ID.Command, List[Document_ID.Exec])] // update of exec state assignment |
|
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
382 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
383 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
384 |
{ |
38373 | 385 |
class Fail(state: State) extends Exception |
386 |
||
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
387 |
object Assignment |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
388 |
{ |
46683 | 389 |
val init: Assignment = new Assignment() |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
390 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
391 |
|
46712 | 392 |
final class Assignment private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
393 |
val command_execs: Map[Document_ID.Command, List[Document_ID.Exec]] = Map.empty, |
46677 | 394 |
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
|
395 |
{ |
44477 | 396 |
def check_finished: Assignment = { require(is_finished); this } |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
397 |
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
|
398 |
|
52563 | 399 |
def assign(update: Assign_Update): Assignment = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
400 |
{ |
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
|
401 |
require(!is_finished) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
402 |
val command_execs1 = |
52563 | 403 |
(command_execs /: update) { |
404 |
case (res, (command_id, exec_ids)) => |
|
405 |
if (exec_ids.isEmpty) res - command_id |
|
406 |
else res + (command_id -> exec_ids) |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
407 |
} |
47388
fe4b245af74c
discontinued obsolete last_execs (cf. cd3ab7625519);
wenzelm
parents:
46997
diff
changeset
|
408 |
new Assignment(command_execs1, true) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
409 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
410 |
} |
46682 | 411 |
|
412 |
val init: State = |
|
52563 | 413 |
State().define_version(Version.init, Assignment.init).assign(Version.init.id, Nil)._2 |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
414 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
415 |
|
46712 | 416 |
final case class State private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
417 |
val versions: Map[Document_ID.Version, Version] = Map.empty, |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
418 |
val blobs: Set[SHA1.Digest] = Set.empty, // inlined files |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
419 |
val commands: Map[Document_ID.Command, Command.State] = Map.empty, // static markup from define_command |
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
420 |
val execs: Map[Document_ID.Exec, Command.State] = Map.empty, // dynamic markup from execution |
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
421 |
val assignments: Map[Document_ID.Version, 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
|
422 |
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
|
423 |
{ |
38373 | 424 |
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
|
425 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
426 |
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
|
427 |
{ |
38417 | 428 |
val id = version.id |
429 |
copy(versions = versions + (id -> version), |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
430 |
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
|
431 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
432 |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
433 |
def define_blob(digest: SHA1.Digest): State = copy(blobs = blobs + digest) |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
434 |
def defined_blob(digest: SHA1.Digest): Boolean = blobs.contains(digest) |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
435 |
|
38373 | 436 |
def define_command(command: Command): State = |
437 |
{ |
|
438 |
val id = command.id |
|
49414 | 439 |
copy(commands = commands + (id -> command.init_state)) |
38373 | 440 |
} |
441 |
||
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
442 |
def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id) |
44582 | 443 |
|
52531 | 444 |
def find_command(version: Version, id: Document_ID.Generic): Option[(Node, Command)] = |
44582 | 445 |
commands.get(id) orElse execs.get(id) match { |
446 |
case None => None |
|
447 |
case Some(st) => |
|
448 |
val command = st.command |
|
46681 | 449 |
val node = version.nodes(command.node_name) |
54328
ffa4e0b1701e
more strict find_command -- avoid invalid hyperlink_command;
wenzelm
parents:
52978
diff
changeset
|
450 |
if (node.commands.contains(command)) Some((node, command)) else None |
44582 | 451 |
} |
38373 | 452 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
453 |
def the_version(id: Document_ID.Version): Version = versions.getOrElse(id, fail) |
52564
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
wenzelm
parents:
52563
diff
changeset
|
454 |
def the_static_state(id: Document_ID.Command): Command.State = commands.getOrElse(id, fail) |
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
wenzelm
parents:
52563
diff
changeset
|
455 |
def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail) |
52563 | 456 |
def the_assignment(version: Version): State.Assignment = assignments.getOrElse(version.id, fail) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
457 |
|
52531 | 458 |
def accumulate(id: Document_ID.Generic, 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
|
459 |
execs.get(id) match { |
44446 | 460 |
case Some(st) => |
49527 | 461 |
val new_st = st + (id, message) |
44446 | 462 |
(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
|
463 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
464 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
465 |
case Some(st) => |
49527 | 466 |
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
|
467 |
(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
|
468 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
469 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
470 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
471 |
|
52563 | 472 |
def assign(id: Document_ID.Version, update: Assign_Update): (List[Command], State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
473 |
{ |
38417 | 474 |
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
|
475 |
|
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
476 |
def upd(exec_id: Document_ID.Exec, st: Command.State) |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
477 |
: Option[(Document_ID.Exec, Command.State)] = |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
478 |
if (execs.isDefinedAt(exec_id)) None else Some(exec_id -> st) |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
479 |
|
44543 | 480 |
val (changed_commands, new_execs) = |
52563 | 481 |
((Nil: List[Command], execs) /: update) { |
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
482 |
case ((commands1, execs1), (command_id, exec)) => |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
483 |
val st = the_static_state(command_id) |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
484 |
val command = st.command |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
485 |
val commands2 = command :: commands1 |
44543 | 486 |
val execs2 = |
487 |
exec match { |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
488 |
case Nil => execs1 |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
489 |
case eval_id :: print_ids => |
52566
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
490 |
execs1 ++ upd(eval_id, st) ++ |
52a0eacf04d1
more formal type assign_update: avoid duplicate results and redundant update of global State.execs;
wenzelm
parents:
52564
diff
changeset
|
491 |
(for (id <- print_ids; up <- upd(id, command.empty_state)) yield up) |
44543 | 492 |
} |
493 |
(commands2, execs2) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
494 |
} |
52563 | 495 |
val new_assignment = the_assignment(version).assign(update) |
43722 | 496 |
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
|
497 |
|
44543 | 498 |
(changed_commands, new_state) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
499 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
500 |
|
38417 | 501 |
def is_assigned(version: Version): Boolean = |
43722 | 502 |
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
|
503 |
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
|
504 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
505 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
506 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
507 |
def is_stable(change: Change): Boolean = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
508 |
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
|
509 |
|
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
510 |
def recent_finished: Change = history.undo_list.find(_.is_finished) getOrElse fail |
44672 | 511 |
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
|
512 |
def tip_stable: Boolean = is_stable(history.tip) |
44475 | 513 |
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
|
514 |
|
44446 | 515 |
def continue_history( |
516 |
previous: Future[Version], |
|
40479 | 517 |
edits: List[Edit_Text], |
43722 | 518 |
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
|
519 |
{ |
46678 | 520 |
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
|
521 |
(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
|
522 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
523 |
|
44672 | 524 |
def prune_history(retain: Int = 0): (List[Version], State) = |
525 |
{ |
|
46679 | 526 |
history.prune(is_stable, retain) match { |
527 |
case Some((dropped, history1)) => |
|
44672 | 528 |
val dropped_versions = dropped.map(change => change.version.get_finished) |
46679 | 529 |
val state1 = copy(history = history1) |
44672 | 530 |
(dropped_versions, state1) |
46679 | 531 |
case None => fail |
44672 | 532 |
} |
533 |
} |
|
534 |
||
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
535 |
def removed_versions(removed: List[Document_ID.Version]): State = |
44676 | 536 |
{ |
537 |
val versions1 = versions -- removed |
|
538 |
val assignments1 = assignments -- removed |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
539 |
var blobs1 = Set.empty[SHA1.Digest] |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
540 |
var commands1 = Map.empty[Document_ID.Command, Command.State] |
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
541 |
var execs1 = Map.empty[Document_ID.Exec, Command.State] |
44676 | 542 |
for { |
543 |
(version_id, version) <- versions1.iterator |
|
46997 | 544 |
command_execs = assignments1(version_id).command_execs |
46723 | 545 |
(_, node) <- version.nodes.entries |
44676 | 546 |
command <- node.commands.iterator |
547 |
} { |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
548 |
for (digest <- command.blobs_digests; if !blobs1.contains(digest)) |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
549 |
blobs1 += digest |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
550 |
|
52568 | 551 |
if (!commands1.isDefinedAt(command.id)) |
552 |
commands.get(command.id).foreach(st => commands1 += (command.id -> st)) |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
553 |
|
52568 | 554 |
for (exec_id <- command_execs.getOrElse(command.id, Nil)) { |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
555 |
if (!execs1.isDefinedAt(exec_id)) |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
556 |
execs.get(exec_id).foreach(st => execs1 += (exec_id -> st)) |
44676 | 557 |
} |
558 |
} |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
559 |
copy(versions = versions1, blobs = blobs1, commands = commands1, execs = execs1, |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
560 |
assignments = assignments1) |
44676 | 561 |
} |
562 |
||
44613 | 563 |
def command_state(version: Version, command: Command): Command.State = |
564 |
{ |
|
565 |
require(is_assigned(version)) |
|
566 |
try { |
|
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
567 |
the_assignment(version).check_finished.command_execs.getOrElse(command.id, Nil) |
52564
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
wenzelm
parents:
52563
diff
changeset
|
568 |
.map(the_dynamic_state(_)) match { |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
569 |
case eval_state :: print_states => (eval_state /: print_states)(_ ++ _) |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
570 |
case Nil => fail |
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52508
diff
changeset
|
571 |
} |
44613 | 572 |
} |
47395
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
573 |
catch { |
e6261a493f04
added static command status markup, to emphasize accepted but unassigned/unparsed commands (notably in overview panel);
wenzelm
parents:
47388
diff
changeset
|
574 |
case _: State.Fail => |
52564
4e855c120f6a
tuned signature -- NB: Command.read is actually part of Command.eval;
wenzelm
parents:
52563
diff
changeset
|
575 |
try { the_static_state(command.id) } |
49414 | 576 |
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
|
577 |
} |
44613 | 578 |
} |
579 |
||
49645 | 580 |
def markup_to_XML(version: Version, node: Node, filter: XML.Elem => Boolean): XML.Body = |
581 |
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
|
582 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
583 |
// persistent user-view |
49346 | 584 |
def snapshot(name: Node.Name = Node.Name.empty, pending_edits: List[Text.Edit] = Nil) |
585 |
: Snapshot = |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
586 |
{ |
44672 | 587 |
val stable = recent_stable |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
588 |
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
|
589 |
|
44156 | 590 |
// 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
|
591 |
val edits = |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
592 |
(pending_edits /: history.undo_list.takeWhile(_ != stable))((edits, change) => |
44156 | 593 |
(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
|
594 |
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
|
595 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
596 |
new Snapshot |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
597 |
{ |
52972 | 598 |
/* global information */ |
599 |
||
44582 | 600 |
val state = State.this |
39698 | 601 |
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
|
602 |
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
|
603 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
604 |
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
|
605 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
43425 | 606 |
def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r)) |
607 |
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
|
608 |
|
52972 | 609 |
|
610 |
/* local node content */ |
|
611 |
||
612 |
val node_name = name |
|
613 |
val node = version.nodes(name) |
|
614 |
||
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
615 |
val thy_load_commands: List[Command] = |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
616 |
if (node_name.is_theory) Nil |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
617 |
else version.nodes.thy_load_commands(node_name) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
618 |
|
51494 | 619 |
def eq_content(other: Snapshot): Boolean = |
55434 | 620 |
{ |
621 |
def eq_commands(commands: (Command, Command)): Boolean = |
|
622 |
state.command_state(version, commands._1) eq_content |
|
623 |
other.state.command_state(other.version, commands._2) |
|
624 |
||
49346 | 625 |
!is_outdated && !other.is_outdated && |
55434 | 626 |
node.commands.size == other.node.commands.size && |
627 |
(node.commands.iterator zip other.node.commands.iterator).forall(eq_commands) && |
|
628 |
thy_load_commands.length == other.thy_load_commands.length && |
|
629 |
(thy_load_commands zip other.thy_load_commands).forall(eq_commands) |
|
630 |
} |
|
49346 | 631 |
|
55620 | 632 |
def cumulate_markup[A](range: Text.Range, info: A, elements: String => Boolean, |
52900
d29bf6db8a2d
more elementary list structures for markup tree traversal;
wenzelm
parents:
52889
diff
changeset
|
633 |
result: Command.State => (A, Text.Markup) => Option[A]): List[Text.Info[A]] = |
45459 | 634 |
{ |
45467 | 635 |
val former_range = revert(range) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
636 |
thy_load_commands match { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
637 |
case thy_load_command :: _ => |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
638 |
val file_name = node_name.node |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
639 |
(for { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
640 |
chunk <- thy_load_command.chunks.get(file_name).iterator |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
641 |
st = state.command_state(version, thy_load_command) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
642 |
res = result(st) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
643 |
Text.Info(r0, a) <- st.get_markup(file_name).cumulate[A]( |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
644 |
former_range.restrict(chunk.range), info, elements, |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
645 |
{ case (a, Text.Info(r0, b)) => res(a, Text.Info(convert(r0), b)) } |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
646 |
).iterator |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
647 |
} yield Text.Info(convert(r0), a)).toList |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
648 |
|
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
649 |
case _ => |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
650 |
(for { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
651 |
(command, command_start) <- node.command_range(former_range) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
652 |
st = state.command_state(version, command) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
653 |
res = result(st) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
654 |
Text.Info(r0, a) <- st.markup.cumulate[A]( |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
655 |
(former_range - command_start).restrict(command.range), info, elements, |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
656 |
{ case (a, Text.Info(r0, b)) => res(a, Text.Info(convert(r0 + command_start), b)) } |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
657 |
).iterator |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
658 |
} yield Text.Info(convert(r0 + command_start), a)).toList |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
659 |
} |
45459 | 660 |
} |
661 |
||
55620 | 662 |
def select_markup[A](range: Text.Range, elements: String => Boolean, |
52900
d29bf6db8a2d
more elementary list structures for markup tree traversal;
wenzelm
parents:
52889
diff
changeset
|
663 |
result: Command.State => Text.Markup => Option[A]): List[Text.Info[A]] = |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
664 |
{ |
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
665 |
def result1(st: Command.State): (Option[A], Text.Markup) => Option[Option[A]] = |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
666 |
{ |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
667 |
val res = result(st) |
52889
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
668 |
(_: Option[A], x: Text.Markup) => |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
669 |
res(x) match { |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
670 |
case None => None |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
671 |
case some => Some(some) |
ea3338812e67
more tight interface for markup cumulate/select: avoid duplicate application, allow to defer decision about definedness;
wenzelm
parents:
52887
diff
changeset
|
672 |
} |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50204
diff
changeset
|
673 |
} |
55620 | 674 |
for (Text.Info(r, Some(x)) <- cumulate_markup(range, None, elements, result1 _)) |
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
675 |
yield Text.Info(r, x) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
676 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
677 |
} |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
678 |
} |
34485 | 679 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
680 |
} |
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
681 |