node-sibling: Node sibling accessors

node-siblingR Documentation

Node sibling accessors

Description

These functions return siblings of the current node, i.e. if you looked "left" or "right" from the current node rather "up" (parent) or "down" (child).

  • node_next_sibling() and node_next_named_sibling() return the next sibling.

  • node_previous_sibling() and node_previous_named_sibling() return the previous sibling.

Usage

node_next_sibling(x)

node_next_named_sibling(x)

node_previous_sibling(x)

node_previous_named_sibling(x)

Arguments

x

⁠[tree_sitter_node]⁠

A node.

Value

A sibling node, or NULL if there is no sibling node.

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)

# Navigate to function definition node
node <- node_child(node, 3)
node

node_previous_sibling(node)

# Skip anonymous operator node
node_previous_named_sibling(node)

# There isn't one!
node_next_sibling(node)


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