diff --git a/R/ast.R b/R/ast.R index 190fde7..4eb40dc 100644 --- a/R/ast.R +++ b/R/ast.R @@ -8,19 +8,33 @@ parse_xml <- function(info) { read_xml(xml_text) } -parse_info <- function(file = "", text = NULL, lines = NULL) { +parse_info <- function(file = "", text = NULL, lines = NULL, xml = NULL) { if (!is_null(text)) { lines <- as_lines(text) } list( file = file, - lines = lines + lines = lines, + xml = xml ) } +parse_info_complete <- function(info) { + if (is.null(info$lines)) { + info$lines <- readLines(info$file) + } + + if (is.null(info$xml)) { + info$xml <- parse_xml(info) + } + + info +} + is_info <- function(x) { - is.list(x) && all(c("file", "lines") %in% names(x)) + is.list(x) && all(c("file", "lines", "xml") %in% names(x)) } + check_info <- function(info, arg = caller_arg(info), call = caller_env()) { diff --git a/R/reshape.R b/R/reshape.R index 76ad324..9f0ca12 100644 --- a/R/reshape.R +++ b/R/reshape.R @@ -26,9 +26,8 @@ can_reshape <- function(data) { } reshape_info <- function(line, col, ..., info, to = NULL) { - xml <- parse_xml(info) - - call <- find_function_call(line, col, data = xml) + info <- parse_info_complete(info) + call <- find_function_call(line, col, data = info$xml) if (is_null(call)) { return() }