node_get_root: Recover the tree root from a node

View source: R/node.R

node_get_rootR Documentation

Recover the tree root from a node

Description

Recover the tree root from a node

Usage

node_get_root(x)

Arguments

x

A node, either from tree_root() or from another ⁠node_*()⁠ function.

Value

A list of two elements: start and end. Each of those is a vector with two values indicating the row and column. Those are 0-indexed.

Examples

src <- "
print('hi')
fn <- function() {
  print('hello')
}
"
root <- src |>
  tree_new() |>
  tree_root()

root |>
  node_find(ast_rule(pattern = "print($A)")) |>
  node_get_root() |>
  tree_root() |>
  node_text()

astgrepr documentation built on June 8, 2025, 11:05 a.m.