Skip to content

Commit e9d65f9

Browse files
some manual tidying.
1 parent cecad69 commit e9d65f9

19 files changed

+78
-86
lines changed

R/indent.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ needs_indention_one <- function(pd, potential_trigger) {
173173
#' Set the multi-line column
174174
#'
175175
#' Sets the column `multi_line` in `pd` by checking row-wise whether any child
176-
#' of a token is a multi-line token.
176+
#' of a token is a multi-line token.
177177
#' @param pd A parse table.
178178
#' @importFrom purrr map_lgl
179179
set_multi_line <- function(pd) {

R/nest.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#' Obtain a nested parse table from a character vector
22
#'
33
#' Parses `text` to a flat parse table and subsequently changes its
4-
#' representation into a nested parse table with
5-
#' [nest_parse_data()].
4+
#' representation into a nested parse table with [nest_parse_data()].
65
#' @param text A character vector to parse.
76
#' @return A nested parse table. See [tokenize()] for details on the columns
87
#' of the parse table.
@@ -24,7 +23,7 @@ compute_parse_data_nested <- function(text) {
2423
#' Enhance the mapping of text to the token "SPECIAL"
2524
#'
2625
#' Map text corresponding to the token "SPECIAL" to a (more) unique token
27-
#' description.
26+
#' description.
2827
#' @param pd A parse table.
2928
enhance_mapping_special <- function(pd) {
3029
pipes <- pd$token == "SPECIAL" & pd$text == "%>%"
@@ -102,11 +101,11 @@ set_spaces <- function(spaces_after_prefix, force_one) {
102101
#' Nest a flat parse table
103102
#'
104103
#' `nest_parse_data` groups `pd_flat` into a parse table with tokens that are
105-
#' a parent to other tokens (called internal) and such that are not (called
106-
#' child). Then, the token in child are joined to their parents in internal
107-
#' and all token information of the children is nested into a column "child".
108-
#' This is done recursively until we are only left with a nested tibble that
109-
#' contains one row: The nested parse table.
104+
#' a parent to other tokens (called internal) and such that are not (called
105+
#' child). Then, the token in child are joined to their parents in internal
106+
#' and all token information of the children is nested into a column "child".
107+
#' This is done recursively until we are only left with a nested tibble that
108+
#' contains one row: The nested parse table.
110109
#' @param pd_flat A flat parse table including both terminals and non-terminals.
111110
#' @seealso [compute_parse_data_nested()]
112111
#' @return A nested parse table.
@@ -136,7 +135,7 @@ nest_parse_data <- function(pd_flat) {
136135
#' Combine child and internal child
137136
#'
138137
#' Binds two parse tables together and arranges them so that the tokens are in
139-
#' the correct order.
138+
#' the correct order.
140139
#' @param child A parse table or `NULL`.
141140
#' @param internal_child A parse table or `NULL`.
142141
#' @details Essentially, this is a wrapper around [dplyr::bind_rows()], but

R/nested_to_tree.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ create_tree <- function(text, structure_only = FALSE) {
1515
#' Convert a nested tibble into a node tree
1616
#'
1717
#' This function is convenient to display all nesting levels of a nested tibble
18-
#' at once.
18+
#' at once.
1919
#' @param pd_nested A nested tibble.
2020
#' @param structure_only Whether or not create a tree that represents the
2121
#' structure of the expression without any information on the tokens. Useful

R/reindent.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#' @name update_indention_ref
66
NULL
77

8-
98
#' @describeIn update_indention_ref Updates the reference pos_id for all
109
#' tokens in `pd_nested` if `pd_nested` contains a function call. Tokens that
1110
#' start on the same line as the opening parenthesis, are not themselves
@@ -111,9 +110,6 @@ apply_ref_indention_one <- function(flattened_pd, target_token) {
111110
flattened_pd
112111
}
113112

114-
115-
116-
117113
#' Set indention of tokens that match regex
118114
#'
119115
#' Force the level of indention of tokens whose text matches a regular

R/relevel.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#' Flatten some token in the nested parse table based on operators
55
#'
66
#' Certain tokens are not placed optimally in the nested parse data with
7-
#' [compute_parse_data_nested()]. For example, the token of arithmetic
8-
#' operations 1 + 1 + 1 should all be on the same level of nesting since
9-
#' the indention is the same for all but the first two terminals. Setting the
10-
#' indention correctly is easier to achieve if they are put on the same level
11-
#' of nesting.
7+
#' [compute_parse_data_nested()]. For example, the token of arithmetic
8+
#' operations 1 + 1 + 1 should all be on the same level of nesting since the
9+
#' indention is the same for all but the first two terminals. Setting the
10+
#' indention correctly is easier to achieve if they are put on the same level of
11+
#' nesting.
1212
#' @param pd_nested A nested parse table to partially flatten.
1313
flatten_operators <- function(pd_nested) {
1414
pd_nested %>%
@@ -17,9 +17,9 @@ flatten_operators <- function(pd_nested) {
1717

1818
#' Flatten one level of nesting with its child
1919
#'
20-
#' Flattening is done in two ways. We can flatten a parse table by moving
21-
#' the left hand token of an operator one level up. Or doing that with the
22-
#' right hand token.
20+
#' Flattening is done in two ways. We can flatten a parse table by moving the
21+
#' left hand token of an operator one level up. Or doing that with the right
22+
#' hand token.
2323
#' @param pd_nested A nested parse table.
2424
#' @include token-define.R
2525
flatten_operators_one <- function(pd_nested) {

R/rules-spacing.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ remove_space_before_comma <- function(pd_flat) {
154154
#' Set space between levels of nesting
155155
#'
156156
#' With the nested approach, certain rules do not have an effect anymore because
157-
#' of the nature of the nested structure. Setting spacing before curly
158-
#' brackets in for / if / while statements and function declarations will be
159-
#' such a case since a curly bracket is always at the first position in a
160-
#' parse table, so spacing cannot be set after the previous token.
157+
#' of the nature of the nested structure. Setting spacing before curly
158+
#' brackets in for / if / while statements and function declarations will be
159+
#' such a case since a curly bracket is always at the first position in a parse
160+
#' table, so spacing cannot be set after the previous token.
161161
#' @param pd_flat A flat parse table.
162162
set_space_between_levels <- function(pd_flat) {
163163
if (pd_flat$token[1] %in% c("FUNCTION", "IF", "WHILE")) {
@@ -173,9 +173,9 @@ set_space_between_levels <- function(pd_flat) {
173173
#' Start comments with a space
174174
#'
175175
#' Forces comments to start with a space, that is, after the regular expression
176-
#' "^#+'*", at least one space must follow if the comment is *non-empty*, i.e
177-
#' there is not just spaces within the comment. Multiple spaces may be legit
178-
#' for indention in some situations.
176+
#' "^#+'*", at least one space must follow if the comment is *non-empty*, i.e
177+
#' there is not just spaces within the comment. Multiple spaces may be legit for
178+
#' indention in some situations.
179179
#' @param pd A parse table.
180180
#' @param force_one Whether or not to force one space or allow multiple spaces
181181
#' after the regex "^#+'*".

R/styler.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#' Non-invasive pretty printing of R code
22
#'
33
#' styler allows you to format .R files, packages or entire R source trees
4-
#' according to a style guide.
5-
#' The following functions can be used for styling:
6-
#' * [style_text()] to style a character vector.
7-
#' * [style_file()] to style a single .R file.
8-
#' * [style_dir()] to style all .R files in a directory.
9-
#' * [style_pkg()] to style the source files of an R package.
10-
#' * [styler_addins] (RStudio Addins) to style either selected code or the
11-
#' active file.
4+
#' according to a style guide.
5+
#' The following functions can be used for styling:
6+
#' * [style_text()] to style a character vector.
7+
#' * [style_file()] to style a single .R file.
8+
#' * [style_dir()] to style all .R files in a directory.
9+
#' * [style_pkg()] to style the source files of an R package.
10+
#' * [styler_addins] (RStudio Addins) to style either selected code or the
11+
#' active file.
1212
#' @examples
1313
#' style_text("call( 1)")
1414
#' style_text("1 + 1", strict = FALSE)

R/token-define.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ lookup_tokens <- function() {
3737
token
3838
}
3939

40-
#' lookup which new tokens were created from "SPECIAL"
40+
#' Lookup which new tokens were created from "SPECIAL"
4141
#'
4242
#' @param regex A regular expression pattern to search for.
4343
#' @importFrom purrr map_chr

R/unindent.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Unindent a child if necessary
22
#'
3-
#' check whether any of the children of `pd` has `token` on the same line as
4-
#' the closing `token` of pd. If so, unindent that token.
3+
#' check whether any of the children of `pd` has `token` on the same line as the
4+
#' closing `token` of pd. If so, unindent that token.
55
#' @inheritParams unindent_child
66
#' @importFrom purrr map
77
#' @importFrom rlang seq2

R/visit.R

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ context_to_terminals <- function(pd_nested,
8282
#' Update the a parse table given outer context
8383
#'
8484
#' `outer_lag_newlines` are added to the first token in `pd`,
85-
#' `outer_indent` is added to all tokens in `pd`, `outer_spaces` is added to
86-
#' the last token in `pd`. [context_to_terminals()] calls this function
87-
#' repeatedly, which means the propagation of the parse information to the
88-
#' terminal tokens.
85+
#' `outer_indent` is added to all tokens in `pd`, `outer_spaces` is added to the
86+
#' last token in `pd`. [context_to_terminals()] calls this function repeatedly,
87+
#' which means the propagation of the parse information to the terminal tokens.
8988
#' @param pd_nested A nested parse table.
9089
#' @param outer_lag_newlines The lag_newlines to be propagated inwards.
9190
#' @param outer_indent The indention depth to be propagated inwards.
@@ -125,16 +124,16 @@ extract_terminals <- function(pd_nested) {
125124
#' possible to compute the exact position a token will have (line and column)
126125
#' when it will be serialized.
127126
#' @details
128-
#' Since we have only terminal tokens now, the line on which a token
129-
#' starts we also be the line on which it ends. We call `line1` the line on
130-
#' which the token starts. `line1` has the same meaning as `line1` that can be
131-
#' found in a flat parse table (see [tokenize()]), just that the `line1`
132-
#' created by `enrich_terminals()` is the updated version of the former
133-
#' `line1`. The same applies for `col1` and `col2`. Note that this function
134-
#' does remove the columns `indent` and `spaces.` All information of the former
135-
#' is stored in `lag_spaces` now. The later was removed because it is redundant
136-
#' after adding the column `lag_spaces`, which is more convenient to work with,
137-
#' in particular when serializing the parse table.
127+
#' Since we have only terminal tokens now, the line on which a token starts we
128+
#' also be the line on which it ends. We call `line1` the line on which the
129+
#' token starts. `line1` has the same meaning as `line1` that can be found in a
130+
#' flat parse table (see [tokenize()]), just that the `line1` created by
131+
#' `enrich_terminals()` is the updated version of the former `line1`. The same
132+
#' applies for `col1` and `col2`. Note that this function does remove the
133+
#' columns `indent` and `spaces.` All information of the former is stored in
134+
#' `lag_spaces` now. The later was removed because it is redundant after adding
135+
#' the column `lag_spaces`, which is more convenient to work with, in particular
136+
#' when serializing the parse table.
138137
#' @inheritParams choose_indention
139138
enrich_terminals <- function(flattened_pd, use_raw_indention = FALSE) {
140139
flattened_pd$lag_spaces <- lag(flattened_pd$spaces, default = 0L)

0 commit comments

Comments
 (0)