node_parent {treesitter} | R 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 |
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)
[Package treesitter version 0.1.0 Index]