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