node-child {treesitter} | R Documentation |
Get a node's child by index
Description
These functions return the i
th child of x
.
-
node_child()
considers both named and anonymous children. -
node_named_child()
considers only named children.
Usage
node_child(x, i)
node_named_child(x, i)
Arguments
x |
A node. |
i |
The index of the child to return. |
Value
The i
th child node of x
or NULL
if there is no child at that index.
Examples
language <- treesitter.r::language()
parser <- parser(language)
text <- "fn <- function() { 1 + 1 }"
tree <- parser_parse(parser, text)
node <- tree_root_node(tree)
# Starts with `program` node for the whole document
node
# Navigate to first child
node <- node_child(node, 1)
node
# Note how the named variant skips the anonymous operator node
node_child(node, 2)
node_named_child(node, 2)
# OOB indices return `NULL`
node_child(node, 5)
[Package treesitter version 0.1.0 Index]