progress functorising

This commit is contained in:
2025-08-04 04:24:24 +01:00
parent 895c286b4b
commit fe9dd0f034

View File

@@ -863,12 +863,16 @@ struct
val toPrevChr = ToPrevChr.foldPrev val toPrevChr = ToPrevChr.foldPrev
structure TillPrevChr =
MakeIfCharFolderPrev
(struct
type env = char
fun helpTillPrevChr fun helpTillPrevChr
( strPos ( strPos
, str , str
, absIdx , absIdx
, stl , stl
, ltl
, origIdx , origIdx
, findChr , findChr
, lastNonLine , lastNonLine
@@ -876,21 +880,20 @@ struct
, lastValid , lastValid
) = ) =
if strPos < 0 then if strPos < 0 then
case (stl, ltl) of case stl of
(shd :: stl, lhd :: ltl) => shd :: stl =>
helpTillPrevChr helpTillPrevChr
( String.size shd - 1 ( String.size shd - 1
, shd , shd
, absIdx , absIdx
, stl , stl
, ltl
, origIdx , origIdx
, findChr , findChr
, lastNonLine , lastNonLine
, lastLine , lastLine
, lastValid , lastValid
) )
| (_, _) => origIdx | [] => origIdx
else else
let let
val chr = String.sub (str, strPos) val chr = String.sub (str, strPos)
@@ -927,7 +930,6 @@ struct
, str , str
, absIdx - 1 , absIdx - 1
, stl , stl
, ltl
, origIdx , origIdx
, findChr , findChr
, lastNonLine , lastNonLine
@@ -937,7 +939,7 @@ struct
end end
end end
fun startTillPrevChr (shd, strIdx, absIdx, stl, ltl, findChr) = fun fStart (strIdx, shd, _, absIdx, stl, ltl, findChr) =
(* we want to start iterating from Prev char after strIdx *) (* we want to start iterating from Prev char after strIdx *)
if strIdx > 0 then if strIdx > 0 then
helpTillPrevChr helpTillPrevChr
@@ -945,7 +947,6 @@ struct
, shd , shd
, absIdx - 1 , absIdx - 1
, stl , stl
, ltl
, absIdx , absIdx
, findChr , findChr
, absIdx , absIdx
@@ -953,56 +954,23 @@ struct
, absIdx , absIdx
) )
else else
case (stl, ltl) of case stl of
(stlhd :: stltl, ltlhd :: ltltl) => stlhd :: stltl =>
helpTillPrevChr helpTillPrevChr
( String.size stlhd - 1 ( String.size stlhd - 1
, stlhd , stlhd
, absIdx - 1 , absIdx - 1
, stltl , stltl
, ltltl
, absIdx , absIdx
, findChr , findChr
, absIdx , absIdx
, absIdx , absIdx
, absIdx , absIdx
) )
| (_, _) => (* tl is empty; return 0 for lineGap start *) 0 | [] => (* tl is empty; return 0 for lineGap start *) 0
end)
fun prevChr (lineGap: LineGap.t, cursorIdx, chr, fStart) = val tillPrevChr = TillPrevChr.foldPrev
let
val
{rightStrings, rightLines, idx = bufferIdx, leftStrings, leftLines, ...} =
lineGap
in
case (rightStrings, rightLines) of
(shd :: stl, lhd :: ltl) =>
let
(* convert absolute cursorIdx to idx relative to hd string *)
val strIdx = cursorIdx - bufferIdx
in
if strIdx < String.size shd then
(* strIdx is in this string *)
fStart (shd, strIdx, cursorIdx, leftStrings, leftLines, chr)
else
(* strIdx is in tl *)
(case (stl, ltl) of
(stlhd :: stltl, ltlhd :: ltltl) =>
let
val strIdx = strIdx - String.size shd
val leftStrings = shd :: leftStrings
val leftLines = lhd :: leftLines
in
fStart
(shd, strIdx, cursorIdx, leftStrings, leftLines, chr)
end
| (_, _) => cursorIdx)
end
| (_, _) => cursorIdx
end
fun tillPrevChr (lineGap, cursorIdx, chr) =
prevChr (lineGap, cursorIdx, chr, startTillPrevChr)
fun helpMatchPairNext fun helpMatchPairNext
(strPos, str, absIdx, stl, origIdx, openChr, openNum, closeChr, closeNum) = (strPos, str, absIdx, stl, origIdx, openChr, openNum, closeChr, closeNum) =