minor bug fix: when we start looping backwards in a DFA and the rightStrings is empty, start iterating from leftStrings if possible

This commit is contained in:
2025-09-16 03:05:33 +01:00
parent 820a6c2462
commit 0793744e24

View File

@@ -60,6 +60,12 @@ end
functor MakePrevDfaLoop(M: MAKE_DFA_LOOP) = functor MakePrevDfaLoop(M: MAKE_DFA_LOOP) =
struct struct
fun startLeftStrings (leftStrings, absIdx, count) =
case leftStrings of
lhd :: ltl =>
M.fStart (String.size lhd - 1, absIdx, lhd, ltl, M.startState, count)
| [] => 0
fun prev (lineGap: LineGap.t, cursorIdx, count) = fun prev (lineGap: LineGap.t, cursorIdx, count) =
let let
val {rightStrings, leftStrings, idx = bufferIdx, ...} = lineGap val {rightStrings, leftStrings, idx = bufferIdx, ...} = lineGap
@@ -88,13 +94,19 @@ struct
, count , count
) )
end end
| [] => cursorIdx) | [] => startLeftStrings (leftStrings, cursorIdx, count))
| [] => cursorIdx | [] => startLeftStrings (leftStrings, cursorIdx, count)
end end
end end
functor MakePrevDfaLoopMinus1(M: MAKE_DFA_LOOP) = functor MakePrevDfaLoopMinus1(M: MAKE_DFA_LOOP) =
struct struct
fun startLeftStrings (leftStrings, absIdx, count) =
case leftStrings of
lhd :: ltl =>
M.fStart (String.size lhd - 1, absIdx, lhd, ltl, M.startState, count)
| [] => 0
fun prev (lineGap: LineGap.t, cursorIdx, count) = fun prev (lineGap: LineGap.t, cursorIdx, count) =
let let
val {idx = bufferIdx, leftStrings, ...} = lineGap val {idx = bufferIdx, leftStrings, ...} = lineGap
@@ -102,16 +114,12 @@ struct
val absIdx = cursorIdx - 1 val absIdx = cursorIdx - 1
in in
if strIdx < 0 then if strIdx < 0 then
case leftStrings of startLeftStrings (leftStrings, absIdx, count)
lhd :: ltl =>
M.fStart
(String.size lhd - 1, absIdx, lhd, ltl, M.startState, count)
| [] => 0
else else
case #rightStrings lineGap of case #rightStrings lineGap of
rhd :: _ => rhd :: _ =>
M.fStart (strIdx, absIdx, rhd, leftStrings, M.startState, count) M.fStart (strIdx, absIdx, rhd, leftStrings, M.startState, count)
| [] => Int.max (0, cursorIdx - 2) | [] => startLeftStrings (leftStrings, absIdx, count)
end end
end end