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
|
| [] => empty
|
||||||
end
|
end
|
||||||
|
|
||||||
fun buildRange (buffer, searchString, finish) =
|
fun buildRange (buffer, searchString, finishIdx) =
|
||||||
if String.size searchString > 0 then
|
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
|
else
|
||||||
empty
|
empty
|
||||||
|
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ struct
|
|||||||
val prevIdx = absIdx - String.size prevHd
|
val prevIdx = absIdx - String.size prevHd
|
||||||
val tl = hd :: tl
|
val tl = hd :: tl
|
||||||
in
|
in
|
||||||
if prevIdx < startIdx then
|
if startIdx < prevIdx then
|
||||||
(* keep backtracking *)
|
(* keep backtracking *)
|
||||||
backtrackRange
|
backtrackRange
|
||||||
( prevHd
|
( prevHd
|
||||||
@@ -243,7 +243,7 @@ struct
|
|||||||
case state of
|
case state of
|
||||||
UNTESTED =>
|
UNTESTED =>
|
||||||
loop
|
loop
|
||||||
( startIdx + 1
|
( strIdx + 1
|
||||||
, hd
|
, hd
|
||||||
, tl
|
, tl
|
||||||
, prevStrings
|
, prevStrings
|
||||||
@@ -259,7 +259,7 @@ struct
|
|||||||
val acc = PersistentVector.append (startIdx, acc)
|
val acc = PersistentVector.append (startIdx, acc)
|
||||||
in
|
in
|
||||||
loop
|
loop
|
||||||
( startIdx + 1
|
( strIdx + 1
|
||||||
, hd
|
, hd
|
||||||
, tl
|
, tl
|
||||||
, prevStrings
|
, prevStrings
|
||||||
@@ -275,7 +275,7 @@ struct
|
|||||||
let
|
let
|
||||||
val prevIdx = absIdx - strIdx
|
val prevIdx = absIdx - strIdx
|
||||||
in
|
in
|
||||||
if prevIdx < startIdx then
|
if startIdx < prevIdx then
|
||||||
backtrackRange
|
backtrackRange
|
||||||
( hd
|
( hd
|
||||||
, tl
|
, tl
|
||||||
@@ -289,7 +289,7 @@ struct
|
|||||||
else
|
else
|
||||||
let
|
let
|
||||||
val strIdx = startIdx - prevIdx + 1
|
val strIdx = startIdx - prevIdx + 1
|
||||||
val absIdx = absIdx + strIdx
|
val absIdx = prevIdx + strIdx
|
||||||
in
|
in
|
||||||
loop
|
loop
|
||||||
( strIdx
|
( strIdx
|
||||||
@@ -474,4 +474,5 @@ struct
|
|||||||
|
|
||||||
val parse = ParseNfa.parse
|
val parse = ParseNfa.parse
|
||||||
val getMatches = NfaMatch.getMatches
|
val getMatches = NfaMatch.getMatches
|
||||||
|
val getMatchesInRange = NfaMatch.getMatchesInRange
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user