node_parent: Get a node's parent

View source: R/node.R

node_parentR Documentation

Get a node's parent

Description

node_parent() looks up the tree and returns the current node's parent.

Usage

node_parent(x)

Arguments

x

⁠[tree_sitter_node]⁠

A node.

Value

The parent node of x or NULL if there is no parent.

Examples


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

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

# Parent of a root node is `NULL`
node_parent(node)

node_function <- node |>
  node_child(1) |>
  node_child(3)

node_function

node_parent(node_function)


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