src/Tools/jEdit/src/proofdocument/ProofDocument.scala
author immler@in.tum.de
Sun, 08 Mar 2009 23:03:49 +0100
changeset 34532 aaafe9c4180b
parent 34531 db1c28e326fc
child 34538 20bfcca24658
permissions -rw-r--r--
ProofDocument without state handle text-events via actor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     1
/*
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
     2
 * Document as list of commands, consisting of lists of tokens
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     3
 *
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     4
 * @author Johannes Hölzl, TU Munich
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
     5
 * @author Fabian Immler, TU Munich
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
     6
 * @author Makarius
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     7
 */
aad6834ba380 added some headers and comments;
wenzelm
parents: 34390
diff changeset
     8
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
     9
package isabelle.proofdocument
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    10
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    11
import scala.collection.mutable.ListBuffer
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    12
import scala.actors.Actor
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    13
import scala.actors.Actor._
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    14
import java.util.regex.Pattern
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    15
import isabelle.prover.{Prover, Command}
34531
db1c28e326fc *very* superficial usage of LinearSet
immler@in.tum.de
parents: 34526
diff changeset
    16
import isabelle.utils.LinearSet
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    17
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    18
case class StructureChange(
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    19
  val before_change: Option[Command],
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    20
  val added_commands: List[Command],
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    21
  val removed_commands: List[Command])
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    22
34483
0923926022d7 superficial tuning;
wenzelm
parents: 34482
diff changeset
    23
object ProofDocument
0923926022d7 superficial tuning;
wenzelm
parents: 34482
diff changeset
    24
{
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    25
  // Be carefully when changing this regex. Not only must it handle the 
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    26
  // spurious end of a token but also:  
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    27
  // Bug ID: 5050507 Pattern.matches throws StackOverflow Error
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    28
  // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    29
  
34483
0923926022d7 superficial tuning;
wenzelm
parents: 34482
diff changeset
    30
  val token_pattern = 
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    31
    Pattern.compile(
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    32
      "\\{\\*([^*]|\\*[^}]|\\*\\z)*(\\z|\\*\\})|" +
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    33
      "\\(\\*([^*]|\\*[^)]|\\*\\z)*(\\z|\\*\\))|" +
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    34
      "(\\?'?|')[A-Za-z_0-9.]*|" + 
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    35
      "[A-Za-z_0-9.]+|" + 
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    36
      "[!#$%&*+-/<=>?@^_|~]+|" +
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    37
      "\"([^\\\\\"]?(\\\\(.|\\z))?)*+(\"|\\z)|" +
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    38
      "`([^\\\\`]?(\\\\(.|\\z))?)*+(`|\\z)|" +
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    39
      "[()\\[\\]{}:;]", Pattern.MULTILINE)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    40
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    41
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    42
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    43
class ProofDocument(val tokens: LinearSet[Token],
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    44
                    val commands: LinearSet[Command],
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    45
                    val active: Boolean,
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    46
                    is_command_keyword: String => Boolean,
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    47
                    structural_changes: EventBus[StructureChange])
34483
0923926022d7 superficial tuning;
wenzelm
parents: 34482
diff changeset
    48
{
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    49
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    50
  def mark_active: ProofDocument = new ProofDocument(tokens, commands, true, is_command_keyword, structural_changes)
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    51
  def activate: ProofDocument = text_changed(new Text.Change(0, content, content.length)).mark_active
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    52
  def set_command_keyword(f: String => Boolean): ProofDocument =
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    53
    new ProofDocument(tokens, commands, active, f, structural_changes)
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    54
  def set_event_bus(bus: EventBus[StructureChange]): ProofDocument =
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    55
    new ProofDocument(tokens, commands, active, is_command_keyword, bus)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    56
34531
db1c28e326fc *very* superficial usage of LinearSet
immler@in.tum.de
parents: 34526
diff changeset
    57
  def content = Token.string_from_tokens(List() ++ tokens)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    58
  /** token view **/
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    59
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
    60
  def text_changed(change: Text.Change): ProofDocument = 
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    61
  {
34531
db1c28e326fc *very* superficial usage of LinearSet
immler@in.tum.de
parents: 34526
diff changeset
    62
    val tokens = List() ++ this.tokens
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    63
    val (begin, remaining) = tokens.span(_.stop < change.start)
34531
db1c28e326fc *very* superficial usage of LinearSet
immler@in.tum.de
parents: 34526
diff changeset
    64
    val (removed, end_unshifted) = remaining.span(_.start <= change.start + change.removed)
db1c28e326fc *very* superficial usage of LinearSet
immler@in.tum.de
parents: 34526
diff changeset
    65
    val end = for (t <- end_unshifted) yield t.shift(change.added.length - change.removed)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    66
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    67
    val split_begin = removed.takeWhile(_.start < change.start).
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    68
      map (t => new Token(t.start,
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    69
                          t.content.substring(0, change.start - t.start),
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    70
                          t.kind))
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    71
    val split_end = removed.dropWhile(_.stop < change.start + change.removed).
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    72
      map (t => new Token(change.start + change.added.length,
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    73
                          t.content.substring(change.start + change.removed - t.start),
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    74
                          t.kind))
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    75
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    76
    var invalid_tokens =  split_begin :::
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    77
      new Token(change.start, change.added, Token.Kind.OTHER) :: split_end ::: end
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    78
    var new_tokens = Nil: List[Token]
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    79
    var old_suffix = Nil: List[Token]
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    80
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    81
    val match_start = invalid_tokens.first.start
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    82
    val matcher = ProofDocument.token_pattern.matcher(Token.string_from_tokens(invalid_tokens))
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    83
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    84
    while (matcher.find() && invalid_tokens != Nil) {
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    85
			val kind =
34505
87f4f70d61bb ProofDocument: pass is_command_keyword directly, not via full-blown Prover object;
wenzelm
parents: 34496
diff changeset
    86
        if (is_command_keyword(matcher.group))
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    87
          Token.Kind.COMMAND_START
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    88
        else if (matcher.end - matcher.start > 2 && matcher.group.substring(0, 2) == "(*")
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    89
          Token.Kind.COMMENT
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    90
        else
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    91
          Token.Kind.OTHER
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    92
      val new_token = new Token(match_start + matcher.start, matcher.group, kind)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    93
      new_tokens ::= new_token
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    94
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    95
      invalid_tokens = invalid_tokens dropWhile (_.stop < new_token.stop)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    96
      invalid_tokens match {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    97
        case t::ts => if(t.start == new_token.start &&
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    98
                         t.start > change.start + change.added.length) {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
    99
          old_suffix = ts
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   100
          invalid_tokens = Nil
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   101
        }
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   102
        case _ =>
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   103
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   104
    }
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   105
    val insert = new_tokens.reverse
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
   106
    val new_tokenset = (new LinearSet() ++ (begin ::: insert ::: old_suffix)).asInstanceOf[LinearSet[Token]]
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   107
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   108
    token_changed(begin.lastOption,
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   109
                  insert,
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   110
                  removed,
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
   111
                  new_tokenset,
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   112
                  old_suffix.firstOption)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   113
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   114
  
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   115
  /** command view **/
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   116
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   117
  def find_command_at(pos: Int): Command = {
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   118
    for (cmd <- commands) { if (pos < cmd.stop) return cmd }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   119
    return null
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   120
  }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   121
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   122
  private def token_changed(before_change: Option[Token],
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   123
                            inserted_tokens: List[Token],
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   124
                            removed_tokens: List[Token],
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
   125
                            new_tokenset: LinearSet[Token],
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
   126
                            after_change: Option[Token]): ProofDocument =
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   127
  {
34531
db1c28e326fc *very* superficial usage of LinearSet
immler@in.tum.de
parents: 34526
diff changeset
   128
    val commands = List() ++ this.commands
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   129
    val (begin, remaining) =
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   130
      before_change match {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   131
        case None => (Nil, commands)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   132
        case Some(bc) => commands.break(_.tokens.contains(bc))
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   133
      }
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   134
    val (_removed, _end) =
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   135
      after_change match {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   136
        case None => (remaining, Nil)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   137
        case Some(ac) => remaining.break(_.tokens.contains(ac))
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   138
      }
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   139
    val (removed, end) = _end match {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   140
      case Nil => (_removed, Nil)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   141
      case acc::end => if (after_change.isDefined && after_change.get.kind == Token.Kind.COMMAND_START)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   142
          (_removed, _end)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   143
        else (_removed ::: List(acc), end)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   144
    }
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   145
    val all_removed_tokens = for(c <- removed; t <- c.tokens) yield t
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   146
    val (pseudo_new_pre, rest) =
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   147
      if (! before_change.isDefined) (Nil, all_removed_tokens)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   148
      else {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   149
        val (a, b) = all_removed_tokens.span (_ != before_change.get)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   150
        b match {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   151
          case Nil => (a, Nil)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   152
          case bc::rest => (a ::: List(bc), b)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   153
        }
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   154
      }
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   155
    val pseudo_new_post = rest.dropWhile(Some(_) != after_change)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   156
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   157
    def tokens_to_commands(tokens: List[Token]): List[Command]= {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   158
      tokens match {
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   159
        case Nil => Nil
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   160
        case t::ts =>
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   161
          val (cmd,rest) = ts.span(_.kind != Token.Kind.COMMAND_START)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   162
          new Command(t::cmd) :: tokens_to_commands (rest)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   163
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   164
    }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   165
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   166
    System.err.println("ins_tokens: " + inserted_tokens)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   167
    val new_commands = tokens_to_commands(pseudo_new_pre ::: inserted_tokens ::: pseudo_new_post)
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   168
    System.err.println("new_commands: " + new_commands)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   169
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
   170
    val new_commandset = (LinearSet() ++ (begin ::: new_commands ::: end)).asInstanceOf[LinearSet[Command]]
34526
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   171
    val before = begin match {case Nil => None case _ => Some (begin.last)}
b504abb6eff6 tokens and commands as lists
immler@in.tum.de
parents: 34516
diff changeset
   172
    structural_changes.event(new StructureChange(before, new_commands, removed))
34532
aaafe9c4180b ProofDocument without state
immler@in.tum.de
parents: 34531
diff changeset
   173
    new ProofDocument(new_tokenset, new_commandset, active, is_command_keyword, structural_changes)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   174
  }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   175
}