Skip to content

Commit

Permalink
Add text_parse() utility
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Jun 19, 2024
1 parent 41a76e6 commit 35b6adc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export(range_end_byte)
export(range_end_point)
export(range_start_byte)
export(range_start_point)
export(text_parse)
export(tree_included_ranges)
export(tree_language)
export(tree_root_node)
Expand Down
24 changes: 24 additions & 0 deletions R/parse.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#' Parse a snippet of text
#'
#' @description
#' `text_parse()` is a convenience utility for quickly parsing a small snippet
#' of text using a particular language and getting access to its root node. It
#' is meant for demonstration purposes. If you are going to need to reparse the
#' text after an edit has been made, you should create a full parser with
#' [parser()] and use [parser_parse()] instead.
#'
#' @param x `[string]`
#'
#' The text to parse.
#'
#' @param language `[tree_sitter_language]`
#'
#' The language to parse with.
#'
#' @export
#' @examplesIf rlang::is_installed("treesitter.r")
#' language <- treesitter.r::language()
#' text <- "map(xs, function(x) 1 + 1)"
#'
#' # Note that this directly returns the root node, not the tree
#' text_parse(text, language)
text_parse <- function(x, language) {
check_string(x)
check_language(language)
Expand Down
33 changes: 33 additions & 0 deletions man/text_parse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35b6adc

Please sign in to comment.