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:
2025-09-29 13:13:14 +01:00
parent b6720ed5f1
commit 7dc94632d6
2 changed files with 13 additions and 7 deletions

View File

@@ -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