From b8a5df814eca37c64ea492e11568ae2e7f90c991 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 3 Aug 2025 16:34:31 +0100 Subject: [PATCH] begin functorising some char-iteration functions --- fcore/cursor-dfa/vi-WORD-dfa.sml | 66 ++++++++++++-------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/fcore/cursor-dfa/vi-WORD-dfa.sml b/fcore/cursor-dfa/vi-WORD-dfa.sml index 952ab87..39676f1 100644 --- a/fcore/cursor-dfa/vi-WORD-dfa.sml +++ b/fcore/cursor-dfa/vi-WORD-dfa.sml @@ -57,26 +57,18 @@ struct (struct val startState = startState - fun fStart (idx, absIdx, str, tl, currentState, counter) = - if idx = String.size str then - case tl of - str :: tl => fStart (0, absIdx, str, tl, currentState, counter) - | [] => Int.max (absIdx - 2, 0) - else - let - val chr = String.sub (str, idx) - val newState = next (currentState, chr) - in - if newState = nonBlankAfterSpaceState then - if counter - 1 = 0 then - 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 + structure Folder = + MakeCharFolderNext + (struct + val startState = startState + val tables = tables + + fun finish x = x + fun isFinal currentState = + currentState = nonBlankAfterSpaceState + end) + + val fStart = Folder.foldNext end) structure EndOfPrevWORD = @@ -84,28 +76,18 @@ struct (struct val startState = startState - fun fStart (idx, absIdx, str, tl, currentState, counter) = - if idx < 0 then - case tl of - str :: tl => - fStart - (String.size str - 1, absIdx, str, tl, currentState, counter) - | [] => 0 - else - let - val chr = String.sub (str, idx) - val newState = next (currentState, chr) - in - 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 + structure Folder = + MakeCharFolderNext + (struct + val startState = startState + val tables = tables + + fun finish x = x + fun isFinal currentState = + currentState = nonBlankAfterSpaceState + end) + + val fStart = Folder.foldNext end) fun startOfCurrentWORD (idx, absIdx, str, tl, currentState, counter) =