tree_walk: Generate a 'TreeCursor' iterator

View source: R/tree.R

tree_walkR Documentation

Generate a TreeCursor iterator

Description

tree_walk() creates a TreeCursor starting at the root node. You can use it to "walk" the tree more efficiently than using node_child() and other similar node functions.

Usage

tree_walk(x)

Arguments

x

⁠[tree_sitter_tree]⁠

A tree.

Value

A TreeCursor object.

Examples


language <- treesitter.r::language()
parser <- parser(language)

text <- "1 + foo"
tree <- parser_parse(parser, text)

cursor <- tree_walk(tree)

cursor$goto_first_child()
cursor$goto_first_child()
cursor$node()
cursor$goto_next_sibling()
cursor$node()


treesitter documentation built on June 24, 2024, 5:07 p.m.