node

struct Node;
A single Node within a syntax Tree.
TSNode tsnode;
The internal TSNode
nothrow @nogc this(TSNode tsnode);
Create a new Node.
Throws: If the passed tsnode is null, it will trigger an error in the debug mode.
static nothrow @nogc @trusted Nullable!Node create(TSNode tsnode);
Creates a new Node from the given nullable TSNode
Parameters:
TSNode tsnode a C tsnode, which can be a null node.
Returns: a Nullable!Node, which gives the node if it is not a null node, and null if it is.
bool isNull();
Check if the Node is a null node.
Note: this function should be only used when creating a Node with its constructor in the release mode (instead of using Node.create). All the methods of Node already use Node.create and return a Nullable!Node.
const nothrow @nogc auto id();
Get a numeric id for this node that is unique.
Within a given syntax tree, no two nodes have the same id. However, if a new tree is created based on an older tree, and a node from the old tree is reused in the process, then that node will have the same id in both trees.
const nothrow @nogc auto kind_id();
Get this node's type as a numerical id.
const nothrow @nogc auto kind();
Get this node's type as a string.
const nothrow @nogc auto language();
const nothrow @nogc auto is_named();
Check if this node is named.
Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.
const nothrow @nogc auto is_extra();
Check if this node is extra.
Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere.
const nothrow @nogc auto has_changes();
Check if this node has been edited
const nothrow @nogc auto has_error();
Check if this node represents a syntax error or contains any syntax errors anywhere within it.
const nothrow @nogc auto is_error();
Check if this node represents a syntax error.
Syntax errors represent parts of the code that could not be incorporated into a valid syntax tree.
const nothrow @nogc auto is_missing();
Check if this node is missing.
Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.
const nothrow @nogc auto start_byte();
Get the byte offsets where this node starts
const nothrow @nogc auto end_byte();
Get the byte offsets where this node end.
const nothrow @nogc auto byte_range();
Get the byte range of source code that this node represents.
const nothrow @nogc auto start_position();
Get this node's start position in terms of rows and columns.
const nothrow @nogc auto end_position();
Get this node's end position in terms of rows and columns.
const nothrow @nogc auto range();
Get the range of source code that this node represents, both in terms of raw bytes and of row/column coordinates.
const nothrow @nogc auto child(size_t child_index);
Get the node's child at the given index, where zero represents the first child.
This method is fairly fast, but its cost is technically log(child_index), so you if you might be iterating over a long list of children, you should use [Node::children] instead.
Returns: A Nulllable!Node
const nothrow @nogc auto child_count();
Get this node's number of children
const nothrow @nogc auto named_child(size_t i);
Get this node's named child at the given index.
See also [Node::is_named]. This method is fairly fast, but its cost is technically log(i), so you if you might be iterating over a long list of children, you should use [Node::named_children] instead.
Returns: A Nulllable!Node
const nothrow @nogc auto named_child_count();
Get this node's number of named children.
See also [Node::is_named].
const auto child_by_field_name(string field_name);
Get the first child with the given field name.
If multiple children may have the same field name, access them using children_by_field_name
Returns: A Nulllable!Node
const nothrow @nogc auto child_by_field_id(ushort field_id);
Get the first child with the given field name.
If multiple children may have the same field name, access them using children_by_field_name
Returns: A Nulllable!Node
const nothrow @nogc auto children(TreeCursor* cursor);
Iterate over this node children.
A !!!!! UNDEFINED MACRO: "DOC_ROOT_tree_cursor" !!!!!!C:\Users\aminy\Github\GitHub\D\d-tree-sitter\d-tree-sitter\docs\d_tree_sitter--d_tree_sitter.tree_cursor.html#.TreeCursor">TreeCursor is used to retrieve the children efficiently. Obtain a !!!!! UNDEFINED MACRO: "DOC_ROOT_tree_cursor" !!!!!!C:\Users\aminy\Github\GitHub\D\d-tree-sitter\d-tree-sitter\docs\d_tree_sitter--d_tree_sitter.tree_cursor.html#.TreeCursor">TreeCursor by calling [Tree::walk] or [Node::walk]. To avoid unnecessary allocations, you should reuse the same cursor for subsequent calls to this method.
If you're walking the tree recursively, you may want to use the TreeCursor APIs directly instead.
const nothrow @nogc auto named_children(TreeCursor* cursor);
Iterate over this node named children.
See also [Node::children].
const nothrow @nogc auto children_by_field_id(ushort field_id, TreeCursor* cursor);
Iterate over this node children with a given field id.
See also [Node::children_by_field_name].
const auto children_by_field_name(string field_name, TreeCursor* cursor);
Iterate over this node children with a given field name.
See also [Node::children].
const nothrow @nogc auto has_parent();
Check if the node has a immediate parent
Note: parent method already does this check
const nothrow @nogc auto parent();
Get this node immediate parent.
Returns: a Nullable!Node, which gives the parent node if it has a parent, and null if the node has no parent.
const nothrow @nogc @trusted auto nth_parent(in uint max_nth = 2);
Find the nth parent of node. It goes up until it hits a null parent or max_nth.
Parameters:
uint max_nth the maximum level to go up.
Returns: A node. If the given node doesn't have a parent, it returns the node itself.
Note: the nth might not be reached if there are no more parents.
const nothrow @nogc auto has_next_sibling();
Check if the node has a next sibling.
Note: next_sibling method already does this check
const nothrow @nogc auto next_sibling();
Get this node next sibling.
Returns: A Nulllable!Node
const nothrow @nogc auto has_prev_sibling();
Check if the node has a previous sibling.
Note: prev_sibling method already does this check
const nothrow @nogc auto prev_sibling();
Get this node previous sibling.
Returns: A Nulllable!Node
const nothrow @nogc auto next_named_sibling();
Get this node next named sibling.
Returns: A Nulllable!Node
const nothrow @nogc auto prev_named_sibling();
Get this node previous named sibling.
Returns: A Nulllable!Node
const nothrow @nogc auto descendant_for_byte_range(uint start, uint end);
Get the smallest node within this node that spans the given range.
Returns: A Nulllable!Node
const nothrow @nogc auto named_descendant_for_byte_range(uint start, uint end);
Get the smallest named node within this node that spans the given range.
Returns: A Nulllable!Node
const nothrow @nogc auto descendant_for_point_range(Point start, Point end);
Get the smallest node within this node that spans the given range.
Returns: A Nulllable!Node
const nothrow @nogc auto named_descendant_for_point_range(Point start, Point end);
Get the smallest named node within this node that spans the given range.
Returns: A Nulllable!Node
const nothrow auto to_string();
Convert Node to string
const nothrow @nogc auto utf8_text(string source_code);
const nothrow @nogc auto utf8_text(ubyte[] source);
Convert Node to utf8 string
const nothrow @nogc auto utf16_text(ushort[] source);
Convert Node to utf16 string
const nothrow @nogc auto walk();
const @nogc @trusted auto hash();
Hash a node. This returns a unique string for this node.
const void traverse(TreeVisitor visitor);
Traverse this Node and all its descendants in a top-down left to right manner while applying the visitor at each Node.
const nothrow void traverse_nothrow(TreeVisitor visitor);
Traverse this Node and all its descendants in a top-down left to right manner while applying the visitor at each Node.
NOTE: if you are sure that TreeVisitor is nothrow
nothrow @nogc auto edit(const InputEdit* edit);
Edit this node to keep it in-sync with source code that has been edited.
This function is only rarely needed. When you edit a syntax tree with the [Tree::edit] method, all of the nodes that you retrieve from the tree afterward will already reflect the edit. You only need to use [Node::edit] when you have a specific Node instance that you want to keep and continue to use after an edit.
struct NodeChildren;
A range to iterate over the node children.
A !!!!! UNDEFINED MACRO: "DOC_ROOT_tree_cursor" !!!!!!C:\Users\aminy\Github\GitHub\D\d-tree-sitter\d-tree-sitter\docs\d_tree_sitter--d_tree_sitter.tree_cursor.html#.TreeCursor">TreeCursor is used to retrieve the children efficiently. Obtain a !!!!! UNDEFINED MACRO: "DOC_ROOT_tree_cursor" !!!!!!C:\Users\aminy\Github\GitHub\D\d-tree-sitter\d-tree-sitter\docs\d_tree_sitter--d_tree_sitter.tree_cursor.html#.TreeCursor">TreeCursor by calling [Tree::walk] or [Node::walk]. To avoid unnecessary allocations, you should reuse the same cursor for subsequent calls to this method.
If you're walking the tree recursively, you may want to use the TreeCursor APIs directly instead.
nothrow @nogc this(Node parent, TreeCursor* cursor);
create a NodeChildren for the given node and cursor
const nothrow @nogc auto front();
Get the current child
nothrow @nogc void popFront();
go to the next child
const nothrow @nogc auto empty();
Is it the end?
struct NodeNamedChildren;
A range the iterates over the node named children.
See also [Node::children].
nothrow @nogc this(Node parent, TreeCursor* cursor);
create a NodeNamedChildren for the given node and cursor
nothrow @nogc auto front();
Get the current child NOTE Do not call this twice in a row without calling popFront and empty in between!
nothrow @nogc void popFront();
go to the next child
const nothrow @nogc auto empty();
Is it the end?
struct NodeChildrenByFieldID;
A range to iterate over the node children with a given field id.
See also [Node::children_by_field_name].
nothrow @nogc this(Node parent, ushort field_id, TreeCursor* cursor);
create a NodeChildrenByFieldID for the given node, field_id, and cursor
nothrow @nogc auto front();
Get the current child NOTE Do not call this twice in a row without calling popFront and empty in between!
nothrow @nogc void popFront();
go to the next child
const nothrow @nogc auto empty();
Is it the end?