% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ts-tree-ast.R
\name{ts_tree_ast}
\alias{ts_tree_ast}
\title{Show the annotated syntax tree of a tree-sitter tree}
\usage{
ts_tree_ast(tree)
}
\arguments{
\item{tree}{A \code{ts_tree} object.}
}
\value{
Character vector, the formatted annotated syntax tree, line by
line. It has class \link[cli:tree]{cli_tree}, from the cli package. It
may contain ANSI escape sequences for coloring and hyperlinks.
}
\description{
\code{ts_tree_ast()} prints the annotated syntax tree of a ts_tree object.
This syntax tree contains all tree-sitter nodes, and it shows the
source code associated with each node, along with line numbers.
}
\details{
\subsection{The syntax tree and the DOM tree}{

This syntax tree contains all nodes of the tree-sitter parse tree,
including both named and unnamed nodes and comments. E.g. for a JSON(C)
document it includes the pairs, brackets, braces, commas, colons,
double quotes and string escape sequences as separate nodes.\if{html}{\out{
</p><p><!-- ------------------------------------------------------>
}}


See \code{\link[tsitter:ts_tree_dom]{tsitter::ts_tree_dom()}} for a tree that
shows the semantic structure of the parsed document, which may be
different from the syntax tree.
}
}
\examples{
\dontshow{if (requireNamespace("tsjsonc", quietly = TRUE)) withAutoprint(\{ # examplesIf}
# Create a parse tree with tsjsonc -------------------------------------
tree <- tsjsonc::ts_parse_jsonc('{"foo": 42, "bar": [1, 2, 3]}')

tree

ts_tree_ast(tree)

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

# Create a parse tree with tstoml --------------------------------------
tree <- tstoml::ts_parse_toml(r"(
  title = "TOML Example"
  [owner]
  name = "Tom Preston-Werner"
  dob = 1979-05-27T07:32:00-08:00
)")

tree

ts_tree_ast(tree)

ts_tree_dom(tree)
\dontshow{\}) # examplesIf}
}
\seealso{
\code{\link[=ts_tree_dom]{ts_tree_dom()}} to show the document object model (DOM) of a
ts_tree object.

Other ts_tree exploration:
\code{\link[=[.ts_tree]{[.ts_tree()}},
\code{\link[=ts_tree_dom]{ts_tree_dom()}},
\code{\link[=ts_tree_query]{ts_tree_query()}},
\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_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_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 exploration}
\concept{ts_tree generics}
