author | wenzelm |
Mon, 02 Mar 2009 19:17:20 +0100 | |
changeset 34533 | 35308320713a |
parent 34505 | 87f4f70d61bb |
child 34534 | b06946a1d4cb |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
34485 | 2 |
* Document as list of commands, consisting of lists of tokens |
34407 | 3 |
* |
4 |
* @author Johannes Hölzl, TU Munich |
|
34485 | 5 |
* @author Makarius |
34407 | 6 |
*/ |
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 | 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 | 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 | 15 |
case class StructureChange( |
16 |
val before_change: Command, |
|
17 |
val added_commands: List[Command], |
|
18 |
val removed_commands: List[Command]) |
|
34485 | 19 |
|
34483 | 20 |
object ProofDocument |
21 |
{ |
|
34485 | 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 | 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 | 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 | 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 | 43 |
def activate() { |
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 | 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 | 48 |
} |
34485 | 49 |
|
50 |
text.changes += (changed => text_changed(changed.start, changed.added, changed.removed)) |
|
51 |
||
52 |
||
53 |
||
54 |
/** token view **/ |
|
55 |
||
34494 | 56 |
private var first_token: Token = null |
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 | 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 | 61 |
def hasNext = current != stop && current != null |
34494 | 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 | 64 |
private def tokens(start: Token): Iterator[Token] = tokens(start, null) |
65 |
private def tokens(): Iterator[Token] = tokens(first_token, null) |
|
34485 | 66 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
67 |
|
34494 | 68 |
private def text_changed(start: Int, added_len: Int, removed_len: Int) |
34485 | 69 |
{ |
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 | 72 |
|
34494 | 73 |
var before_change = |
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 | 77 |
var first_removed = |
78 |
if (before_change != null) before_change.next |
|
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 | 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 | 84 |
var shift_token = |
85 |
if (last_removed != null) last_removed |
|
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 | 89 |
while (shift_token != null) { |
90 |
shift_token.shift(added_len - removed_len, start) |
|
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 | 96 |
val match_start = if (before_change == null) 0 else before_change.stop |
97 |
var first_added: Token = null |
|
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 | 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 | 103 |
while (matcher.find(position) && !finished) { |
104 |
position = matcher.end |
|
34485 | 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 | 107 |
Token.Kind.COMMAND_START |
34494 | 108 |
else if (matcher.end - matcher.start > 2 && matcher.group.substring(0, 2) == "(*") |
34485 | 109 |
Token.Kind.COMMENT |
110 |
else |
|
111 |
Token.Kind.OTHER |
|
34494 | 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 | 114 |
if (first_added == null) |
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 | 117 |
new_token.prev = last_added |
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 | 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 | 122 |
while (Token.check_stop(last_removed, _ < new_token.stop) && |
123 |
last_removed.next != null) |
|
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 | 126 |
if (new_token.stop >= start + added_len && |
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 | 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 | 134 |
if (first_added != null && first_added == first_removed && |
135 |
first_added.stop < start) { |
|
136 |
before_change = first_removed |
|
137 |
if (last_removed == first_removed) { |
|
138 |
last_removed = null |
|
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 | 142 |
first_removed = first_removed.next |
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 | 146 |
if (last_added == first_added) { |
147 |
last_added = null |
|
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 | 150 |
if (first_added != null) |
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 | 155 |
if (last_added != null && last_added == last_removed && |
156 |
last_added.start > start + added_len) { |
|
157 |
after_change = last_removed |
|
158 |
if (first_removed == last_removed) { |
|
159 |
first_removed = null |
|
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 | 163 |
last_removed = last_removed.prev |
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 | 167 |
if (last_added == first_added) { |
168 |
last_added = null |
|
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 | 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 | 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 | 178 |
if (first_token == null) { |
179 |
first_token = first_added |
|
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 | 184 |
if (first_removed != null) |
185 |
first_removed.prev = null |
|
186 |
if (last_removed != null) |
|
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 | 189 |
if (first_token == first_removed) |
190 |
if (first_added != null) |
|
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 | 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 | 195 |
if (last_token == last_removed) |
196 |
if (last_added != null) |
|
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 | 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 | 202 |
if (first_added != null) { |
203 |
first_added.prev = before_change |
|
204 |
if (before_change != null) |
|
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 | 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 | 209 |
else if (before_change != null) |
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 | 212 |
if (last_added != null) { |
213 |
last_added.next = after_change |
|
214 |
if (after_change != null) |
|
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 | 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 | 219 |
else if (after_change != null) |
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 | 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 | 227 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
228 |
|
34485 | 229 |
/** command view **/ |
230 |
||
231 |
val structural_changes = new EventBus[StructureChange] |
|
232 |
||
233 |
def commands = new Iterator[Command] { |
|
34494 | 234 |
var current = first_token |
34485 | 235 |
def hasNext = current != null |
236 |
def next() = { val s = current.command ; current = s.last.next ; s } |
|
237 |
} |
|
238 |
||
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
239 |
def find_command_at(pos: Int): Command = { |
34485 | 240 |
for (cmd <- commands) { if (pos < cmd.stop) return cmd } |
241 |
return null |
|
242 |
} |
|
243 |
||
244 |
private def token_changed(start: Token, stop: Token, removed: Token) |
|
245 |
{ |
|
34494 | 246 |
var removed_commands: List[Command] = Nil |
34485 | 247 |
var first: Command = null |
248 |
var last: Command = null |
|
249 |
||
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
250 |
for (t <- tokens(removed)) { |
34485 | 251 |
if (first == null) |
252 |
first = t.command |
|
253 |
if (t.command != last) |
|
34494 | 254 |
removed_commands = t.command :: removed_commands |
34485 | 255 |
last = t.command |
256 |
} |
|
257 |
||
258 |
var before: Command = null |
|
34494 | 259 |
if (!removed_commands.isEmpty) { |
34485 | 260 |
if (first.first == removed) { |
261 |
if (start == null) |
|
262 |
before = null |
|
263 |
else |
|
264 |
before = start.command |
|
265 |
} |
|
266 |
else |
|
267 |
before = first.prev |
|
268 |
} |
|
269 |
||
34494 | 270 |
var added_commands: List[Command] = Nil |
34485 | 271 |
var scan: Token = null |
272 |
if (start != null) { |
|
273 |
val next = start.next |
|
274 |
if (first != null && first.first != removed) { |
|
275 |
scan = first.first |
|
276 |
if (before == null) |
|
277 |
before = first.prev |
|
278 |
} |
|
279 |
else if (next != null && next != stop) { |
|
280 |
if (next.kind == Token.Kind.COMMAND_START) { |
|
281 |
before = start.command |
|
282 |
scan = next |
|
283 |
} |
|
284 |
else if (first == null || first.first == removed) { |
|
285 |
first = start.command |
|
34494 | 286 |
removed_commands = first :: removed_commands |
34485 | 287 |
scan = first.first |
288 |
if (before == null) |
|
289 |
before = first.prev |
|
290 |
} |
|
291 |
else { |
|
292 |
scan = first.first |
|
293 |
if (before == null) |
|
294 |
before = first.prev |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
else |
|
34494 | 299 |
scan = first_token |
34485 | 300 |
|
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
301 |
var stop_scan: Token = null |
34485 | 302 |
if (stop != null) { |
303 |
if (stop == stop.command.first) |
|
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
304 |
stop_scan = stop |
34485 | 305 |
else |
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
306 |
stop_scan = stop.command.last.next |
34485 | 307 |
} |
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 | 310 |
else |
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
311 |
stop_scan = null |
34485 | 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 | 315 |
var overrun = false |
316 |
var finished = false |
|
317 |
while (scan != null && !finished) { |
|
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
318 |
if (scan == stop_scan) { |
34485 | 319 |
if (scan.kind == Token.Kind.COMMAND_START) |
320 |
finished = true |
|
321 |
else |
|
322 |
overrun = true |
|
323 |
} |
|
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 | 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 | 330 |
} |
331 |
else |
|
332 |
finished = true |
|
333 |
} |
|
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 | 338 |
} |
339 |
if (overrun && !finished) { |
|
340 |
if (scan.command != last) |
|
34494 | 341 |
removed_commands = scan.command :: removed_commands |
34485 | 342 |
last = scan.command |
343 |
} |
|
344 |
||
345 |
if (!finished) |
|
346 |
scan = scan.next |
|
347 |
} |
|
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 | 351 |
|
352 |
// relink commands |
|
34494 | 353 |
added_commands = added_commands.reverse |
354 |
removed_commands = removed_commands.reverse |
|
34485 | 355 |
|
34494 | 356 |
structural_changes.event(new StructureChange(before, added_commands, removed_commands)) |
34485 | 357 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
358 |
} |