progress functorising text builder

This commit is contained in:
2025-08-17 17:15:15 +01:00
parent 28593486ed
commit 3e67d90512
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
signature MAKE_TEXT_BUILDER =
sig
type state
type env
type pos_data =
{chr: char, strIdx: int, absIdx: int, hd: string, tl: string list}
val folder: pos_data * env * state -> state
val stopFold: state -> bool
end
functor MakeTextBuilder(Fn: MAKE_TEXT_BUILDER) =
struct
fun buildLoop (strIdx, absIdx, hd, tl, env, state) =
if Fn.stopFold state then
state
else if strIdx = String.size hd then
case tl of
hd :: tl => buildLoop (0, absIdx, hd, tl, env, state)
| [] => state
else
let
val chr = String.sub (hd, strIdx)
val posData =
{chr = chr, strIdx = strIdx, absIdx = absIdx, hd = hd, tl = tl}
val state = Fn.folder (posData, env, state)
in
buildLoop (strIdx + 1, absIdx + 1, hd, tl, env, state)
end
end