minor formatting changes to exception logging, and begin building from new search list functionality as well
This commit is contained in:
@@ -81,10 +81,11 @@ struct
|
|||||||
fun fromStart (app, cursorIdx, buffer, searchString) =
|
fun fromStart (app, cursorIdx, buffer, searchString) =
|
||||||
if String.size searchString > 0 then
|
if String.size searchString > 0 then
|
||||||
let
|
let
|
||||||
|
val buffer = LineGap.goToEnd buffer
|
||||||
|
val searchList = SearchLineGap.search (buffer, searchString)
|
||||||
val buffer = LineGap.goToStart buffer
|
val buffer = LineGap.goToStart buffer
|
||||||
in
|
in
|
||||||
helpFromStart
|
AppWith.searchList (app, searchList, buffer, searchString)
|
||||||
(app, cursorIdx, 0, buffer, searchString, SearchList.empty)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
app
|
app
|
||||||
@@ -130,15 +131,11 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
fun fromRange (startIdx, length, buffer, searchString, searchList) =
|
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)
|
(buffer, searchList)
|
||||||
else
|
end
|
||||||
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
|
||||||
|
|||||||
@@ -1,8 +1,21 @@
|
|||||||
structure SearchLineGap =
|
structure SearchLineGap =
|
||||||
struct
|
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) =
|
fun searchStep (pos, hd, absIdx, tl, acc, searchPos, searchString) =
|
||||||
if searchPos < 0 then
|
if searchPos < 0 then
|
||||||
(absIdx + 1) :: acc
|
cons (absIdx + 1, acc)
|
||||||
else if pos < 0 then
|
else if pos < 0 then
|
||||||
case tl of
|
case tl of
|
||||||
hd :: tl =>
|
hd :: tl =>
|
||||||
@@ -33,17 +46,22 @@ struct
|
|||||||
loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString)
|
loopSearch (pos - 1, hd, absIdx - 1, tl, acc, searchString)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun search (buffer, searchString) =
|
(* Prerequisite: move buffer/LineGap to end *)
|
||||||
if String.size searchString = 0 then
|
fun search (buffer: LineGap.t, searchString) =
|
||||||
[]
|
let
|
||||||
else
|
val acc =
|
||||||
let
|
if String.size searchString = 0 then
|
||||||
val buffer = LineGap.goToEnd buffer
|
[]
|
||||||
val {leftStrings, idx = absIdx, ...} = buffer
|
else
|
||||||
in
|
let
|
||||||
case leftStrings of
|
val {leftStrings, idx = absIdx, ...} = buffer
|
||||||
hd :: tl =>
|
in
|
||||||
loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
|
case leftStrings of
|
||||||
| [] => []
|
hd :: tl =>
|
||||||
end
|
loopSearch (String.size hd - 1, hd, absIdx - 1, tl, [], searchString)
|
||||||
|
| [] => []
|
||||||
|
end
|
||||||
|
in
|
||||||
|
{left = [], right = acc}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,18 +19,18 @@ struct
|
|||||||
let
|
let
|
||||||
(* print stack trace for debugging purposes,
|
(* print stack trace for debugging purposes,
|
||||||
* and then raise another exception to exit the program *)
|
* and then raise another exception to exit the program *)
|
||||||
|
val errName = General.exnName e ^ "\n"
|
||||||
val stackTrace = MLton.Exn.history e
|
val stackTrace = MLton.Exn.history e
|
||||||
val stackTrace = String.concatWith "\n" stackTrace
|
val stackTrace = (String.concatWith "\n" stackTrace) ^ "\n"
|
||||||
val () = print "ERROR:\n"
|
|
||||||
val () = print (stackTrace ^ "\n\n")
|
|
||||||
|
|
||||||
val history = !textCommands ^ "\n\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 io = TextIO.openAppend "exceptions.log"
|
||||||
val () = TextIO.output (io, textOutput)
|
val () = TextIO.output (io, log)
|
||||||
val () = TextIO.closeOut io
|
val () = TextIO.closeOut io
|
||||||
in
|
in
|
||||||
raise e
|
raise e
|
||||||
|
|||||||
Reference in New Issue
Block a user