next_terminal: Tell me what the next terminal is

View source: R/utils-navigate-nest.R

next_terminalR Documentation

Tell me what the next terminal is

Description

If the first is a terminal, return it. If not, go inside it and search the next terminal

Usage

next_terminal(
  pd,
  stack = FALSE,
  vars = c("pos_id", "token", "text"),
  tokens_exclude = NULL
)

Arguments

pd

A nest.

stack

Whether or not to also return information on the tokens that are between pd and the first terminal, so the returned data frame can be understood as a transition path from pd to the next terminal, instead of the information at the terminal only. The order is inside-out, i.e. the first non-terminal on top, the terminal last.

vars

The variables to return.

tokens_exclude

A vector with tokens to exclude. This can be helpful if one wants to find the next token that is not a comment for example.

Value

Returns a data frame (which is not a valid parse table for stack = TRUE), with vars and another variable position that denotes the index each element in the transition. This can be helpful in conjunction with purrr::pluck() or purrr::modify_in() to reach the terminal in the nested structure.

Examples

withr::with_options(
  list(styler.cache_name = NULL), # temporarily deactivate cache
  {
    pd <- compute_parse_data_nested("if (TRUE) f()")
    styler:::next_terminal(pd)
  }
)

krlmlr/styler documentation built on April 8, 2024, 7:53 p.m.