lang/include/name_tree.hpp

81 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
#include "tree_sitter_wrapper.hpp"
2023-07-20 14:38:44 +03:00
#include <vector>
namespace names {
// IN PROGRESS
class NameTree {
public:
2023-07-20 14:38:44 +03:00
struct Node {};
NameTree() {}
2023-07-20 14:38:44 +03:00
bool insert_path(const std::vector<std::string> &path, Node node) {}
private:
};
2023-07-20 14:38:44 +03:00
class NameStorage;
class NameProxy {
friend NameStorage;
public:
NameProxy(NameStorage *name_storage, size_t id)
: name_storage_(name_storage), id_(id) {}
std::string *get();
const std::string *get() const;
bool operator==(const NameProxy &other) const {
return name_storage_ == other.name_storage_ && id_ == other.id_;
}
bool operator<(const NameProxy &other) const {
return name_storage_ < other.name_storage_ ||
(name_storage_ == other.name_storage_ && id_ < other.id_);
}
private:
NameStorage *name_storage_;
size_t id_;
};
class NameStorage {
friend NameProxy;
public:
NameProxy add_expression(const std::string &name) {
storage_.push_back(name);
return NameProxy(this, storage_.size() - 1);
}
NameProxy add_expression(std::string &&name) {
storage_.push_back(std::move(name));
return NameProxy(this, storage_.size() - 1);
}
private:
std::string *get_expression(size_t id) { return &storage_.at(id); }
const std::string *get_expression(size_t id) const {
return &storage_.at(id);
}
private:
std::vector<std::string> storage_;
};
std::vector<std::string> string_to_path(const std::string &str) {
std::vector<std::string> path;
for (;;) {
}
return path;
} // IN PROGRESS
} // namespace names