Skip to content

Commit 2f71190

Browse files
Merge branch 'main' into split-roxygen
2 parents a6518fc + 0c4187c commit 2f71190

18 files changed

+962
-656
lines changed

R/addins.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ set_style_transformers <- function() {
157157
current_style
158158
)
159159
if (!is.null(new_style)) {
160-
parsed_new_style <- rlang::with_handlers(
160+
parsed_new_style <- rlang::try_fetch(
161161
{
162162
transformers <- eval(parse(text = new_style))
163163
style_text(
@@ -208,7 +208,7 @@ communicate_addins_style_transformers <- function() {
208208
#' [make_transformer()].
209209
#' @keywords internal
210210
try_transform_as_r_file <- function(context, transformer) {
211-
rlang::with_handlers(
211+
rlang::try_fetch(
212212
transformer(context$contents),
213213
error = function(e) {
214214
preamble_for_unsaved <- paste(

R/io.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ transform_utf8 <- function(path, fun, dry) {
2020
#' @keywords internal
2121
transform_utf8_one <- function(path, fun, dry) {
2222
rlang::arg_match(dry, c("on", "off", "fail"))
23-
rlang::with_handlers(
23+
rlang::try_fetch(
2424
{
2525
file_with_info <- read_utf8(path)
2626
# only write back when changed OR when there was a missing newline
@@ -70,7 +70,7 @@ transform_utf8_one <- function(path, fun, dry) {
7070
#' @param path A path to a file to read.
7171
#' @keywords internal
7272
read_utf8 <- function(path) {
73-
out <- rlang::with_handlers(
73+
out <- rlang::try_fetch(
7474
read_utf8_bare(path),
7575
warning = function(w) w,
7676
error = function(e) e

R/nest.R

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -330,33 +330,35 @@ set_spaces <- function(spaces_after_prefix, force_one) {
330330
#' @return A nested parse table.
331331
#' @keywords internal
332332
nest_parse_data <- function(pd_flat) {
333-
if (all(pd_flat$parent <= 0L)) {
334-
return(pd_flat)
333+
repeat {
334+
if (all(pd_flat$parent <= 0L)) {
335+
return(pd_flat)
336+
}
337+
pd_flat$internal <- with(pd_flat, (id %in% parent) | (parent <= 0L))
338+
split_data <- split(pd_flat, pd_flat$internal)
339+
340+
child <- split_data$`FALSE`
341+
internal <- split_data$`TRUE`
342+
343+
internal$internal_child <- internal$child
344+
internal$child <- NULL
345+
346+
child$parent_ <- child$parent
347+
348+
rhs <- nest_(child, "child", setdiff(names(child), "parent_"))
349+
350+
nested <- left_join(internal, rhs, by = c("id" = "parent_"))
351+
352+
children <- nested$child
353+
for (i in seq_along(children)) {
354+
new <- combine_children(children[[i]], nested$internal_child[[i]])
355+
# Work around is.null(new)
356+
children[i] <- list(new)
357+
}
358+
nested$child <- children
359+
nested$internal_child <- NULL
360+
pd_flat <- nested
335361
}
336-
pd_flat$internal <- with(pd_flat, (id %in% parent) | (parent <= 0L))
337-
split_data <- split(pd_flat, pd_flat$internal)
338-
339-
child <- split_data$`FALSE`
340-
internal <- split_data$`TRUE`
341-
342-
internal$internal_child <- internal$child
343-
internal$child <- NULL
344-
345-
child$parent_ <- child$parent
346-
347-
rhs <- nest_(child, "child", setdiff(names(child), "parent_"))
348-
349-
nested <- left_join(internal, rhs, by = c("id" = "parent_"))
350-
351-
children <- nested$child
352-
for (i in seq_along(children)) {
353-
new <- combine_children(children[[i]], nested$internal_child[[i]])
354-
# Work around is.null(new)
355-
children[i] <- list(new)
356-
}
357-
nested$child <- children
358-
nested$internal_child <- NULL
359-
nest_parse_data(nested)
360362
}
361363

362364
#' Combine child and internal child

R/parse.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#'
1616
#' styler:::parse_safely("a + 3 -4 -> \n glück + 1")
1717
parse_safely <- function(text, ...) {
18-
tried_parsing <- rlang::with_handlers(
18+
tried_parsing <- rlang::try_fetch(
1919
parse(text = text, ...),
2020
error = function(e) e,
2121
warning = function(w) w

R/roxygen-examples-parse.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ parse_roxygen <- function(roxygen) {
6666
#' )
6767
#' @keywords internal
6868
roxygen_remove_extra_brace <- function(parsed) {
69-
parsed <- rlang::with_handlers(
69+
parsed <- rlang::try_fetch(
7070
{
7171
parse(text = paste0(gsub("^\\\\[[:alpha:]]*", "", parsed), collapse = ""))
7272
parsed
@@ -92,7 +92,7 @@ roxygen_remove_extra_brace <- function(parsed) {
9292
parsed <- parsed[-last(linebreak)]
9393
}
9494
# try if can be parsed (need remve dontrun)
95-
worth_trying_to_remove_brace <- rlang::with_handlers(
95+
worth_trying_to_remove_brace <- rlang::try_fetch(
9696
{
9797
# this will error informatively
9898
parse(text = gsub("^\\\\[[:alpha:]]+", "", parsed))
@@ -143,10 +143,12 @@ emulate_rd <- function(roxygen) {
143143
)
144144
roxygen <- gsub("(^#)[^']", "#' #", roxygen)
145145

146-
text <- roxygen2::roc_proc_text(
146+
processed <- roxygen2::roc_proc_text(
147147
roxygen2::rd_roclet(),
148148
paste(roxygen, collapse = "\n")
149-
)[[1L]]$get_section("examples")
149+
)
150+
151+
text <- processed[[1L]]$get_section("examples")
150152
text <- as.character(text)[-1L]
151153
text <- c(
152154
if (grepl("^#'(\\s|\t)*@examples(\\s|\t)*$", roxygen[2L])) "",

R/roxygen-examples.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ style_roxygen_code_example_one <- function(example_one,
3535
) %>%
3636
flatten_chr()
3737
if (bare$example_type == "examplesIf") {
38-
rlang::with_handlers(
38+
rlang::try_fetch(
3939
parse_text(unmasked[1L]),
4040
error = function(e) {
4141
abort(paste0(

R/transform-files.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ parse_tree_must_be_identical <- function(transformers) {
413413
#' @keywords internal
414414
verify_roundtrip <- function(old_text, new_text, parsable_only = FALSE) {
415415
if (parsable_only) {
416-
rlang::with_handlers(
416+
rlang::try_fetch(
417417
parse_safely(new_text),
418418
error = function(e) {
419419
rlang::abort(paste0(

tests/testthat/curly-curly/mixed-in_tree

Lines changed: 73 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/indention_operators/eq_formals_complex_indention-in_tree

Lines changed: 95 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)