Skip to content

Commit

Permalink
Assemble comment blocks for interim lines
Browse files Browse the repository at this point in the history
  • Loading branch information
slodge committed Nov 14, 2023
1 parent 1e9bc66 commit 7f05924
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions R/plumb-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,46 @@ plumbBlock <- function(lineNum, file, envir = parent.frame()){
props <- NULL
requestBodyObjectName <- NULL

verbose_line_building <- TRUE
line_carryover <- character()

while (lineNum > 0 && (stri_detect_regex(file[lineNum], pattern="^#['\\*]?|^\\s*$") || stri_trim_both(file[lineNum]) == "")){

line <- file[lineNum]
if (verbose_line_building) message("*** line seen: ", line)


# If the line does not start with a plumber tag `#*` or `#'`, continue to next line
if (!stri_detect_regex(line, pattern="^#['\\*]")) {
lineNum <- lineNum - 1
next
}

if (is.na(stringi::stri_match_first(line, regex="^#['\\*]\\s*@\\w+")[1,1])) {
# if the line does not start with "#* @" followed by any alphabetic character
# then it is a continuation of the previous line

# trim the opening "#* " from the line
line <- gsub("^#['\\*]\\s*", "", line)
line <- trimws(line)

if (length(line_carryover) > 0 &&
stringi::stri_length(line) == 0) {
line <- "\n"
if (verbose_line_building) message("*** lineend added to carryover")
} else {
if (verbose_line_building) message("*** carryover added to ", line)
}
line_carryover <- c(line, line_carryover)
lineNum <- lineNum - 1
next
}

line <- c(line, line_carryover)
line_carryover <- character()
line <- paste(line, collapse = " ")
if (verbose_line_building) message("*** line for processing: ", line)

epMat <- stri_match(line, regex="^#['\\*]\\s*@(get|put|post|use|delete|head|options|patch)(\\s+(.*)$)?")
if (!is.na(epMat[1,2])){
p <- stri_trim_both(epMat[1,4])
Expand Down Expand Up @@ -323,6 +353,10 @@ plumbBlock <- function(lineNum, file, envir = parent.frame()){
lineNum <- lineNum - 1
}

# any excess line_carryover now are comments... but reversed... oh my
comments <- rev(line_carryover)
line_carryover <- character()

list(
paths = rev(paths),
preempt = preempt,
Expand Down

0 comments on commit 7f05924

Please sign in to comment.