| author | wenzelm | 
| Tue, 12 Aug 2014 00:23:30 +0200 | |
| changeset 57907 | 7fc36b4c7cce | 
| parent 57906 | 020df63dd0a9 | 
| child 59077 | 7e0d3da6e6d8 | 
| permissions | -rw-r--r-- | 
| 34268 | 1  | 
/* Title: Pure/Thy/thy_syntax.scala  | 
2  | 
Author: Makarius  | 
|
3  | 
||
| 38374 | 4  | 
Superficial theory syntax: tokens and spans.  | 
| 34268 | 5  | 
*/  | 
6  | 
||
7  | 
package isabelle  | 
|
8  | 
||
9  | 
||
| 
38239
 
89a4d1028fb3
parse_spans: somewhat faster low-level implementation;
 
wenzelm 
parents: 
36956 
diff
changeset
 | 
10  | 
import scala.collection.mutable  | 
| 38374 | 11  | 
import scala.annotation.tailrec  | 
| 
38239
 
89a4d1028fb3
parse_spans: somewhat faster low-level implementation;
 
wenzelm 
parents: 
36956 
diff
changeset
 | 
12  | 
|
| 
 
89a4d1028fb3
parse_spans: somewhat faster low-level implementation;
 
wenzelm 
parents: 
36956 
diff
changeset
 | 
13  | 
|
| 34303 | 14  | 
object Thy_Syntax  | 
| 34268 | 15  | 
{
 | 
| 
44436
 
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
 
wenzelm 
parents: 
44388 
diff
changeset
 | 
16  | 
/** perspective **/  | 
| 44388 | 17  | 
|
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
18  | 
def command_perspective(  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
19  | 
node: Document.Node,  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
20  | 
perspective: Text.Perspective,  | 
| 52887 | 21  | 
overlays: Document.Node.Overlays): (Command.Perspective, Command.Perspective) =  | 
| 44388 | 22  | 
  {
 | 
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
23  | 
if (perspective.is_empty && overlays.is_empty)  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
24  | 
(Command.Perspective.empty, Command.Perspective.empty)  | 
| 44388 | 25  | 
    else {
 | 
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
26  | 
val has_overlay = overlays.commands  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
27  | 
val visible = new mutable.ListBuffer[Command]  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
28  | 
val visible_overlay = new mutable.ListBuffer[Command]  | 
| 44388 | 29  | 
@tailrec  | 
30  | 
def check_ranges(ranges: List[Text.Range], commands: Stream[(Command, Text.Offset)])  | 
|
31  | 
      {
 | 
|
32  | 
        (ranges, commands) match {
 | 
|
33  | 
case (range :: more_ranges, (command, offset) #:: more_commands) =>  | 
|
34  | 
val command_range = command.range + offset  | 
|
35  | 
            range compare command_range match {
 | 
|
36  | 
case 0 =>  | 
|
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
37  | 
visible += command  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
38  | 
visible_overlay += command  | 
| 44388 | 39  | 
check_ranges(ranges, more_commands)  | 
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
40  | 
case c =>  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
41  | 
if (has_overlay(command)) visible_overlay += command  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
42  | 
|
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
43  | 
if (c < 0) check_ranges(more_ranges, commands)  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
44  | 
else check_ranges(ranges, more_commands)  | 
| 44388 | 45  | 
}  | 
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
46  | 
|
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
47  | 
case (Nil, (command, _) #:: more_commands) =>  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
48  | 
if (has_overlay(command)) visible_overlay += command  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
49  | 
|
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
50  | 
check_ranges(Nil, more_commands)  | 
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
51  | 
|
| 44388 | 52  | 
case _ =>  | 
53  | 
}  | 
|
54  | 
}  | 
|
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
55  | 
|
| 
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
56  | 
val commands =  | 
| 
56373
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
57  | 
(if (overlays.is_empty) node.command_iterator(perspective.range)  | 
| 
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
58  | 
else node.command_iterator()).toStream  | 
| 
 
0605d90be6fc
tuned signature -- more explicit iterator terminology;
 
wenzelm 
parents: 
56372 
diff
changeset
 | 
59  | 
check_ranges(perspective.ranges, commands)  | 
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
60  | 
(Command.Perspective(visible.toList), Command.Perspective(visible_overlay.toList))  | 
| 44388 | 61  | 
}  | 
62  | 
}  | 
|
63  | 
||
64  | 
||
65  | 
||
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
66  | 
/** header edits: structure and outer syntax **/  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
67  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
68  | 
private def header_edits(  | 
| 
56394
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
69  | 
resources: Resources,  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
70  | 
previous: Document.Version,  | 
| 
55134
 
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
 
wenzelm 
parents: 
55118 
diff
changeset
 | 
71  | 
edits: List[Document.Edit_Text]):  | 
| 
56393
 
22f533e6a049
more abstract Prover.Syntax, as proposed by Carst Tankink;
 
wenzelm 
parents: 
56373 
diff
changeset
 | 
72  | 
(Prover.Syntax, Boolean, Boolean, List[Document.Node.Name], Document.Nodes,  | 
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
73  | 
List[Document.Edit_Command]) =  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
74  | 
  {
 | 
| 
47987
 
4e9df6ffcc6e
reparse descendants after update of imports, e.g. required for 'primrec' (line 17 of "src/HOL/Power.thy");
 
wenzelm 
parents: 
47346 
diff
changeset
 | 
75  | 
var updated_imports = false  | 
| 
 
4e9df6ffcc6e
reparse descendants after update of imports, e.g. required for 'primrec' (line 17 of "src/HOL/Power.thy");
 
wenzelm 
parents: 
47346 
diff
changeset
 | 
76  | 
var updated_keywords = false  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
77  | 
var nodes = previous.nodes  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
78  | 
val doc_edits = new mutable.ListBuffer[Document.Edit_Command]  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
79  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
80  | 
    edits foreach {
 | 
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
81  | 
case (name, Document.Node.Deps(header)) =>  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
82  | 
val node = nodes(name)  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
83  | 
val update_header =  | 
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
84  | 
!node.header.errors.isEmpty || !header.errors.isEmpty || node.header != header  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
85  | 
        if (update_header) {
 | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
86  | 
val node1 = node.update_header(header)  | 
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
87  | 
updated_imports = updated_imports || (node.header.imports != node1.header.imports)  | 
| 
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
88  | 
updated_keywords = updated_keywords || (node.header.keywords != node1.header.keywords)  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
89  | 
nodes += (name -> node1)  | 
| 
48707
 
ba531af91148
simplified Document.Node.Header -- internalized errors;
 
wenzelm 
parents: 
48706 
diff
changeset
 | 
90  | 
doc_edits += (name -> Document.Node.Deps(header))  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
91  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
92  | 
case _ =>  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
93  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
94  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
95  | 
val (syntax, syntax_changed) =  | 
| 
56394
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
96  | 
      previous.syntax match {
 | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
97  | 
case Some(syntax) if !updated_keywords =>  | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
98  | 
(syntax, false)  | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
99  | 
case _ =>  | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
100  | 
val syntax =  | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
101  | 
            (resources.base_syntax /: nodes.iterator) {
 | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
102  | 
case (syn, (_, node)) => syn.add_keywords(node.header.keywords)  | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
103  | 
}  | 
| 
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
104  | 
(syntax, true)  | 
| 
55134
 
1b67b17cdad5
propagate update of outer syntax keywords: global propertiesChanged, buffer TokenMarker.markTokens, text area repainting;
 
wenzelm 
parents: 
55118 
diff
changeset
 | 
105  | 
}  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
106  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
107  | 
val reparse =  | 
| 
47987
 
4e9df6ffcc6e
reparse descendants after update of imports, e.g. required for 'primrec' (line 17 of "src/HOL/Power.thy");
 
wenzelm 
parents: 
47346 
diff
changeset
 | 
108  | 
if (updated_imports || updated_keywords)  | 
| 
 
4e9df6ffcc6e
reparse descendants after update of imports, e.g. required for 'primrec' (line 17 of "src/HOL/Power.thy");
 
wenzelm 
parents: 
47346 
diff
changeset
 | 
109  | 
nodes.descendants(doc_edits.iterator.map(_._1).toList)  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
110  | 
else Nil  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
111  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
112  | 
(syntax, syntax_changed, updated_imports, reparse, nodes, doc_edits.toList)  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
113  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
114  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
115  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
116  | 
|
| 38374 | 117  | 
/** text edits **/  | 
118  | 
||
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
119  | 
/* edit individual command source */  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
120  | 
|
| 50761 | 121  | 
@tailrec def edit_text(eds: List[Text.Edit], commands: Linear_Set[Command]): Linear_Set[Command] =  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
122  | 
  {
 | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
123  | 
    eds match {
 | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
124  | 
case e :: es =>  | 
| 
52901
 
8be75f53db82
maintain commands together with index -- avoid redundant reconstruction of full_index;
 
wenzelm 
parents: 
52887 
diff
changeset
 | 
125  | 
        Document.Node.Commands.starts(commands.iterator).find {
 | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
126  | 
case (cmd, cmd_start) =>  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
127  | 
e.can_edit(cmd.source, cmd_start) ||  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
128  | 
e.is_insert && e.start == cmd_start + cmd.length  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
129  | 
        } match {
 | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
130  | 
case Some((cmd, cmd_start)) if e.can_edit(cmd.source, cmd_start) =>  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
131  | 
val (rest, text) = e.edit(cmd.source, cmd_start)  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
132  | 
val new_commands = commands.insert_after(Some(cmd), Command.unparsed(text)) - cmd  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
133  | 
edit_text(rest.toList ::: es, new_commands)  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
134  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
135  | 
case Some((cmd, cmd_start)) =>  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
136  | 
edit_text(es, commands.insert_after(Some(cmd), Command.unparsed(e.text)))  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
137  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
138  | 
case None =>  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
139  | 
require(e.is_insert && e.start == 0)  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
140  | 
edit_text(es, commands.insert_after(None, Command.unparsed(e.text)))  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
141  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
142  | 
case Nil => commands  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
143  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
144  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
145  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
146  | 
|
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
147  | 
/* reparse range of command spans */  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
148  | 
|
| 
48748
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
149  | 
@tailrec private def chop_common(  | 
| 55779 | 150  | 
cmds: List[Command],  | 
| 
57905
 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 
wenzelm 
parents: 
57904 
diff
changeset
 | 
151  | 
blobs_spans: List[(List[Command.Blob], Command_Span.Span)])  | 
| 
 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 
wenzelm 
parents: 
57904 
diff
changeset
 | 
152  | 
: (List[Command], List[(List[Command.Blob], Command_Span.Span)]) =  | 
| 55779 | 153  | 
  {
 | 
154  | 
    (cmds, blobs_spans) match {
 | 
|
155  | 
case (cmd :: cmds, (blobs, span) :: rest) if cmd.blobs == blobs && cmd.span == span =>  | 
|
156  | 
chop_common(cmds, rest)  | 
|
157  | 
case _ => (cmds, blobs_spans)  | 
|
| 
48748
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
158  | 
}  | 
| 55779 | 159  | 
}  | 
| 
48748
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
160  | 
|
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
161  | 
private def reparse_spans(  | 
| 56208 | 162  | 
resources: Resources,  | 
| 
56393
 
22f533e6a049
more abstract Prover.Syntax, as proposed by Carst Tankink;
 
wenzelm 
parents: 
56373 
diff
changeset
 | 
163  | 
syntax: Prover.Syntax,  | 
| 56336 | 164  | 
get_blob: Document.Node.Name => Option[Document.Blob],  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
165  | 
name: Document.Node.Name,  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
166  | 
commands: Linear_Set[Command],  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
167  | 
first: Command, last: Command): Linear_Set[Command] =  | 
| 
48748
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
168  | 
  {
 | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
169  | 
val cmds0 = commands.iterator(first, last).toList  | 
| 55779 | 170  | 
val blobs_spans0 =  | 
| 57906 | 171  | 
syntax.parse_spans(cmds0.iterator.map(_.source).mkString).  | 
| 
57905
 
c0c5652e796e
separate module Command_Span: mostly syntactic representation;
 
wenzelm 
parents: 
57904 
diff
changeset
 | 
172  | 
map(span => (Command_Span.resolve_files(resources, syntax, name, span, get_blob), span))  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
173  | 
|
| 55779 | 174  | 
val (cmds1, blobs_spans1) = chop_common(cmds0, blobs_spans0)  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
175  | 
|
| 55779 | 176  | 
val (rev_cmds2, rev_blobs_spans2) = chop_common(cmds1.reverse, blobs_spans1.reverse)  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
177  | 
val cmds2 = rev_cmds2.reverse  | 
| 55779 | 178  | 
val blobs_spans2 = rev_blobs_spans2.reverse  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
179  | 
|
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
180  | 
    cmds2 match {
 | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
181  | 
case Nil =>  | 
| 55779 | 182  | 
assert(blobs_spans2.isEmpty)  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
183  | 
commands  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
184  | 
case cmd :: _ =>  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
185  | 
val hook = commands.prev(cmd)  | 
| 54462 | 186  | 
val inserted =  | 
| 55779 | 187  | 
          blobs_spans2.map({ case (blobs, span) => Command(Document_ID.make(), name, blobs, span) })
 | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
188  | 
(commands /: cmds2)(_ - _).append_after(hook, inserted)  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
189  | 
}  | 
| 
48748
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
190  | 
}  | 
| 
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
191  | 
|
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
192  | 
|
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
193  | 
/* recover command spans after edits */  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
194  | 
|
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
195  | 
// FIXME somewhat slow  | 
| 
48746
 
9e1b2aafbc7f
more direct Linear_Set.reverse, swapping orientation of the graph;
 
wenzelm 
parents: 
48718 
diff
changeset
 | 
196  | 
private def recover_spans(  | 
| 56208 | 197  | 
resources: Resources,  | 
| 
56393
 
22f533e6a049
more abstract Prover.Syntax, as proposed by Carst Tankink;
 
wenzelm 
parents: 
56373 
diff
changeset
 | 
198  | 
syntax: Prover.Syntax,  | 
| 56336 | 199  | 
get_blob: Document.Node.Name => Option[Document.Blob],  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
200  | 
name: Document.Node.Name,  | 
| 
48748
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
201  | 
perspective: Command.Perspective,  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
202  | 
commands: Linear_Set[Command]): Linear_Set[Command] =  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
203  | 
  {
 | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
204  | 
val visible = perspective.commands.toSet  | 
| 
48748
 
89b4e7d83d6f
refined recover_spans: take visible range into account, reparse and trim results -- to improve editing experience wrt. unbalanced quotations etc.;
 
wenzelm 
parents: 
48747 
diff
changeset
 | 
205  | 
|
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
206  | 
def next_invisible_command(cmds: Linear_Set[Command], from: Command): Command =  | 
| 57904 | 207  | 
cmds.iterator(from).dropWhile(cmd => !cmd.is_proper || visible(cmd))  | 
208  | 
.find(_.is_proper) getOrElse cmds.last  | 
|
| 
48746
 
9e1b2aafbc7f
more direct Linear_Set.reverse, swapping orientation of the graph;
 
wenzelm 
parents: 
48718 
diff
changeset
 | 
209  | 
|
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
210  | 
@tailrec def recover(cmds: Linear_Set[Command]): Linear_Set[Command] =  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
211  | 
      cmds.find(_.is_unparsed) match {
 | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
212  | 
case Some(first_unparsed) =>  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
213  | 
val first = next_invisible_command(cmds.reverse, first_unparsed)  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
214  | 
val last = next_invisible_command(cmds, first_unparsed)  | 
| 56336 | 215  | 
recover(reparse_spans(resources, syntax, get_blob, name, cmds, first, last))  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
216  | 
case None => cmds  | 
| 
48746
 
9e1b2aafbc7f
more direct Linear_Set.reverse, swapping orientation of the graph;
 
wenzelm 
parents: 
48718 
diff
changeset
 | 
217  | 
}  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
218  | 
recover(commands)  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
219  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
220  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
221  | 
|
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
222  | 
/* consolidate unfinished spans */  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
223  | 
|
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
224  | 
private def consolidate_spans(  | 
| 56208 | 225  | 
resources: Resources,  | 
| 
56393
 
22f533e6a049
more abstract Prover.Syntax, as proposed by Carst Tankink;
 
wenzelm 
parents: 
56373 
diff
changeset
 | 
226  | 
syntax: Prover.Syntax,  | 
| 56336 | 227  | 
get_blob: Document.Node.Name => Option[Document.Blob],  | 
| 
49524
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
228  | 
reparse_limit: Int,  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
229  | 
name: Document.Node.Name,  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
230  | 
perspective: Command.Perspective,  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
231  | 
commands: Linear_Set[Command]): Linear_Set[Command] =  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
232  | 
  {
 | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
233  | 
if (perspective.commands.isEmpty) commands  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
234  | 
    else {
 | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
235  | 
      commands.find(_.is_unfinished) match {
 | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
236  | 
case Some(first_unfinished) =>  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
237  | 
val visible = perspective.commands.toSet  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
238  | 
          commands.reverse.find(visible) match {
 | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
239  | 
case Some(last_visible) =>  | 
| 
49524
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
240  | 
val it = commands.iterator(last_visible)  | 
| 
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
241  | 
var last = last_visible  | 
| 
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
242  | 
var i = 0  | 
| 
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
243  | 
              while (i < reparse_limit && it.hasNext) {
 | 
| 
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
244  | 
last = it.next  | 
| 
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
245  | 
i += last.length  | 
| 
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
246  | 
}  | 
| 56336 | 247  | 
reparse_spans(resources, syntax, get_blob, name, commands, first_unfinished, last)  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
248  | 
case None => commands  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
249  | 
}  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
250  | 
case None => commands  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
251  | 
}  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
252  | 
}  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
253  | 
}  | 
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
254  | 
|
| 
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
255  | 
|
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
256  | 
/* main */  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
257  | 
|
| 50761 | 258  | 
def diff_commands(old_cmds: Linear_Set[Command], new_cmds: Linear_Set[Command])  | 
| 52849 | 259  | 
: List[Command.Edit] =  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
260  | 
  {
 | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
261  | 
val removed = old_cmds.iterator.filter(!new_cmds.contains(_)).toList  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
262  | 
val inserted = new_cmds.iterator.filter(!old_cmds.contains(_)).toList  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
263  | 
|
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
264  | 
removed.reverse.map(cmd => (old_cmds.prev(cmd), None)) :::  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
265  | 
inserted.map(cmd => (new_cmds.prev(cmd), Some(cmd)))  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
266  | 
}  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
267  | 
|
| 54513 | 268  | 
private def text_edit(  | 
| 56208 | 269  | 
resources: Resources,  | 
| 
56393
 
22f533e6a049
more abstract Prover.Syntax, as proposed by Carst Tankink;
 
wenzelm 
parents: 
56373 
diff
changeset
 | 
270  | 
syntax: Prover.Syntax,  | 
| 56336 | 271  | 
get_blob: Document.Node.Name => Option[Document.Blob],  | 
| 54513 | 272  | 
reparse_limit: Int,  | 
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
273  | 
node: Document.Node, edit: Document.Edit_Text): Document.Node =  | 
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
274  | 
  {
 | 
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
275  | 
    edit match {
 | 
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
276  | 
case (_, Document.Node.Clear()) => node.clear  | 
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
277  | 
|
| 
56335
 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 
wenzelm 
parents: 
56316 
diff
changeset
 | 
278  | 
case (_, Document.Node.Blob(blob)) => node.init_blob(blob)  | 
| 
54562
 
301a721af68b
clarified node edits sent to prover -- Clear/Blob only required for text edits within editor;
 
wenzelm 
parents: 
54524 
diff
changeset
 | 
279  | 
|
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
280  | 
case (name, Document.Node.Edits(text_edits)) =>  | 
| 
56335
 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 
wenzelm 
parents: 
56316 
diff
changeset
 | 
281  | 
        if (name.is_theory) {
 | 
| 
55435
 
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
 
wenzelm 
parents: 
55431 
diff
changeset
 | 
282  | 
val commands0 = node.commands  | 
| 
 
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
 
wenzelm 
parents: 
55431 
diff
changeset
 | 
283  | 
val commands1 = edit_text(text_edits, commands0)  | 
| 
 
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
 
wenzelm 
parents: 
55431 
diff
changeset
 | 
284  | 
val commands2 =  | 
| 56336 | 285  | 
recover_spans(resources, syntax, get_blob, name, node.perspective.visible, commands1)  | 
| 
55435
 
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
 
wenzelm 
parents: 
55431 
diff
changeset
 | 
286  | 
node.update_commands(commands2)  | 
| 
 
662e0fd39823
maintain blob edits within history, which is important for Snapshot.convert/revert;
 
wenzelm 
parents: 
55431 
diff
changeset
 | 
287  | 
}  | 
| 
56335
 
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
 
wenzelm 
parents: 
56316 
diff
changeset
 | 
288  | 
else node  | 
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
289  | 
|
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
290  | 
case (_, Document.Node.Deps(_)) => node  | 
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
291  | 
|
| 52849 | 292  | 
case (name, Document.Node.Perspective(required, text_perspective, overlays)) =>  | 
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
293  | 
val (visible, visible_overlay) = command_perspective(node, text_perspective, overlays)  | 
| 52849 | 294  | 
val perspective: Document.Node.Perspective_Command =  | 
| 
52861
 
e93d73b51fd0
commands with overlay remain visible, to avoid loosing printed output;
 
wenzelm 
parents: 
52849 
diff
changeset
 | 
295  | 
Document.Node.Perspective(required, visible_overlay, overlays)  | 
| 
52808
 
143f225e50f5
allow explicit indication of required node: full eval, no prints;
 
wenzelm 
parents: 
52535 
diff
changeset
 | 
296  | 
if (node.same_perspective(perspective)) node  | 
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
297  | 
else  | 
| 
49524
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
298  | 
node.update_perspective(perspective).update_commands(  | 
| 56336 | 299  | 
consolidate_spans(resources, syntax, get_blob, reparse_limit,  | 
| 54517 | 300  | 
name, visible, node.commands))  | 
| 
48755
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
301  | 
}  | 
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
302  | 
}  | 
| 
 
393a37003851
apply all text edits to each node, before determining the resulting doc_edits -- allow several iterations to consolidate spans etc.;
 
wenzelm 
parents: 
48754 
diff
changeset
 | 
303  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
304  | 
def parse_change(  | 
| 56208 | 305  | 
resources: Resources,  | 
| 
49524
 
68796a77c42b
Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
 
wenzelm 
parents: 
49414 
diff
changeset
 | 
306  | 
reparse_limit: Int,  | 
| 43722 | 307  | 
previous: Document.Version,  | 
| 
54521
 
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
 
wenzelm 
parents: 
54519 
diff
changeset
 | 
308  | 
doc_blobs: Document.Blobs,  | 
| 56315 | 309  | 
edits: List[Document.Edit_Text]): Session.Change =  | 
| 38374 | 310  | 
  {
 | 
| 56336 | 311  | 
def get_blob(name: Document.Node.Name) =  | 
312  | 
doc_blobs.get(name) orElse previous.nodes(name).get_blob  | 
|
313  | 
||
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
314  | 
val (syntax, syntax_changed, deps_changed, reparse0, nodes0, doc_edits0) =  | 
| 
56394
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
315  | 
header_edits(resources, previous, edits)  | 
| 
54518
 
81a9a54c57fc
always reparse nodes with thy_load commands, to update inlined files;
 
wenzelm 
parents: 
54517 
diff
changeset
 | 
316  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
317  | 
val (doc_edits, version) =  | 
| 
56394
 
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
 
wenzelm 
parents: 
56393 
diff
changeset
 | 
318  | 
if (edits.isEmpty) (Nil, Document.Version.make(Some(syntax), previous.nodes))  | 
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
319  | 
      else {
 | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
320  | 
val reparse =  | 
| 
56372
 
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
 
wenzelm 
parents: 
56336 
diff
changeset
 | 
321  | 
          (reparse0 /: nodes0.iterator)({
 | 
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
322  | 
case (reparse, (name, node)) =>  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
323  | 
if (node.load_commands.exists(_.blobs_changed(doc_blobs)))  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
324  | 
name :: reparse  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
325  | 
else reparse  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
326  | 
})  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
327  | 
val reparse_set = reparse.toSet  | 
| 
46946
 
acc8ebf980ca
more explicit header_edits before main text_edits;
 
wenzelm 
parents: 
46942 
diff
changeset
 | 
328  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
329  | 
var nodes = nodes0  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
330  | 
val doc_edits = new mutable.ListBuffer[Document.Edit_Command]; doc_edits ++= doc_edits0  | 
| 
54521
 
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
 
wenzelm 
parents: 
54519 
diff
changeset
 | 
331  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
332  | 
val node_edits =  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
333  | 
(edits ::: reparse.map((_, Document.Node.Edits(Nil)))).groupBy(_._1)  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
334  | 
.asInstanceOf[Map[Document.Node.Name, List[Document.Edit_Text]]] // FIXME ???  | 
| 38374 | 335  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
336  | 
        node_edits foreach {
 | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
337  | 
case (name, edits) =>  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
338  | 
val node = nodes(name)  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
339  | 
val commands = node.commands  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48748 
diff
changeset
 | 
340  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
341  | 
val node1 =  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
342  | 
if (reparse_set(name) && !commands.isEmpty)  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
343  | 
node.update_commands(  | 
| 56336 | 344  | 
reparse_spans(resources, syntax, get_blob,  | 
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
345  | 
name, commands, commands.head, commands.last))  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
346  | 
else node  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
347  | 
val node2 =  | 
| 56336 | 348  | 
(node1 /: edits)(text_edit(resources, syntax, get_blob, reparse_limit, _, _))  | 
| 
54521
 
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
 
wenzelm 
parents: 
54519 
diff
changeset
 | 
349  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
350  | 
if (!(node.same_perspective(node2.perspective)))  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
351  | 
doc_edits += (name -> node2.perspective)  | 
| 
54521
 
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
 
wenzelm 
parents: 
54519 
diff
changeset
 | 
352  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
353  | 
doc_edits += (name -> Document.Node.Edits(diff_commands(commands, node2.commands)))  | 
| 
54521
 
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
 
wenzelm 
parents: 
54519 
diff
changeset
 | 
354  | 
|
| 
56316
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
355  | 
nodes += (name -> node2)  | 
| 
 
b1cf8ddc2e04
propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
 
wenzelm 
parents: 
56315 
diff
changeset
 | 
356  | 
}  | 
| 57625 | 357  | 
(doc_edits.toList.filterNot(_._2.is_void), Document.Version.make(Some(syntax), nodes))  | 
| 54513 | 358  | 
}  | 
359  | 
||
| 
57842
 
8e4ae2db1849
more direct access to persistent blobs (see also 8953d4cc060a), avoiding fragile digest lookup from later version (which might have removed unused blobs already);
 
wenzelm 
parents: 
57625 
diff
changeset
 | 
360  | 
Session.Change(previous, syntax_changed, deps_changed, doc_edits, version)  | 
| 38374 | 361  | 
}  | 
| 34268 | 362  | 
}  |