% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ts-tree-query.R
\name{ts_tree_query}
\alias{ts_tree_query}
\title{Run tree-sitter queries on tree-sitter trees}
\usage{
ts_tree_query(tree, query)
}
\arguments{
\item{tree}{A \code{ts_tree} object.}

\item{query}{Character string, the tree-sitter query to run.}
}
\value{
A list with entries \code{patterns} and \code{matched_captures}.\if{html}{\out{
</p><p><!-- ------------------------------------------------------>
}}


\code{patterns} contains information about all patterns in the queries and
it is a data frame with columns: \code{id}, \code{name}, \code{pattern}, \code{match_count}.\if{html}{\out{
</p><p><!-- ------------------------------------------------------>
}}


\code{matched_captures} contains information about all matches, and it has
columns \code{id}, \code{pattern}, \code{match}, \code{start_byte}, \code{end_byte}, \code{start_row},
\code{start_column}, \code{end_row}, \code{end_column}, \code{name}, \code{code}.\if{html}{\out{
</p><p><!-- ------------------------------------------------------>
}}


The \code{pattern} column of \code{matched_captured} refers to the \code{id} column of
\code{patterns}.
}
\description{
Use \href{https://tree-sitter.github.io/tree-sitter/}{
tree-sitter's query language} to find nodes in a tree-sitter tree.
}
\details{
You probably need to know some details about the specific tree-sitter
parser you are using, to write effective queries. See the documentation
of the parser package you are using for details about the node types
and the query language support. See links below.
}
\examples{
\dontshow{if (requireNamespace("tsjsonc", quietly = TRUE)) withAutoprint(\{ # examplesIf}
# Select all numbers in a JSONC document ------------------------------------
json <- tsjsonc::ts_parse_jsonc(
  '{ "a": 1, "b": [10, 20, 30], "c": { "c1": true, "c2": 100 } }'
)
ts_tree_query(json, "(number) @number")
\dontshow{\}) # examplesIf}
}
\seealso{
\code{\link[=ts_tree_select]{ts_tree_select()}} to select the nodes matching a query.

Other ts_tree exploration:
\code{\link[=[.ts_tree]{[.ts_tree()}},
\code{\link[=ts_tree_ast]{ts_tree_ast()}},
\code{\link[=ts_tree_dom]{ts_tree_dom()}},
\code{\link[=ts_tree_sexpr]{ts_tree_sexpr()}}

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_new]{ts_tree_new()}},
\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 exploration}
\concept{ts_tree generics}
