Rename node position to offset
This commit is contained in:
parent
12582d5e96
commit
d910a2d0e7
4 changed files with 30 additions and 25 deletions
|
|
@ -39,7 +39,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
const void *data;
|
||||
TSLength position;
|
||||
TSLength offset;
|
||||
} TSNode;
|
||||
|
||||
typedef unsigned short TSSymbol;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ std::ostream &operator<<(std::ostream &stream, const TSTree *tree) {
|
|||
return stream << std::string(ts_tree_string(tree, symbol_names));;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const TSNode ref) {
|
||||
return stream << std::string("{") << (const TSTree *)ref.data <<
|
||||
std::string(", ") << std::to_string(ref.position.chars) << std::string("}");
|
||||
std::ostream &operator<<(std::ostream &stream, const TSNode node) {
|
||||
return stream << std::string("{") << (const TSTree *)node.data <<
|
||||
std::string(", ") << std::to_string(ts_node_pos(node).chars) << std::string("}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,38 +4,43 @@
|
|||
#include "runtime/tree.h"
|
||||
#include "runtime/document.h"
|
||||
|
||||
TSNode ts_node_make(const TSTree *tree, TSLength position) {
|
||||
return (TSNode){.data = tree, .position = position };
|
||||
TSNode ts_node_make(const TSTree *tree, TSLength offset) {
|
||||
return (TSNode){.data = tree, .offset = offset };
|
||||
}
|
||||
|
||||
static inline const TSTree *get_tree(TSNode this) {
|
||||
static inline const TSTree *ts_node__tree(TSNode this) {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
static inline TSLength ts_node__offset(TSNode this) {
|
||||
return this.offset;
|
||||
}
|
||||
|
||||
TSLength ts_node_pos(TSNode this) {
|
||||
return ts_length_add(this.position, get_tree(this)->padding);
|
||||
return ts_length_add(ts_node__offset(this), ts_node__tree(this)->padding);
|
||||
}
|
||||
|
||||
TSLength ts_node_size(TSNode this) {
|
||||
return get_tree(this)->size;
|
||||
return ts_node__tree(this)->size;
|
||||
}
|
||||
|
||||
bool ts_node_eq(TSNode this, TSNode other) {
|
||||
return ts_tree_eq(get_tree(this), get_tree(other)) &&
|
||||
ts_length_eq(this.position, other.position);
|
||||
return ts_tree_eq(ts_node__tree(this), ts_node__tree(other)) &&
|
||||
ts_length_eq(ts_node__offset(this), ts_node__offset(other));
|
||||
}
|
||||
|
||||
const char *ts_node_name(TSNode this, const TSDocument *document) {
|
||||
return document->parser.language->symbol_names[get_tree(this)->symbol];
|
||||
return document->parser.language->symbol_names[ts_node__tree(this)->symbol];
|
||||
}
|
||||
|
||||
const char *ts_node_string(TSNode this, const TSDocument *document) {
|
||||
return ts_tree_string(get_tree(this), document->parser.language->symbol_names);
|
||||
return ts_tree_string(ts_node__tree(this),
|
||||
document->parser.language->symbol_names);
|
||||
}
|
||||
|
||||
TSNode ts_node_parent(TSNode this) {
|
||||
const TSTree *tree = get_tree(this);
|
||||
TSLength position = this.position;
|
||||
const TSTree *tree = ts_node__tree(this);
|
||||
TSLength position = ts_node__offset(this);
|
||||
|
||||
do {
|
||||
TSTree *parent = tree->context.parent;
|
||||
|
|
@ -54,8 +59,8 @@ TSNode ts_node_parent(TSNode this) {
|
|||
}
|
||||
|
||||
TSNode ts_node_prev_sibling(TSNode this) {
|
||||
const TSTree *tree = get_tree(this);
|
||||
TSLength position = this.position;
|
||||
const TSTree *tree = ts_node__tree(this);
|
||||
TSLength position = ts_node__offset(this);
|
||||
|
||||
do {
|
||||
TSTree *parent = tree->context.parent;
|
||||
|
|
@ -79,8 +84,8 @@ TSNode ts_node_prev_sibling(TSNode this) {
|
|||
}
|
||||
|
||||
TSNode ts_node_next_sibling(TSNode this) {
|
||||
const TSTree *tree = get_tree(this);
|
||||
TSLength position = this.position;
|
||||
const TSTree *tree = ts_node__tree(this);
|
||||
TSLength position = ts_node__offset(this);
|
||||
|
||||
do {
|
||||
TSTree *parent = tree->context.parent;
|
||||
|
|
@ -105,12 +110,12 @@ TSNode ts_node_next_sibling(TSNode this) {
|
|||
}
|
||||
|
||||
size_t ts_node_child_count(TSNode this) {
|
||||
return get_tree(this)->visible_child_count;
|
||||
return ts_node__tree(this)->visible_child_count;
|
||||
}
|
||||
|
||||
TSNode ts_node_child(TSNode this, size_t child_index) {
|
||||
const TSTree *tree = get_tree(this);
|
||||
TSLength position = this.position;
|
||||
const TSTree *tree = ts_node__tree(this);
|
||||
TSLength position = ts_node__offset(this);
|
||||
|
||||
bool did_descend = true;
|
||||
while (did_descend) {
|
||||
|
|
@ -141,8 +146,8 @@ TSNode ts_node_child(TSNode this, size_t child_index) {
|
|||
}
|
||||
|
||||
TSNode ts_node_find_for_range(TSNode this, size_t min, size_t max) {
|
||||
const TSTree *tree = get_tree(this), *last_visible_tree = tree;
|
||||
TSLength position = this.position, last_visible_position = position;
|
||||
const TSTree *tree = ts_node__tree(this), *last_visible_tree = tree;
|
||||
TSLength position = ts_node__offset(this), last_visible_position = position;
|
||||
|
||||
bool did_descend = true;
|
||||
while (did_descend) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
TSNode ts_node_make(const TSTree *, TSLength);
|
||||
|
||||
static inline TSNode ts_node_null() {
|
||||
return (TSNode){.data = NULL, .position = ts_length_zero() };
|
||||
return (TSNode){.data = NULL, .offset = ts_length_zero() };
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue