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)
# Starts with `program` node for the whole document
node
# Navigate to first child
node <- node_child(node, 1)
node
# Note how the named variant skips the anonymous operator node
node_child(node, 2)
node_named_child(node, 2)
# OOB indices return `NULL`
node_child(node, 5)
}
Run the code above in your browser using DataLab