Skip to content

Commit

Permalink
Improved interpreter error message handling and printing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Sep 16, 2024
1 parent a8c9f06 commit 5b1d2e4
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/Zhivo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,35 @@ auto interpreter() -> int {
return 0;
}
catch(const LexicalAnalysisException& lexAnlExc) {
std::cerr << "[LEXANL]: " << lexAnlExc.what() << std::endl;
std::cerr << "[\u001b[1;31mLexical Error\u001b[0m]:" << std::endl
<< "\t" << lexAnlExc.what() << std::endl;
}
catch(const ParserException& parserExc) {
std::cerr << "[PARSER]: " << parserExc.what() << std::endl;
std::cerr << " " <<
std::cerr << "[\u001b[1;31mParser Error\u001b[0m]: \u001b[3;37m"
<< parserExc.what() << "\u001b[0m" << std::endl;
std::cerr << " " <<
parserExc.getAddress()->toString() << std::endl;
}
catch(const TerminativeReturnSignal& retExc) {
std::cerr << "[OBJECT]: " <<
retExc.getObject().toString() << std::endl;
}
catch(const TerminativeBreakSignal& breakExc) {
std::cerr << "[RUNTIME]: " <<
"Invalid break statement signal caught." << std::endl;
std::cerr << "[\u001b[1;31mRuntime Error\u001b[0m]: "
<< "\u001b[3;37mInvalid break statement signal caught.\u001b[0m"
<< std::endl << " "
<< breakExc.getAddress().toString() << std::endl;
}
catch(const TerminativeContinueSignal& continueExc) {
std::cerr << "[RUNTIME]: " <<
"Invalid break statement signal caught." << std::endl;
std::cerr << "[\u001b[1;31mRuntime Error\u001b[0m]: "
<< "\u001b[3;37mInvalid break statement signal caught.\u001b[0m"
<< std::endl << " "
<< continueExc.getAddress().toString() << std::endl;
}
catch(const TerminativeReturnSignal& retExc) {
std::cerr << "\u001b[0;93m"
<< retExc.getObject().toString()
<< "\u001b[0m" << std::endl;
}
catch(const std::exception& exc) {
std::cerr << "[RUNTIME]: " << exc.what() << std::endl;
std::cerr << "[\u001b[1;31mRuntime Error\u001b[0m]: \u001b[3;37m"
<< exc.what() << "\u001b[0m" << std::endl;
}

return 1;
Expand Down

0 comments on commit 5b1d2e4

Please sign in to comment.