tree_root_node: Retrieve the root node of the tree

View source: R/tree.R

tree_root_nodeR Documentation

Retrieve the root node of the tree

Description

tree_root_node() is the entry point for accessing nodes within a specific tree. It returns the "root" of the tree, from which you can use other ⁠node_*()⁠ functions to navigate around.

Usage

tree_root_node(x)

Arguments

x

⁠[tree_sitter_tree]⁠

A tree.

Value

A node.

Examples


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

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

# Trees and nodes have a similar print method, but you can
# only use other `node_*()` functions on nodes.
tree
node

node |>
  node_child(1) |>
  node_children()


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