Skip to contents

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.

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()
#> [[1]]
#> [1] "print('hi')\nfn <- function() {\n  print('hello')\n}\n"
#>