node-location: Node byte and point accessors

node-locationR Documentation

Node byte and point accessors

Description

These functions return information about the location of x in the document. The byte, row, and column locations are all 0-indexed.

  • node_start_byte() returns the start byte.

  • node_end_byte() returns the end byte.

  • node_start_point() returns the start point, containing a row and column location within the document. Use accessors like point_row() to extract the row and column positions.

  • node_end_point() returns the end point, containing a row and column location within the document. Use accessors like point_row() to extract the row and column positions.

  • node_range() returns a range object that contains all of the above information. Use accessors like range_start_point() to extract individual pieces from the range.

Usage

node_start_byte(x)

node_end_byte(x)

node_start_point(x)

node_end_point(x)

node_range(x)

Arguments

x

⁠[tree_sitter_node]⁠

A node.

Value

  • node_start_byte() and node_end_byte() return a single numeric value.

  • node_start_point() and node_end_point() return single points.

  • node_range() returns a range.

Examples


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

text <- "fn <- function() { 1 + 1 }"
tree <- parser_parse(parser, text)
node <- tree_root_node(tree)

# Navigate to first child
node <- node_child(node, 1)

# Navigate to function definition node
node <- node_child(node, 3)
node

node_start_byte(node)
node_end_byte(node)

node_start_point(node)
node_end_point(node)

node_range(node)


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