Skip to content

Commit 95f2af2

Browse files
Merge pull request #188 from lorenzwalthert/fix_parsing
- Fix parsing inconsistency (#188).
2 parents 1678023 + 17d25ea commit 95f2af2

File tree

7 files changed

+248
-0
lines changed

7 files changed

+248
-0
lines changed

R/nested.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ compute_parse_data_nested <- function(text) {
2626
#' @param text A character vector.
2727
#' @return A flat parse table
2828
tokenize <- function(text) {
29+
# avoid https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16041
30+
parse(text = text, keep.source = TRUE)
2931
parsed <- parse(text = text, keep.source = TRUE)
3032
parse_data <- as_tibble(utils::getParseData(parsed, includeText = NA)) %>%
3133
enhance_mapping_special()

R/utils.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,17 @@ add_newlines <- function(n) {
2525
add_spaces <- function(n) {
2626
rep_char(" ", n)
2727
}
28+
29+
#' Invoke a system command
30+
#'
31+
#' Wraps a system command into [shell()] or [system()], depending on the
32+
#' os.
33+
#' @param sys_call The call to be executed.
34+
#' @param ... Arguments passed to [shell()] or [system()].
35+
calls_sys <- function(sys_call, ...) {
36+
if (Sys.info()[1] == "Windows") {
37+
error <- shell(sys_call, ...)
38+
} else {
39+
error <- system(sys_call, ...)
40+
}
41+
}

man/calls_sys.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
#
3+
#
4+
r <- function(y, s, g = 10) {
5+
b("", "")
6+
7+
#
8+
q <- g(d(i), function(i) {
9+
d(op(t[[p]]), n(i = i))
10+
})
11+
f(calls) <- f(g)
12+
13+
mb <- j(c(
14+
q(a::b), r,
15+
y(u = 1)
16+
))
17+
k(b)
18+
}
19+
20+
#
21+
#

tests/testthat/parsing/repeated_parsing-in_tree

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
#
3+
#
4+
r <- function(y, s, g = 10) {
5+
b("", "")
6+
7+
#
8+
q <- g(d(i), function(i) {
9+
d(op(t[[p]]), n(i = i))
10+
})
11+
f(calls) <- f(g)
12+
13+
mb <- j(c(
14+
q(a::b), r,
15+
y(u = 1)
16+
))
17+
k(b)
18+
}
19+
20+
#
21+
#

tests/testthat/test-parsing.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
context("circumvent parsing bugs")
2+
3+
test_that("repreated parsing solves wrong parent assignment", {
4+
expect_warning(test_collection(
5+
"parsing", "repeated_parsing",
6+
transformer = style_text,
7+
strict = FALSE),
8+
NA)
9+
10+
# move to temp dir
11+
dir <- tempfile("styler")
12+
dir.create(dir)
13+
path_temp <- file.path(dir, "repeated_parsing-in.R")
14+
path_perm <- testthat_file("parsing", "repeated_parsing-in.R")
15+
file.copy(path_perm, dir)
16+
17+
sys_call <- paste0(
18+
"R -q -e \"styler::style_file(\\\"", path_temp, "\\\")\""
19+
)
20+
calls_sys(sys_call, intern = FALSE, ignore.stdout = TRUE, ignore.stderr = TRUE)
21+
ref <- utf8::read_lines_enc(construct_out(path_perm))
22+
result <- utf8::read_lines_enc(path_temp)
23+
expect_equal(ref, result)
24+
unlink(dir)
25+
})

0 commit comments

Comments
 (0)