Skip to content

Commit

Permalink
Gets rid of weird segfaults from REPL parser errors
Browse files Browse the repository at this point in the history
Previously, ParserError() calls would actually be able to continue chugging beyond an error, when running under the REPL.

While being able to walk a trainwreck is a desirable property of a parser, it's not one that we have at the moment, so the REPL does not get access to any such thing, just like typical execution, until it's actually implemented.
  • Loading branch information
Altoids1 committed Nov 1, 2023
1 parent 1909239 commit dc3058e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "FailureOr.h"
#include "Terminal.h"
#include "Object.h"
#include "Error.h"

#include <sstream>
#include <exception>
Expand Down Expand Up @@ -103,7 +104,12 @@ static std::optional<Value> try_run_expression(Program& prog, std::string&& expr
if(scn.is_malformed)
return {};
Parser prs(scn);
ASTNode* ptr = prs.parse_repl_expression();
ASTNode* ptr;
try {
ptr = prs.parse_repl_expression();
} catch (error::parser& err) {
return {};
}
if(ptr == nullptr)
return {};
Interpreter interp(prog,true);
Expand Down
11 changes: 6 additions & 5 deletions Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,15 @@ class Parser
if (t)
std::cerr << t->dump();
std::cerr << std::endl; // This is an emscripten thing. We need to make sure this is flushed.
if (!is_interactive)
#ifdef JOAO_SAFE
if(is_interactive) {
t_program.is_malformed = true;
throw error::parser(what);
}
#ifdef JOAO_SAFE
throw error::parser(what);
#else
exit(1);
exit(1);
#endif
else
t_program.is_malformed = true;
}
Program parse();

Expand Down

0 comments on commit dc3058e

Please sign in to comment.