src/Pure/Thy/thy_syntax.scala
changeset 56335 8953d4cc060a
parent 56316 b1cf8ddc2e04
child 56336 60434514ec0a
--- a/src/Pure/Thy/thy_syntax.scala	Mon Mar 31 12:35:39 2014 +0200
+++ b/src/Pure/Thy/thy_syntax.scala	Mon Mar 31 15:05:24 2014 +0200
@@ -262,14 +262,14 @@
       syntax: Outer_Syntax,
       node_name: Document.Node.Name,
       span: List[Token],
-      doc_blobs: Document.Blobs)
+      doc_blobs_default: Document.Blobs)
     : List[Command.Blob] =
   {
     span_files(syntax, span).map(file_name =>
       Exn.capture {
         val name =
           Document.Node.Name(resources.append(node_name.master_dir, Path.explode(file_name)))
-        val blob = doc_blobs.get(name).map(blob => ((blob.bytes.sha1_digest, blob.file)))
+        val blob = doc_blobs_default.get(name).map(blob => ((blob.bytes.sha1_digest, blob.file)))
         (name, blob)
       })
   }
@@ -292,7 +292,7 @@
   private def reparse_spans(
     resources: Resources,
     syntax: Outer_Syntax,
-    doc_blobs: Document.Blobs,
+    doc_blobs_default: Document.Blobs,
     name: Document.Node.Name,
     commands: Linear_Set[Command],
     first: Command, last: Command): Linear_Set[Command] =
@@ -300,7 +300,7 @@
     val cmds0 = commands.iterator(first, last).toList
     val blobs_spans0 =
       parse_spans(syntax.scan(cmds0.iterator.map(_.source).mkString)).
-        map(span => (resolve_files(resources, syntax, name, span, doc_blobs), span))
+        map(span => (resolve_files(resources, syntax, name, span, doc_blobs_default), span))
 
     val (cmds1, blobs_spans1) = chop_common(cmds0, blobs_spans0)
 
@@ -327,7 +327,7 @@
   private def recover_spans(
     resources: Resources,
     syntax: Outer_Syntax,
-    doc_blobs: Document.Blobs,
+    doc_blobs_default: Document.Blobs,
     name: Document.Node.Name,
     perspective: Command.Perspective,
     commands: Linear_Set[Command]): Linear_Set[Command] =
@@ -343,7 +343,7 @@
         case Some(first_unparsed) =>
           val first = next_invisible_command(cmds.reverse, first_unparsed)
           val last = next_invisible_command(cmds, first_unparsed)
-          recover(reparse_spans(resources, syntax, doc_blobs, name, cmds, first, last))
+          recover(reparse_spans(resources, syntax, doc_blobs_default, name, cmds, first, last))
         case None => cmds
       }
     recover(commands)
@@ -355,7 +355,7 @@
   private def consolidate_spans(
     resources: Resources,
     syntax: Outer_Syntax,
-    doc_blobs: Document.Blobs,
+    doc_blobs_default: Document.Blobs,
     reparse_limit: Int,
     name: Document.Node.Name,
     perspective: Command.Perspective,
@@ -375,7 +375,8 @@
                 last = it.next
                 i += last.length
               }
-              reparse_spans(resources, syntax, doc_blobs, name, commands, first_unfinished, last)
+              reparse_spans(
+                resources, syntax, doc_blobs_default, name, commands, first_unfinished, last)
             case None => commands
           }
         case None => commands
@@ -399,24 +400,25 @@
   private def text_edit(
     resources: Resources,
     syntax: Outer_Syntax,
-    doc_blobs: Document.Blobs,
+    doc_blobs_default: Document.Blobs,
     reparse_limit: Int,
     node: Document.Node, edit: Document.Edit_Text): Document.Node =
   {
     edit match {
       case (_, Document.Node.Clear()) => node.clear
 
-      case (_, Document.Node.Blob()) => node.init_blob
+      case (_, Document.Node.Blob(blob)) => node.init_blob(blob)
 
       case (name, Document.Node.Edits(text_edits)) =>
-        if (node.is_blob) node
-        else {
+        if (name.is_theory) {
           val commands0 = node.commands
           val commands1 = edit_text(text_edits, commands0)
           val commands2 =
-            recover_spans(resources, syntax, doc_blobs, name, node.perspective.visible, commands1)
+            recover_spans(
+              resources, syntax, doc_blobs_default, name, node.perspective.visible, commands1)
           node.update_commands(commands2)
         }
+        else node
 
       case (_, Document.Node.Deps(_)) => node
 
@@ -427,7 +429,7 @@
         if (node.same_perspective(perspective)) node
         else
           node.update_perspective(perspective).update_commands(
-            consolidate_spans(resources, syntax, doc_blobs, reparse_limit,
+            consolidate_spans(resources, syntax, doc_blobs_default, reparse_limit,
               name, visible, node.commands))
     }
   }
@@ -454,6 +456,8 @@
             })
         val reparse_set = reparse.toSet
 
+        val doc_blobs_default = doc_blobs.default(previous.nodes)
+
         var nodes = nodes0
         val doc_edits = new mutable.ListBuffer[Document.Edit_Command]; doc_edits ++= doc_edits0
 
@@ -469,11 +473,11 @@
             val node1 =
               if (reparse_set(name) && !commands.isEmpty)
                 node.update_commands(
-                  reparse_spans(resources, syntax, doc_blobs,
+                  reparse_spans(resources, syntax, doc_blobs_default,
                     name, commands, commands.head, commands.last))
               else node
             val node2 =
-              (node1 /: edits)(text_edit(resources, syntax, doc_blobs, reparse_limit, _, _))
+              (node1 /: edits)(text_edit(resources, syntax, doc_blobs_default, reparse_limit, _, _))
 
             if (!(node.same_perspective(node2.perspective)))
               doc_edits += (name -> node2.perspective)