class
NodeA syntax node in a parsed tree.
Contents
Wrapper for a TSNode.
Nodes can be named or anonymous (see Named vs Anonymous Nodes).
Nodes can't be null. If you try to create a null node the constructor will throw a NullNodeException. (But this constructor should only be used internally.)
Supports equality operators.
Features not included (because we currently don't use them):
- Get child by field:
ts_node_child_by_field_name
ts_node_child_by_field_id
- Get child/decendant for byte/point (range):
ts_node_first_child_for_byte
ts_node_first_named_child_for_byte
ts_node_descendant_for_byte_range
ts_node_descendant_for_point_range
ts_node_named_descendant_for_byte_range
ts_node_named_descendant_for_point_range
- Editing nodes directly (but we support this through the Tree):
ts_node_edit
Public static variables
Public static functions
Constructors, destructors, conversion operators
Public functions
- auto raw() const -> TSNode
- Returns the raw Tree-Sitter node.
- auto tree() const -> const Tree&
- The Tree this node was created from.
- auto type() const -> const char*
- The substring of the source code this node represents.
- auto type_id() const -> TypeId
- The numeric TypeId of the node.
- auto is_named() const -> bool
- Check if the node is named.
- auto is_missing() const -> bool
- Check if the node is missing.
- auto is_extra() const -> bool
- Check if the node is extra.
- auto has_changes() const -> bool
- Check if the node has been edited.
- auto has_error() const -> bool
- Check if the node (or any of its children) is a syntax error.
- auto parent() const -> std::optional<Node>
- The parent of the node.
- auto child(std::uint32_t index) const -> std::optional<Node>
- The n-th child (0 indexed). Counts named and anonymous nodes.
- auto child_count() const -> std::uint32_t
- The number of all children (named and anonymous).
- auto children() const -> std::vector<Node>
- List of all children (named and anonymous).
- auto named_child(std::uint32_t index) const -> std::optional<Node>
- The n-th named child (0 indexed).
- auto named_child_count() const -> std::uint32_t
- The number of named children.
- auto named_children() const -> std::vector<Node>
- List of all named children.
- auto next_sibling() const -> std::optional<Node>
- The node's next sibling.
- auto prev_sibling() const -> std::optional<Node>
- The node's previous sibling.
- auto next_named_sibling() const -> std::optional<Node>
- The node's next named sibling.
- auto prev_named_sibling() const -> std::optional<Node>
- The node's previous named sibling.
- auto start_byte() const -> std::uint32_t
- Start position as byte offset.
- auto end_byte() const -> std::uint32_t
- End position as byte offset.
- auto start_point() const -> Point
- The start position as Point (row and column).
- auto end_point() const -> Point
- The end position as Point (row and column).
- auto start() const -> Location
- The start position as Location (row, column and byte offset).
- auto end() const -> Location
- The end position as Location (row, column and byte offset).
- auto range() const -> Range
- The Range of the node (start and end Location).
- auto text() const -> std::string
- The substring of source code this node represents.
- auto as_s_expr() const -> std::string
- A string representation of the syntax tree starting from the node represented as an s-expression.
Function documentation
ts:: Node:: Node(TSNode node,
const Tree& tree)
Creates a new node from the given tree-sitter node and the tree.
Will throw NullNodeException if the node is null.
TSNode ts:: Node:: raw() const
Returns the raw Tree-Sitter node.
bool ts:: Node:: is_missing() const
Check if the node is missing.
Missing nodes are used to recover from some kinds of syntax errors.
bool ts:: Node:: is_extra() const
Check if the node is extra.
Extra nodes represent things like comments.
std::optional<Node> ts:: Node:: named_child(std::uint32_t index) const
The n-th named child (0 indexed).
This will not return anonymous nodes and the index only considers named nodes.
Returns std::nullopt
if the child does not exist.
std::optional<Node> ts:: Node:: next_sibling() const
The node's next sibling.
This will also return anonymous nodes.
Returns std::nullopt
if there are no more siblings.
std::optional<Node> ts:: Node:: prev_sibling() const
The node's previous sibling.
This will also return anonymous nodes.
Returns std::nullopt
if this node is already the first sibling.
std::optional<Node> ts:: Node:: next_named_sibling() const
The node's next named sibling.
This will not return anonymous nodes.
Returns std::nullopt
if there are no more named siblings.
std::optional<Node> ts:: Node:: prev_named_sibling() const
The node's previous named sibling.
This will not return anonymous nodes.
Returns std::nullopt
if this node is already the first named sibling.
std::uint32_t ts:: Node:: end_byte() const
End position as byte offset.
Returns the position after the last character.