Skip to contents

Get more precise information on a node

Usage

node_matches(x, ..., files = NULL)

node_inside(x, ..., files = NULL)

node_has(x, ..., files = NULL)

node_precedes(x, ..., files = NULL)

node_follows(x, ..., files = NULL)

Arguments

x

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

...

Any number of rules created with ast_rule().

files

A vector of filenames containing rules. Those must be .yaml files.

Examples

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

some_node <- root |>
  node_find(ast_rule(pattern = "print($A)"))

node_text(some_node)
#> $rule_1
#> [1] "print('hi')"
#> 

some_node |>
  node_get_match("A") |>
  node_matches(ast_rule(kind = "argument"))
#> $rule_1
#> $rule_1[[1]]
#> [1] TRUE
#> 
#>