Learn R Programming

treesitter (version 0.3.0)

node_text: Get a node's underlying text

Description

node_text() returns the document text underlying a node.

Usage

node_text(x)

Value

A single string containing the node's text.

Arguments

x

[tree_sitter_node]

A node.

Examples

Run this code
if (FALSE) { # rlang::is_installed("treesitter.r")
language <- treesitter.r::language()
parser <- parser(language)

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

node |>
  node_child(1) |>
  node_child_by_field_name("rhs") |>
  node_text()
}

Run the code above in your browser using DataLab