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