Learn R Programming

treesitter (version 0.3.0)

node-sibling: 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)

Value

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

Arguments

x

[tree_sitter_node]

A node.

Examples

Run this code
if (FALSE) { # rlang::is_installed("treesitter.r")
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)
}

Run the code above in your browser using DataLab