From 0729662eef6b9c021b1cff56a63c86ebf9a4feb7 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 5 Aug 2025 13:59:10 +0100 Subject: [PATCH] minor formatting changes to exception logging, and begin building from new search list functionality as well --- fcore/build-search-list.sml | 21 +++++++-------- fcore/search/search-line-gap.sml | 46 ++++++++++++++++++++++---------- shell/exception-logger.sml | 14 +++++----- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/fcore/build-search-list.sml b/fcore/build-search-list.sml index 5295cc4..2378179 100644 --- a/fcore/build-search-list.sml +++ b/fcore/build-search-list.sml @@ -81,10 +81,11 @@ struct fun fromStart (app, cursorIdx, buffer, searchString) = if String.size searchString > 0 then let + val buffer = LineGap.goToEnd buffer + val searchList = SearchLineGap.search (buffer, searchString) val buffer = LineGap.goToStart buffer in - helpFromStart - (app, cursorIdx, 0, buffer, searchString, SearchList.empty) + AppWith.searchList (app, searchList, buffer, searchString) end else app @@ -130,15 +131,11 @@ struct end fun fromRange (startIdx, length, buffer, searchString, searchList) = - if String.size searchString = 0 then + let + val buffer = LineGap.goToEnd buffer + val searchList = SearchLineGap.search (buffer, searchString) + val buffer = LineGap.goToStart buffer + in (buffer, searchList) - else - let - val finishIdx = startIdx + length + String.size searchString - val bufferIdx = startIdx - String.size searchString - val bufferIdx = Int.max (bufferIdx, 0) - in - helpFromRange - (startIdx, bufferIdx, finishIdx, buffer, searchString, searchList) - end + end end diff --git a/fcore/search/search-line-gap.sml b/fcore/search/search-line-gap.sml index 32feac1..4e3cc51 100644 --- a/fcore/search/search-line-gap.sml +++ b/fcore/search/search-line-gap.sml @@ -1,8 +1,21 @@ structure SearchLineGap = struct + fun cons (num, acc) = + let + val num = Vector.fromList [num] + in + case acc of + hd :: tl => + if Vector.length hd < 32 then + (Vector.concat [num, hd]) :: tl + else + num :: acc + | [] => num :: acc + end + fun searchStep (pos, hd, absIdx, tl, acc, searchPos, searchString) = if searchPos < 0 then - (absIdx + 1) :: acc + cons (absIdx + 1, acc) else if pos < 0 then case tl of hd :: tl => @@ -33,17 +46,22 @@ struct loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString) end - fun search (buffer, searchString) = - if String.size searchString = 0 then - [] - else - let - val buffer = LineGap.goToEnd buffer - val {leftStrings, idx = absIdx, ...} = buffer - in - case leftStrings of - hd :: tl => - loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString) - | [] => [] - end + (* Prerequisite: move buffer/LineGap to end *) + fun search (buffer: LineGap.t, searchString) = + let + val acc = + if String.size searchString = 0 then + [] + else + let + val {leftStrings, idx = absIdx, ...} = buffer + in + case leftStrings of + hd :: tl => + loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString) + | [] => [] + end + in + {left = [], right = acc} + end end diff --git a/shell/exception-logger.sml b/shell/exception-logger.sml index 8caa3cd..96ad17b 100644 --- a/shell/exception-logger.sml +++ b/shell/exception-logger.sml @@ -19,18 +19,18 @@ struct let (* print stack trace for debugging purposes, * and then raise another exception to exit the program *) + val errName = General.exnName e ^ "\n" val stackTrace = MLton.Exn.history e - val stackTrace = String.concatWith "\n" stackTrace - val () = print "ERROR:\n" - val () = print (stackTrace ^ "\n\n") - + val stackTrace = (String.concatWith "\n" stackTrace) ^ "\n" val history = !textCommands ^ "\n\n" - val () = print ("HISTORY: " ^ history) - val textOutput = stackTrace ^ "\n" ^ history + val log = String.concat + ["ERROR: ", errName, stackTrace, "HISTORY: ", history] + + val () = print ("\n" ^ log) val io = TextIO.openAppend "exceptions.log" - val () = TextIO.output (io, textOutput) + val () = TextIO.output (io, log) val () = TextIO.closeOut io in raise e