basic node builders

This commit is contained in:
ProgramSnail 2023-07-20 14:38:44 +03:00
parent 1b28f41810
commit 696a9c3a1a
11 changed files with 442 additions and 37 deletions

View file

@ -16,63 +16,63 @@ public:
Node(const TSNode &node, const std::string *source)
: node_(node), source_(source) {}
std::string GetType() { return ts_node_type(node_); }
std::string get_type() { return ts_node_type(node_); }
std::pair<size_t, size_t> GetStartPoint() {
std::pair<size_t, size_t> get_start_point() {
TSPoint point = ts_node_start_point(node_);
return {point.row, point.column};
}
std::pair<size_t, size_t> GetEndPoint() {
std::pair<size_t, size_t> get_end_point() {
TSPoint point = ts_node_end_point(node_);
return {point.row, point.column};
}
std::string GetAsSExpression() { return ts_node_string(node_); }
std::string get_as_sexpression() { return ts_node_string(node_); }
std::string GetValue() { // from source
std::string get_value() { // from source
size_t start = ts_node_start_byte(node_);
size_t end = ts_node_end_byte(node_);
return source_->substr(start, end - start);
}
bool IsNull() { return ts_node_is_null(node_); }
bool is_null() { return ts_node_is_null(node_); }
bool IsNamed() { return ts_node_is_named(node_); }
bool is_named() { return ts_node_is_named(node_); }
bool IsMissing() { return ts_node_is_missing(node_); }
bool is_missing() { return ts_node_is_missing(node_); }
bool IsExtra() { // comments, etc.
bool is_extra() { // comments, etc.
return ts_node_is_extra(node_);
}
bool HasError() { return ts_node_has_error(node_); }
bool has_error() { return ts_node_has_error(node_); }
Node NthChild(size_t n) { return Node(ts_node_child(node_, n), source_); }
Node nth_child(size_t n) { return Node(ts_node_child(node_, n), source_); }
size_t ChildCount() { return ts_node_child_count(node_); }
size_t child_count() { return ts_node_child_count(node_); }
Node NthNamedChild(size_t n) {
Node nth_named_child(size_t n) {
return Node(ts_node_named_child(node_, n), source_);
}
size_t NamedChildCount() { return ts_node_named_child_count(node_); }
size_t named_child_count() { return ts_node_named_child_count(node_); }
Node ChildByFieldName(const std::string &name) {
Node child_by_field_name(const std::string &name) {
return Node(ts_node_child_by_field_name(node_, name.c_str(), name.size()),
source_);
}
Node PreviousSibling() {
Node previous_sibling() {
return Node(ts_node_prev_sibling(node_), source_);
}
Node PreviousNamedSibling() {
Node previous_named_sibling() {
return Node(ts_node_prev_named_sibling(node_), source_);
}
Node NextSibling() { return Node(ts_node_next_sibling(node_), source_); }
Node next_sibling() { return Node(ts_node_next_sibling(node_), source_); }
Node NextNamedSibling() {
Node next_named_dibling() {
return Node(ts_node_next_named_sibling(node_), source_);
}
@ -94,12 +94,12 @@ public:
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_); }
Node get_root() const { return Node(ts_tree_root_node(tree_), &source_); }
~ParseTree() { ts_tree_delete(tree_); }
bool IsProperlyParsed() { // TODO: find place
return !GetRoot().HasError();
bool is_properly_parsed() { // TODO: find place
return !get_root().has_error();
}
private: