chore: add pause on end of application when in debug mode, improve exception handling

This commit is contained in:
TopchetoEU 2022-10-11 14:38:42 +03:00
parent 349bcc462c
commit ff6d01034a

View File

@ -141,31 +141,43 @@ int main(int argc, const char *argv[]) {
std::vector<std::string> files; std::vector<std::string> files;
messages::msg_stack_t msg_stack; messages::msg_stack_t msg_stack;
options::parser_t parser; try {
data::map_t conf; options::parser_t parser;
add_flags(parser); data::map_t conf;
add_flags(parser);
for (const auto &arg : args) { for (const auto &arg : args) {
if (!parser.parse(arg, msg_stack, conf)) { if (!parser.parse(arg, msg_stack, conf)) {
files.push_back(arg); files.push_back(arg);
}
} }
}
for (const auto &file : files) { for (const auto &file : files) {
std::ifstream f { file, std::ios_base::in }; std::ifstream f { file, std::ios_base::in };
try {
auto tokens = token_t::parse_many(msg_stack, lex::token_t::parse_file(msg_stack, file, f)); auto tokens = token_t::parse_many(msg_stack, lex::token_t::parse_file(msg_stack, file, f));
data::map_t ast; data::map_t ast;
if (!ast::ast_ctx_t::parse(msg_stack, tokens, ast)) continue; if (!ast::ast_ctx_t::parse(msg_stack, tokens, ast)) continue;
std::cout << data::json::stringify(ast) << std::endl; std::cout << data::json::stringify(ast) << std::endl;
} }
catch (const messages::message_t &msg) { throw 15.0f;
msg_stack.push(msg); }
} catch (const messages::message_t &msg) {
msg_stack.push(msg);
}
catch (const std::string &msg) {
msg_stack.push(message_t::error(msg));
}
catch (...) {
std::cout << std::endl;
msg_stack.push(message_t::error("A fatal error occurred."));
} }
msg_stack.print(std::cout, messages::message_t::DEBUG, true); msg_stack.print(std::cout, messages::message_t::DEBUG, true);
#ifdef PROFILE_debug
system("pause");
#endif
return 0; return 0;
} }