add function to verify line metadata in rope.sml

This commit is contained in:
2024-03-14 08:07:12 +00:00
parent e991156a3a
commit 3f768bab4e
2 changed files with 18 additions and 1 deletions

View File

@@ -10,4 +10,5 @@ in
end
tiny_rope.sml
rope.sml
utils.sml

View File

@@ -5,6 +5,11 @@ sig
val fromString: string -> t
val foldr: ('a * string * int vector -> 'a) * 'a * t -> 'a
val insert: int * string * t -> t
(* This below function verifies that line metadata is as expected,
* raising an exception if it is different,
* and returning true if it is the same. *)
val verifyLines: t -> bool
end
structure Rope :> ROPE =
@@ -438,7 +443,6 @@ struct
(node, DeletedNode)
end
fun ins (curIdx, newStr, newVec, rope) =
case rope of
N2 (l, lms, lmv, r) =>
@@ -500,4 +504,16 @@ struct
| DeletedNode => delRoot rope)
end
fun verifyLines rope =
foldr
( (fn (_, str, vec) =>
let
val strVec = countLineBreaks str
val isSame = strVec = vec
in
if isSame then true else raise Empty
end)
, true
, rope
)
end