begin functorins vi word char iterators

This commit is contained in:
2025-08-03 17:01:50 +01:00
parent cf93d5885f
commit cd6ce4ffcc

View File

@@ -91,29 +91,21 @@ struct
(struct (struct
val startState = startState val startState = startState
fun fStart (idx, absIdx, str, tl, currentState, counter) = structure Folder =
if idx = String.size str then MakeCharFolderNext
case tl of (struct
str :: tl => fStart (0, absIdx, str, tl, currentState, counter) val startState = startState
| [] => Int.max (0, absIdx - 2) val tables = tables
else
let fun isFinal currentState =
val chr = String.sub (str, idx) currentState = alphaToPunct orelse currentState = punctToAlpha
val newState = next (currentState, chr) orelse currentState = spaceToAlpha
in orelse currentState = spaceToPunct
if
newState = alphaToPunct orelse newState = punctToAlpha fun finish x = x
orelse newState = spaceToAlpha orelse newState = spaceToPunct end)
then
if counter - 1 = 0 then val fStart = Folder.foldNext
absIdx
else
(* reset state *)
fStart
(idx + 1, absIdx + 1, str, tl, startState, counter - 1)
else
fStart (idx + 1, absIdx + 1, str, tl, newState, counter)
end
end) end)
structure EndOfPrevWord = structure EndOfPrevWord =
@@ -121,30 +113,21 @@ struct
(struct (struct
val startState = startState val startState = startState
fun fStart (idx, absIdx, str, tl, currentState, counter) = structure Folder =
if idx < 0 then MakeCharFolderPrev
case tl of (struct
str :: tl => val startState = startState
fStart val tables = tables
(String.size str - 1, absIdx, str, tl, currentState, counter)
| [] => 0 fun isFinal currentState =
else currentState = alphaToPunct orelse currentState = punctToAlpha
let orelse currentState = spaceToAlpha
val chr = String.sub (str, idx) orelse currentState = spaceToPunct
val newState = next (currentState, chr)
in fun finish x = x
if end)
newState = alphaToPunct orelse newState = punctToAlpha
orelse newState = spaceToAlpha orelse newState = spaceToPunct val fStart = Folder.foldPrev
then
if counter - 1 = 0 then
absIdx
else
fStart
(idx - 1, absIdx - 1, str, tl, startState, counter - 1)
else
fStart (idx - 1, absIdx - 1, str, tl, newState, counter)
end
end) end)
fun startOfCurrentWord (idx, absIdx, str, tl, currentState, counter) = fun startOfCurrentWord (idx, absIdx, str, tl, currentState, counter) =