parse wildcard . character for NFA too

This commit is contained in:
2025-09-30 14:05:39 +01:00
parent 5fa784b4c6
commit b52b5ff28c

View File

@@ -10,6 +10,7 @@ struct
| ZERO_OR_MORE of regex * state | ZERO_OR_MORE of regex * state
| ONE_OR_MORE of regex * state | ONE_OR_MORE of regex * state
| GROUP of regex * state | GROUP of regex * state
| WILDCARD of state
fun getState regex = fun getState regex =
case regex of case regex of
@@ -20,6 +21,7 @@ struct
| ZERO_OR_MORE (_, state) => state | ZERO_OR_MORE (_, state) => state
| ONE_OR_MORE (_, state) => state | ONE_OR_MORE (_, state) => state
| GROUP (_, state) => state | GROUP (_, state) => state
| WILDCARD state => state
structure NfaMatch = structure NfaMatch =
struct struct
@@ -321,19 +323,23 @@ struct
if level < concatLevel then if level < concatLevel then
SOME (pos, lhs) SOME (pos, lhs)
else else
case let
climb (pos + 1, str, CHAR_LITERAL (chr, UNTESTED), concatLevel) val currentState =
of if chr = #"." then WILDCARD UNTESTED
SOME (pos, rhs) => else CHAR_LITERAL (chr, UNTESTED)
let in
val result = case climb (pos + 1, str, currentState, concatLevel) of
case rhs of SOME (pos, rhs) =>
CONCAT (lst, _) => CONCAT (lhs :: lst, UNTESTED) let
| _ => CONCAT ([lhs, rhs], UNTESTED) val result =
in case rhs of
SOME (pos, result) CONCAT (lst, _) => CONCAT (lhs :: lst, UNTESTED)
end | _ => CONCAT ([lhs, rhs], UNTESTED)
| NONE => NONE in
SOME (pos, result)
end
| NONE => NONE
end
and loop (pos, str, ast) = and loop (pos, str, ast) =
if pos = String.size str then if pos = String.size str then