node-child | R Documentation |
These functions return the i
th child of x
.
node_child()
considers both named and anonymous children.
node_named_child()
considers only named children.
node_child(x, i)
node_named_child(x, i)
x |
A node. |
i |
The index of the child to return. |
The i
th child node of x
or NULL
if there is no child at that index.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.