address compiler warnings and errors in src/line_gap.sml

This commit is contained in:
2024-07-14 17:43:43 +01:00
parent 1439138d50
commit 7c7a4103d8

View File

@@ -948,6 +948,7 @@ struct
end
(* Delete function and helper functions for it. *)
local
fun deleteRightFromHere
( origIdx
, origLine
@@ -979,9 +980,12 @@ struct
(* Base case: delete from the start of this string and stop moving. *)
let
(* Delete part of string. *)
val newStrStart = finish - curIdx
val newStrStart = finish - moveIdx
val newStr = String.substring
(hd, newStrStart, String.size hd - newStrStart)
( rightStringsHd
, newStrStart
, String.size rightStringsHd - newStrStart
)
(* Delete from line vector if we need to. *)
val newLines =
@@ -1009,7 +1013,7 @@ struct
, line = origLine
, leftStrings = leftStrings
, leftLines = leftLines
, rightStrings = newStr :: rightStringTl
, rightStrings = newStr :: rightStringsTl
, rightLines = newLines :: rightLinesTl
}
end
@@ -1023,21 +1027,29 @@ struct
, rightLines = rightLinesTl
}
end
| (_, _) =>
{ idx = 0
, line = 0
, leftStrings = []
, leftLines = []
, rightStrings = rightStrings
, rightLines = rightLines
}
fun moveRightAndDelete
( start
, finish
, curIdx
, curLine
, leftStrings
, leftLines
, rightStrings
, rightLines
, leftStrings: string list
, leftLines: int vector list
, rightStrings: string list
, rightLines: int vector list
) =
case (rightStrings, rightLines) of
(rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) =>
let
val nextIdx = curIdx + String.size rightLinesHd
val nextIdx = curIdx + String.size rightStringsHd
in
if nextIdx < start then
(* Keep moving right.
@@ -1049,12 +1061,16 @@ struct
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
if
isInLimit
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
( leftStringsHd
, rightStringsHd
, leftLinesHd
, rightLinesHd
)
then
(* We can join the heads while staying in limit, so do so. *)
let
val newLeftStringsHd = leftStringsHd ^ rightStringsHd
val newLeftLinesHd =
val newLeftLinesHd: int vector =
Vector.tabulate
( Vector.length leftLinesHd
+ Vector.length rightLinesHd
@@ -1063,8 +1079,9 @@ struct
Vector.sub (leftLinesHd, idx)
else
Vector.sub
(rightLinesHd, idx - Vector.length leftLinesHd)
+ String.size leftStringsHd
( rightLinesHd
, idx - Vector.length leftLinesHd
) + String.size leftStringsHd
)
val newLeftStrings = newLeftStringsHd :: leftStringsTl
val newLeftLines = newLeftLinesHd :: leftLinesTl
@@ -1128,7 +1145,9 @@ struct
in
(* Try joining new string with left head if possible. *)
(case (leftStrings, leftLines) of
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
( leftStringsHd :: leftStringsTl
, leftLinesHd :: leftLinesTl
) =>
if
isInLimit
(newString, leftStringsHd, newLines, leftLinesHd)
@@ -1145,13 +1164,15 @@ struct
Vector.sub (leftLinesHd, idx)
else
Vector.sub
(newLines, idx - Vector.length leftLinesHd)
+ String.size leftStringHd
( newLines
, idx - Vector.length leftLinesHd
) + String.size leftStringsHd
)
in
deleteRightFromHere
( nextIdx
, nextLine
, nextIdx
, finish
, newLeftStringsHd :: leftStringsTl
, newLeftLinesHd :: leftLinesTl
@@ -1165,9 +1186,10 @@ struct
deleteRightFromHere
( nextIdx
, nextLine
, nextIdx
, finish
, newString :: leftStrings
, newLines :: leftLinesHd
, newLines :: leftLines
, rightStringsTl
, rightLinesTl
)
@@ -1175,9 +1197,10 @@ struct
deleteRightFromHere
( nextIdx
, nextLine
, nextIdx
, finish
, newString :: leftStrings
, newLines :: leftLinesHd
, newLines :: leftLines
, rightStringsTl
, rightLinesTl
))
@@ -1187,7 +1210,8 @@ struct
let
val sub1Length = start - curIdx
val sub1 = String.substring (rightStringsHd, 0, sub1Length)
val sub1LineEnd = binSearch (String.size sub1 - 1, rightLinesHd)
val sub1LineEnd = binSearch
(String.size sub1 - 1, rightLinesHd)
val sub1Lines =
if sub1LineEnd >= 0 then
let
@@ -1218,10 +1242,13 @@ struct
Vector.fromList []
in
(case (leftStrings, leftLines) of
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
( leftStringsHd :: leftStringsTl
, leftLinesHd :: leftLinesTl
) =>
let
val isLeftInLimit =
isInLimit (leftStringsHd, sub1, leftLinesHd, sub1Lines)
isInLimit
(leftStringsHd, sub1, leftLinesHd, sub1Lines)
val isRightInLimit =
isInLimit
(rightStringsHd, sub2, rightLinesHd, sub2Lines)
@@ -1229,7 +1256,7 @@ struct
if isLeftInLimit andalso isRightInLimit then
let
val newLeftStringsHd = leftStringsHd ^ sub1
val newLinesLinesHd =
val newLeftLinesHd =
Vector.tabulate
( Vector.length leftLinesHd
+ Vector.length sub1Lines
@@ -1263,14 +1290,15 @@ struct
, leftStrings = newLeftStringsHd :: leftStringsTl
, leftLines = newLeftLinesHd :: leftLinesTl
, rightStrings = newRightStringsHd :: rightStringsTl
, rightStrings =
newRightStringsHd :: rightStringsTl
, rightLines = newRightLinesHd :: rightLinesTl
}
end
else if isLeftInLimit then
let
val newLeftStringsHd = leftStringsHd ^ sub1
val newLinesLinesHd =
val newLeftLinesHd =
Vector.tabulate
( Vector.length leftLinesHd
+ Vector.length sub1Lines
@@ -1314,7 +1342,8 @@ struct
, leftStrings = sub1 :: leftStrings
, leftLines = sub1Lines :: leftLines
, rightStrings = newRightStringsHd :: rightStringsTl
, rightStrings =
newRightStringsHd :: rightStringsTl
, rightLines = newRightLinesHd :: rightLinesTl
}
end
@@ -1347,7 +1376,7 @@ struct
if midpoint >= 0 then
let
val slice = VectorSlice.slice
(leftLines, 0, SOME (midpoint + 1))
(rightLinesHd, 0, SOME (midpoint + 1))
in
VectorSlice.vector slice
end
@@ -1390,7 +1419,7 @@ struct
}
fun deleteLeftFromHere
(start, curIdx, curLines, leftStrings, leftLines, rightStrings, rightLines) =
(start, curIdx, curLine, leftStrings, leftLines, rightStrings, rightLines) =
case (leftStrings, leftLines) of
(leftStringsHd :: leftStringsTl, leftLinesHd :: leftLinesTl) =>
let
@@ -1512,10 +1541,16 @@ struct
* limit if this is possible while staying in limit.
* If this is not possible, we just cons instead. *)
(case (rightStrings, rightLines) of
(rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) =>
( rightStringsHd :: rightStringsTl
, rightLinesHd :: rightLinesTl
) =>
if
isInLimit
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
( leftStringsHd
, rightStringsHd
, leftLinesHd
, rightLinesHd
)
then
(* Can join while staying in limit, so do join. *)
let
@@ -1529,8 +1564,9 @@ struct
Vector.sub (leftLinesHd, idx)
else
Vector.sub
(rightLinesHd, idx - Vector.length leftLinesHd)
+ String.size leftStringsHd
( rightLinesHd
, idx - Vector.length leftLinesHd
) + String.size leftStringsHd
)
val newRightStrings = newRightStringsHd :: rightStringsTl
val newRightLines = newRightLinesHd :: rightLinesTl
@@ -1624,7 +1660,8 @@ struct
val sub1Lines =
let
val midpoint = binSearch (String.size sub1 - 1, leftLinesHd)
val midpoint = binSearch
(String.size sub1 - 1, leftLinesHd)
in
if midpoint >= 0 then
let
@@ -1645,7 +1682,8 @@ struct
Vector.tabulate
( Vector.length leftLinesHd - midpoint
, fn idx =>
Vector.sub (leftLinesHd, idx + midpoint) - sub2Start
Vector.sub (leftLinesHd, idx + midpoint)
- sub2Start
)
else
Vector.fromList []
@@ -1679,14 +1717,16 @@ struct
Vector.tabulate
( Vector.length leftLinesHd - lineStart
, fn idx =>
Vector.sub (leftLinesHd, idx + lineStart) - strStart
Vector.sub (leftLinesHd, idx + lineStart)
- strStart
)
else
Vector.fromList []
end
in
{ idx = prevIdx
, line = (curLine - Vector.length leftLinesHd) + String.size str
, line =
(curLine - Vector.length leftLinesHd) + String.size str
, leftStrings = str :: leftStringsTl
, leftLines = lines :: leftLinesTl
, rightStrings = rightStrings
@@ -1699,10 +1739,16 @@ struct
* Optimsation: Try joining leftStrings/LinesHd with
* rightStrings/LinesHd if possible while staying in limit. *)
(case (rightStrings, rightLines) of
(rightStringsHd :: rightStringsTl, rightLinesHd :: rightLinesTl) =>
( rightStringsHd :: rightStringsTl
, rightLinesHd :: rightLinesTl
) =>
if
isInLimit
(leftStringsHd, rightStringsHd, leftLinesHd, rightLinesHd)
( leftStringsHd
, rightStringsHd
, leftLinesHd
, rightLinesHd
)
then
(* Can join while staying in limit. *)
let
@@ -1716,8 +1762,9 @@ struct
Vector.sub (leftLinesHd, idx)
else
Vector.sub
(rightLinesHd, idx - Vector.length leftLinesHd)
+ String.size leftStringsHd
( rightLinesHd
, idx - Vector.length leftLinesHd
) + String.size leftStringsHd
)
in
deleteLeftFromHere
@@ -1761,6 +1808,79 @@ struct
, rightLines = rightLines
}
fun del
( start
, finish
, curIdx
, curLine
, leftStrings
, leftLines
, rightStrings
, rightLines
) =
if start > curIdx then
moveRightAndDelete
( start
, finish
, curIdx
, curLine
, leftStrings
, leftLines
, rightStrings
, rightLines
)
else if start < curIdx then
if finish <= curIdx then
moveLeftAndDelete
( start
, finish
, curIdx
, curLine
, leftStrings
, leftLines
, rightStrings
, rightLines
)
else
deleteFromLetAndRight
( start
, finish
, curIdx
, curLine
, leftStrings
, leftLines
, rightStrings
, rightLines
)
else
deleteRightFromHere
( curIdx
, curLine
, curIdx
, finish
, leftStrings
, leftLines
, rightStrings
, rightLines
)
in
fun delete (start, length, buffer: t) =
if length > 0 then
del
( start
, start + length
, #idx buffer
, #line buffer
, #leftStrings buffer
, #leftLines buffer
, #rightStrings buffer
, #rightLines buffer
)
else
buffer
end
(* TEST CODE *)
local
fun lineBreaksToString vec =