fix bug revealed by checking for incorrect index metadta in line_gap.sml

This commit is contained in:
2024-07-18 15:38:31 +01:00
parent 117ffeba6e
commit 371bc093ff

View File

@@ -108,8 +108,7 @@ struct
fun calcIndexList (accIdx, lst) = fun calcIndexList (accIdx, lst) =
case lst of case lst of
[] => accIdx [] => accIdx
| hd::tl => | hd :: tl => calcIndexList (String.size hd + accIdx, tl)
calcIndexList (String.size hd + accIdx, tl)
fun calcIndexStart lst = calcIndexList (0, lst) fun calcIndexStart lst = calcIndexList (0, lst)
@@ -123,13 +122,13 @@ struct
print "idx is correct\n" print "idx is correct\n"
else else
let let
val msg = String.concat [ val msg = String.concat
"idx is incorrect;", [ "idx is incorrect;"
"bufferIdx: ", , "bufferIdx: "
Int.toString bufferIdx, , Int.toString bufferIdx
"; correctIdx: ", , "; correctIdx: "
Int.toString correctIdx, , Int.toString correctIdx
"\n" , "\n"
] ]
val _ = print msg val _ = print msg
val _ = raise Size val _ = raise Size
@@ -1118,24 +1117,30 @@ struct
end end
else else
(* Delete this node fully, but delete no further. *) (* Delete this node fully, but delete no further. *)
let val _ = println "1085" in let
val _ = println "1085"
in
{ idx = origIdx { idx = origIdx
, line = origLine , line = origLine
, leftStrings = leftStrings , leftStrings = leftStrings
, leftLines = leftLines , leftLines = leftLines
, rightStrings = rightStringsTl , rightStrings = rightStringsTl
, rightLines = rightLinesTl , rightLines = rightLinesTl
} end }
end
end end
| (_, _) => | (_, _) =>
let val _ = println "1095" in let
val _ = println "1095"
in
{ idx = 0 { idx = 0
, line = 0 , line = 0
, leftStrings = [] , leftStrings = []
, leftLines = [] , leftLines = []
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} end }
end
fun moveRightAndDelete fun moveRightAndDelete
( start ( start
@@ -1297,7 +1302,9 @@ struct
else else
(* Can't join new string with left head (* Can't join new string with left head
* while staying in limit, so just cons. *) * while staying in limit, so just cons. *)
let val _ = println "1264" in let
val _ = println "1264"
in
deleteRightFromHere deleteRightFromHere
( nextIdx ( nextIdx
, nextLine , nextLine
@@ -1307,9 +1314,12 @@ struct
, newLines :: leftLines , newLines :: leftLines
, rightStringsTl , rightStringsTl
, rightLinesTl , rightLinesTl
) end )
end
| (_, _) => | (_, _) =>
let val _ = println "1276" in let
val _ = println "1276"
in
deleteRightFromHere deleteRightFromHere
( nextIdx ( nextIdx
, nextLine , nextLine
@@ -1319,7 +1329,8 @@ struct
, newLines :: leftLines , newLines :: leftLines
, rightStringsTl , rightStringsTl
, rightLinesTl , rightLinesTl
) end) )
end)
end end
else if nextIdx > finish then else if nextIdx > finish then
(* Base case: delete from the middle part of this string. *) (* Base case: delete from the middle part of this string. *)
@@ -1406,7 +1417,9 @@ struct
* and it may extend beyond the current head. * and it may extend beyond the current head.
* So pass the rightStringsTl and rightLinesTl to a function that * So pass the rightStringsTl and rightLinesTl to a function that
* will delete rightwards if it needs to, or else terminates. *) * will delete rightwards if it needs to, or else terminates. *)
let val _ = println "1373" in let
val _ = println "1373"
in
deleteRightFromHere deleteRightFromHere
( curIdx ( curIdx
, curLine , curLine
@@ -1416,17 +1429,21 @@ struct
, leftLines , leftLines
, rightStringsTl , rightStringsTl
, rightLinesTl , rightLinesTl
) end )
end
end end
| (_, _) => | (_, _) =>
let val _ = println "1386" in let
val _ = println "1386"
in
{ idx = curIdx { idx = curIdx
, line = curLine , line = curLine
, leftStrings = leftStrings , leftStrings = leftStrings
, leftLines = leftLines , leftLines = leftLines
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} end }
end
fun deleteLeftFromHere fun deleteLeftFromHere
(start, curIdx, curLine, leftStrings, leftLines, rightStrings, rightLines) = (start, curIdx, curLine, leftStrings, leftLines, rightStrings, rightLines) =
@@ -1479,24 +1496,30 @@ struct
else else
(* start = prevIdx (* start = prevIdx
* Base case: Remove leftStrings/LinesHd without removing any further. *) * Base case: Remove leftStrings/LinesHd without removing any further. *)
let val _ = println "1446" in let
val _ = println "1446"
in
{ idx = prevIdx { idx = prevIdx
, line = prevLine , line = prevLine
, leftStrings = leftStringsTl , leftStrings = leftStringsTl
, leftLines = leftLinesTl , leftLines = leftLinesTl
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} end }
end
end end
| (_, _) => | (_, _) =>
let val _ = println "1456" in let
val _ = println "1456"
in
{ idx = curIdx { idx = curIdx
, line = curLine , line = curLine
, leftStrings = leftStrings , leftStrings = leftStrings
, leftLines = leftLines , leftLines = leftLines
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} end }
end
fun deleteFromLetAndRight fun deleteFromLetAndRight
( start ( start
@@ -1627,14 +1650,17 @@ struct
| (_, _) => | (_, _) =>
(* Base case: reached empty list while trying to move leftwards. (* Base case: reached empty list while trying to move leftwards.
* Cannot do anything so just return. *) * Cannot do anything so just return. *)
let val _ = println "1594" in let
val _ = println "1594"
in
{ idx = 0 { idx = 0
, line = 0 , line = 0
, leftStrings = leftStrings , leftStrings = leftStrings
, leftLines = leftLines , leftLines = leftLines
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} end) }
end)
else if prevIdx < finish then else if prevIdx < finish then
if prevIdx > start then if prevIdx > start then
(* Delete from start point of this string, (* Delete from start point of this string,
@@ -1776,7 +1802,7 @@ struct
end end
val _ = println "1741" val _ = println "1741"
in in
{ idx = prevIdx { idx = prevIdx + String.size str
, line = , line =
(curLine - Vector.length leftLinesHd) + String.size str (curLine - Vector.length leftLinesHd) + String.size str
, leftStrings = str :: leftStringsTl , leftStrings = str :: leftStringsTl
@@ -1847,25 +1873,31 @@ struct
end end
| (_, _) => | (_, _) =>
(* Left strings and lines are empty, so just return. *) (* Left strings and lines are empty, so just return. *)
let val _ = println "1814" in let
val _ = println "1814"
in
{ idx = 0 { idx = 0
, line = 0 , line = 0
, leftStrings = [] , leftStrings = []
, leftLines = [] , leftLines = []
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} end) }
end)
end end
| (_, _) => | (_, _) =>
(* Can't move further leftward so just return. *) (* Can't move further leftward so just return. *)
let val _ = println "1825" in let
val _ = println "1825"
in
{ idx = 0 { idx = 0
, line = 0 , line = 0
, leftStrings = [] , leftStrings = []
, leftLines = [] , leftLines = []
, rightStrings = rightStrings , rightStrings = rightStrings
, rightLines = rightLines , rightLines = rightLines
} end }
end
fun del fun del
( start ( start