mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
print + build partially tested
This commit is contained in:
parent
0d62ae0814
commit
15e36c203a
22 changed files with 179 additions and 116 deletions
|
|
@ -13,8 +13,16 @@ class ParseTree {
|
|||
public:
|
||||
class Node {
|
||||
public:
|
||||
Node() = default;
|
||||
Node(const TSNode &node, const std::string* source) : node_(node), source_(source) {}
|
||||
Node() : uninitialized_(true) {
|
||||
for (unsigned int& i : node_.context) {
|
||||
i = 0;
|
||||
}
|
||||
node_.id = nullptr;
|
||||
node_.tree = nullptr;
|
||||
|
||||
source_ = nullptr;
|
||||
};
|
||||
Node(const TSNode& node, const std::string* source) : uninitialized_(false), node_(node), source_(source) {}
|
||||
|
||||
std::string GetType() {
|
||||
return ts_node_type(node_);
|
||||
|
|
@ -81,8 +89,9 @@ public:
|
|||
// ?? use field id instaed of name ??
|
||||
// ?? node equality check needed ??
|
||||
private:
|
||||
bool uninitialized_;
|
||||
TSNode node_;
|
||||
const std::string* source_ = nullptr;
|
||||
const std::string* source_;
|
||||
};
|
||||
class Cursor { // ?? needed ??
|
||||
public:
|
||||
|
|
@ -106,15 +115,22 @@ public:
|
|||
|
||||
tree_ = ts_parser_parse_string(
|
||||
parser,
|
||||
NULL,
|
||||
nullptr,
|
||||
source_.c_str(),
|
||||
source_.size());
|
||||
|
||||
ts_parser_delete(parser);
|
||||
}
|
||||
|
||||
ParseTree(const ParseTree& parse_tree) : tree_(ts_tree_copy(parse_tree.tree_)), source_(parse_tree.source_) {}
|
||||
|
||||
Node GetRoot() const {
|
||||
return Node(ts_tree_root_node(tree_), &source_);
|
||||
}
|
||||
|
||||
~ParseTree() {
|
||||
ts_tree_delete(tree_);
|
||||
}
|
||||
private:
|
||||
TSTree* tree_;
|
||||
std::string source_; // for token value extraction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue