Skip to content

Commit

Permalink
Reorganise source
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Jul 15, 2024
1 parent 0c9910e commit 2e066cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
32 changes: 0 additions & 32 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,3 @@ odin_parse <- function(expr, input_type = NULL) {
exprs <- lapply(dat$exprs, function(x) parse_expr(x$value, x, call = call))
NULL
}


odin_parse_error <- function(msg, src, call, ...,
.envir = parent.frame()) {
if (!is.null(names(src))) {
src <- list(src)
}
cli::cli_abort(msg,
class = "odin_parse_error",
src = src,
call = call,
...,
.envir = .envir)
}


##' @importFrom rlang cnd_footer
##' @export
cnd_footer.odin_parse_error <- function(cnd, ...) {
## TODO: later, we might want to point at specific bits of the error
## and say "here, this is where you are wrong" but that's not done
## yet...
src <- cnd$src
if (is.null(src[[1]]$str)) {
context <- unlist(lapply(cnd$src, function(x) deparse1(x$value)))
} else {
line <- unlist(lapply(src, function(x) seq(x$start, x$end)))
src <- unlist(lapply(src, "[[", "str"))
context <- sprintf("%s| %s", gsub(" ", "\u00a0", format(line)), src)
}
c(">" = "Context:", context)
}
30 changes: 30 additions & 0 deletions R/parse_error.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
odin_parse_error <- function(msg, src, call, ...,
.envir = parent.frame()) {
if (!is.null(names(src))) {
src <- list(src)
}
cli::cli_abort(msg,
class = "odin_parse_error",
src = src,
call = call,
...,
.envir = .envir)
}


##' @importFrom rlang cnd_footer
##' @export
cnd_footer.odin_parse_error <- function(cnd, ...) {
## TODO: later, we might want to point at specific bits of the error
## and say "here, this is where you are wrong" but that's not done
## yet...
src <- cnd$src
if (is.null(src[[1]]$str)) {
context <- unlist(lapply(cnd$src, function(x) deparse1(x$value)))
} else {
line <- unlist(lapply(src, function(x) seq(x$start, x$end)))
src <- unlist(lapply(src, "[[", "str"))
context <- sprintf("%s| %s", gsub(" ", "\u00a0", format(line)), src)
}
c(">" = "Context:", context)
}

0 comments on commit 2e066cb

Please sign in to comment.