class
CursorAllows efficient walking of a Tree.
Contents
This is more efficient than using the methods on Node because we don't create a new Node after every navigation step.
Features not included (because we currently don't use them):
ts_tree_cursor_goto_first_child_for_byte
Constructors, destructors, conversion operators
Public functions
- auto operator=(const Cursor&) -> Cursor& noexcept
- auto operator=(Cursor&&) -> Cursor& defaulted
- void reset(Node)
- Reset the cursor to the given node.
- void reset(const Tree&)
- Reset the cursor to the root node of the given tree.
- auto current_node() const -> Node
- The node the cursor is currently pointing at.
- auto current_field_name() const -> const char*
- The field name of the node the cursor is currently pointing at.
- auto current_field_id() const -> FieldId
- The FieldId of the node the cursor is currently pointing at.
- auto goto_parent() -> bool
- Move the cursor to the parent of the current node.
- auto goto_next_sibling() -> bool
- Move the cursor to the next sibling of the current node.
- auto skip_n_siblings(int n) -> int
- Similar to calling Cursor::
goto_next_sibling n times. - auto goto_first_child() -> bool
- Move the cursor to the first child of the current node.
- auto goto_next_named_sibling() -> bool
- Move the cursor to the next named sibling of the current node.
- auto goto_first_named_child() -> bool
- Move the cursor to the next named sibling of the current node.
-
template<typename Fn>auto skip_siblings_while(Fn fn) -> bool
- Skips over nodes while the given callback returns
true
. -
template<typename Fn>void foreach_remaining_siblings(Fn fn)
- Calls the provided callback for every sibling and moves the cursor.
- auto children() -> std::vector<Node>
- List of all child nodes of the current node.
- auto named_children() -> std::vector<Node>
- List of all named child nodes of the current node.
Friends
Function documentation
bool ts:: Cursor:: goto_parent()
Move the cursor to the parent of the current node.
Returns only false if the cursor is already at the root node.
bool ts:: Cursor:: goto_next_sibling()
Move the cursor to the next sibling of the current node.
Returns false if there was no next sibling.
int ts:: Cursor:: skip_n_siblings(int n)
Similar to calling Cursor::
Returns the number of siblings skipped.
bool ts:: Cursor:: goto_first_child()
Move the cursor to the first child of the current node.
Returns false
if there were no children.
bool ts:: Cursor:: goto_next_named_sibling()
Move the cursor to the next named sibling of the current node.
Returns false
if there was no next sibling.
bool ts:: Cursor:: goto_first_named_child()
Move the cursor to the next named sibling of the current node.
Returns false
if there was no next sibling.
NOTE: This method might move the cursor to another unnamed node and then still return false if there is no named node.
template<typename Fn>
bool ts:: Cursor:: skip_siblings_while(Fn fn)
Skips over nodes while the given callback returns true
.
The method returns false
if there were no more siblings to skip while the callback still returned true
.
template<typename Fn>
void ts:: Cursor:: foreach_remaining_siblings(Fn fn)
Calls the provided callback for every sibling and moves the cursor.
The callback will also be called on the current node. So it will always be called at least once.
std::vector<Node> ts:: Cursor:: children()
List of all child nodes of the current node.
This will also move the cursor to the last child but you can Cursor::
std::vector<Node> ts:: Cursor:: named_children()
List of all named child nodes of the current node.
This will also move the cursor to the last child but you can Cursor::