node-child {treesitter}R Documentation

Get a node's child by index

Description

These functions return the ith child of x.

Usage

node_child(x, i)

node_named_child(x, i)

Arguments

x

⁠[tree_sitter_node]⁠

A node.

i

⁠[integer(1)]⁠

The index of the child to return.

Value

The ith 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]