Skip to content

Remove outdated line and col information #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2017
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
6 changes: 6 additions & 0 deletions R/initialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ initialize_attributes <- function(pd_flat) {
init_pd <-
initialize_newlines(pd_flat) %>%
initialize_spaces() %>%
remove_line_col() %>%
initialize_multi_line() %>%
initialize_indention_ref_id() %>%
initialize_indent() %>%
Expand Down Expand Up @@ -37,6 +38,11 @@ initialize_spaces <- function(pd_flat) {
pd_flat
}

remove_line_col <- function(pd_flat) {
pd_flat[c("line1", "line2", "col1", "col2")] <- NULL
pd_flat
}

#' @describeIn initialize_attributes Initializes `multi_line`.
initialize_multi_line <- function(pd_flat) {
nrow <- nrow(pd_flat)
Expand Down
6 changes: 3 additions & 3 deletions R/nested.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ combine_children <- function(child, internal_child) {
#' Get the start right
#'
#' On what line does the first token occur?
#' @param pd A parse table.
#' @param pd_nested A nested parse table.
#' @return The line number on which the first token occurs.
start_on_line <- function(pd) {
pd$line1[1]
find_start_line <- function(pd_nested) {
pd_nested$line1[1]
}
6 changes: 3 additions & 3 deletions R/serialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#'
#' Collapses a flattened parse table into character vector representation.
#' @param flattened_pd A flattened parse table.
serialize_parse_data_flattened <- function(flattened_pd) {
flattened_pd$lag_newlines[1] <- flattened_pd$line1[1] - 1

#' @param start_line The line number on which the code starts.
serialize_parse_data_flattened <- function(flattened_pd, start_line = 1) {
flattened_pd$lag_newlines[1] <- start_line - 1
res <- with(flattened_pd,
paste0(collapse = "",
map(lag_newlines, add_newlines), map(lag_spaces, add_spaces), text)
Expand Down
4 changes: 0 additions & 4 deletions R/token-create.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ create_tokens <- function(tokens,
spaces = spaces,
multi_line = rep(FALSE, len_text),
indention_ref_id = indention_ref_ids,
line1 = rep(NA, len_text),
line2 = rep(NA, len_text),
col1 = rep(NA, len_text),
col2 = rep(NA, len_text),
indent = indents,
child = rep(list(NULL), len_text)
)
Expand Down
5 changes: 3 additions & 2 deletions R/transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ make_transformer <- function(transformers) {
#' @inheritParams apply_transformers
parse_transform_serialize <- function(text, transformers) {
pd_nested <- compute_parse_data_nested(text)

start_line <- find_start_line(pd_nested)
if (nrow(pd_nested) == 0) {
warning(
"Text to style did not contain any tokens. Returning empty string.",
Expand All @@ -98,7 +98,8 @@ parse_transform_serialize <- function(text, transformers) {
enrich_terminals(transformers$use_raw_indention) %>%
apply_ref_indention()

serialized_transformed_text <- serialize_parse_data_flattened(flattened_pd)
serialized_transformed_text <-
serialize_parse_data_flattened(flattened_pd, start_line = start_line)
serialized_transformed_text
}

Expand Down
2 changes: 1 addition & 1 deletion R/visit.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ enrich_terminals <- function(flattened_pd, use_raw_indention = FALSE) {
flattened_pd$spaces <- NULL # depreciate spaces
flattened_pd <- choose_indention(flattened_pd, use_raw_indention)
flattened_pd$line1 <-
cumsum(flattened_pd$lag_newlines) + flattened_pd$line1[1]
cumsum(flattened_pd$lag_newlines)

flattened_pd$newlines <- lead(flattened_pd$lag_newlines, default = 0L)
flattened_pd$nchar <- nchar(flattened_pd$text, type = "width")
Expand Down
8 changes: 4 additions & 4 deletions man/start_on_line.Rd → man/find_start_line.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/serialize_parse_data_flattened.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/testthat/test-create_token.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ test_that("can create a token that has relevant columns", {
pd_names <- c(
"token", "text", "short", "lag_newlines", "newlines", "pos_id",
"parent", "token_before", "token_after", "id", "terminal", "internal",
"spaces", "multi_line", "indention_ref_id", "line1", "line2",
"col1", "col2", "indent", "child"
"spaces", "multi_line", "indention_ref_id", "indent", "child"
)

expect_equal(
Expand Down