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;
|
if (h.ended()) return false;
|
||||||
|
|
||||||
auto &nmsp = (out["namespace"] = map_t()).map();
|
auto &nmsp = out["namespace"].map({});
|
||||||
nmsp["$_name"] = "$_nmsp";
|
|
||||||
auto &nmsp_content = (out["namespace"].map()["content"] = array_t()).array();
|
|
||||||
size_t ptr_n = 0;
|
size_t ptr_n = 0;
|
||||||
|
|
||||||
if (!h.push_parse(parse_identifier, nmsp_content)) return false;
|
if (!h.parse(parse_nmsp, nmsp)) 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!h.ended() && h.curr().is_operator(operator_t::MULTIPLY)) {
|
while (!h.ended() && h.curr().is_operator(operator_t::MULTIPLY)) {
|
||||||
ptr_n++;
|
ptr_n++;
|
||||||
if (!h.try_advance()) break;
|
if (!h.try_advance()) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out["location"] = conv::loc_to_map(h.res_loc());
|
auto &nmsp_arr = nmsp["content"].array();
|
||||||
out["name"] = nmsp_content[nmsp_content.size() - 1];
|
|
||||||
out["ptr_n"] = (float)ptr_n;
|
|
||||||
nmsp_content.pop_back();
|
|
||||||
|
|
||||||
if (nmsp_content.size() == 0) {
|
out["location"] = conv::loc_to_map(h.res_loc());
|
||||||
auto loc = h.res_loc();
|
out["name"] = nmsp_arr.back();
|
||||||
loc.length = 1;
|
out["ptr_n"] = (float)ptr_n;
|
||||||
nmsp["location"] = conv::loc_to_map(loc);
|
nmsp_arr.pop_back();
|
||||||
}
|
if (nmsp_arr.empty()) out["namespace"] = null;
|
||||||
else {
|
else {
|
||||||
auto loc_1 = conv::map_to_loc(nmsp_content[0].map()["location"].string());
|
auto loc_1 = conv::map_to_loc(nmsp_arr.front().map()["location"].string());
|
||||||
auto loc_2 = conv::map_to_loc(nmsp_content[nmsp_content.size() - 1].map()["location"].string());
|
auto loc_2 = conv::map_to_loc(nmsp_arr.back().map()["location"].string());
|
||||||
auto loc = loc_1.intersect(loc_2);
|
auto loc = loc_1.intersect(loc_2);
|
||||||
nmsp["location"] = conv::loc_to_map(loc);
|
nmsp["location"] = conv::loc_to_map(loc);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user