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)
node <- node_child(node, 1)
fn <- node_child(node, 1)
operator <- node_child(node, 2)
fn
node_is_named(fn)
operator
node_is_named(operator)
# Examples of `TRUE` cases for these are a bit hard to come up with, because
# they are dependent on the exact state of the grammar and the error recovery
# algorithm
node_is_missing(node)
node_is_extra(node)
}
Run the code above in your browser using DataLab