node-child-count: Get a node's child count

node-child-countR Documentation

Get a node's child count

Description

These functions return the number of children of x.

  • node_child_count() considers both named and anonymous children.

  • node_named_child_count() considers only named children.

Usage

node_child_count(x)

node_named_child_count(x)

Arguments

x

⁠[tree_sitter_node]⁠

A node.

Value

A single integer, the number of children of x.

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

# Note how the named variant doesn't count the anonymous operator node
node_child_count(node)
node_named_child_count(node)


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