fix backtracking bug in 'Nfa.getMatchesInRange' (we were passing the wrong value instead of 'strIdx' in the recursive call to the loop function)
This commit is contained in:
@@ -238,9 +238,14 @@ struct
|
||||
| [] => empty
|
||||
end
|
||||
|
||||
fun buildRange (buffer, searchString, finish) =
|
||||
fun buildRange (buffer, searchString, finishIdx) =
|
||||
if String.size searchString > 0 then
|
||||
searchRange (buffer, searchString, finish)
|
||||
let
|
||||
val nfa = Nfa.parse searchString
|
||||
val startIdx = #idx buffer
|
||||
in
|
||||
Nfa.getMatchesInRange (startIdx, finishIdx, buffer : LineGap.t, nfa)
|
||||
end
|
||||
else
|
||||
empty
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ struct
|
||||
val prevIdx = absIdx - String.size prevHd
|
||||
val tl = hd :: tl
|
||||
in
|
||||
if prevIdx < startIdx then
|
||||
if startIdx < prevIdx then
|
||||
(* keep backtracking *)
|
||||
backtrackRange
|
||||
( prevHd
|
||||
@@ -243,7 +243,7 @@ struct
|
||||
case state of
|
||||
UNTESTED =>
|
||||
loop
|
||||
( startIdx + 1
|
||||
( strIdx + 1
|
||||
, hd
|
||||
, tl
|
||||
, prevStrings
|
||||
@@ -259,7 +259,7 @@ struct
|
||||
val acc = PersistentVector.append (startIdx, acc)
|
||||
in
|
||||
loop
|
||||
( startIdx + 1
|
||||
( strIdx + 1
|
||||
, hd
|
||||
, tl
|
||||
, prevStrings
|
||||
@@ -275,7 +275,7 @@ struct
|
||||
let
|
||||
val prevIdx = absIdx - strIdx
|
||||
in
|
||||
if prevIdx < startIdx then
|
||||
if startIdx < prevIdx then
|
||||
backtrackRange
|
||||
( hd
|
||||
, tl
|
||||
@@ -289,7 +289,7 @@ struct
|
||||
else
|
||||
let
|
||||
val strIdx = startIdx - prevIdx + 1
|
||||
val absIdx = absIdx + strIdx
|
||||
val absIdx = prevIdx + strIdx
|
||||
in
|
||||
loop
|
||||
( strIdx
|
||||
@@ -474,4 +474,5 @@ struct
|
||||
|
||||
val parse = ParseNfa.parse
|
||||
val getMatches = NfaMatch.getMatches
|
||||
val getMatchesInRange = NfaMatch.getMatchesInRange
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user