a bit of refactoring
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
signature MAKE_DFA_LOOP =
|
signature MAKE_DFA_LOOP =
|
||||||
sig
|
sig
|
||||||
val fNext: int * int * string * string list * Word8.word * int -> int
|
val fStart: int * int * string * string list * Word8.word * int -> int
|
||||||
val fPrev: int * int * string * string list * Word8.word * int -> int
|
|
||||||
val startState: Word8.word
|
val startState: Word8.word
|
||||||
end
|
end
|
||||||
|
|
||||||
functor MakeDfaLoop(M: MAKE_DFA_LOOP) =
|
functor MakeNextDfaLoop(M: MAKE_DFA_LOOP) =
|
||||||
struct
|
struct
|
||||||
fun next (lineGap: LineGap.t, cursorIdx) =
|
fun next (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
@@ -19,17 +18,20 @@ struct
|
|||||||
in
|
in
|
||||||
if strIdx < String.size shd then
|
if strIdx < String.size shd then
|
||||||
(* strIdx is in this string *)
|
(* strIdx is in this string *)
|
||||||
M.fNext (strIdx, cursorIdx, shd, stl, M.startState, 1)
|
M.fStart (strIdx, cursorIdx, shd, stl, M.startState, 1)
|
||||||
else
|
else
|
||||||
(* strIdx is in tl *)
|
(* strIdx is in tl *)
|
||||||
case stl of
|
case stl of
|
||||||
stlhd :: stltl =>
|
stlhd :: stltl =>
|
||||||
M.fNext (strIdx, cursorIdx, stlhd, stltl, M.startState, 1)
|
M.fStart (strIdx, cursorIdx, stlhd, stltl, M.startState, 1)
|
||||||
| _ => cursorIdx
|
| _ => cursorIdx
|
||||||
end
|
end
|
||||||
| [] => cursorIdx
|
| [] => cursorIdx
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
functor MakePrevDfaLoop(M: MAKE_DFA_LOOP) =
|
||||||
|
struct
|
||||||
fun prev (lineGap: LineGap.t, cursorIdx) =
|
fun prev (lineGap: LineGap.t, cursorIdx) =
|
||||||
let
|
let
|
||||||
val {rightStrings, leftStrings, idx = bufferIdx, ...} = lineGap
|
val {rightStrings, leftStrings, idx = bufferIdx, ...} = lineGap
|
||||||
@@ -42,7 +44,7 @@ struct
|
|||||||
in
|
in
|
||||||
if strIdx < String.size shd then
|
if strIdx < String.size shd then
|
||||||
(* strIdx is in this string *)
|
(* strIdx is in this string *)
|
||||||
M.fPrev (strIdx, cursorIdx, shd, leftStrings, M.startState, 1)
|
M.fStart (strIdx, cursorIdx, shd, leftStrings, M.startState, 1)
|
||||||
else
|
else
|
||||||
(* strIdx is in tl *)
|
(* strIdx is in tl *)
|
||||||
(case stl of
|
(case stl of
|
||||||
@@ -51,7 +53,7 @@ struct
|
|||||||
val strIdx = strIdx - String.size shd
|
val strIdx = strIdx - String.size shd
|
||||||
val leftStrings = shd :: leftStrings
|
val leftStrings = shd :: leftStrings
|
||||||
in
|
in
|
||||||
M.fPrev
|
M.fStart
|
||||||
(strIdx, cursorIdx, stlhd, leftStrings, M.startState, 1)
|
(strIdx, cursorIdx, stlhd, leftStrings, M.startState, 1)
|
||||||
end
|
end
|
||||||
| [] => cursorIdx)
|
| [] => cursorIdx)
|
||||||
|
|||||||
@@ -35,15 +35,15 @@ struct
|
|||||||
Vector.sub (currentTable, charIdx)
|
Vector.sub (currentTable, charIdx)
|
||||||
end
|
end
|
||||||
|
|
||||||
structure TraverseWORD =
|
structure StartOfNextWORD =
|
||||||
MakeDfaLoop
|
MakeNextDfaLoop
|
||||||
(struct
|
(struct
|
||||||
val startState = startState
|
val startState = startState
|
||||||
|
|
||||||
fun fNext (idx, absIdx, str, tl, currentState, counter) =
|
fun fStart (idx, absIdx, str, tl, currentState, counter) =
|
||||||
if idx = String.size str then
|
if idx = String.size str then
|
||||||
case tl of
|
case tl of
|
||||||
str :: tl => fNext (0, absIdx, str, tl, currentState, counter)
|
str :: tl => fStart (0, absIdx, str, tl, currentState, counter)
|
||||||
| [] => Int.max (absIdx - 2, 0)
|
| [] => Int.max (absIdx - 2, 0)
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
@@ -55,16 +55,23 @@ struct
|
|||||||
absIdx
|
absIdx
|
||||||
else
|
else
|
||||||
(* new loop, so reset to start state and proceed *)
|
(* new loop, so reset to start state and proceed *)
|
||||||
fNext (idx + 1, absIdx + 1, str, tl, startState, counter - 1)
|
fStart
|
||||||
|
(idx + 1, absIdx + 1, str, tl, startState, counter - 1)
|
||||||
else
|
else
|
||||||
fNext (idx + 1, absIdx + 1, str, tl, newState, counter)
|
fStart (idx + 1, absIdx + 1, str, tl, newState, counter)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
fun fPrev (idx, absIdx, str, tl, currentState, counter) =
|
structure EndOfPrevWORD =
|
||||||
|
MakePrevDfaLoop
|
||||||
|
(struct
|
||||||
|
val startState = startState
|
||||||
|
|
||||||
|
fun fStart (idx, absIdx, str, tl, currentState, counter) =
|
||||||
if idx < 0 then
|
if idx < 0 then
|
||||||
case tl of
|
case tl of
|
||||||
str :: tl =>
|
str :: tl =>
|
||||||
fPrev
|
fStart
|
||||||
(String.size str - 1, absIdx, str, tl, currentState, counter)
|
(String.size str - 1, absIdx, str, tl, currentState, counter)
|
||||||
| [] => 0
|
| [] => 0
|
||||||
else
|
else
|
||||||
@@ -77,12 +84,13 @@ struct
|
|||||||
absIdx
|
absIdx
|
||||||
else
|
else
|
||||||
(* reset to start state and proceed *)
|
(* reset to start state and proceed *)
|
||||||
fPrev (idx - 1, absIdx - 1, str, tl, startState, counter - 1)
|
fStart
|
||||||
|
(idx - 1, absIdx - 1, str, tl, startState, counter - 1)
|
||||||
else
|
else
|
||||||
fPrev (idx - 1, absIdx - 1, str, tl, newState, counter)
|
fStart (idx - 1, absIdx - 1, str, tl, newState, counter)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
val next = TraverseWORD.next
|
val startOfNextWORD = StartOfNextWORD.next
|
||||||
val prev = TraverseWORD.prev
|
val endOfPrevWORD = EndOfPrevWORD.prev
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -886,7 +886,7 @@ struct
|
|||||||
toNextWord (lineGap, cursorIdx, helpNextWord)
|
toNextWord (lineGap, cursorIdx, helpNextWord)
|
||||||
|
|
||||||
(* equivalent of vi's 'W' command *)
|
(* equivalent of vi's 'W' command *)
|
||||||
val nextWORD = ViWORDDfa.next
|
val nextWORD = ViWORDDfa.startOfNextWORD
|
||||||
|
|
||||||
fun helpPrevWord (strPos, str, absIdx, strTl, lineTl) =
|
fun helpPrevWord (strPos, str, absIdx, strTl, lineTl) =
|
||||||
if strPos < 0 then
|
if strPos < 0 then
|
||||||
@@ -1077,8 +1077,7 @@ struct
|
|||||||
toEndOfPrevWord (lineGap, cursorIdx, helpEndOfPrevWord)
|
toEndOfPrevWord (lineGap, cursorIdx, helpEndOfPrevWord)
|
||||||
|
|
||||||
(* equivalent of vi's 'gE' command *)
|
(* equivalent of vi's 'gE' command *)
|
||||||
fun endOfPrevWORD (lineGap, cursorIdx) =
|
val endOfPrevWORD = ViWORDDfa.endOfPrevWORD
|
||||||
toEndOfPrevWord (lineGap, cursorIdx, helpEndOfPrevWORD)
|
|
||||||
|
|
||||||
fun helpEndOfWord (strPos, str, absIdx, stl, ltl) =
|
fun helpEndOfWord (strPos, str, absIdx, stl, ltl) =
|
||||||
if strPos = String.size str then
|
if strPos = String.size str then
|
||||||
|
|||||||
Reference in New Issue
Block a user