% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/collapse.R, R/error.R
\name{ts_collapse}
\alias{ts_collapse}
\alias{ts_cnd}
\alias{ts_caller_arg}
\alias{as_ts_caller_arg}
\alias{as.character.ts_caller_arg}
\alias{ts_caller_env}
\alias{ts_check_named_arg}
\alias{ts_parse_error_cnd}
\title{Utility functions for ts language implementations (internal)}
\usage{
ts_collapse(
  s,
  sep = ", ",
  sep2 = sub("^,", "", last),
  last = ", and ",
  trunc = Inf,
  width = Inf,
  ellipsis = "...",
  style = c("both-ends", "head")
)

ts_cnd(..., class = NULL, call = ts_caller_env(), .envir = parent.frame())

ts_caller_arg(arg)

as_ts_caller_arg(x)

\method{as.character}{ts_caller_arg}(x, ...)

ts_caller_env(n = 1)

ts_check_named_arg(arg, frame = -1)

ts_parse_error_cnd(tree, text, call = ts_caller_env())
}
\arguments{
\item{s}{For \code{ts_collapse()} a character vector to collapse.}

\item{sep}{Separator string for most elements.}

\item{sep2}{Separator string for two elements.}

\item{last}{Separator string before the last element.}

\item{trunc}{Integer, maximum number of elements to show before
truncation.}

\item{width}{Integer, maximum display width of the collapsed string.
If the collapsed string exceeds this width, it will be truncated
with \code{ellipsis}.}

\item{ellipsis}{String to indicate truncation.}

\item{style}{Character, the collapsing style to use. Possible values are
\code{"both-ends"} (the default), which shows the first few and last few
elements when truncating, and \code{"head"}, which shows only the first few
elements.}

\item{...}{Arguments collapsed and interpolated into a condition message.}

\item{class}{A character vector of classes for the condition.}

\item{call}{Environment of the call to associate with the error
condition, defaults to the caller's environment.}

\item{.envir}{The environment in which to evaluate the \code{...} expressions,
defaults to the parent frame.}

\item{arg}{Argument to check.}

\item{x}{A ts_caller_arg object.}

\item{n}{Number of frames to go up to find the caller environment.}

\item{frame}{Frame number to inspect, defaults to the caller's frame.}

\item{tree}{A \code{ts_tree} object as returned by \code{\link[=ts_tree_new]{ts_tree_new()}}.}

\item{text}{Raw vector, the original text used to parse the tree.}
}
\value{
\code{ts_collapse()} returns a character scalar, the collapsed string.

\code{ts_cnd()} returns an error condition object.

\code{ts_caller_arg()} returns the captured expression as a
ts_caller_arg object.

\code{as_ts_caller_arg()} returns a ts_caller_arg object.

\code{as.character.ts_caller_arg()} returns a short string
representation of the caller argument, a character scalar.

\code{ts_caller_env()} returns an environment, or \code{NULL} is called
from the global environment.

\code{ts_check_named_arg()} returns \code{TRUE} invisibly if the argument
was named, otherwise it raises an error.

\code{ts_parse_error_cnd()} returns a ts_parse_error condition
}
\description{
These functions are for packages implementing new parsers based on the ts
package. It is very unlikely that you will need to call these functions
directly.
}
\details{
\code{ts_collapse()} collapses a character vector into a single string,
with options for truncation by number of elements or display width.
It is useful for creating informative error messages.

\code{ts_cnd()} creates a condition object. It interpolates its
arguments into a single message.

\code{ts_caller_arg()} captures the expression used as an argument
to a function, for use in error messages.

\code{as_ts_caller_arg()} converts an object into a caller argument
object. This is useful when referring to parts of the caller argument
in downstream error messages.

\code{as.character.ts_caller_arg()} formats a caller argument
object as a short string for use in error messages. Multi-line
expressions are truncated after the first line.

\code{ts_caller_env()} returns the environment of the caller function,
\code{n} levels up the call stack. This is useful for associating error
conditions with the correct call.

\code{ts_check_named_arg()} checks whether an argument was supplied
with a name. If not, it raises an error.

\code{ts_parse_error_cnd()} creates a parse error condition
associated with a \code{ts_tree} object and the original text.
The error message includes information about the location of
parse errors in the text. It also has \code{format()} and \code{print()}
methods to display the error together with the relevant lines
of the original text.
}
\examples{
ts_collapse(letters[1:3])
ts_collapse(letters[1:10], trunc = 5)
}
\keyword{internal}
