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