From 161caee62aff30fed98c23fd7ebef61f3928a012 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Wed, 17 Sep 2025 02:31:38 +0100 Subject: [PATCH] create DFA for Vi's 'l' motion --- fcore/cursor-dfa/vi-l-dfa.sml | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 fcore/cursor-dfa/vi-l-dfa.sml diff --git a/fcore/cursor-dfa/vi-l-dfa.sml b/fcore/cursor-dfa/vi-l-dfa.sml new file mode 100644 index 0000000..32b929d --- /dev/null +++ b/fcore/cursor-dfa/vi-l-dfa.sml @@ -0,0 +1,37 @@ +structure ViLDfa = +struct + val startState: Word8.word = 0w0 + val notNewlineState: Word8.word = 0w1 + val oneNewlineState: Word8.word = 0w2 + + fun makeStart i = + if Char.chr i = #"\n" then oneNewlineState else notNewlineState + + fun makeOneNewline _ = notNewlineState + + val startTable = Vector.tabulate (255, makeStart) + val notNewlineTable = startTable + val oneNewlineTable = Vector.tabulate (255, makeOneNewline) + + val tables = #[startTable, notNewlineTable, oneNewlineTable] + + structure ViL = + MakeNextDfaLoop + (struct + val startState = startState + + structure Folder = + MakeCharFolderNext + (struct + val startState = startState + val tables = tables + + fun finish x = x + fun isFinal currentState = currentState = notNewlineState + end) + + val fStart = Folder.foldNext + end) + + val next = ViL.next +end