mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-07 23:48:44 +00:00
basic node builders
This commit is contained in:
parent
1b28f41810
commit
696a9c3a1a
11 changed files with 442 additions and 37 deletions
|
|
@ -2,10 +2,79 @@
|
|||
|
||||
#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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue