mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-12 01:48:45 +00:00
highlighting improvements
This commit is contained in:
parent
195a26f9b7
commit
bf7fe1f821
9 changed files with 139 additions and 22 deletions
|
|
@ -1,4 +1,6 @@
|
|||
#include "name_tree.hpp"
|
||||
#include "error_handling.hpp"
|
||||
#include "statement_nodes.hpp"
|
||||
|
||||
namespace names {
|
||||
|
||||
|
|
@ -17,18 +19,18 @@ bool NameTree::insert(const std::string &path, nodes::Statement &&statement) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool NameTree::insert(const std::string &path,
|
||||
const nodes::Statement &statement) {
|
||||
nodes::CombineResult NameTree::insert_combine(const std::string &path,
|
||||
nodes::Statement &&statement) {
|
||||
auto name_ids = slice_path_to_name_ids(path);
|
||||
|
||||
size_t node_id = add_node(get_root(), name_ids);
|
||||
|
||||
if (nodes_[node_id].get_statement().has_value()) {
|
||||
return false;
|
||||
if (!nodes_[node_id].get_statement().has_value()) {
|
||||
nodes_[node_id].set_statement(std::move(statement));
|
||||
return nodes::CombineResult::OK;
|
||||
}
|
||||
|
||||
nodes_[node_id].set_statement(statement);
|
||||
return true;
|
||||
return nodes_[node_id].get_statement().value()->combine(std::move(statement));
|
||||
}
|
||||
|
||||
std::optional<nodes::Statement *> NameTree::find(const std::string &path) {
|
||||
|
|
@ -64,6 +66,41 @@ NameTree::find(const std::string &path) const {
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
void NameTree::print(printers::Printer &printer) const {
|
||||
nodes_[get_root()].print(nodes_, printer);
|
||||
}
|
||||
|
||||
// TODO
|
||||
void NameTree::add_statement_children_to_tree() {
|
||||
for (auto &node : nodes_) {
|
||||
if (!node.get_statement().has_value()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (node.get_statement().value()->get_any()->index()) {
|
||||
case 0: // Import
|
||||
// TODO: link imported symbols, if named import, otherwise link imported
|
||||
// symbols to root
|
||||
break;
|
||||
case 1: // FunctionDefinition
|
||||
// TODO: link to result type
|
||||
break;
|
||||
case 2: // TypeDefinition
|
||||
// TODO: link methods + link children to types + connect to typeclasses
|
||||
break;
|
||||
case 3: // TypeclassDefinition
|
||||
// TODO: link methods + connect typeclasses
|
||||
break;
|
||||
case 4: // EmptyLines
|
||||
break;
|
||||
default:
|
||||
error_handling::handle_general_error(
|
||||
"Unexpected statement type in name tree");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- private
|
||||
|
||||
size_t NameTree::add_node(size_t current_node,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue