i dont even remember bruh

This commit is contained in:
TopchetoEU 2022-11-24 14:25:42 +02:00
parent ee16dfbe71
commit a36c7e5fa7
2 changed files with 550 additions and 545 deletions

View File

@ -232,7 +232,19 @@ bool ast::parse_exp(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
} }
if (h.curr().is_operator()) { if (h.curr().is_operator()) {
auto op = h.curr()._operator(); auto op = h.curr()._operator();
if (op == operator_t::PAREN_CLOSE && (last_val || (!op_stack.empty() && op_stack.back().precedence == precedence_t::CALL_START))) { if (last_val) {
if (op == operator_t::PAREN_OPEN) {
h.advance("Expected an argument or closing parens.");
op_stack.push_back({ h.loc(), { precedence_t::CALL_START } });
if (h.curr().is_operator(operator_t::PAREN_CLOSE)) {
pop_call(0, h.loc(), op_stack, res);
}
else {
call_args_n.push_back(1);
}
last_val = false;
}
else if (op == operator_t::PAREN_CLOSE) {
bool is_call = false, is_paren = false; bool is_call = false, is_paren = false;
for (auto i = op_stack.rbegin(); i != op_stack.rend(); i++) { for (auto i = op_stack.rbegin(); i != op_stack.rend(); i++) {
@ -246,19 +258,15 @@ bool ast::parse_exp(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
} }
} }
if (is_call) pop_call(call_args_n.back(), h.loc(), op_stack, res); if (is_call) {
pop_call(call_args_n.back(), h.loc(), op_stack, res);
call_args_n.pop_back();
}
else if (is_paren) pop_paren(op_stack, res); else if (is_paren) pop_paren(op_stack, res);
else break; else break;
if (!h.try_advance()) break; if (!h.try_advance()) break;
} }
else if (last_val) {
if (op == operator_t::PAREN_OPEN) {
h.advance("Expected an argument.");
call_args_n.push_back(0);
op_stack.push_back({ h.loc(), { precedence_t::CALL_START } });
last_val = false;
}
else if (op == operator_t::COMMA) { else if (op == operator_t::COMMA) {
if (call_args_n.size() == 0) break; if (call_args_n.size() == 0) break;
h.advance("Expected an argument."); h.advance("Expected an argument.");

View File

@ -156,6 +156,7 @@ int main(int argc, const char *argv[]) {
for (const auto &file : files) { for (const auto &file : files) {
try { try {
std::ifstream f { file, std::ios_base::in }; std::ifstream f { file, std::ios_base::in };
if (!f.is_open()) throw message_t::error("The file doesn't exist.", { file });
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));
auto ast = ast_ctx_t::parse(ast::parse_glob, msg_stack, tokens); auto ast = ast_ctx_t::parse(ast::parse_glob, msg_stack, tokens);
@ -181,9 +182,5 @@ int main(int argc, const char *argv[]) {
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;
} }