when deleting from buffer and search list both, don't try to find any matches if the DFA is empty (has a length of 0), because that means there is no search to find a match for
This commit is contained in:
@@ -146,6 +146,21 @@ struct
|
|||||||
end
|
end
|
||||||
else if PersistentVector.isInRange (idx, searchList) then
|
else if PersistentVector.isInRange (idx, searchList) then
|
||||||
(buffer, searchList)
|
(buffer, searchList)
|
||||||
|
else if Dfa.isDead curState then
|
||||||
|
if prevFinalPos = ~1 then
|
||||||
|
(* no match found: restart search from `startPos + 1` *)
|
||||||
|
insertUntilMatch
|
||||||
|
(startPos + 1, buffer, searchList, dfa, 0, startPos + 1, ~1)
|
||||||
|
else
|
||||||
|
(* new match. Insert and continue *)
|
||||||
|
let
|
||||||
|
val searchList =
|
||||||
|
PersistentVector.insertMatchKeepingAbsoluteInddices
|
||||||
|
(startPos, prevFinalPos, searchList)
|
||||||
|
val newStart = prevFinalPos + 1
|
||||||
|
in
|
||||||
|
insertUntilMatch (newStart, buffer, searchList, dfa, 0, newStart, ~1)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val buffer = LineGap.goToIdx (idx, buffer)
|
val buffer = LineGap.goToIdx (idx, buffer)
|
||||||
@@ -154,26 +169,9 @@ struct
|
|||||||
val prevFinalPos =
|
val prevFinalPos =
|
||||||
if Dfa.isFinal (dfa, newState) then idx else prevFinalPos
|
if Dfa.isFinal (dfa, newState) then idx else prevFinalPos
|
||||||
in
|
in
|
||||||
if Dfa.isDead newState then
|
(* continue *)
|
||||||
if prevFinalPos = ~1 then
|
insertUntilMatch
|
||||||
(* no match found: restart search from `startPos + 1` *)
|
(idx + 1, buffer, searchList, dfa, newState, startPos, prevFinalPos)
|
||||||
insertUntilMatch
|
|
||||||
(startPos + 1, buffer, searchList, dfa, 0, startPos + 1, ~1)
|
|
||||||
else
|
|
||||||
(* new match. Insert and continue *)
|
|
||||||
let
|
|
||||||
val searchList =
|
|
||||||
PersistentVector.insertMatchKeepingAbsoluteInddices
|
|
||||||
(startPos, prevFinalPos, searchList)
|
|
||||||
val newStart = prevFinalPos + 1
|
|
||||||
in
|
|
||||||
insertUntilMatch
|
|
||||||
(newStart, buffer, searchList, dfa, 0, newStart, ~1)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
(* continue *)
|
|
||||||
insertUntilMatch
|
|
||||||
(idx + 1, buffer, searchList, dfa, newState, startPos, prevFinalPos)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun tryExtendingPrevMatch
|
fun tryExtendingPrevMatch
|
||||||
@@ -223,7 +221,10 @@ struct
|
|||||||
PersistentVector.helpPrevMatch (start, searchList, 0)
|
PersistentVector.helpPrevMatch (start, searchList, 0)
|
||||||
val searchStart = searchStart + 1
|
val searchStart = searchStart + 1
|
||||||
in
|
in
|
||||||
insertUntilMatch
|
if Vector.length dfa = 0 then
|
||||||
(searchStart, buffer, searchList, dfa, 0, searchStart, ~1)
|
(buffer, searchList)
|
||||||
|
else
|
||||||
|
insertUntilMatch
|
||||||
|
(searchStart, buffer, searchList, dfa, 0, searchStart, ~1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user