grammar refactoring: build_visitor fixed & visitors tested

This commit is contained in:
ProgramSnail 2023-04-11 13:49:22 +03:00
parent 3c2d496a85
commit e4802896bd
35 changed files with 118128 additions and 91770 deletions

View file

@ -45,7 +45,7 @@ public:
std::string GetValue() { // from source
size_t start = ts_node_start_byte(node_);
size_t end = ts_node_end_byte(node_);
return source_->substr(start, end - start); // TODO check
return source_->substr(start, end - start);
}
bool IsNull() {
@ -86,28 +86,18 @@ public:
return Node(ts_node_child_by_field_name(node_, name.c_str(), name.size()), source_);
}
// ?? use field id instaed of name ??
// ?? node equality check needed ??
Node NextSibling() {
return Node(ts_node_next_sibling(node_), source_);
}
Node NextNamedSibling() {
return Node(ts_node_next_named_sibling(node_), source_);
}
private:
bool uninitialized_;
TSNode node_;
const std::string* source_;
};
class Cursor { // ?? needed ??
public:
Cursor(const Node& node);
void ResetTo(const Node& node);
Node GetCurrentNode();
std::string GetCurrentNodeName();
bool GoToParent();
bool GoToNextSibling();
bool GoToFirstChild();
private:
TSTreeCursor cursor_;
};
ParseTree(const std::string& source) : source_(source) {
TSParser* parser = ts_parser_new();