begin functorising some char-iteration functions

This commit is contained in:
2025-08-03 16:34:31 +01:00
parent 473ea8e35d
commit b8a5df814e

View File

@@ -57,26 +57,18 @@ 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 (absIdx - 2, 0) val tables = tables
else
let fun finish x = x
val chr = String.sub (str, idx) fun isFinal currentState =
val newState = next (currentState, chr) currentState = nonBlankAfterSpaceState
in end)
if newState = nonBlankAfterSpaceState then
if counter - 1 = 0 then val fStart = Folder.foldNext
absIdx
else
(* new loop, so reset to start state and proceed *)
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 =
@@ -84,28 +76,18 @@ struct
(struct (struct
val startState = startState val startState = startState
fun fStart (idx, absIdx, str, tl, currentState, counter) = structure Folder =
if idx < 0 then MakeCharFolderNext
case tl of (struct
str :: tl => val startState = startState
fStart val tables = tables
(String.size str - 1, absIdx, str, tl, currentState, counter)
| [] => 0 fun finish x = x
else fun isFinal currentState =
let currentState = nonBlankAfterSpaceState
val chr = String.sub (str, idx) end)
val newState = next (currentState, chr)
in val fStart = Folder.foldNext
if newState = nonBlankAfterSpaceState then
if counter - 1 = 0 then
absIdx
else
(* reset to start state and proceed *)
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) =