Learn R Programming

treesitter (version 0.3.0)

tree_root_node: 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)

Value

A node.

Arguments

x

[tree_sitter_tree]

A tree.

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)

# 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()
}

Run the code above in your browser using DataLab