author | immler@in.tum.de |
Wed, 27 May 2009 15:24:01 +0200 | |
changeset 34575 | 70d11544685f |
parent 34554 | 7dc6c231da40 |
child 34582 | 5d5d253c7c29 |
child 34592 | b17ebec3690c |
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 |
|
34532 | 5 |
* @author Fabian Immler, TU Munich |
34485 | 6 |
* @author Makarius |
34407 | 7 |
*/ |
8 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
package isabelle.proofdocument |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
10 |
|
34526 | 11 |
import scala.collection.mutable.ListBuffer |
34532 | 12 |
import scala.actors.Actor |
13 |
import scala.actors.Actor._ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
14 |
import java.util.regex.Pattern |
34485 | 15 |
import isabelle.prover.{Prover, Command} |
34531 | 16 |
import isabelle.utils.LinearSet |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
17 |
|
34494 | 18 |
case class StructureChange( |
34526 | 19 |
val before_change: Option[Command], |
34494 | 20 |
val added_commands: List[Command], |
21 |
val removed_commands: List[Command]) |
|
34485 | 22 |
|
34483 | 23 |
object ProofDocument |
24 |
{ |
|
34485 | 25 |
// Be carefully when changing this regex. Not only must it handle the |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
26 |
// spurious end of a token but also: |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
27 |
// Bug ID: 5050507 Pattern.matches throws StackOverflow Error |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
28 |
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507 |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
29 |
|
34483 | 30 |
val token_pattern = |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
31 |
Pattern.compile( |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
32 |
"\\{\\*([^*]|\\*[^}]|\\*\\z)*(\\z|\\*\\})|" + |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
33 |
"\\(\\*([^*]|\\*[^)]|\\*\\z)*(\\z|\\*\\))|" + |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
34 |
"(\\?'?|')[A-Za-z_0-9.]*|" + |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
35 |
"[A-Za-z_0-9.]+|" + |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
36 |
"[!#$%&*+-/<=>?@^_|~]+|" + |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
37 |
"\"([^\\\\\"]?(\\\\(.|\\z))?)*+(\"|\\z)|" + |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
38 |
"`([^\\\\`]?(\\\\(.|\\z))?)*+(`|\\z)|" + |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
39 |
"[()\\[\\]{}:;]", Pattern.MULTILINE) |
34485 | 40 |
|
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
41 |
val empty = |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
42 |
new ProofDocument(isabelle.jedit.Isabelle.plugin.id(), LinearSet(), Map(), LinearSet(), false, _ => false) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
43 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
44 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
45 |
|
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
46 |
class ProofDocument(val id: String, |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
47 |
val tokens: LinearSet[Token], |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
48 |
val token_start: Map[Token, Int], |
34532 | 49 |
val commands: LinearSet[Command], |
50 |
val active: Boolean, |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
51 |
is_command_keyword: String => Boolean) |
34483 | 52 |
{ |
34485 | 53 |
|
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
54 |
def mark_active: ProofDocument = |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
55 |
new ProofDocument(id, tokens, token_start, commands, true, is_command_keyword) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
56 |
def activate: (ProofDocument, StructureChange) = { |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
57 |
val (doc, change) = |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
58 |
text_changed(new Text.Change(isabelle.jedit.Isabelle.plugin.id(), 0, content, content.length)) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
59 |
return (doc.mark_active, change) |
34456 | 60 |
} |
34532 | 61 |
def set_command_keyword(f: String => Boolean): ProofDocument = |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
62 |
new ProofDocument(id, tokens, token_start, commands, active, f) |
34485 | 63 |
|
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
64 |
def content = Token.string_from_tokens(List() ++ tokens, token_start) |
34485 | 65 |
/** token view **/ |
66 |
||
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
67 |
def text_changed(change: Text.Change): (ProofDocument, StructureChange) = |
34485 | 68 |
{ |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
69 |
//indices of tokens |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
70 |
var start: Map[Token, Int] = token_start |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
71 |
def stop(t: Token) = start(t) + t.length |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
72 |
// split old token lists |
34531 | 73 |
val tokens = List() ++ this.tokens |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
74 |
val (begin, remaining) = tokens.span(stop(_) < change.start) |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
75 |
val (removed, end) = remaining.span(token_start(_) <= change.start + change.removed) |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
76 |
// update indices |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
77 |
start = end.foldLeft (start) ((s, t) => s + (t -> (s(t) + change.added.length - change.removed))) |
34485 | 78 |
|
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
79 |
val split_begin = removed.takeWhile(start(_) < change.start). |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
80 |
map (t => { |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
81 |
val split_tok = new Token(t.content.substring(0, change.start - start(t)), t.kind) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
82 |
start += (split_tok -> start(t)) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
83 |
split_tok |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
84 |
}) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
85 |
|
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
86 |
val split_end = removed.dropWhile(stop(_) < change.start + change.removed). |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
87 |
map (t => { |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
88 |
val split_tok = new Token(t.content.substring(change.start + change.removed - start(t)), |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
89 |
t.kind) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
90 |
start += (split_tok -> start(t)) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
91 |
split_tok |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
92 |
}) |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
93 |
// update indices |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
94 |
start = removed.foldLeft (start) ((s, t) => s - t) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
95 |
start = split_end.foldLeft (start) ((s, t) => |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
96 |
s + (t -> (change.start + change.added.length))) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
97 |
|
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
98 |
val ins = new Token(change.added, Token.Kind.OTHER) |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
99 |
start += (ins -> change.start) |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
100 |
|
34526 | 101 |
var invalid_tokens = split_begin ::: |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
102 |
ins :: split_end ::: end |
34526 | 103 |
var new_tokens = Nil: List[Token] |
104 |
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
|
105 |
|
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
106 |
val match_start = invalid_tokens.firstOption.map(start(_)).getOrElse(0) |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
107 |
val matcher = ProofDocument.token_pattern.matcher(Token.string_from_tokens(invalid_tokens, start)) |
34526 | 108 |
|
109 |
while (matcher.find() && invalid_tokens != Nil) { |
|
34485 | 110 |
val kind = |
34505
87f4f70d61bb
ProofDocument: pass is_command_keyword directly, not via full-blown Prover object;
wenzelm
parents:
34496
diff
changeset
|
111 |
if (is_command_keyword(matcher.group)) |
34485 | 112 |
Token.Kind.COMMAND_START |
34494 | 113 |
else if (matcher.end - matcher.start > 2 && matcher.group.substring(0, 2) == "(*") |
34485 | 114 |
Token.Kind.COMMENT |
115 |
else |
|
116 |
Token.Kind.OTHER |
|
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
117 |
val new_token = new Token(matcher.group, kind) |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
118 |
start += (new_token -> (match_start + matcher.start)) |
34526 | 119 |
new_tokens ::= new_token |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
120 |
|
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
121 |
invalid_tokens = invalid_tokens dropWhile (stop(_) < stop(new_token)) |
34526 | 122 |
invalid_tokens match { |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
123 |
case t::ts => if(start(t) == start(new_token) && |
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
124 |
start(t) > change.start + change.added.length) { |
34526 | 125 |
old_suffix = ts |
126 |
invalid_tokens = Nil |
|
127 |
} |
|
128 |
case _ => |
|
34318
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 |
} |
34526 | 131 |
val insert = new_tokens.reverse |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
132 |
val new_token_list = begin ::: insert ::: old_suffix |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
133 |
val new_tokenset = (LinearSet() ++ new_token_list).asInstanceOf[LinearSet[Token]] |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
134 |
token_changed(change.id, |
34550
171c8c6e5707
prepared proofdocument for only needed changes
immler@in.tum.de
parents:
34544
diff
changeset
|
135 |
begin.lastOption, |
34526 | 136 |
insert, |
34550
171c8c6e5707
prepared proofdocument for only needed changes
immler@in.tum.de
parents:
34544
diff
changeset
|
137 |
old_suffix.firstOption, |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
138 |
new_tokenset, |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
139 |
start) |
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 |
|
34485 | 142 |
/** command view **/ |
143 |
||
34496
1b2995592bb9
renamed getNextCommandContaining to find_command_at;
wenzelm
parents:
34494
diff
changeset
|
144 |
def find_command_at(pos: Int): Command = { |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
145 |
for (cmd <- commands) { if (pos < cmd.stop(this)) return cmd } |
34485 | 146 |
return null |
147 |
} |
|
148 |
||
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
149 |
private def token_changed(new_id: String, |
34550
171c8c6e5707
prepared proofdocument for only needed changes
immler@in.tum.de
parents:
34544
diff
changeset
|
150 |
before_change: Option[Token], |
34526 | 151 |
inserted_tokens: List[Token], |
34550
171c8c6e5707
prepared proofdocument for only needed changes
immler@in.tum.de
parents:
34544
diff
changeset
|
152 |
after_change: Option[Token], |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
153 |
new_tokenset: LinearSet[Token], |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
154 |
new_token_start: Map[Token, Int]): (ProofDocument, StructureChange) = |
34485 | 155 |
{ |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
156 |
val cmd_first_changed = |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
157 |
if (before_change.isDefined) commands.find(_.tokens.contains(before_change.get)) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
158 |
else None |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
159 |
val cmd_last_changed = |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
160 |
if (after_change.isDefined) commands.find(_.tokens.contains(after_change.get)) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
161 |
else None |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
162 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
163 |
val cmd_before_change = |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
164 |
if (cmd_first_changed.isDefined) commands.prev(cmd_first_changed.get) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
165 |
else None |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
166 |
val cmd_after_change = |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
167 |
if (cmd_last_changed.isDefined) commands.next(cmd_last_changed.get) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
168 |
else None |
34485 | 169 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
170 |
val removed_commands = commands.dropWhile(Some(_) != cmd_first_changed). |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
171 |
takeWhile(Some(_) != cmd_after_change) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
172 |
|
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
173 |
// calculate inserted commands |
34526 | 174 |
def tokens_to_commands(tokens: List[Token]): List[Command]= { |
175 |
tokens match { |
|
176 |
case Nil => Nil |
|
177 |
case t::ts => |
|
34575 | 178 |
val (cmd,rest) = ts.span(t => t.kind != Token.Kind.COMMAND_START && t.kind != Token.Kind.COMMENT) |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
179 |
new Command(t::cmd, new_token_start) :: tokens_to_commands (rest) |
34485 | 180 |
} |
181 |
} |
|
182 |
||
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
183 |
val split_begin_tokens = |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
184 |
if (!cmd_first_changed.isDefined || !before_change.isDefined) Nil |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
185 |
else { |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
186 |
cmd_first_changed.get.tokens.takeWhile(_ != before_change.get) ::: List(before_change.get) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
187 |
} |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
188 |
val split_end_tokens = |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
189 |
if (!cmd_last_changed.isDefined || !after_change.isDefined) Nil |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
190 |
else { |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
191 |
cmd_last_changed.get.tokens.dropWhile(_ != after_change.get) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
192 |
} |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
193 |
|
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
194 |
val rescanning_tokens = split_begin_tokens ::: inserted_tokens ::: split_end_tokens |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
195 |
val inserted_commands = tokens_to_commands(rescanning_tokens) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
196 |
|
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
197 |
val change = new StructureChange(cmd_before_change, inserted_commands, removed_commands.toList) |
34550
171c8c6e5707
prepared proofdocument for only needed changes
immler@in.tum.de
parents:
34544
diff
changeset
|
198 |
// build new document |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
199 |
val new_commandset = commands.delete_between(cmd_before_change, cmd_after_change). |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
200 |
insert_after(cmd_before_change, inserted_commands) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34551
diff
changeset
|
201 |
|
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34541
diff
changeset
|
202 |
val doc = |
34551
bd2b8fde9e25
incomplete changes of immutable tokens and commands
immler@in.tum.de
parents:
34550
diff
changeset
|
203 |
new ProofDocument(new_id, new_tokenset, new_token_start, new_commandset, active, is_command_keyword) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
204 |
return (doc, change) |
34485 | 205 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
206 |
} |