Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tinyrox
Title: Minimal R Documentation Generator
Version: 0.3.3
Version: 0.3.3.1
Authors@R:
person("Troy", "Hernandez", email = "troy@cornball.ai", role = c("aut", "cre"),
comment = c(ORCID = "0009-0005-4248-604X"))
Expand Down
30 changes: 27 additions & 3 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,33 @@ parse_file <- function(file) {
next
}

# For multi-line function definitions, collect lines until we have complete signature
# Look ahead up to 20 lines to capture full function signature
definition_lines <- lines[next_line:min(next_line + 20, length(lines))]
# Collect the definition. For a multi-line function signature, read until
# its parentheses balance rather than a fixed window (a fixed window
# truncates long signatures and breaks formals parsing); a definition
# with no opening paren is a one-liner and stops after its first line.
end_line <- next_line
depth <- 0L
seen_paren <- FALSE
repeat {
chars <- strsplit(lines[end_line], "")[[1]]
for (ch in chars) {
if (ch == "(") {
depth <- depth + 1L
seen_paren <- TRUE
} else if (ch == ")") {
depth <- depth - 1L
}
}
if (!seen_paren || (depth <= 0L)) {
break
}
if (end_line >= length(lines) ||
end_line - next_line >= 1000L) {
break
}
end_line <- end_line + 1L
}
definition_lines <- lines[next_line:end_line]
definition_text <- paste(definition_lines, collapse = "\n")

# Parse the object definition
Expand Down
15 changes: 15 additions & 0 deletions inst/tinytest/test_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,18 @@ result <- tinyrox:::parse_formals_text("")
expect_equal(result$names, character())

expect_equal(tinyrox:::parse_formals_text("...")$names, "...")

# Regression: a multi-line signature longer than the old fixed 20-line lookahead
# must be captured in full (formals were silently truncated before).
long_args <- paste0("a", 1:30, " = NULL", collapse = ",\n ")
big_src <- c("#' Big", "#' @export",
paste0("big_fn <- function(\n ", long_args, ") {"),
" NULL", "}")
tmp <- tempfile(fileext = ".R")
writeLines(big_src, tmp)
big <- Filter(function(o) identical(o$object, "big_fn"),
tinyrox:::parse_file(tmp))[[1]]
expect_equal(length(big$formals$names), 30L)
expect_equal(big$formals$names[30], "a30")
expect_true(all(grepl("= NULL$", big$formals$usage)))
unlink(tmp)