address some bugs with one deletion function
This commit is contained in:
182
src/line_gap.sml
182
src/line_gap.sml
@@ -53,6 +53,58 @@ struct
|
|||||||
, rightLines = []
|
, rightLines = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(* TEST CODE *)
|
||||||
|
fun lineBreaksToString vec =
|
||||||
|
(Vector.foldr (fn (el, acc) => Int.toString el ^ ", " ^ acc) "" vec) ^ "\n"
|
||||||
|
|
||||||
|
fun checkLineBreaks (v1, v2) =
|
||||||
|
if v1 = v2 then
|
||||||
|
()
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val _ = print ("broken: " ^ (lineBreaksToString v1))
|
||||||
|
val _ = print ("fixed: " ^ (lineBreaksToString v2))
|
||||||
|
in
|
||||||
|
()
|
||||||
|
end
|
||||||
|
|
||||||
|
fun goToStart (leftStrings, leftLines, accStrings, accLines) =
|
||||||
|
case (leftStrings, leftLines) of
|
||||||
|
(lsHd :: lsTl, llHd :: llTl) =>
|
||||||
|
goToStart (lsTl, llTl, lsHd :: accStrings, llHd :: accLines)
|
||||||
|
| (_, _) => (accStrings, accLines)
|
||||||
|
|
||||||
|
fun verifyLineList (strings, lines) =
|
||||||
|
case (strings, lines) of
|
||||||
|
(strHd :: strTl, lHd :: lTl) =>
|
||||||
|
let
|
||||||
|
val checkLines = countLineBreaks strHd
|
||||||
|
in
|
||||||
|
if checkLines = lHd then
|
||||||
|
verifyLineList (strTl, lTl)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val _ = print "line metadata is incorrect\n"
|
||||||
|
val _ = checkLineBreaks (lHd, checkLines)
|
||||||
|
in
|
||||||
|
raise Empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
| (_, _) => print "verified lines; no problems\n"
|
||||||
|
fun verifyLines (buffer: t) =
|
||||||
|
let
|
||||||
|
val (strings, lines) =
|
||||||
|
goToStart
|
||||||
|
( #leftStrings buffer
|
||||||
|
, #leftLines buffer
|
||||||
|
, #rightStrings buffer
|
||||||
|
, #rightLines buffer
|
||||||
|
)
|
||||||
|
in
|
||||||
|
verifyLineList (strings, lines)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local
|
local
|
||||||
fun helpToString (acc, input) =
|
fun helpToString (acc, input) =
|
||||||
case input of
|
case input of
|
||||||
@@ -947,7 +999,8 @@ struct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun println str = print (str ^ "\n")
|
fun println str =
|
||||||
|
print (str ^ "\n")
|
||||||
|
|
||||||
(* Delete function and helper functions for it. *)
|
(* Delete function and helper functions for it. *)
|
||||||
local
|
local
|
||||||
@@ -968,6 +1021,9 @@ struct
|
|||||||
in
|
in
|
||||||
if nextIdx < finish then
|
if nextIdx < finish then
|
||||||
(* Keep moving right. *)
|
(* Keep moving right. *)
|
||||||
|
let
|
||||||
|
val _ = println "971"
|
||||||
|
in
|
||||||
deleteRightFromHere
|
deleteRightFromHere
|
||||||
( origIdx
|
( origIdx
|
||||||
, origLine
|
, origLine
|
||||||
@@ -978,6 +1034,7 @@ struct
|
|||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
)
|
)
|
||||||
|
end
|
||||||
else if nextIdx > finish then
|
else if nextIdx > finish then
|
||||||
(* 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
|
||||||
@@ -1089,6 +1146,9 @@ struct
|
|||||||
)
|
)
|
||||||
val newLeftStrings = newLeftStringsHd :: leftStringsTl
|
val newLeftStrings = newLeftStringsHd :: leftStringsTl
|
||||||
val newLeftLines = newLeftLinesHd :: leftLinesTl
|
val newLeftLines = newLeftLinesHd :: leftLinesTl
|
||||||
|
in
|
||||||
|
let
|
||||||
|
val _ = println "1093"
|
||||||
in
|
in
|
||||||
moveRightAndDelete
|
moveRightAndDelete
|
||||||
( start
|
( start
|
||||||
@@ -1101,8 +1161,12 @@ struct
|
|||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
(* Can't join heads while staying in limit, so just cons. *)
|
(* Can't join heads while staying in limit, so just cons. *)
|
||||||
|
let
|
||||||
|
val _ = println "1108"
|
||||||
|
in
|
||||||
moveRightAndDelete
|
moveRightAndDelete
|
||||||
( start
|
( start
|
||||||
, finish
|
, finish
|
||||||
@@ -1113,8 +1177,12 @@ struct
|
|||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
)
|
)
|
||||||
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* Can't join heads while staying in limit, so just cons. *)
|
(* Can't join heads while staying in limit, so just cons. *)
|
||||||
|
let
|
||||||
|
val _ = println "1121"
|
||||||
|
in
|
||||||
moveRightAndDelete
|
moveRightAndDelete
|
||||||
( start
|
( start
|
||||||
, finish
|
, finish
|
||||||
@@ -1124,7 +1192,8 @@ struct
|
|||||||
, rightLinesHd :: leftLines
|
, rightLinesHd :: leftLines
|
||||||
, rightStringsTl
|
, rightStringsTl
|
||||||
, rightLinesTl
|
, rightLinesTl
|
||||||
))
|
)
|
||||||
|
end)
|
||||||
else if nextIdx > start then
|
else if nextIdx > start then
|
||||||
if nextIdx < finish then
|
if nextIdx < finish then
|
||||||
(* Start deleting from the end of this string,
|
(* Start deleting from the end of this string,
|
||||||
@@ -1239,13 +1308,16 @@ struct
|
|||||||
val sub2LineStart = forwardBinSearch (sub2Start, rightLinesHd)
|
val sub2LineStart = forwardBinSearch (sub2Start, rightLinesHd)
|
||||||
val sub2Lines =
|
val sub2Lines =
|
||||||
if sub2LineStart < Vector.length rightLinesHd then
|
if sub2LineStart < Vector.length rightLinesHd then
|
||||||
let val _ = println "1242" in
|
let
|
||||||
|
val _ = println "1242"
|
||||||
|
in
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
( Vector.length rightLinesHd - Vector.length sub1Lines
|
( Vector.length rightLinesHd - Vector.length sub1Lines
|
||||||
, fn idx =>
|
, fn idx =>
|
||||||
Vector.sub (rightLinesHd, idx + sub2LineStart)
|
Vector.sub (rightLinesHd, idx + sub2LineStart)
|
||||||
- (String.size rightStringsHd - String.size sub2)
|
- (String.size rightStringsHd - String.size sub2)
|
||||||
) end
|
)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Vector.fromList []
|
Vector.fromList []
|
||||||
in
|
in
|
||||||
@@ -1441,6 +1513,9 @@ struct
|
|||||||
in
|
in
|
||||||
if start < prevIdx then
|
if start < prevIdx then
|
||||||
(* Continue deleting leftward. *)
|
(* Continue deleting leftward. *)
|
||||||
|
let
|
||||||
|
val _ = println "1449"
|
||||||
|
in
|
||||||
deleteLeftFromHere
|
deleteLeftFromHere
|
||||||
( start
|
( start
|
||||||
, prevIdx
|
, prevIdx
|
||||||
@@ -1450,6 +1525,7 @@ struct
|
|||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
)
|
)
|
||||||
|
end
|
||||||
else if start > prevIdx then
|
else if start > prevIdx then
|
||||||
(* Base case: delete end part of this string and return. *)
|
(* Base case: delete end part of this string and return. *)
|
||||||
let
|
let
|
||||||
@@ -1585,6 +1661,9 @@ struct
|
|||||||
)
|
)
|
||||||
val newRightStrings = newRightStringsHd :: rightStringsTl
|
val newRightStrings = newRightStringsHd :: rightStringsTl
|
||||||
val newRightLines = newRightLinesHd :: rightLinesTl
|
val newRightLines = newRightLinesHd :: rightLinesTl
|
||||||
|
in
|
||||||
|
let
|
||||||
|
val _ = println "1595"
|
||||||
in
|
in
|
||||||
moveLeftAndDelete
|
moveLeftAndDelete
|
||||||
( start
|
( start
|
||||||
@@ -1597,8 +1676,12 @@ struct
|
|||||||
, newRightLines
|
, newRightLines
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
(* Cannot join while staying in limit, so don't. *)
|
(* Cannot join while staying in limit, so don't. *)
|
||||||
|
let
|
||||||
|
val _ = println "1609"
|
||||||
|
in
|
||||||
moveLeftAndDelete
|
moveLeftAndDelete
|
||||||
( start
|
( start
|
||||||
, finish
|
, finish
|
||||||
@@ -1609,6 +1692,7 @@ struct
|
|||||||
, leftStringsHd :: rightStrings
|
, leftStringsHd :: rightStrings
|
||||||
, leftLinesHd :: rightLines
|
, leftLinesHd :: rightLines
|
||||||
)
|
)
|
||||||
|
end
|
||||||
| (_, _) =>
|
| (_, _) =>
|
||||||
(* 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. *)
|
||||||
@@ -1675,6 +1759,7 @@ struct
|
|||||||
)
|
)
|
||||||
|
|
||||||
val sub1Lines =
|
val sub1Lines =
|
||||||
|
if Vector.length leftLinesHd > 0 then
|
||||||
let
|
let
|
||||||
val midpoint = binSearch
|
val midpoint = binSearch
|
||||||
(String.size sub1 - 1, leftLinesHd)
|
(String.size sub1 - 1, leftLinesHd)
|
||||||
@@ -1682,30 +1767,60 @@ struct
|
|||||||
if midpoint >= 0 then
|
if midpoint >= 0 then
|
||||||
let
|
let
|
||||||
val _ = println "1684"
|
val _ = println "1684"
|
||||||
|
val _ = println
|
||||||
|
("midpoint: " ^ Int.toString midpoint)
|
||||||
|
val _ = println
|
||||||
|
("lenth: "
|
||||||
|
^ Int.toString (Vector.length leftLinesHd))
|
||||||
val slice = VectorSlice.slice
|
val slice = VectorSlice.slice
|
||||||
(leftLinesHd, 0, SOME (midpoint))
|
(leftLinesHd, 0, SOME (midpoint + 1))
|
||||||
in
|
in
|
||||||
VectorSlice.vector slice
|
VectorSlice.vector slice
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Vector.fromList []
|
Vector.fromList []
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
leftLinesHd
|
||||||
|
|
||||||
|
val realsub1lines = countLineBreaks sub1
|
||||||
|
val _ =
|
||||||
|
if realsub1lines = sub1Lines then
|
||||||
|
()
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val _ = println "realsub1lines error"
|
||||||
|
val _ = checkLineBreaks (sub1Lines, realsub1lines)
|
||||||
|
val _ = println "after realsub1lines error"
|
||||||
|
in
|
||||||
|
()
|
||||||
|
end
|
||||||
|
|
||||||
val sub2Lines =
|
val sub2Lines =
|
||||||
let
|
let
|
||||||
val midpoint = forwardBinSearch (sub2Start, leftLinesHd)
|
val midpoint = forwardBinSearch (sub2Start, leftLinesHd)
|
||||||
val _ = println "1697"
|
val _ = println "1697"
|
||||||
|
val _ = println
|
||||||
|
("leftLinesHd: "
|
||||||
|
^ Int.toString (Vector.length leftLinesHd))
|
||||||
|
val _ = println ("midpoint: " ^ Int.toString (midpoint))
|
||||||
in
|
in
|
||||||
if midpoint < Vector.length leftLinesHd then
|
if midpoint < Vector.length leftLinesHd then
|
||||||
Vector.tabulate
|
Vector.tabulate
|
||||||
( Vector.length leftLinesHd - midpoint
|
( Vector.length leftLinesHd - midpoint
|
||||||
, fn idx =>
|
, fn idx =>
|
||||||
Vector.sub (leftLinesHd, idx + midpoint)
|
Vector.sub (leftLinesHd, idx + (midpoint))
|
||||||
- sub2Start
|
- sub2Start
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
Vector.fromList []
|
Vector.fromList []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
val realsub2lines = countLineBreaks sub2
|
||||||
|
val _ =
|
||||||
|
if realsub2lines = sub2Lines then ()
|
||||||
|
else println "realsub2lines error"
|
||||||
|
|
||||||
in
|
in
|
||||||
{ idx = prevIdx + String.size sub1
|
{ idx = prevIdx + String.size sub1
|
||||||
, line =
|
, line =
|
||||||
@@ -1883,7 +1998,6 @@ struct
|
|||||||
, rightStrings
|
, rightStrings
|
||||||
, rightLines
|
, rightLines
|
||||||
)
|
)
|
||||||
|
|
||||||
in
|
in
|
||||||
fun delete (start, length, buffer: t) =
|
fun delete (start, length, buffer: t) =
|
||||||
if length > 0 then
|
if length > 0 then
|
||||||
@@ -1901,58 +2015,4 @@ struct
|
|||||||
buffer
|
buffer
|
||||||
end
|
end
|
||||||
|
|
||||||
(* TEST CODE *)
|
|
||||||
local
|
|
||||||
fun lineBreaksToString vec =
|
|
||||||
(Vector.foldr (fn (el, acc) => Int.toString el ^ ", " ^ acc) "" vec)
|
|
||||||
^ "\n"
|
|
||||||
|
|
||||||
fun checkLineBreaks (v1, v2) =
|
|
||||||
if v1 = v2 then
|
|
||||||
()
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val _ = print ("broken: " ^ (lineBreaksToString v1))
|
|
||||||
val _ = print ("fixed: " ^ (lineBreaksToString v2))
|
|
||||||
in
|
|
||||||
()
|
|
||||||
end
|
|
||||||
|
|
||||||
fun goToStart (leftStrings, leftLines, accStrings, accLines) =
|
|
||||||
case (leftStrings, leftLines) of
|
|
||||||
(lsHd :: lsTl, llHd :: llTl) =>
|
|
||||||
goToStart (lsTl, llTl, lsHd :: accStrings, llHd :: accLines)
|
|
||||||
| (_, _) => (accStrings, accLines)
|
|
||||||
|
|
||||||
fun verifyLineList (strings, lines) =
|
|
||||||
case (strings, lines) of
|
|
||||||
(strHd :: strTl, lHd :: lTl) =>
|
|
||||||
let
|
|
||||||
val checkLines = countLineBreaks strHd
|
|
||||||
in
|
|
||||||
if checkLines = lHd then
|
|
||||||
verifyLineList (strTl, lTl)
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val _ = print "line metadata is incorrect\n"
|
|
||||||
val _ = checkLineBreaks (lHd, checkLines)
|
|
||||||
in
|
|
||||||
raise Empty
|
|
||||||
end
|
|
||||||
end
|
|
||||||
| (_, _) => print "verified lines; no problems\n"
|
|
||||||
in
|
|
||||||
fun verifyLines (buffer: t) =
|
|
||||||
let
|
|
||||||
val (strings, lines) =
|
|
||||||
goToStart
|
|
||||||
( #leftStrings buffer
|
|
||||||
, #leftLines buffer
|
|
||||||
, #rightStrings buffer
|
|
||||||
, #rightLines buffer
|
|
||||||
)
|
|
||||||
in
|
|
||||||
verifyLineList (strings, lines)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ struct
|
|||||||
val gapBuffer =
|
val gapBuffer =
|
||||||
if strSize > 0 then LineGap.insert (pos, insStr, gapBuffer)
|
if strSize > 0 then LineGap.insert (pos, insStr, gapBuffer)
|
||||||
else gapBuffer
|
else gapBuffer
|
||||||
|
val _ = LineGap.verifyLines gapBuffer
|
||||||
|
|
||||||
val ropeString = TinyRope.toString rope
|
val ropeString = TinyRope.toString rope
|
||||||
val gapBufferString = LineGap.toString gapBuffer
|
val gapBufferString = LineGap.toString gapBuffer
|
||||||
|
|||||||
Reference in New Issue
Block a user