mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 06:58:46 +00:00
80 lines
1.5 KiB
C++
80 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "tree_sitter_wrapper.hpp"
|
|
|
|
#include <vector>
|
|
|
|
namespace names {
|
|
|
|
// IN PROGRESS
|
|
class NameTree {
|
|
public:
|
|
struct Node {};
|
|
|
|
NameTree() {}
|
|
|
|
bool insert_path(const std::vector<std::string> &path, Node node) {}
|
|
|
|
private:
|
|
};
|
|
|
|
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
|