node_field_name_for_child: Get a child's field name by index

View source: R/node.R

node_field_name_for_childR Documentation

Get a child's field name by index

Description

node_field_name_for_child() returns the field name for the ith child, considering both named and anonymous nodes.

Nodes themselves don't know their own field names, because they don't know if they are fields or not. You must have access to their parents to query their field names.

Usage

node_field_name_for_child(x, i)

Arguments

x

⁠[tree_sitter_node]⁠

A node.

i

⁠[integer(1)]⁠

The index of the child to get the field name for.

Value

The field name for the ith child of x, or NA_character_ if that child doesn't exist.

Examples


language <- treesitter.r::language()
parser <- parser(language)

text <- "fn <- function() { 1 + 1 }"
tree <- parser_parse(parser, text)
node <- tree_root_node(tree)

# Navigate to first child
node <- node_child(node, 1)
node

# Get the field name of the first few children (note that anonymous children
# are considered)
node_field_name_for_child(node, 1)
node_field_name_for_child(node, 2)

# 10th child doesn't exist, this returns `NA_character_`
node_field_name_for_child(node, 10)


treesitter documentation built on June 24, 2024, 5:07 p.m.