adjust nfa to return all matches in string, instead of just testing for one match and then returning true
This commit is contained in:
BIN
fcore/search-list/nfa
Executable file
BIN
fcore/search-list/nfa
Executable file
Binary file not shown.
@@ -135,25 +135,28 @@ struct
|
|||||||
| _ =>
|
| _ =>
|
||||||
raise Fail "nfa.sml 69: not char literal or concat or alternation"
|
raise Fail "nfa.sml 69: not char literal or concat or alternation"
|
||||||
|
|
||||||
fun loop (pos, str, nfa, origNfa, startPos) =
|
fun loop (pos, str, nfa, origNfa, startPos, acc) =
|
||||||
if pos = String.size str then
|
if pos = String.size str then
|
||||||
false
|
PersistentVector.toVector acc
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val chr = String.sub (str, pos)
|
val chr = String.sub (str, pos)
|
||||||
val (nfa, state) = rebuild (nfa, chr, pos)
|
val (nfa, state) = rebuild (nfa, chr, pos)
|
||||||
in
|
in
|
||||||
case state of
|
case state of
|
||||||
VALID _ => true
|
VALID finishIdx =>
|
||||||
|
let val acc = PersistentVector.append (pos, acc)
|
||||||
|
in loop (finishIdx, str, origNfa, origNfa, finishIdx, acc)
|
||||||
|
end
|
||||||
| INVALID =>
|
| INVALID =>
|
||||||
(* backtrack to another position in the string
|
(* backtrack to another position in the string
|
||||||
* to see if the NFA matches that portion of the string *)
|
* to see if the NFA matches that portion of the string *)
|
||||||
loop (startPos + 1, str, origNfa, origNfa, startPos + 1)
|
loop (startPos + 1, str, origNfa, origNfa, startPos + 1, acc)
|
||||||
| UNTESTED => loop (pos + 1, str, nfa, origNfa, startPos)
|
| UNTESTED => loop (pos + 1, str, nfa, origNfa, startPos, acc)
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
fun hasAnyMatch (str, nfa) =
|
fun getMatches (str, nfa) =
|
||||||
loop (0, str, nfa, nfa, 0)
|
loop (0, str, nfa, nfa, 0, PersistentVector.empty)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -275,5 +278,5 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
val parse = ParseNfa.parse
|
val parse = ParseNfa.parse
|
||||||
val hasAnyMatch = NfaMatch.hasAnyMatch
|
val getMatches = NfaMatch.getMatches
|
||||||
end
|
end
|
||||||
|
|||||||
1
shf.mlb
1
shf.mlb
@@ -19,6 +19,7 @@ end
|
|||||||
|
|
||||||
fcore/escape-string.sml
|
fcore/escape-string.sml
|
||||||
fcore/bin-search.sml
|
fcore/bin-search.sml
|
||||||
|
fcore/search-list/nfa.sml
|
||||||
fcore/search-list.sml
|
fcore/search-list.sml
|
||||||
|
|
||||||
fcore/app-type.sml
|
fcore/app-type.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user