From d15bcc542c027823dda4cb8e61ef6f34746bdc96 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:31:21 +0300 Subject: [PATCH] fix: type output map's namespace is not null when empty --- src/compiler/treeifier/ast/parsers/type.cc | 32 +++++++--------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/compiler/treeifier/ast/parsers/type.cc b/src/compiler/treeifier/ast/parsers/type.cc index 4242a05..483e216 100644 --- a/src/compiler/treeifier/ast/parsers/type.cc +++ b/src/compiler/treeifier/ast/parsers/type.cc @@ -5,38 +5,26 @@ bool ast::parse_type(ast_ctx_t &ctx, size_t &res_i, map_t &out) { if (h.ended()) return false; - auto &nmsp = (out["namespace"] = map_t()).map(); - nmsp["$_name"] = "$_nmsp"; - auto &nmsp_content = (out["namespace"].map()["content"] = array_t()).array(); + auto &nmsp = out["namespace"].map({}); size_t ptr_n = 0; - if (!h.push_parse(parse_identifier, nmsp_content)) return false; - - while (true) { - if (h.ended()) break; - if (!h.curr().is_operator(operator_t::DOUBLE_COLON)) break; - h.advance("Expected an identifier."); - h.force_push_parse(parse_identifier, "Expected an identifier.", nmsp_content); - } + if (!h.parse(parse_nmsp, nmsp)) return false; while (!h.ended() && h.curr().is_operator(operator_t::MULTIPLY)) { ptr_n++; if (!h.try_advance()) break; } - out["location"] = conv::loc_to_map(h.res_loc()); - out["name"] = nmsp_content[nmsp_content.size() - 1]; - out["ptr_n"] = (float)ptr_n; - nmsp_content.pop_back(); + auto &nmsp_arr = nmsp["content"].array(); - if (nmsp_content.size() == 0) { - auto loc = h.res_loc(); - loc.length = 1; - nmsp["location"] = conv::loc_to_map(loc); - } + out["location"] = conv::loc_to_map(h.res_loc()); + out["name"] = nmsp_arr.back(); + out["ptr_n"] = (float)ptr_n; + nmsp_arr.pop_back(); + if (nmsp_arr.empty()) out["namespace"] = null; else { - auto loc_1 = conv::map_to_loc(nmsp_content[0].map()["location"].string()); - auto loc_2 = conv::map_to_loc(nmsp_content[nmsp_content.size() - 1].map()["location"].string()); + auto loc_1 = conv::map_to_loc(nmsp_arr.front().map()["location"].string()); + auto loc_2 = conv::map_to_loc(nmsp_arr.back().map()["location"].string()); auto loc = loc_1.intersect(loc_2); nmsp["location"] = conv::loc_to_map(loc); }