122 for (cmd <- commands) { if (pos < cmd.stop) return cmd } |
124 for (cmd <- commands) { if (pos < cmd.stop) return cmd } |
123 return null |
125 return null |
124 } |
126 } |
125 |
127 |
126 private def token_changed(new_id: String, |
128 private def token_changed(new_id: String, |
|
129 before_change: Option[Token], |
127 inserted_tokens: List[Token], |
130 inserted_tokens: List[Token], |
128 removed_tokens: List[Token], |
131 removed_tokens: List[Token], |
|
132 after_change: Option[Token], |
129 new_token_list: List[Token]): (ProofDocument, StructureChange) = |
133 new_token_list: List[Token]): (ProofDocument, StructureChange) = |
130 { |
134 { |
131 val commands = List[Command]() ++ this.commands |
135 val commands = List[Command]() ++ this.commands |
132 |
136 |
133 // calculate removed commands |
137 // calculate removed commands |
137 val (begin, remaining) = |
141 val (begin, remaining) = |
138 first_removed match { |
142 first_removed match { |
139 case None => (Nil: List[Command], commands) |
143 case None => (Nil: List[Command], commands) |
140 case Some(fr) => commands.break(_.tokens.contains(fr)) |
144 case Some(fr) => commands.break(_.tokens.contains(fr)) |
141 } |
145 } |
142 val removed: List[Command]= |
146 val removed_commands: List[Command]= |
143 last_removed match { |
147 last_removed match { |
144 case None => Nil |
148 case None => Nil |
145 case Some(lr) => |
149 case Some(lr) => |
146 remaining.takeWhile(!_.tokens.contains(lr)) ++ |
150 remaining.takeWhile(!_.tokens.contains(lr)) ++ |
147 (remaining.find(_.tokens.contains(lr)) match { |
151 (remaining.find(_.tokens.contains(lr)) match { |
158 new Command(t::cmd) :: tokens_to_commands (rest) |
162 new Command(t::cmd) :: tokens_to_commands (rest) |
159 } |
163 } |
160 } |
164 } |
161 |
165 |
162 // calculate inserted commands |
166 // calculate inserted commands |
163 val first_inserted = inserted_tokens.firstOption |
|
164 val last_inserted = inserted_tokens.lastOption |
|
165 |
|
166 val new_commands = tokens_to_commands(new_token_list) |
167 val new_commands = tokens_to_commands(new_token_list) |
167 |
|
168 // drop known commands from the beginning |
|
169 val after_change = new_commands |
|
170 val inserted_commands = new_commands.dropWhile(_.tokens.contains(first_inserted)) |
|
171 |
|
172 val new_tokenset = (LinearSet() ++ new_token_list).asInstanceOf[LinearSet[Token]] |
168 val new_tokenset = (LinearSet() ++ new_token_list).asInstanceOf[LinearSet[Token]] |
173 val new_commandset = (LinearSet() ++ (new_commands)).asInstanceOf[LinearSet[Command]] |
169 val new_commandset = (LinearSet() ++ (new_commands)).asInstanceOf[LinearSet[Command]] |
174 |
170 // drop known commands from the beginning |
175 val before = begin match {case Nil => None case _ => Some (begin.last)} |
171 val first_changed = before_change match { |
176 val change = new StructureChange(None,List() ++ new_commandset, removed) |
172 case None => new_tokenset.first_elem |
177 |
173 case Some(bc) => new_tokenset.next(bc) |
|
174 } |
|
175 val changed_commands = first_changed match { |
|
176 case None => Nil |
|
177 case Some(fc) => new_commands.dropWhile(!_.tokens.contains(fc)) |
|
178 } |
|
179 val inserted_commands = after_change match { |
|
180 case None => changed_commands |
|
181 case Some(ac) => changed_commands.takeWhile(!_.tokens.contains(ac)) |
|
182 } |
|
183 //val change = new StructureChange(new_commands.find(_.tokens.contains(before_change)), |
|
184 // inserted_commands, removed_commands) |
|
185 // TODO: revert to upper change, when commands and tokens are ok |
|
186 val change = new StructureChange(None, List() ++ new_commandset, commands) |
|
187 // build new document |
178 val doc = |
188 val doc = |
179 new ProofDocument(new_id, new_tokenset, new_commandset, active, is_command_keyword) |
189 new ProofDocument(new_id, new_tokenset, new_commandset, active, is_command_keyword) |
180 return (doc, change) |
190 return (doc, change) |
181 } |
191 } |
182 } |
192 } |