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