parser-parse {treesitter}R Documentation

Parse or reparse text

Description

All bytes and points should be 0-indexed.

Usage

parser_parse(x, text, ..., encoding = "UTF-8")

parser_reparse(
  x,
  text,
  tree,
  start_byte,
  start_point,
  old_end_byte,
  old_end_point,
  new_end_byte,
  new_end_point,
  ...,
  encoding = "UTF-8"
)

Arguments

x

⁠[tree_sitter_parser]⁠

A parser.

text

⁠[string]⁠

The text to parse.

...

These dots are for future extensions and must be empty.

encoding

⁠[string]⁠

The expected encoding of the text. Either "UTF-8" or "UTF-16".

tree

⁠[tree_sitter_tree]⁠

The original tree returned by parser_parse(). Components of the tree will be reused to perform the incremental reparse.

start_byte, start_point

⁠[double(1) / tree_sitter_point]⁠

The starting byte and starting point of the edit location.

old_end_byte, old_end_point

⁠[double(1) / tree_sitter_point]⁠

The old ending byte and old ending point of the edit location.

new_end_byte, new_end_point

⁠[double(1) / tree_sitter_point]⁠

The new ending byte and new ending point of the edit location.

Value

A new tree.

Examples


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

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

text <- "1 + bar(foo)"
parser_reparse(
  parser,
  text,
  tree,
  start_byte = 4,
  start_point = point(0, 4),
  old_end_byte = 7,
  old_end_point = point(0, 7),
  new_end_byte = 12,
  new_end_point = point(0, 12)
)


[Package treesitter version 0.1.0 Index]