Skip to content

Commit

Permalink
generate expression xml parse data from full xml parse data (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshesITR committed May 23, 2022
1 parent 86f65a4 commit 0fe67b6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions R/get_source_expressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ get_source_expressions <- function(filename, lines = NULL) {
# Don't create expression list if it's unreliable (invalid encoding or unhandled parse error)
expressions <- list()
} else {
xml_parsed_content <- safe_parse_to_xml(parsed_content)

expressions <- lapply(
X = top_level_expressions(parsed_content),
FUN = get_single_source_expression,
Expand All @@ -94,14 +96,24 @@ get_source_expressions <- function(filename, lines = NULL) {
top_level_map
)

if (!is.null(xml_parsed_content) && !is.na(xml_parsed_content)) {
expression_xmls <- lapply(
xml2::xml_find_all(xml_parsed_content, "/exprlist/*"),
function(top_level_expr) xml2::xml_add_parent(xml2::xml_new_root(top_level_expr), "exprlist")
)
for (i in seq_along(expressions)) {
expressions[[i]]$xml_parsed_content <- expression_xmls[[i]]
}
}

# add global expression
expressions[[length(expressions) + 1L]] <-
list(
filename = filename,
file_lines = source_expression$lines,
content = source_expression$lines,
full_parsed_content = parsed_content,
full_xml_parsed_content = safe_parse_to_xml(parsed_content),
full_xml_parsed_content = xml_parsed_content,
terminal_newline = terminal_newline
)
}
Expand Down Expand Up @@ -384,7 +396,7 @@ get_single_source_expression <- function(loc,
column = parsed_content[loc, "col1"],
lines = expr_lines,
parsed_content = pc,
xml_parsed_content = safe_parse_to_xml(pc),
xml_parsed_content = xml2::xml_missing(),
content = content,
find_line = find_line_fun(content),
find_column = find_column_fun(content)
Expand Down

0 comments on commit 0fe67b6

Please sign in to comment.