@@ -227,16 +227,24 @@ let pos_at_end parsed =
227
227
| Some (stop , _ ) -> stop
228
228
| None -> - 1
229
229
230
+ let string_of_parsed_ast { tokens } =
231
+ (* TODO implement printer for vernac_entry *)
232
+ " [" ^ String. concat " --" (List. map (Tok. extract_string false ) tokens) ^ " ]"
233
+
230
234
let patch_sentence parsed scheduler_state_before id ({ parsing_start; ast; start; stop; synterp_state } : pre_sentence ) =
231
- log @@ " Patching sentence " ^ Stateid. to_string id;
232
235
let old_sentence = SM. find id parsed.sentences_by_id in
236
+ log @@ Format. sprintf " Patching sentence %s , %s" (Stateid. to_string id) (string_of_parsed_ast old_sentence.ast);
233
237
let scheduler_state_after, schedule =
234
238
let ast = (ast.ast, ast.classification, synterp_state) in
235
239
Scheduler. schedule_sentence (id,ast) scheduler_state_before parsed.schedule
236
240
in
237
241
let new_sentence = { old_sentence with ast; parsing_start; start; stop; scheduler_state_before; scheduler_state_after } in
238
242
let sentences_by_id = SM. add id new_sentence parsed.sentences_by_id in
239
- let sentences_by_end = LM. remove old_sentence.stop parsed.sentences_by_end in
243
+ let sentences_by_end = match LM. find_opt old_sentence.stop parsed.sentences_by_end with
244
+ | Some { id } when Stateid. equal id new_sentence.id ->
245
+ LM. remove old_sentence.stop parsed.sentences_by_end
246
+ | _ -> parsed.sentences_by_end
247
+ in
240
248
let sentences_by_end = LM. add new_sentence.stop new_sentence sentences_by_end in
241
249
{ parsed with sentences_by_end; sentences_by_id; schedule }, scheduler_state_after
242
250
@@ -245,9 +253,11 @@ type diff =
245
253
| Added of pre_sentence list
246
254
| Equal of (sentence_id * pre_sentence ) list
247
255
256
+
257
+
248
258
let same_tokens (s1 : sentence ) (s2 : pre_sentence ) =
249
259
CList. equal Tok. equal s1.ast.tokens s2.ast.tokens
250
-
260
+
251
261
(* TODO improve diff strategy (insertions,etc) *)
252
262
let rec diff old_sentences new_sentences =
253
263
match old_sentences, new_sentences with
@@ -256,13 +266,10 @@ let rec diff old_sentences new_sentences =
256
266
| old_sentences , [] -> [Deleted (List. map (fun s -> s.id) old_sentences)]
257
267
(* FIXME something special should be done when `Deleted` is applied to a parsing effect *)
258
268
| old_sentence ::old_sentences , new_sentence ::new_sentences ->
259
- if same_tokens old_sentence new_sentence then
269
+ if same_tokens old_sentence new_sentence then
260
270
Equal [(old_sentence.id,new_sentence)] :: diff old_sentences new_sentences
261
- else Deleted [old_sentence.id] :: Added [new_sentence] :: diff old_sentences new_sentences
262
-
263
- let string_of_parsed_ast { tokens } =
264
- (* TODO implement printer for vernac_entry *)
265
- " [" ^ String. concat " --" (List. map (Tok. extract_string false ) tokens) ^ " ]"
271
+ else
272
+ Deleted [old_sentence.id] :: Added [new_sentence] :: diff old_sentences new_sentences
266
273
267
274
let string_of_diff_item doc = function
268
275
| Deleted ids ->
@@ -434,6 +441,13 @@ let invalidate top_edit top_id parsed_doc new_sentences =
434
441
invalidate_diff parsed_doc scheduler_state invalid_ids diffs
435
442
in
436
443
let (_,_synterp_state,scheduler_state) = state_at_pos parsed_doc top_edit in
444
+ let sentence_strings = LM. bindings @@ LM. map (fun s -> string_of_parsed_ast s.ast) parsed_doc.sentences_by_end in
445
+ let sentence_strings = List. map (fun s -> snd s) sentence_strings in
446
+ let sentence_string = String. concat " " sentence_strings in
447
+ let sentence_strings_id = SM. bindings @@ SM. map (fun s -> string_of_parsed_ast s.ast) parsed_doc.sentences_by_id in
448
+ let sentence_strings_id = List. map (fun s -> snd s) sentence_strings_id in
449
+ let sentence_string_id = String. concat " " sentence_strings_id in
450
+ log @@ Format. sprintf " Top edit: %i, Doc: %s, Doc by id: %s" top_edit sentence_string sentence_string_id;
437
451
let old_sentences = sentences_after parsed_doc top_edit in
438
452
let diff = diff old_sentences new_sentences in
439
453
let unchanged_id = unchanged_id top_id diff in
0 commit comments