src/Tools/jEdit/src/proofdocument/ProofDocument.scala
author wenzelm
Mon, 02 Mar 2009 19:17:20 +0100
changeset 34533 35308320713a
parent 34505 87f4f70d61bb
child 34534 b06946a1d4cb
permissions -rw-r--r--
preliminary/failed attempt to use the new IsarDocument access model to the prover; misc tuning;
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
34483
0923926022d7 superficial tuning;
wenzelm
parents: 34482
diff changeset
    10
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}
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    13
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(
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    16
  val before_change: Command,
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
{
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
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
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    46
      text_changed(0, text.length, 0)
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
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    50
  text.changes += (changed => text_changed(changed.start, changed.added, changed.removed))
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    51
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    52
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    53
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    54
  /** token view **/
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    55
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    56
  private var first_token: Token = null
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    57
  private var last_token: Token = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    58
  
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    59
  private def tokens(start: Token, stop: Token) = new Iterator[Token] {
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    60
      var current = start
34483
0923926022d7 superficial tuning;
wenzelm
parents: 34482
diff changeset
    61
      def hasNext = current != stop && current != null
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    62
      def next() = { val save = current; current = current.next; save }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    63
    }
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    64
  private def tokens(start: Token): Iterator[Token] = tokens(start, null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    65
  private def tokens(): Iterator[Token] = tokens(first_token, null)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    66
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    67
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    68
  private def text_changed(start: Int, added_len: Int, removed_len: Int)
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    69
  {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    70
    if (!active)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    71
      return
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
    72
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    73
    var before_change =
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    74
      if (Token.check_stop(first_token, _ < start)) Token.scan(first_token, _.stop >= start)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    75
      else null
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    76
    
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    77
    var first_removed =
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    78
      if (before_change != null) before_change.next
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    79
      else if (Token.check_start(first_token, _ <= start + removed_len)) first_token
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    80
      else null 
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    81
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    82
    var last_removed = Token.scan(first_removed, _.start > start + removed_len)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    83
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    84
    var shift_token =
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    85
      if (last_removed != null) last_removed
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    86
      else if (Token.check_start(first_token, _ > start)) first_token
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    87
      else null
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    88
    
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    89
    while (shift_token != null) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    90
      shift_token.shift(added_len - removed_len, start)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    91
      shift_token = shift_token.next
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    92
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    93
    
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    94
    // scan changed tokens until the end of the text or a matching token is
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    95
    // found which is beyond the changed area
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    96
    val match_start = if (before_change == null) 0 else before_change.stop
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    97
    var first_added: Token = null
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
    98
    var last_added: Token = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    99
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   100
    val matcher = ProofDocument.token_pattern.matcher(text.content(match_start, text.length))
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   101
    var finished = false
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   102
    var position = 0 
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   103
    while (matcher.find(position) && !finished) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   104
      position = matcher.end
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   105
			val kind =
34505
87f4f70d61bb ProofDocument: pass is_command_keyword directly, not via full-blown Prover object;
wenzelm
parents: 34496
diff changeset
   106
        if (is_command_keyword(matcher.group))
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   107
          Token.Kind.COMMAND_START
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   108
        else if (matcher.end - matcher.start > 2 && matcher.group.substring(0, 2) == "(*")
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   109
          Token.Kind.COMMENT
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   110
        else
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   111
          Token.Kind.OTHER
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   112
      val new_token = new Token(matcher.start + match_start, matcher.end + match_start, kind)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   113
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   114
      if (first_added == null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   115
        first_added = new_token
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   116
      else {
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   117
        new_token.prev = last_added
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   118
        last_added.next = new_token
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   119
      }
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   120
      last_added = new_token
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   121
      
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   122
      while (Token.check_stop(last_removed, _ < new_token.stop) &&
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   123
              last_removed.next != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   124
        last_removed = last_removed.next
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   125
			
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   126
      if (new_token.stop >= start + added_len &&
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   127
            Token.check_stop(last_removed, _ == new_token.stop))
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   128
        finished = true
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   129
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   130
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   131
    var after_change = if (last_removed != null) last_removed.next else null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   132
		
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   133
    // remove superflous first token-change
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   134
    if (first_added != null && first_added == first_removed &&
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   135
          first_added.stop < start) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   136
      before_change = first_removed
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   137
      if (last_removed == first_removed) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   138
        last_removed = null
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   139
        first_removed = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   140
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   141
      else {
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   142
        first_removed = first_removed.next
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   143
        assert(first_removed != null)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   144
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   145
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   146
      if (last_added == first_added) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   147
        last_added = null
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   148
        first_added = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   149
      }
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   150
      if (first_added != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   151
        first_added = first_added.next
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   152
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   153
    
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   154
    // remove superflous last token-change
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   155
    if (last_added != null && last_added == last_removed &&
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   156
          last_added.start > start + added_len) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   157
      after_change = last_removed
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   158
      if (first_removed == last_removed) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   159
        first_removed = null
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   160
        last_removed = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   161
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   162
      else {
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   163
        last_removed = last_removed.prev
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   164
        assert(last_removed != null)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   165
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   166
      
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   167
      if (last_added == first_added) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   168
        last_added = null
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   169
        first_added = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   170
      }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   171
      else
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   172
        last_added = last_added.prev
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   173
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   174
    
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   175
    if (first_removed == null && first_added == null)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   176
      return
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   177
    
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   178
    if (first_token == null) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   179
      first_token = first_added
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   180
      last_token = last_added
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   181
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   182
    else {
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   183
      // cut removed tokens out of list
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   184
      if (first_removed != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   185
        first_removed.prev = null
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   186
      if (last_removed != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   187
        last_removed.next = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   188
      
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   189
      if (first_token == first_removed)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   190
        if (first_added != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   191
          first_token = first_added
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   192
        else
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   193
          first_token = after_change
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   194
      
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   195
      if (last_token == last_removed)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   196
        if (last_added != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   197
          last_token = last_added
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   198
        else
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   199
          last_token = before_change
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   200
      
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   201
      // insert new tokens into list
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   202
      if (first_added != null) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   203
        first_added.prev = before_change
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   204
        if (before_change != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   205
          before_change.next = first_added
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   206
        else
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   207
          first_token = first_added
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   208
      }
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   209
      else if (before_change != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   210
        before_change.next = after_change
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   211
      
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   212
      if (last_added != null) {
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   213
        last_added.next = after_change
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   214
        if (after_change != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   215
          after_change.prev = last_added
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   216
        else
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   217
          last_token = last_added
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   218
      }
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   219
      else if (after_change != null)
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   220
        after_change.prev = before_change
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   221
    }
34533
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34505
diff changeset
   222
35308320713a preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents: 34505
diff changeset
   223
    System.err.println("token_changed: " + before_change + " " + after_change + " " + first_removed)
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   224
    token_changed(before_change, after_change, first_removed)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   225
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   226
  
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   227
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   228
  
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   229
  /** command view **/
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   230
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   231
  val structural_changes = new EventBus[StructureChange]
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   232
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   233
  def commands = new Iterator[Command] {
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   234
    var current = first_token
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   235
    def hasNext = current != null
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   236
    def next() = { val s = current.command ; current = s.last.next ; s }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   237
  }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   238
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   239
  def find_command_at(pos: Int): Command = {
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   240
    for (cmd <- commands) { if (pos < cmd.stop) return cmd }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   241
    return null
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   242
  }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   243
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   244
  private def token_changed(start: Token, stop: Token, removed: Token)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   245
  {
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   246
    var removed_commands: List[Command] = Nil
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   247
    var first: Command = null
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   248
    var last: Command = null
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   249
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   250
    for (t <- tokens(removed)) {
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   251
      if (first == null)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   252
        first = t.command
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   253
      if (t.command != last)
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   254
        removed_commands = t.command :: removed_commands
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   255
      last = t.command
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   256
    }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   257
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   258
    var before: Command = null
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   259
    if (!removed_commands.isEmpty) {
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   260
      if (first.first == removed) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   261
        if (start == null)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   262
          before = null
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   263
        else
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   264
          before = start.command
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   265
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   266
      else
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   267
        before = first.prev
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   268
    }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   269
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   270
    var added_commands: List[Command] = Nil
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   271
    var scan: Token = null
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   272
    if (start != null) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   273
      val next = start.next
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   274
      if (first != null && first.first != removed) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   275
        scan = first.first
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   276
        if (before == null)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   277
          before = first.prev
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   278
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   279
      else if (next != null && next != stop) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   280
        if (next.kind == Token.Kind.COMMAND_START) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   281
          before = start.command
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   282
          scan = next
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   283
        }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   284
        else if (first == null || first.first == removed) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   285
          first = start.command
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   286
          removed_commands = first :: removed_commands
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   287
          scan = first.first
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   288
          if (before == null)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   289
            before = first.prev
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   290
        }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   291
        else {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   292
          scan = first.first
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   293
          if (before == null)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   294
            before = first.prev
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   295
        }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   296
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   297
    }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   298
    else
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   299
      scan = first_token
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   300
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   301
    var stop_scan: Token = null
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   302
    if (stop != null) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   303
      if (stop == stop.command.first)
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   304
        stop_scan = stop
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   305
      else
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   306
        stop_scan = stop.command.last.next
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   307
    }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   308
    else if (last != null)
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   309
      stop_scan = last.last.next
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   310
    else
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   311
      stop_scan = null
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   312
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   313
    var cmd_start: Token = null
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   314
    var cmd_stop: Token = null
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   315
    var overrun = false
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   316
    var finished = false
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   317
    while (scan != null && !finished) {
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   318
      if (scan == stop_scan) {
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   319
        if (scan.kind == Token.Kind.COMMAND_START)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   320
          finished = true
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   321
        else
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   322
          overrun = true
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   323
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   324
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   325
      if (scan.kind == Token.Kind.COMMAND_START && cmd_start != null && !finished) {
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   326
        if (!overrun) {
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   327
          added_commands = new Command(text, cmd_start, cmd_stop) :: added_commands
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   328
          cmd_start = scan
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   329
          cmd_stop = scan
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   330
        }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   331
        else
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   332
          finished = true
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   333
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   334
      else if (!finished) {
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   335
        if (cmd_start == null)
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   336
          cmd_start = scan
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   337
        cmd_stop = scan
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   338
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   339
      if (overrun && !finished) {
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   340
        if (scan.command != last)
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   341
          removed_commands = scan.command :: removed_commands
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   342
        last = scan.command
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   343
      }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   344
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   345
      if (!finished)
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   346
        scan = scan.next
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   347
    }
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   348
34496
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   349
    if (cmd_start != null)
1b2995592bb9 renamed getNextCommandContaining to find_command_at;
wenzelm
parents: 34494
diff changeset
   350
      added_commands = new Command(text, cmd_start, cmd_stop) :: added_commands
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   351
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   352
    // relink commands
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   353
    added_commands = added_commands.reverse
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   354
    removed_commands = removed_commands.reverse
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   355
34494
47f9303db81d misc tuning -- de-camelization;
wenzelm
parents: 34491
diff changeset
   356
    structural_changes.event(new StructureChange(before, added_commands, removed_commands))
34485
6475bfb4ff99 joined Document with ProofDocument;
wenzelm
parents: 34483
diff changeset
   357
  }
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   358
}