handle edge case when building dfa from a string, where an exception was raised when our search regex contains an alternation where the second alternation is a substring of the first alternation, and add a test for it to make sure that it passes

This commit is contained in:
2025-10-14 02:24:45 +01:00
parent be7a9b3035
commit 22a8b807d2
2 changed files with 18 additions and 1 deletions

View File

@@ -729,13 +729,21 @@ struct
in in
Vector.concat [dtran, el] Vector.concat [dtran, el]
end end
else else if dStateIdx < Vector.length dtran then
let let
val el = Vector.sub (dtran, dStateIdx) val el = Vector.sub (dtran, dStateIdx)
val el = Set.insertOrReplace (char, toStateIdx, el) val el = Set.insertOrReplace (char, toStateIdx, el)
in in
Vector.update (dtran, dStateIdx, el) Vector.update (dtran, dStateIdx, el)
end end
else
let
val appendLength = dStateIdx - Vector.length dtran
val appendVecs = Vector.tabulate (appendLength, fn _ => Set.LEAF)
val dtran = Vector.concat [dtran, appendVecs]
in
insert (dStateIdx, char, toStateIdx, dtran)
end
end end
fun convertChar fun convertChar

View File

@@ -67,6 +67,15 @@ struct
in in
Expect.isTrue true Expect.isTrue true
end) end)
, test
"DfaGen does not cause exception \
\when parsing alternation that contains a char \
\from the previous alternation (1)"
(fn _ =>
(let val dfa = CaseSensitiveDfa.fromString "str|s"
in Expect.isTrue true
end)
handle _ => Expect.isTrue false)
] ]
val tests = [charEventTests] val tests = [charEventTests]