diff --git a/fcore/cursor-dfa/vi-h-dfa.sml b/fcore/cursor-dfa/vi-h-dfa.sml new file mode 100644 index 0000000..a1b9f83 --- /dev/null +++ b/fcore/cursor-dfa/vi-h-dfa.sml @@ -0,0 +1,76 @@ +structure ViHDfa = +struct + val startState: Word8.word = 0w0 + val oneNewlineState: Word8.word = 0w1 + val twoNewlineState: Word8.word = 0w2 + val chrState: Word8.word = 0w3 + val chrBeforeNewlieState: Word8.word = 0w4 + + fun makeStart i = + if Char.chr i = #"\n" then oneNewlineState else chrState + + fun makeOneNewline i = + if Char.chr i = #"\n" then twoNewlineState else chrBeforeNewlieState + + val startTable = Vector.tabulate (255, makeStart) + val oneNewlineTable = Vector.tabulate (255, makeOneNewline) + val twoNewlineTable = oneNewlineTable + val chrTable = startTable + val chrBeforeNewlieTable = startTable + + val tables = + #[ startTable + , oneNewlineTable + , twoNewlineTable + , chrTable + , chrBeforeNewlieTable + ] + + fun next (currentState, chr) = + let val table = Vector.sub (tables, Word8.toInt currentState) + in Vector.sub (table, Char.ord chr) + end + + structure ViH = + MakePrevDfaLoop + (struct + val startState = startState + + fun loop (idx, absIdx, str, tl, currentState, counter) = + if idx < 0 then + case tl of + str :: tl => + loop + (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 = chrBeforeNewlieState orelse newState = chrState then + if counter - 1 = ~1 then + absIdx + else + loop (idx - 1, absIdx - 1, str, tl, startState, counter - 1) + else if newState = twoNewlineState then + if counter - 1 = ~1 then + absIdx + 1 + else + loop + ( idx - 1 + , absIdx - 1 + , str + , tl + , oneNewlineState + , counter - 1 + ) + else + loop (idx - 1, absIdx - 1, str, tl, newState, counter) + end + + val fStart = loop + end) + + val prev = ViH.prev +end diff --git a/fcore/cursor-dfa/vi-hl-dfa.sml b/fcore/cursor-dfa/vi-hl-dfa.sml deleted file mode 100644 index 356bcc5..0000000 --- a/fcore/cursor-dfa/vi-hl-dfa.sml +++ /dev/null @@ -1,118 +0,0 @@ -structure ViHlDfa = -struct - val startState: Word8.word = 0w0 - val notNewlineState: Word8.word = 0w1 - val oneNewlineState: Word8.word = 0w2 - val twoNewlineState: Word8.word = 0w3 - - fun makeStart i = - if Char.chr i = #"\n" then oneNewlineState else notNewlineState - - fun makeOneNewline i = - if Char.chr i = #"\n" then twoNewlineState else notNewlineState - - val startTable = Vector.tabulate (255, makeStart) - val notNewlineTable = startTable - val oneNewlineTable = Vector.tabulate (255, makeOneNewline) - val twoNewLineTable = startTable - - val tables = #[startTable, notNewlineTable, oneNewlineTable, twoNewLineTable] - - fun next (currentState, chr) = - let val table = Vector.sub (tables, Word8.toInt currentState) - in Vector.sub (table, Char.ord chr) - end - - structure ViL = - MakeNextDfaLoopPlus1 - (struct - val startState = startState - - fun loop (idx, absIdx, str, tl, currentState, counter) = - if idx = String.size str then - case tl of - str :: tl => loop (0, absIdx, str, tl, currentState, counter) - | [] => absIdx - else - let - val chr = String.sub (str, idx) - val newState = next (currentState, chr) - in - if newState = twoNewlineState then - if counter - 1 = 0 then - absIdx - 1 - else - loop - ( idx + 1 - , absIdx + 1 - , str - , tl - , oneNewlineState - , counter - 1 - ) - else if newState = notNewlineState then - if counter - 1 = 0 then - absIdx - else - loop (idx + 1, absIdx + 1, str, tl, startState, counter - 1) - else - loop (idx + 1, absIdx + 1, str, tl, newState, counter) - end - - val fStart = loop - end) - - structure ViH = - MakePrevDfaLoop - (struct - val startState = startState - - fun loop (idx, absIdx, str, tl, currentState, counter) = - if idx < 0 then - case tl of - str :: tl => - loop - (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 = twoNewlineState then - if counter - 1 = 0 then - absIdx - else - loop - ( idx - 1 - , absIdx - 1 - , str - , tl - , oneNewlineState - , counter - 1 - ) - else if newState = notNewlineState then - if counter - 1 = 0 then - absIdx - else - loop (idx - 1, absIdx - 1, str, tl, startState, counter - 1) - else - loop (idx - 1, absIdx - 1, str, tl, newState, counter) - end - - fun fStart (idx, absIdx, str, tl, _, counter) = - if idx < 0 then - case tl of - str :: tl => - loop - (String.size str - 1, absIdx, str, tl, startState, counter) - | [] => 0 - else if String.sub (str, idx) = #"\n" then - loop (idx - 1, absIdx - 1, str, tl, oneNewlineState, counter) - else - loop (idx - 1, absIdx - 1, str, tl, startState, counter) - end) - - val l = ViL.next - val h = ViH.prev -end diff --git a/fcore/cursor.sml b/fcore/cursor.sml index c25f00a..48f4358 100644 --- a/fcore/cursor.sml +++ b/fcore/cursor.sml @@ -57,7 +57,7 @@ struct val viDlrForDelete = ViDlrDfa.nextForDelete val viL = ViLDfa.next - val viH = ViHlDfa.h + val viH = ViHDfa.prev fun helpGetCursorColumn (distanceFromLine, strList, lineList) = case (strList, lineList) of diff --git a/shf-tests.mlb b/shf-tests.mlb index 7e1e817..c7493e7 100644 --- a/shf-tests.mlb +++ b/shf-tests.mlb @@ -34,7 +34,8 @@ in fcore/cursor-dfa/vi-word-dfa.sml fcore/cursor-dfa/vi-caps-word-dfa.sml fcore/cursor-dfa/vi-dlr-dfa.sml - fcore/cursor-dfa/vi-hl-dfa.sml + fcore/cursor-dfa/vi-l-dfa.sml + fcore/cursor-dfa/vi-h-dfa.sml fcore/rect.sml fcore/pipe-cursor.sml end @@ -61,7 +62,6 @@ fcore/normal-mode/normal-search-mode.sml fcore/app-update.sml - (* TEST FILES *) $(SML_LIB)/basis/mlton.mlb shell/exception-logger.sml diff --git a/shf.mlb b/shf.mlb index e12d73f..ae83ab3 100644 --- a/shf.mlb +++ b/shf.mlb @@ -35,7 +35,7 @@ in fcore/cursor-dfa/vi-caps-word-dfa.sml fcore/cursor-dfa/vi-dlr-dfa.sml fcore/cursor-dfa/vi-l-dfa.sml - fcore/cursor-dfa/vi-hl-dfa.sml + fcore/cursor-dfa/vi-h-dfa.sml fcore/rect.sml fcore/pipe-cursor.sml end