From eb8d7cd1f1bb90bed690c59de179ab8fde3f273b Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 12 Oct 2022 11:59:54 +0300 Subject: [PATCH] refactor: modify ast_ctx_t::parse signature to fit other stages --- include/compiler/treeifier/ast.hh | 2 +- src/compiler/treeifier/ast.cc | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/compiler/treeifier/ast.hh b/include/compiler/treeifier/ast.hh index 47c3443..e4c80ef 100644 --- a/include/compiler/treeifier/ast.hh +++ b/include/compiler/treeifier/ast.hh @@ -73,7 +73,7 @@ namespace ppc::comp::tree::ast { } bool parse(std::string parser, size_t &pi, data::map_t &out); - static bool parse(msg_stack_t &messages, std::vector &tokens, data::map_t &out); + static data::map_t parse(msg_stack_t &messages, std::vector &tokens); ~ast_ctx_t(); ast_ctx_t(msg_stack_t &messages, std::vector &tokens): diff --git a/src/compiler/treeifier/ast.cc b/src/compiler/treeifier/ast.cc index 7a30834..b93e5e4 100644 --- a/src/compiler/treeifier/ast.cc +++ b/src/compiler/treeifier/ast.cc @@ -30,18 +30,14 @@ namespace ppc::comp::tree::ast { groups.emplace(parser); } - bool ast_ctx_t::parse(msg_stack_t &messages, std::vector &tokens, data::map_t &out) { + data::map_t ast_ctx_t::parse(msg_stack_t &messages, std::vector &tokens) { ast_ctx_t ctx(messages, tokens); ctx.init(); size_t i = 0; + data::map_t res; - try { - return ctx.parse("$_glob", i, out); - } - catch (const message_t &msg) { - messages.push(msg); - return false; - } + if (!ctx.parse("$_glob", i, res)) throw message_t::error("Failed to compile."); + return res; } bool ast_ctx_t::parse(std::string parser, size_t &pi, data::map_t &out) { return this->parser[parser] (*this, pi, out);