fix: type output map's namespace is not null when empty
This commit is contained in:
parent
28a18feb3f
commit
d15bcc542c
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user