src/Pure/Thy/thy_syntax.scala
author wenzelm
Tue, 19 Nov 2013 12:57:56 +0100
changeset 54515 570ba266f5b5
parent 54513 5545aff878b1
child 54517 044bee8c5e69
permissions -rw-r--r--
clarified boundary cases of Document.Node.Name;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34268
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Thy/thy_syntax.scala
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     3
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
     4
Superficial theory syntax: tokens and spans.
34268
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     5
*/
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     6
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     7
package isabelle
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     8
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
     9
38239
89a4d1028fb3 parse_spans: somewhat faster low-level implementation;
wenzelm
parents: 36956
diff changeset
    10
import scala.collection.mutable
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
    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
98425e77cfeb plain object;
wenzelm
parents: 34268
diff changeset
    14
object Thy_Syntax
34268
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
    15
{
40454
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    16
  /** nested structure **/
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    17
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    18
  object Structure
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    19
  {
40478
4bae781b8f7c replaced Document.Node_Text_Edit by Document.Text_Edit, with treatment of deleted nodes;
wenzelm
parents: 40457
diff changeset
    20
    sealed abstract class Entry { def length: Int }
40454
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    21
    case class Block(val name: String, val body: List[Entry]) extends Entry
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    22
    {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    23
      val length: Int = (0 /: body)(_ + _.length)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    24
    }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    25
    case class Atom(val command: Command) extends Entry
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    26
    {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    27
      def length: Int = command.length
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    28
    }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    29
46811
03a2dc9e0624 clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents: 46749
diff changeset
    30
    def parse(syntax: Outer_Syntax, node_name: Document.Node.Name, text: CharSequence): Entry =
40454
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    31
    {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    32
      /* stack operations */
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    33
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    34
      def buffer(): mutable.ListBuffer[Entry] = new mutable.ListBuffer[Entry]
44615
a4ff8a787202 more abstract Document.Node.Name;
wenzelm
parents: 44607
diff changeset
    35
      var stack: List[(Int, String, mutable.ListBuffer[Entry])] =
54515
570ba266f5b5 clarified boundary cases of Document.Node.Name;
wenzelm
parents: 54513
diff changeset
    36
        List((0, node_name.toString, buffer()))
40454
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    37
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    38
      @tailrec def close(level: Int => Boolean)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    39
      {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    40
        stack match {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    41
          case (lev, name, body) :: (_, _, body2) :: rest if level(lev) =>
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    42
            body2 += Block(name, body.toList)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    43
            stack = stack.tail
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    44
            close(level)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    45
          case _ =>
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    46
        }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    47
      }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    48
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    49
      def result(): Entry =
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    50
      {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    51
        close(_ => true)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    52
        val (_, name, body) = stack.head
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    53
        Block(name, body.toList)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    54
      }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    55
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    56
      def add(command: Command)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    57
      {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    58
        syntax.heading_level(command) match {
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    59
          case Some(i) =>
46969
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46946
diff changeset
    60
            close(_ > i)
481b7d9ad6fe more abstract heading level;
wenzelm
parents: 46946
diff changeset
    61
            stack = (i + 1, command.source, buffer()) :: stack
40454
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    62
          case None =>
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    63
        }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    64
        stack.head._3 += Atom(command)
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    65
      }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    66
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    67
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    68
      /* result structure */
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    69
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    70
      val spans = parse_spans(syntax.scan(text))
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
    71
      spans.foreach(span => add(Command(Document_ID.none, node_name, span, Nil)))
40454
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    72
      result()
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    73
    }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    74
  }
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    75
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    76
2516ea25a54b some support for nested source structure, based on section headings;
wenzelm
parents: 38878
diff changeset
    77
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
    78
  /** parse spans **/
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
    79
52535
b7badd371e4d tuned signature -- eliminated pointless type synonym;
wenzelm
parents: 52530
diff changeset
    80
  def parse_spans(toks: List[Token]): List[List[Token]] =
34268
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
    81
  {
52535
b7badd371e4d tuned signature -- eliminated pointless type synonym;
wenzelm
parents: 52530
diff changeset
    82
    val result = new mutable.ListBuffer[List[Token]]
38239
89a4d1028fb3 parse_spans: somewhat faster low-level implementation;
wenzelm
parents: 36956
diff changeset
    83
    val span = new mutable.ListBuffer[Token]
53843
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    84
    val improper = new mutable.ListBuffer[Token]
34268
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
    85
53843
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    86
    def flush()
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    87
    {
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    88
      if (!span.isEmpty) { result += span.toList; span.clear }
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    89
      if (!improper.isEmpty) { result += improper.toList; improper.clear }
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    90
    }
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    91
    for (tok <- toks) {
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    92
      if (tok.is_command) { flush(); span += tok }
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    93
      else if (tok.is_improper) improper += tok
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    94
      else { span ++= improper; improper.clear; span += tok }
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    95
    }
46811
03a2dc9e0624 clarified command span: include trailing whitespace/comments and thus reduce number of ignored spans with associated transactions and states (factor 2);
wenzelm
parents: 46749
diff changeset
    96
    flush()
53843
88c6e630c15f clarified command spans (again, see also 03a2dc9e0624): restrict to proper range to allow Isabelle.command_edit adding material monotonically without destroying the command (e.g. relevant for sendback from sledgehammer);
wenzelm
parents: 52901
diff changeset
    97
38239
89a4d1028fb3 parse_spans: somewhat faster low-level implementation;
wenzelm
parents: 36956
diff changeset
    98
    result.toList
34268
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
    99
  }
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   100
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   101
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   102
44436
546adfa8a6fc update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents: 44388
diff changeset
   103
  /** perspective **/
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   104
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   105
  def command_perspective(
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   106
      node: Document.Node,
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   107
      perspective: Text.Perspective,
52887
98eac7b7eec3 tuned signature;
wenzelm
parents: 52861
diff changeset
   108
      overlays: Document.Node.Overlays): (Command.Perspective, Command.Perspective) =
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   109
  {
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   110
    if (perspective.is_empty && overlays.is_empty)
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   111
      (Command.Perspective.empty, Command.Perspective.empty)
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   112
    else {
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   113
      val has_overlay = overlays.commands
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   114
      val visible = new mutable.ListBuffer[Command]
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   115
      val visible_overlay = new mutable.ListBuffer[Command]
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   116
      @tailrec
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   117
      def check_ranges(ranges: List[Text.Range], commands: Stream[(Command, Text.Offset)])
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   118
      {
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   119
        (ranges, commands) match {
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   120
          case (range :: more_ranges, (command, offset) #:: more_commands) =>
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   121
            val command_range = command.range + offset
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   122
            range compare command_range match {
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   123
              case 0 =>
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   124
                visible += command
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   125
                visible_overlay += command
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   126
                check_ranges(ranges, more_commands)
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   127
              case c =>
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   128
                if (has_overlay(command)) visible_overlay += command
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   129
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   130
                if (c < 0) check_ranges(more_ranges, commands)
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   131
                else check_ranges(ranges, more_commands)
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   132
            }
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   133
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   134
          case (Nil, (command, _) #:: more_commands) =>
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   135
            if (has_overlay(command)) visible_overlay += command
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   136
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   137
            check_ranges(Nil, more_commands)
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   138
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   139
          case _ =>
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   140
        }
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   141
      }
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   142
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   143
      val commands =
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   144
        if (overlays.is_empty) node.command_range(perspective.range)
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   145
        else node.command_range()
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   146
      check_ranges(perspective.ranges, commands.toStream)
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   147
      (Command.Perspective(visible.toList), Command.Perspective(visible_overlay.toList))
44388
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   148
    }
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   149
  }
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   150
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   151
5f9ad3583e0a tuned signature;
wenzelm
parents: 44385
diff changeset
   152
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   153
  /** header edits: structure and outer syntax **/
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   154
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   155
  private def header_edits(
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   156
    base_syntax: Outer_Syntax,
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   157
    previous: Document.Version,
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   158
    edits: List[Document.Edit_Text])
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   159
    : (Outer_Syntax, List[Document.Node.Name], Document.Nodes, List[Document.Edit_Command]) =
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   160
  {
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
   161
    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
   162
    var updated_keywords = false
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   163
    var nodes = previous.nodes
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   164
    val doc_edits = new mutable.ListBuffer[Document.Edit_Command]
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   165
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   166
    edits foreach {
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48706
diff changeset
   167
      case (name, Document.Node.Deps(header)) =>
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   168
        val node = nodes(name)
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   169
        val update_header =
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48706
diff changeset
   170
          !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
   171
        if (update_header) {
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   172
          val node1 = node.update_header(header)
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48706
diff changeset
   173
          updated_imports = updated_imports || (node.header.imports != node1.header.imports)
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48706
diff changeset
   174
          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
   175
          nodes += (name -> node1)
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48706
diff changeset
   176
          doc_edits += (name -> Document.Node.Deps(header))
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   177
        }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   178
      case _ =>
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   179
    }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   180
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   181
    val syntax =
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
   182
      if (previous.is_init || updated_keywords)
48873
18b17f15bc62 more direct cumulation of (sparse) keywords;
wenzelm
parents: 48755
diff changeset
   183
        (base_syntax /: nodes.entries) {
18b17f15bc62 more direct cumulation of (sparse) keywords;
wenzelm
parents: 48755
diff changeset
   184
          case (syn, (_, node)) => syn.add_keywords(node.header.keywords)
18b17f15bc62 more direct cumulation of (sparse) keywords;
wenzelm
parents: 48755
diff changeset
   185
        }
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   186
      else previous.syntax
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   187
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   188
    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
   189
      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
   190
        nodes.descendants(doc_edits.iterator.map(_._1).toList)
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   191
      else Nil
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   192
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   193
    (syntax, reparse, nodes, doc_edits.toList)
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   194
  }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   195
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   196
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   197
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   198
  /** text edits **/
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   199
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
   200
  /* edit individual command source */
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   201
50761
f6811984983b export some generally useful operations;
wenzelm
parents: 50501
diff changeset
   202
  @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
   203
  {
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   204
    eds match {
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   205
      case e :: es =>
52901
8be75f53db82 maintain commands together with index -- avoid redundant reconstruction of full_index;
wenzelm
parents: 52887
diff changeset
   206
        Document.Node.Commands.starts(commands.iterator).find {
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   207
          case (cmd, cmd_start) =>
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   208
            e.can_edit(cmd.source, cmd_start) ||
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   209
              e.is_insert && e.start == cmd_start + cmd.length
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   210
        } match {
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   211
          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
   212
            val (rest, text) = e.edit(cmd.source, cmd_start)
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   213
            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
   214
            edit_text(rest.toList ::: es, new_commands)
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   215
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   216
          case Some((cmd, cmd_start)) =>
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   217
            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
   218
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   219
          case None =>
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   220
            require(e.is_insert && e.start == 0)
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   221
            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
   222
        }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   223
      case Nil => commands
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   224
    }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   225
  }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   226
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   227
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   228
  /* inlined files */
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   229
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   230
  private def find_file(tokens: List[Token]): Option[String] =
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   231
  {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   232
    def clean(toks: List[Token]): List[Token] =
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   233
      toks match {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   234
        case t :: _ :: ts if t.is_keyword && (t.source == "%" || t.source == "--") => clean(ts)
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   235
        case t :: ts => t :: clean(ts)
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   236
        case Nil => Nil
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   237
      }
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   238
    val clean_tokens = clean(tokens.filter(_.is_proper))
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   239
    clean_tokens.reverse.find(_.is_name).map(_.content)
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   240
  }
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   241
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   242
  def span_files(syntax: Outer_Syntax, span: List[Token]): List[String] =
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   243
    syntax.thy_load(span) match {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   244
      case Some(exts) =>
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   245
        find_file(span) match {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   246
          case Some(file) =>
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   247
            if (exts.isEmpty) List(file)
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   248
            else exts.map(ext => file + "." + ext)
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   249
          case None => Nil
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   250
        }
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   251
      case None => Nil
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   252
    }
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   253
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   254
  def resolve_files(
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   255
      syntax: Outer_Syntax,
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   256
      all_blobs: Map[Document.Node.Name, Bytes],
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   257
      name: Document.Node.Name,
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   258
      span: List[Token]): Command.Blobs =
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   259
  {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   260
    val files = span_files(syntax, span)
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   261
    files.map(file => {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   262
      // FIXME proper thy_load append
54515
570ba266f5b5 clarified boundary cases of Document.Node.Name;
wenzelm
parents: 54513
diff changeset
   263
      val file_name = Document.Node.Name(name.master_dir + file)
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   264
      (file_name, all_blobs.get(file_name).map(_.sha1_digest))
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   265
    })
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   266
  }
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   267
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   268
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
   269
  /* reparse range of command spans */
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   270
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
   271
  @tailrec private def chop_common(
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   272
      cmds: List[Command], spans: List[(List[Token], Command.Blobs)])
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   273
      : (List[Command], List[(List[Token], Command.Blobs)]) =
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
   274
    (cmds, spans) match {
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   275
      case (c :: cs, (span, blobs) :: ps) if c.span == span && c.blobs == blobs =>
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   276
        chop_common(cs, ps)
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
   277
      case _ => (cmds, spans)
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
   278
    }
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
   279
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   280
  private def reparse_spans(
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   281
    syntax: Outer_Syntax,
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   282
    all_blobs: Map[Document.Node.Name, Bytes],
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   283
    name: Document.Node.Name,
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   284
    commands: Linear_Set[Command],
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   285
    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
   286
  {
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   287
    val cmds0 = commands.iterator(first, last).toList
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   288
    val spans0 =
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   289
      parse_spans(syntax.scan(cmds0.iterator.map(_.source).mkString)).
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   290
        map(span => (span, resolve_files(syntax, all_blobs, name, span)))
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   291
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   292
    val (cmds1, spans1) = chop_common(cmds0, spans0)
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   293
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
   294
    val (rev_cmds2, rev_spans2) = chop_common(cmds1.reverse, spans1.reverse)
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   295
    val cmds2 = rev_cmds2.reverse
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   296
    val spans2 = rev_spans2.reverse
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   297
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   298
    cmds2 match {
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   299
      case Nil =>
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   300
        assert(spans2.isEmpty)
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   301
        commands
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   302
      case cmd :: _ =>
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   303
        val hook = commands.prev(cmd)
54462
c9bb76303348 explicit indication of thy_load commands;
wenzelm
parents: 53843
diff changeset
   304
        val inserted =
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   305
          spans2.map({ case (span, blobs) => Command(Document_ID.make(), name, span, blobs) })
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   306
        (commands /: cmds2)(_ - _).append_after(hook, inserted)
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   307
    }
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
   308
  }
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
   309
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   310
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
   311
  /* recover command spans after edits */
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   312
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
   313
  // FIXME somewhat slow
48746
9e1b2aafbc7f more direct Linear_Set.reverse, swapping orientation of the graph;
wenzelm
parents: 48718
diff changeset
   314
  private def recover_spans(
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   315
    syntax: Outer_Syntax,
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   316
    all_blobs: Map[Document.Node.Name, Bytes],
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   317
    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
   318
    perspective: Command.Perspective,
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   319
    commands: Linear_Set[Command]): Linear_Set[Command] =
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   320
  {
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   321
    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
   322
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   323
    def next_invisible_command(cmds: Linear_Set[Command], from: Command): Command =
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   324
      cmds.iterator(from).dropWhile(cmd => !cmd.is_command || visible(cmd))
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   325
        .find(_.is_command) getOrElse cmds.last
48746
9e1b2aafbc7f more direct Linear_Set.reverse, swapping orientation of the graph;
wenzelm
parents: 48718
diff changeset
   326
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   327
    @tailrec def recover(cmds: Linear_Set[Command]): Linear_Set[Command] =
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   328
      cmds.find(_.is_unparsed) match {
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   329
        case Some(first_unparsed) =>
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   330
          val first = next_invisible_command(cmds.reverse, first_unparsed)
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   331
          val last = next_invisible_command(cmds, first_unparsed)
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   332
          recover(reparse_spans(syntax, all_blobs, name, cmds, first, last))
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   333
        case None => cmds
48746
9e1b2aafbc7f more direct Linear_Set.reverse, swapping orientation of the graph;
wenzelm
parents: 48718
diff changeset
   334
      }
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   335
    recover(commands)
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   336
  }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   337
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   338
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
   339
  /* consolidate unfinished spans */
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   340
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   341
  private def consolidate_spans(
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   342
    syntax: Outer_Syntax,
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   343
    all_blobs: Map[Document.Node.Name, Bytes],
49524
68796a77c42b Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
wenzelm
parents: 49414
diff changeset
   344
    reparse_limit: Int,
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   345
    name: Document.Node.Name,
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   346
    perspective: Command.Perspective,
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   347
    commands: Linear_Set[Command]): Linear_Set[Command] =
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   348
  {
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   349
    if (perspective.commands.isEmpty) commands
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   350
    else {
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   351
      commands.find(_.is_unfinished) match {
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   352
        case Some(first_unfinished) =>
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   353
          val visible = perspective.commands.toSet
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   354
          commands.reverse.find(visible) match {
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   355
            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
   356
              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
   357
              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
   358
              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
   359
              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
   360
                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
   361
                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
   362
              }
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   363
              reparse_spans(syntax, all_blobs, name, commands, first_unfinished, last)
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   364
            case None => commands
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   365
          }
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   366
        case None => commands
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   367
      }
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   368
    }
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   369
  }
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   370
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   371
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
   372
  /* main */
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   373
50761
f6811984983b export some generally useful operations;
wenzelm
parents: 50501
diff changeset
   374
  def diff_commands(old_cmds: Linear_Set[Command], new_cmds: Linear_Set[Command])
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   375
    : List[Command.Edit] =
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   376
  {
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   377
    val removed = old_cmds.iterator.filter(!new_cmds.contains(_)).toList
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   378
    val inserted = new_cmds.iterator.filter(!old_cmds.contains(_)).toList
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   379
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   380
    removed.reverse.map(cmd => (old_cmds.prev(cmd), None)) :::
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   381
    inserted.map(cmd => (new_cmds.prev(cmd), Some(cmd)))
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   382
  }
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   383
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   384
  private def text_edit(
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   385
    syntax: Outer_Syntax,
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   386
    all_blobs: Map[Document.Node.Name, Bytes],
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   387
    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
   388
    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
   389
  {
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
   390
    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
   391
      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
   392
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
   393
      case (name, Document.Node.Edits(text_edits)) =>
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
   394
        val commands0 = node.commands
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
   395
        val commands1 = edit_text(text_edits, commands0)
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   396
        val commands2 = recover_spans(syntax, all_blobs, name, node.perspective.visible, commands1)
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
   397
        node.update_commands(commands2)
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
   398
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
   399
      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
   400
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   401
      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
   402
        val (visible, visible_overlay) = command_perspective(node, text_perspective, overlays)
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   403
        val perspective: Document.Node.Perspective_Command =
52861
e93d73b51fd0 commands with overlay remain visible, to avoid loosing printed output;
wenzelm
parents: 52849
diff changeset
   404
          Document.Node.Perspective(required, visible_overlay, overlays)
52808
143f225e50f5 allow explicit indication of required node: full eval, no prints;
wenzelm
parents: 52535
diff changeset
   405
        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
   406
        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
   407
          node.update_perspective(perspective).update_commands(
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   408
            consolidate_spans(syntax, all_blobs, reparse_limit, name, visible, node.commands))
54509
1f77110c94ef maintain document model for all files, with document view for theory only, and special blob for non-theory files;
wenzelm
parents: 54462
diff changeset
   409
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   410
      case (_, Document.Node.Blob(_)) => 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
   411
    }
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
   412
  }
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
   413
43722
9b5dadb0c28d propagate header changes to prover process;
wenzelm
parents: 43715
diff changeset
   414
  def text_edits(
46942
f5c2d66faa04 basic support for outer syntax keywords in theory header;
wenzelm
parents: 46941
diff changeset
   415
      base_syntax: Outer_Syntax,
49524
68796a77c42b Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
wenzelm
parents: 49414
diff changeset
   416
      reparse_limit: Int,
43722
9b5dadb0c28d propagate header changes to prover process;
wenzelm
parents: 43715
diff changeset
   417
      previous: Document.Version,
44157
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
   418
      edits: List[Document.Edit_Text])
a21d3e1e64fd uniform treatment of header edits as document edits;
wenzelm
parents: 44156
diff changeset
   419
    : (List[Document.Edit_Command], Document.Version) =
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   420
  {
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   421
    val (syntax, reparse, nodes0, doc_edits0) = header_edits(base_syntax, previous, edits)
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   422
    val reparse_set = reparse.toSet
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   423
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   424
    var nodes = nodes0
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   425
    val doc_edits = new mutable.ListBuffer[Document.Edit_Command]; doc_edits ++= doc_edits0
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   426
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
   427
    val node_edits =
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
   428
      (edits ::: reparse.map((_, Document.Node.Edits(Nil)))).groupBy(_._1)
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
   429
        .asInstanceOf[Map[Document.Node.Name, List[Document.Edit_Text]]]  // FIXME ???
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   430
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   431
    val all_blobs: Map[Document.Node.Name, Bytes] =
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   432
      (Map.empty[Document.Node.Name, Bytes] /: node_edits) {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   433
        case (bs1, (_, es)) => (bs1 /: es) {
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   434
          case (bs, (name, Document.Node.Blob(blob))) => bs + (name -> blob)
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   435
          case (bs, _) => bs
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   436
        }
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   437
      }
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   438
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
   439
    node_edits foreach {
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
   440
      case (name, edits) =>
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
   441
        val node = nodes(name)
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
   442
        val commands = node.commands
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   443
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
   444
        val node1 =
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
   445
          if (reparse_set(name) && !commands.isEmpty)
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   446
            node.update_commands(
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   447
              reparse_spans(syntax, all_blobs, name, commands, commands.head, commands.last))
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
   448
          else node
54513
5545aff878b1 inline blobs into command, via SHA1 digest;
wenzelm
parents: 54509
diff changeset
   449
        val node2 = (node1 /: edits)(text_edit(syntax, all_blobs, reparse_limit, _, _))
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   450
52808
143f225e50f5 allow explicit indication of required node: full eval, no prints;
wenzelm
parents: 52535
diff changeset
   451
        if (!(node.same_perspective(node2.perspective)))
52849
199e9fa5a5c2 maintain overlays within node perspective;
wenzelm
parents: 52808
diff changeset
   452
          doc_edits += (name -> node2.perspective)
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
   453
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
   454
        doc_edits += (name -> Document.Node.Edits(diff_commands(commands, node2.commands)))
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
   455
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
   456
        nodes += (name -> node2)
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   457
    }
48754
c2c1e5944536 clarified undefined, unparsed, unfinished command spans;
wenzelm
parents: 48748
diff changeset
   458
46946
acc8ebf980ca more explicit header_edits before main text_edits;
wenzelm
parents: 46942
diff changeset
   459
    (doc_edits.toList, Document.Version.make(syntax, nodes))
38374
7eb0f6991e25 moved Document.text_edits to Thy_Syntax;
wenzelm
parents: 38373
diff changeset
   460
  }
34268
b149b7083236 separate module Thy_Syntax for command span parsing;
wenzelm
parents:
diff changeset
   461
}