The Node API provides functions for inspecting node properties and traversing syntax trees. Unlike other Tree-sitter types,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt
Use this file to discover all available pages before exploring further.
TSNode is passed by value rather than by pointer.
Node properties
ts_node_type
Get the node’s type as a null-terminated string.The node to inspect
ts_node_symbol
Get the node’s type as a numerical id.The node to inspect
ts_node_language
Get the node’s language.The node to inspect
ts_node_grammar_type
Get the node’s type as it appears in the grammar ignoring aliases as a null-terminated string.The node to inspect
ts_node_grammar_symbol
Get the node’s type as a numerical id as it appears in the grammar ignoring aliases.The node to inspect
ts_language_next_state instead of ts_node_symbol.
Node positions
ts_node_start_byte
Get the node’s start byte.The node to inspect
ts_node_start_point
Get the node’s start position in terms of rows and columns.The node to inspect
ts_node_end_byte
Get the node’s end byte.The node to inspect
ts_node_end_point
Get the node’s end position in terms of rows and columns.The node to inspect
Node state
ts_node_string
Get an S-expression representing the node as a string.The node to convert to a string
free).
Example:
ts_node_is_null
Check if the node is null.The node to check
true if the node is null.
Functions like ts_node_child and ts_node_next_sibling return a null node to indicate that no such node was found.
ts_node_is_named
Check if the node is named.The node to check
true if the node is named.
Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.
ts_node_is_missing
Check if the node is missing.The node to check
true if the node is missing.
Missing nodes are inserted by the parser to recover from certain kinds of syntax errors.
ts_node_is_extra
Check if the node is extra.The node to check
true if the node is extra.
Extra nodes represent things like comments, which are not required by the grammar but can appear anywhere.
ts_node_has_changes
Check if a syntax node has been edited.The node to check
true if the node has been edited.
ts_node_has_error
Check if the node is a syntax error or contains any syntax errors.The node to check
true if the node is or contains an error.
ts_node_is_error
Check if the node is a syntax error.The node to check
true if the node is an error.
ts_node_parse_state
Get this node’s parse state.The node to inspect
ts_node_next_parse_state
Get the parse state after this node.The node to inspect
Node relationships
ts_node_parent
Get the node’s immediate parent.The node to inspect
ts_node_child_with_descendant for iterating over the node’s ancestors.
ts_node_child_with_descendant
Get the node that contains the given descendant.The ancestor node
The descendant node
self that contains descendant.
Note that this can return descendant itself if it’s a direct child of self.
ts_node_child
Get the node’s child at the given index.The parent node
The child index, where zero represents the first child
ts_node_field_name_for_child
Get the field name for the node’s child at the given index.The parent node
The child index
NULL if no field is found.
ts_node_field_name_for_named_child
Get the field name for the node’s named child at the given index.The parent node
The named child index
NULL if no field is found.
ts_node_child_count
Get the node’s number of children.The node to inspect
ts_node_named_child
Get the node’s named child at the given index.The parent node
The named child index
ts_node_is_named.
ts_node_named_child_count
Get the node’s number of named children.The node to inspect
ts_node_is_named.
ts_node_child_by_field_name
Get the node’s child with the given field name.The parent node
The field name
The length of the field name
ts_node_child_by_field_id
Get the node’s child with the given numerical field id.The parent node
The numerical field ID
ts_language_field_id_for_name.
Siblings
ts_node_next_sibling
Get the node’s next sibling.The node to inspect
ts_node_prev_sibling
Get the node’s previous sibling.The node to inspect
ts_node_next_named_sibling
Get the node’s next named sibling.The node to inspect
ts_node_prev_named_sibling
Get the node’s previous named sibling.The node to inspect
Searching
ts_node_first_child_for_byte
Get the node’s first child that contains or starts after the given byte offset.The parent node
The byte offset to search for
ts_node_first_named_child_for_byte
Get the node’s first named child that contains or starts after the given byte offset.The parent node
The byte offset to search for
ts_node_descendant_count
Get the node’s number of descendants, including one for the node itself.The node to inspect
ts_node_descendant_for_byte_range
Get the smallest node within this node that spans the given range of bytes.The node to search within
The start byte offset
The end byte offset
ts_node_descendant_for_point_range
Get the smallest node within this node that spans the given range of positions.The node to search within
The start position
The end position
ts_node_named_descendant_for_byte_range
Get the smallest named node within this node that spans the given range of bytes.The node to search within
The start byte offset
The end byte offset
ts_node_named_descendant_for_point_range
Get the smallest named node within this node that spans the given range of positions.The node to search within
The start position
The end position
Editing
ts_node_edit
Edit the node to keep it in-sync with source code that has been edited.Pointer to the node to edit
Description of the edit
ts_tree_edit, all of the nodes that you retrieve from the tree afterward will already reflect the edit. You only need to use ts_node_edit when you have a TSNode instance that you want to keep and continue to use after an edit.
ts_point_edit
Edit a point to keep it in-sync with source code that has been edited.Pointer to the point to edit
Pointer to the byte offset to edit
Description of the edit
ts_range_edit
Edit a range to keep it in-sync with source code that has been edited.Pointer to the range to edit
Description of the edit
Comparison
ts_node_eq
Check if two nodes are identical.The first node
The second node
true if the nodes are identical.