% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ts-tree-new.R
\name{ts_tree_new}
\alias{ts_tree_new}
\title{Create tree-sitter tree from file or string}
\usage{
ts_tree_new(
  language,
  file = NULL,
  text = NULL,
  ranges = NULL,
  fail_on_parse_error = TRUE,
  ...
)
}
\arguments{
\item{language}{Language of the file or string, a \code{ts_language} object, e.g. the return
value of \code{tsjsonc::ts_language_jsonc()}.}

\item{file}{Path of a file to parse. Use either \code{file} or \code{text}, but not both.}

\item{text}{String to parse. Use either \code{file} or \code{text}, but not both.}

\item{ranges}{Can be used to parse part(s) of the input. It must be a data frame with
integer columns \code{start_row}, \code{start_col}, \code{end_row}, \code{end_col},
\code{start_byte}, \code{end_byte}, in this order.}

\item{fail_on_parse_error}{Logical, whether to error if there are parse errors in the document.
Default is \code{TRUE}.}

\item{...}{Additional arguments for methods.}
}
\value{
A \code{ts_tree} object representing the parse tree of the input. You can
use the single bracket \code{\link[tsitter:ts_tree-brackets]{[}}
operator to convert it to a data frame.
}
\description{
This is the main function to create a tree-sitter parse tree, using a
ts parser implemented in another package.

The result is a \code{ts_tree} object. A \code{ts_tree} object may be queried,
edited, formatted, written to file, etc. using \code{ts_tree} methods.
}
\details{
A package that implements a tree-sitter parser provides a function that
creates a \code{ts_language} object for that parser. E.g.
tsjsonc has \code{tsjsonc::ts_language_jsonc()}.
You need to use the returned \code{ts_language} object as the \code{language}
argument of \code{\link[tsitter:ts_tree_new]{ts_tree_new()}}.
}
\examples{
\dontshow{if (requireNamespace("tsjsonc", quietly = TRUE)) withAutoprint(\{ # examplesIf}

# JSONC example, needs the tsjsonc package -----------------------------
json <- ts_tree_new(
  tsjsonc::ts_language_jsonc(),
  text = '{ "a": 1, "b": 2 }'
)

json

ts_tree_format(json)
\dontshow{\}) # examplesIf}
\dontshow{if (requireNamespace("tstoml", quietly = TRUE)) withAutoprint(\{ # examplesIf}

# TOML example, needs the tstoml package -------------------------------
toml <- ts_tree_new(
  tstoml::ts_language_toml(),
  text = '[section]\nkey = "value"\nnumber = 42\n'
)

toml

ts_tree_format(toml)
\dontshow{\}) # examplesIf}
}
\seealso{
The tree-sitter parser packages typically include shortcuts to
create parse trees from strings and file, e.g.
\code{tsjsonc::ts_parse_jsonc()} and \code{tsjsonc::ts_read_jsonc()}.

Other ts_tree generics:
\code{\link[=[[.ts_tree]{[[.ts_tree()}},
\code{\link[=[[<-.ts_tree]{[[<-.ts_tree()}},
\code{\link[=format.ts_tree]{format.ts_tree()}},
\code{\link[=print.ts_tree]{print.ts_tree()}},
\code{\link{select-set}},
\code{\link[=ts_tree_ast]{ts_tree_ast()}},
\code{\link[=ts_tree_delete]{ts_tree_delete()}},
\code{\link[=ts_tree_dom]{ts_tree_dom()}},
\code{\link[=ts_tree_format]{ts_tree_format()}},
\code{\link[=ts_tree_insert]{ts_tree_insert()}},
\code{\link[=ts_tree_query]{ts_tree_query()}},
\code{\link[=ts_tree_select]{ts_tree_select()}},
\code{\link[=ts_tree_sexpr]{ts_tree_sexpr()}},
\code{\link[=ts_tree_unserialize]{ts_tree_unserialize()}},
\code{\link[=ts_tree_update]{ts_tree_update()}},
\code{\link[=ts_tree_write]{ts_tree_write()}}
}
\concept{ts_tree generics}
