Hello,
Actually when an error is encountered during parsing and evaluation in
parseAndEvalString and parseAndEvalStringEqNum the output is just:
"error". I modified the throwed output to be the one of the interpreter.
I may be wrong but nothing is affected (src/hyper/*, jFRiCAS or
TeXmacs extensions). I just see one concern about
the overhead but I believe for their use it
is acceptable.
Below is to show here the mechanism:
parseAndEvalToString str ==
$collectOutput:local := true
$outputLines: local := nil
$IOindex: local := nil
- v := CATCH('SPAD_READER, CATCH('top_level, parseAndEvalStr str))
- v = 'restart => ['"error"]
+ str_stream := MAKE_-STRING_-OUTPUT_-STREAM()
+ old_stream := $algebra_out_rec.$stream_off
+ $algebra_out_rec.$stream_off := cons(false, str_stream)
+ v := UNWIND_-PROTECT(
+ CATCH('SPAD_READER, CATCH('top_level, parseAndEvalStr str)),
+ ($algebra_out_rec.$stream_off := old_stream)
+ )
+ captured_msg := GET_-OUTPUT_-STREAM_-STRING(str_stream)
+ v = 'restart =>
+ captured_msg = '"" => ['"Unknown error during parsing in BOOT
function parseAndEvalToString"]
+ string2Lines(captured_msg)
NREVERSE $outputLines
Personally, I use these two functions for the FriCAS MCP server and
therefore the FriCAS extension I am
working on for the VS Code compatible editors. They have an integrated
pseudo terminal which can be tightly related to the editor (think
about a .input file you are working on).
BTW, I always like informative error messages.
Patch attached.
Greg
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/fricas-devel/CAHnU2dZ4raqxTQu0%3DHkobgDW%2BUjdWFnhYsSexJR1kY4ecAuK2g%40mail.gmail.com.
diff --git a/src/interp/server.boot b/src/interp/server.boot
index 9d8a73a4..2bf0e973 100644
--- a/src/interp/server.boot
+++ b/src/interp/server.boot
@@ -144,19 +144,44 @@ parseAndEvalToHypertex str ==
for s in lines repeat
sockSendString($MenuServer, s)
+string2Lines(str) ==
+ s := MAKE_-STRING_-INPUT_-STREAM(str)
+ lines := nil
+ while not (null (line := read_line(s))) repeat
+ lines := [line, :lines]
+ NREVERSE lines
+
parseAndEvalToString str ==
$collectOutput:local := true
$outputLines: local := nil
$IOindex: local := nil
- v := CATCH('SPAD_READER, CATCH('top_level, parseAndEvalStr str))
- v = 'restart => ['"error"]
+ str_stream := MAKE_-STRING_-OUTPUT_-STREAM()
+ old_stream := $algebra_out_rec.$stream_off
+ $algebra_out_rec.$stream_off := cons(false, str_stream)
+ v := UNWIND_-PROTECT(
+ CATCH('SPAD_READER, CATCH('top_level, parseAndEvalStr str)),
+ ($algebra_out_rec.$stream_off := old_stream)
+ )
+ captured_msg := GET_-OUTPUT_-STREAM_-STRING(str_stream)
+ v = 'restart =>
+ captured_msg = '"" => ['"Unknown error during parsing in BOOT function parseAndEvalToString"]
+ string2Lines(captured_msg)
NREVERSE $outputLines
parseAndEvalToStringEqNum str ==
$collectOutput:local := true
$outputLines: local := nil
- v := CATCH('SPAD_READER, CATCH('top_level, parseAndEvalStr str))
- v = 'restart => ['"error"]
+ str_stream := MAKE_-STRING_-OUTPUT_-STREAM()
+ old_stream := $algebra_out_rec.$stream_off
+ $algebra_out_rec.$stream_off := cons(false, str_stream)
+ v := UNWIND_-PROTECT(
+ CATCH('SPAD_READER, CATCH('top_level, parseAndEvalStr str)),
+ ($algebra_out_rec.$stream_off := old_stream)
+ )
+ captured_msg := GET_-OUTPUT_-STREAM_-STRING(str_stream)
+ v = 'restart =>
+ captured_msg = '"" => ['"Unknown error during parsing in BOOT function parseAndEvalToStringEqNum"]
+ string2Lines(captured_msg)
NREVERSE $outputLines
parseAndEvalStr string ==